Skip to content

Commit 1bb1444

Browse files
committed
Get rid of the .note interpretation of rustc dylib metadata.
1 parent 02aec40 commit 1bb1444

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

src/librustc_metadata/loader.rs

+18-23
Original file line numberDiff line numberDiff line change
@@ -867,34 +867,29 @@ fn get_metadata_section_imp(target: &Target, flavor: CrateFlavor, filename: &Pat
867867
}
868868

869869
pub fn meta_section_name(target: &Target) -> &'static str {
870+
// Historical note:
871+
//
872+
// When using link.exe it was seen that the section name `.note.rustc`
873+
// was getting shortened to `.note.ru`, and according to the PE and COFF
874+
// specification:
875+
//
876+
// > Executable images do not use a string table and do not support
877+
// > section names longer than 8 characters
878+
//
879+
// https://msdn.microsoft.com/en-us/library/windows/hardware/gg463119.aspx
880+
//
881+
// As a result, we choose a slightly shorter name! As to why
882+
// `.note.rustc` works on MinGW, that's another good question...
883+
870884
if target.options.is_like_osx {
871-
"__DATA,__note.rustc"
872-
} else if target.options.is_like_msvc {
873-
// When using link.exe it was seen that the section name `.note.rustc`
874-
// was getting shortened to `.note.ru`, and according to the PE and COFF
875-
// specification:
876-
//
877-
// > Executable images do not use a string table and do not support
878-
// > section names longer than 8 characters
879-
//
880-
// https://msdn.microsoft.com/en-us/library/windows/hardware/gg463119.aspx
881-
//
882-
// As a result, we choose a slightly shorter name! As to why
883-
// `.note.rustc` works on MinGW, that's another good question...
884-
".rustc"
885+
"__DATA,.rustc"
885886
} else {
886-
".note.rustc"
887+
".rustc"
887888
}
888889
}
889890

890-
pub fn read_meta_section_name(target: &Target) -> &'static str {
891-
if target.options.is_like_osx {
892-
"__note.rustc"
893-
} else if target.options.is_like_msvc {
894-
".rustc"
895-
} else {
896-
".note.rustc"
897-
}
891+
pub fn read_meta_section_name(_target: &Target) -> &'static str {
892+
".rustc"
898893
}
899894

900895
// A diagnostic function for dumping crate metadata to an output stream

src/librustc_trans/base.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -2250,10 +2250,17 @@ fn write_metadata(cx: &SharedCrateContext,
22502250
};
22512251
unsafe {
22522252
llvm::LLVMSetInitializer(llglobal, llconst);
2253-
let name =
2253+
let section_name =
22542254
cx.tcx().sess.cstore.metadata_section_name(&cx.sess().target.target);
2255-
let name = CString::new(name).unwrap();
2256-
llvm::LLVMSetSection(llglobal, name.as_ptr())
2255+
let name = CString::new(section_name).unwrap();
2256+
llvm::LLVMSetSection(llglobal, name.as_ptr());
2257+
2258+
// Also generate a .section directive to force no
2259+
// flags, at least for ELF outputs, so that the
2260+
// metadata doesn't get loaded into memory.
2261+
let directive = format!(".section {}", section_name);
2262+
let directive = CString::new(directive).unwrap();
2263+
llvm::LLVMSetModuleInlineAsm(cx.metadata_llmod(), directive.as_ptr())
22572264
}
22582265
return metadata;
22592266
}

0 commit comments

Comments
 (0)