@@ -18,7 +18,6 @@ use crate::builder::Builder;
1818use crate :: common;
1919use crate :: context:: CodegenCx ;
2020use crate :: llvm;
21- use crate :: metadata;
2221use crate :: value:: Value ;
2322
2423use rustc_codegen_ssa:: base:: maybe_create_entry_wrapper;
@@ -47,6 +46,21 @@ pub fn write_compressed_metadata<'tcx>(
4746 use snap:: write:: FrameEncoder ;
4847 use std:: io:: Write ;
4948
49+ // Historical note:
50+ //
51+ // When using link.exe it was seen that the section name `.note.rustc`
52+ // was getting shortened to `.note.ru`, and according to the PE and COFF
53+ // specification:
54+ //
55+ // > Executable images do not use a string table and do not support
56+ // > section names longer than 8 characters
57+ //
58+ // https://docs.microsoft.com/en-us/windows/win32/debug/pe-format
59+ //
60+ // As a result, we choose a slightly shorter name! As to why
61+ // `.note.rustc` works on MinGW, that's another good question...
62+ let section_name = if tcx. sess . target . is_like_osx { "__DATA,.rustc" } else { ".rustc" } ;
63+
5064 let ( metadata_llcx, metadata_llmod) = ( & * llvm_module. llcx , llvm_module. llmod ( ) ) ;
5165 let mut compressed = tcx. metadata_encoding_version ( ) ;
5266 FrameEncoder :: new ( & mut compressed) . write_all ( & metadata. raw_data ) . unwrap ( ) ;
@@ -59,7 +73,6 @@ pub fn write_compressed_metadata<'tcx>(
5973 unsafe { llvm:: LLVMAddGlobal ( metadata_llmod, common:: val_ty ( llconst) , buf. as_ptr ( ) ) } ;
6074 unsafe {
6175 llvm:: LLVMSetInitializer ( llglobal, llconst) ;
62- let section_name = metadata:: metadata_section_name ( & tcx. sess . target ) ;
6376 let name = SmallCStr :: new ( section_name) ;
6477 llvm:: LLVMSetSection ( llglobal, name. as_ptr ( ) ) ;
6578
0 commit comments