about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_metadata/loader.rs41
-rw-r--r--src/librustc_trans/base.rs13
2 files changed, 28 insertions, 26 deletions
diff --git a/src/librustc_metadata/loader.rs b/src/librustc_metadata/loader.rs
index 48c8bcff1ec..cf1dd71a0a1 100644
--- a/src/librustc_metadata/loader.rs
+++ b/src/librustc_metadata/loader.rs
@@ -867,34 +867,29 @@ fn get_metadata_section_imp(target: &Target, flavor: CrateFlavor, filename: &Pat
 }
 
 pub fn meta_section_name(target: &Target) -> &'static str {
+    // Historical note:
+    //
+    // When using link.exe it was seen that the section name `.note.rustc`
+    // was getting shortened to `.note.ru`, and according to the PE and COFF
+    // specification:
+    //
+    // > Executable images do not use a string table and do not support
+    // > section names longer than 8 characters
+    //
+    // https://msdn.microsoft.com/en-us/library/windows/hardware/gg463119.aspx
+    //
+    // As a result, we choose a slightly shorter name! As to why
+    // `.note.rustc` works on MinGW, that's another good question...
+
     if target.options.is_like_osx {
-        "__DATA,__note.rustc"
-    } else if target.options.is_like_msvc {
-        // When using link.exe it was seen that the section name `.note.rustc`
-        // was getting shortened to `.note.ru`, and according to the PE and COFF
-        // specification:
-        //
-        // > Executable images do not use a string table and do not support
-        // > section names longer than 8 characters
-        //
-        // https://msdn.microsoft.com/en-us/library/windows/hardware/gg463119.aspx
-        //
-        // As a result, we choose a slightly shorter name! As to why
-        // `.note.rustc` works on MinGW, that's another good question...
-        ".rustc"
+        "__DATA,.rustc"
     } else {
-        ".note.rustc"
+        ".rustc"
     }
 }
 
-pub fn read_meta_section_name(target: &Target) -> &'static str {
-    if target.options.is_like_osx {
-        "__note.rustc"
-    } else if target.options.is_like_msvc {
-        ".rustc"
-    } else {
-        ".note.rustc"
-    }
+pub fn read_meta_section_name(_target: &Target) -> &'static str {
+    ".rustc"
 }
 
 // A diagnostic function for dumping crate metadata to an output stream
diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs
index 1077cb296c1..df893842337 100644
--- a/src/librustc_trans/base.rs
+++ b/src/librustc_trans/base.rs
@@ -2250,10 +2250,17 @@ fn write_metadata(cx: &SharedCrateContext,
     };
     unsafe {
         llvm::LLVMSetInitializer(llglobal, llconst);
-        let name =
+        let section_name =
             cx.tcx().sess.cstore.metadata_section_name(&cx.sess().target.target);
-        let name = CString::new(name).unwrap();
-        llvm::LLVMSetSection(llglobal, name.as_ptr())
+        let name = CString::new(section_name).unwrap();
+        llvm::LLVMSetSection(llglobal, name.as_ptr());
+
+        // Also generate a .section directive to force no
+        // flags, at least for ELF outputs, so that the
+        // metadata doesn't get loaded into memory.
+        let directive = format!(".section {}", section_name);
+        let directive = CString::new(directive).unwrap();
+        llvm::LLVMSetModuleInlineAsm(cx.metadata_llmod(), directive.as_ptr())
     }
     return metadata;
 }