@@ -526,8 +526,7 @@ impl<'a> Context<'a> {
526
526
527
527
for ( lib, kind) in m {
528
528
info ! ( "{} reading metadata from: {}" , flavor, lib. display( ) ) ;
529
- let metadata = match get_metadata_section ( self . target . options . is_like_osx ,
530
- & lib) {
529
+ let metadata = match get_metadata_section ( self . target , & lib) {
531
530
Ok ( blob) => {
532
531
if self . crate_matches ( blob. as_slice ( ) , & lib) {
533
532
blob
@@ -715,17 +714,19 @@ impl ArchiveMetadata {
715
714
}
716
715
717
716
// Just a small wrapper to time how long reading metadata takes.
718
- fn get_metadata_section ( is_osx : bool , filename : & Path ) -> Result < MetadataBlob , String > {
717
+ fn get_metadata_section ( target : & Target , filename : & Path )
718
+ -> Result < MetadataBlob , String > {
719
719
let mut ret = None ;
720
720
let dur = Duration :: span ( || {
721
- ret = Some ( get_metadata_section_imp ( is_osx , filename) ) ;
721
+ ret = Some ( get_metadata_section_imp ( target , filename) ) ;
722
722
} ) ;
723
723
info ! ( "reading {:?} => {}ms" , filename. file_name( ) . unwrap( ) ,
724
724
dur. num_milliseconds( ) ) ;
725
725
return ret. unwrap ( ) ; ;
726
726
}
727
727
728
- fn get_metadata_section_imp ( is_osx : bool , filename : & Path ) -> Result < MetadataBlob , String > {
728
+ fn get_metadata_section_imp ( target : & Target , filename : & Path )
729
+ -> Result < MetadataBlob , String > {
729
730
if !filename. exists ( ) {
730
731
return Err ( format ! ( "no such file: '{}'" , filename. display( ) ) ) ;
731
732
}
@@ -769,7 +770,7 @@ fn get_metadata_section_imp(is_osx: bool, filename: &Path) -> Result<MetadataBlo
769
770
name_len as usize ) . to_vec ( ) ;
770
771
let name = String :: from_utf8 ( name) . unwrap ( ) ;
771
772
debug ! ( "get_metadata_section: name {}" , name) ;
772
- if read_meta_section_name ( is_osx ) == name {
773
+ if read_meta_section_name ( target ) == name {
773
774
let cbuf = llvm:: LLVMGetSectionContents ( si. llsi ) ;
774
775
let csz = llvm:: LLVMGetSectionSize ( si. llsi ) as usize ;
775
776
let cvbuf: * const u8 = cbuf as * const u8 ;
@@ -799,26 +800,41 @@ fn get_metadata_section_imp(is_osx: bool, filename: &Path) -> Result<MetadataBlo
799
800
}
800
801
}
801
802
802
- pub fn meta_section_name ( is_osx : bool ) -> & ' static str {
803
- if is_osx {
803
+ pub fn meta_section_name ( target : & Target ) -> & ' static str {
804
+ if target . options . is_like_osx {
804
805
"__DATA,__note.rustc"
806
+ } else if target. options . is_like_msvc {
807
+ // When using link.exe it was seen that the section name `.note.rustc`
808
+ // was getting shortened to `.note.ru`, and according to the PE and COFF
809
+ // specification:
810
+ //
811
+ // > Executable images do not use a string table and do not support
812
+ // > section names longer than 8 characters
813
+ //
814
+ // https://msdn.microsoft.com/en-us/library/windows/hardware/gg463119.aspx
815
+ //
816
+ // As a result, we choose a slightly shorter name! As to why
817
+ // `.note.rustc` works on MinGW, that's another good question...
818
+ ".rustc"
805
819
} else {
806
820
".note.rustc"
807
821
}
808
822
}
809
823
810
- pub fn read_meta_section_name ( is_osx : bool ) -> & ' static str {
811
- if is_osx {
824
+ pub fn read_meta_section_name ( target : & Target ) -> & ' static str {
825
+ if target . options . is_like_osx {
812
826
"__note.rustc"
827
+ } else if target. options . is_like_msvc {
828
+ ".rustc"
813
829
} else {
814
830
".note.rustc"
815
831
}
816
832
}
817
833
818
834
// A diagnostic function for dumping crate metadata to an output stream
819
- pub fn list_file_metadata ( is_osx : bool , path : & Path ,
835
+ pub fn list_file_metadata ( target : & Target , path : & Path ,
820
836
out : & mut io:: Write ) -> io:: Result < ( ) > {
821
- match get_metadata_section ( is_osx , path) {
837
+ match get_metadata_section ( target , path) {
822
838
Ok ( bytes) => decoder:: list_crate_metadata ( bytes. as_slice ( ) , out) ,
823
839
Err ( msg) => {
824
840
write ! ( out, "{}\n " , msg)
0 commit comments