@@ -36,7 +36,7 @@ use metadata;
3636use rustc:: hir:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
3737use rustc:: middle:: lang_items:: StartFnLangItem ;
3838use rustc:: middle:: weak_lang_items;
39- use rustc:: mir:: mono:: { Linkage , Visibility , Stats } ;
39+ use rustc:: mir:: mono:: { Linkage , Visibility , Stats , CodegenUnitNameBuilder } ;
4040use rustc:: middle:: cstore:: { EncodedMetadata } ;
4141use rustc:: ty:: { self , Ty , TyCtxt } ;
4242use rustc:: ty:: layout:: { self , Align , TyLayout , LayoutOf } ;
@@ -742,19 +742,23 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
742742
743743 let crate_hash = tcx. crate_hash ( LOCAL_CRATE ) ;
744744 let link_meta = link:: build_link_meta ( crate_hash) ;
745+ let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( tcx) ;
745746
746747 // Codegen the metadata.
747748 tcx. sess . profiler ( |p| p. start_activity ( ProfileCategory :: Codegen ) ) ;
748- let llmod_id = "metadata" ;
749- let metadata_llvm_module = ModuleLlvm :: new ( tcx. sess , llmod_id) ;
749+
750+ let metadata_cgu_name = cgu_name_builder. build_cgu_name ( LOCAL_CRATE ,
751+ & [ "crate" ] ,
752+ Some ( "metadata" ) ) . as_str ( )
753+ . to_string ( ) ;
754+ let metadata_llvm_module = ModuleLlvm :: new ( tcx. sess , & metadata_cgu_name) ;
750755 let metadata = time ( tcx. sess , "write metadata" , || {
751756 write_metadata ( tcx, & metadata_llvm_module, & link_meta)
752757 } ) ;
753758 tcx. sess . profiler ( |p| p. end_activity ( ProfileCategory :: Codegen ) ) ;
754759
755760 let metadata_module = ModuleCodegen {
756- name : link:: METADATA_MODULE_NAME . to_string ( ) ,
757- llmod_id : llmod_id. to_string ( ) ,
761+ name : metadata_cgu_name,
758762 source : ModuleSource :: Codegened ( metadata_llvm_module) ,
759763 kind : ModuleKind :: Metadata ,
760764 } ;
@@ -833,20 +837,22 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
833837 let allocator_module = if any_dynamic_crate {
834838 None
835839 } else if let Some ( kind) = * tcx. sess . allocator_kind . get ( ) {
836- unsafe {
837- let llmod_id = "allocator" ;
838- let modules = ModuleLlvm :: new ( tcx. sess , llmod_id) ;
839- time ( tcx. sess , "write allocator module" , || {
840+ let llmod_id = cgu_name_builder. build_cgu_name ( LOCAL_CRATE ,
841+ & [ "crate" ] ,
842+ Some ( "allocator" ) ) . as_str ( )
843+ . to_string ( ) ;
844+ let modules = ModuleLlvm :: new ( tcx. sess , & llmod_id) ;
845+ time ( tcx. sess , "write allocator module" , || {
846+ unsafe {
840847 allocator:: codegen ( tcx, & modules, kind)
841- } ) ;
848+ }
849+ } ) ;
842850
843- Some ( ModuleCodegen {
844- name : link:: ALLOCATOR_MODULE_NAME . to_string ( ) ,
845- llmod_id : llmod_id. to_string ( ) ,
846- source : ModuleSource :: Codegened ( modules) ,
847- kind : ModuleKind :: Allocator ,
848- } )
849- }
851+ Some ( ModuleCodegen {
852+ name : llmod_id,
853+ source : ModuleSource :: Codegened ( modules) ,
854+ kind : ModuleKind :: Allocator ,
855+ } )
850856 } else {
851857 None
852858 } ;
@@ -889,21 +895,10 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
889895 // succeed it means that none of the dependencies has changed
890896 // and we can safely re-use.
891897 if let Some ( dep_node_index) = tcx. dep_graph . try_mark_green ( tcx, dep_node) {
892- // Append ".rs" to LLVM module identifier.
893- //
894- // LLVM code generator emits a ".file filename" directive
895- // for ELF backends. Value of the "filename" is set as the
896- // LLVM module identifier. Due to a LLVM MC bug[1], LLVM
897- // crashes if the module identifier is same as other symbols
898- // such as a function name in the module.
899- // 1. http://llvm.org/bugs/show_bug.cgi?id=11479
900- let llmod_id = format ! ( "{}.rs" , cgu. name( ) ) ;
901-
902898 let module = ModuleCodegen {
903899 name : cgu. name ( ) . to_string ( ) ,
904900 source : ModuleSource :: Preexisting ( buf) ,
905901 kind : ModuleKind :: Regular ,
906- llmod_id,
907902 } ;
908903 tcx. dep_graph . mark_loaded_from_cache ( dep_node_index, true ) ;
909904 write:: submit_codegened_module_to_llvm ( tcx, module, 0 ) ;
@@ -1212,21 +1207,8 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12121207 {
12131208 let cgu_name = cgu. name ( ) . to_string ( ) ;
12141209
1215- // Append ".rs" to LLVM module identifier.
1216- //
1217- // LLVM code generator emits a ".file filename" directive
1218- // for ELF backends. Value of the "filename" is set as the
1219- // LLVM module identifier. Due to a LLVM MC bug[1], LLVM
1220- // crashes if the module identifier is same as other symbols
1221- // such as a function name in the module.
1222- // 1. http://llvm.org/bugs/show_bug.cgi?id=11479
1223- let llmod_id = format ! ( "{}-{}.rs" ,
1224- cgu. name( ) ,
1225- tcx. crate_disambiguator( LOCAL_CRATE )
1226- . to_fingerprint( ) . to_hex( ) ) ;
1227-
12281210 // Instantiate monomorphizations without filling out definitions yet...
1229- let llvm_module = ModuleLlvm :: new ( tcx. sess , & llmod_id ) ;
1211+ let llvm_module = ModuleLlvm :: new ( tcx. sess , & cgu_name ) ;
12301212 let stats = {
12311213 let cx = CodegenCx :: new ( tcx, cgu, & llvm_module) ;
12321214 let mono_items = cx. codegen_unit
@@ -1282,7 +1264,6 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12821264 name : cgu_name,
12831265 source : ModuleSource :: Codegened ( llvm_module) ,
12841266 kind : ModuleKind :: Regular ,
1285- llmod_id,
12861267 } )
12871268 }
12881269}
0 commit comments