Skip to content

Commit

Permalink
Actually set IMAGE_SCN_LNK_REMOVE for .rmeta
Browse files Browse the repository at this point in the history
The code intended to set the IMAGE_SCN_LNK_REMOVE flag for the
.rmeta section, however the value of this flag was set to zero.
Instead use the actual value provided by the object crate.

This dates back to the original introduction of this code in
PR rust-lang#84449, so we were never setting this flag. As I'm not on
Windows, I'm not sure whether that means we were embedding .rmeta
into executables, or whether the section ended up getting stripped
for some other reason.
  • Loading branch information
nikic committed Dec 19, 2021
1 parent 41c3017 commit 6eb5072
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions compiler/rustc_codegen_ssa/src/back/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::path::Path;

use object::write::{self, StandardSegment, Symbol, SymbolSection};
use object::{
elf, Architecture, BinaryFormat, Endianness, FileFlags, Object, ObjectSection, SectionFlags,
SectionKind, SymbolFlags, SymbolKind, SymbolScope,
elf, pe, Architecture, BinaryFormat, Endianness, FileFlags, Object, ObjectSection,
SectionFlags, SectionKind, SymbolFlags, SymbolKind, SymbolScope,
};

use snap::write::FrameEncoder;
Expand Down Expand Up @@ -216,13 +216,12 @@ pub fn create_rmeta_file(sess: &Session, metadata: &[u8]) -> Vec<u8> {
);
match file.format() {
BinaryFormat::Coff => {
const IMAGE_SCN_LNK_REMOVE: u32 = 0;
file.section_mut(section).flags =
SectionFlags::Coff { characteristics: IMAGE_SCN_LNK_REMOVE };
SectionFlags::Coff { characteristics: pe::IMAGE_SCN_LNK_REMOVE };
}
BinaryFormat::Elf => {
const SHF_EXCLUDE: u64 = 0x80000000;
file.section_mut(section).flags = SectionFlags::Elf { sh_flags: SHF_EXCLUDE };
file.section_mut(section).flags =
SectionFlags::Elf { sh_flags: elf::SHF_EXCLUDE as u64 };
}
_ => {}
};
Expand Down

0 comments on commit 6eb5072

Please sign in to comment.