Skip to content

Commit 79d5309

Browse files
committed
Explicitly set no ELF flags for .rustc section
For a data section, the object crate will set the SHF_ALLOC by default, which is exactly what we don't want. Explicitly set sh_flags to zero to avoid this.
1 parent 16d8a91 commit 79d5309

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: compiler/rustc_codegen_ssa/src/back/metadata.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,15 @@ pub fn create_compressed_metadata_file(
259259
let section = file.add_section(
260260
file.segment_name(StandardSegment::Data).to_vec(),
261261
b".rustc".to_vec(),
262-
SectionKind::Data,
262+
SectionKind::ReadOnlyData,
263263
);
264+
match file.format() {
265+
BinaryFormat::Elf => {
266+
// Explicitly set no flags to avoid SHF_ALLOC default for data section.
267+
file.section_mut(section).flags = SectionFlags::Elf { sh_flags: 0 };
268+
}
269+
_ => {}
270+
};
264271
let offset = file.append_section_data(section, &compressed, 1);
265272

266273
// For MachO and probably PE this is necessary to prevent the linker from throwing away the

0 commit comments

Comments
 (0)