Skip to content

Commit

Permalink
Rollup merge of #92029 - nikic:section-flags-fix, r=davidtwco
Browse files Browse the repository at this point in the history
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.

I checked with `objdump -h` that this produces the right flags for ELF.

Fixes #92013.
  • Loading branch information
matthiaskrgr committed Dec 19, 2021
2 parents fba0d04 + 79d5309 commit 9415c67
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,15 @@ pub fn create_compressed_metadata_file(
let section = file.add_section(
file.segment_name(StandardSegment::Data).to_vec(),
b".rustc".to_vec(),
SectionKind::Data,
SectionKind::ReadOnlyData,
);
match file.format() {
BinaryFormat::Elf => {
// Explicitly set no flags to avoid SHF_ALLOC default for data section.
file.section_mut(section).flags = SectionFlags::Elf { sh_flags: 0 };
}
_ => {}
};
let offset = file.append_section_data(section, &compressed, 1);

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

0 comments on commit 9415c67

Please sign in to comment.