@@ -36,7 +36,7 @@ use metadata;
36
36
use rustc:: hir:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
37
37
use rustc:: middle:: lang_items:: StartFnLangItem ;
38
38
use rustc:: middle:: weak_lang_items;
39
- use rustc:: mir:: mono:: { Linkage , Visibility , Stats } ;
39
+ use rustc:: mir:: mono:: { Linkage , Visibility , Stats , CodegenUnitNameBuilder } ;
40
40
use rustc:: middle:: cstore:: { EncodedMetadata } ;
41
41
use rustc:: ty:: { self , Ty , TyCtxt } ;
42
42
use rustc:: ty:: layout:: { self , Align , TyLayout , LayoutOf } ;
@@ -742,19 +742,23 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
742
742
743
743
let crate_hash = tcx. crate_hash ( LOCAL_CRATE ) ;
744
744
let link_meta = link:: build_link_meta ( crate_hash) ;
745
+ let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( tcx) ;
745
746
746
747
// Codegen the metadata.
747
748
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) ;
750
755
let metadata = time ( tcx. sess , "write metadata" , || {
751
756
write_metadata ( tcx, & metadata_llvm_module, & link_meta)
752
757
} ) ;
753
758
tcx. sess . profiler ( |p| p. end_activity ( ProfileCategory :: Codegen ) ) ;
754
759
755
760
let metadata_module = ModuleCodegen {
756
- name : link:: METADATA_MODULE_NAME . to_string ( ) ,
757
- llmod_id : llmod_id. to_string ( ) ,
761
+ name : metadata_cgu_name,
758
762
source : ModuleSource :: Codegened ( metadata_llvm_module) ,
759
763
kind : ModuleKind :: Metadata ,
760
764
} ;
@@ -833,20 +837,22 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
833
837
let allocator_module = if any_dynamic_crate {
834
838
None
835
839
} 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 {
840
847
allocator:: codegen ( tcx, & modules, kind)
841
- } ) ;
848
+ }
849
+ } ) ;
842
850
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
+ } )
850
856
} else {
851
857
None
852
858
} ;
@@ -889,21 +895,10 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
889
895
// succeed it means that none of the dependencies has changed
890
896
// and we can safely re-use.
891
897
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
-
902
898
let module = ModuleCodegen {
903
899
name : cgu. name ( ) . to_string ( ) ,
904
900
source : ModuleSource :: Preexisting ( buf) ,
905
901
kind : ModuleKind :: Regular ,
906
- llmod_id,
907
902
} ;
908
903
tcx. dep_graph . mark_loaded_from_cache ( dep_node_index, true ) ;
909
904
write:: submit_codegened_module_to_llvm ( tcx, module, 0 ) ;
@@ -1212,21 +1207,8 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1212
1207
{
1213
1208
let cgu_name = cgu. name ( ) . to_string ( ) ;
1214
1209
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
-
1228
1210
// 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 ) ;
1230
1212
let stats = {
1231
1213
let cx = CodegenCx :: new ( tcx, cgu, & llvm_module) ;
1232
1214
let mono_items = cx. codegen_unit
@@ -1282,7 +1264,6 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1282
1264
name : cgu_name,
1283
1265
source : ModuleSource :: Codegened ( llvm_module) ,
1284
1266
kind : ModuleKind :: Regular ,
1285
- llmod_id,
1286
1267
} )
1287
1268
}
1288
1269
}
0 commit comments