@@ -739,15 +739,18 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
739
739
let link_meta = link:: build_link_meta ( crate_hash) ;
740
740
741
741
// Codegen the metadata.
742
- let llmod_id = "metadata" ;
742
+ let metadata_cgu_name = CodegenUnit :: build_cgu_name ( tcx,
743
+ LOCAL_CRATE ,
744
+ & [ "crate" ] ,
745
+ Some ( "metadata" ) ) . as_str ( )
746
+ . to_string ( ) ;
743
747
let ( metadata_llcx, metadata_llmod, metadata) =
744
748
time ( tcx. sess , "write metadata" , || {
745
- write_metadata ( tcx, llmod_id , & link_meta)
749
+ write_metadata ( tcx, & metadata_cgu_name , & link_meta)
746
750
} ) ;
747
751
748
752
let metadata_module = ModuleCodegen {
749
- name : link:: METADATA_MODULE_NAME . to_string ( ) ,
750
- llmod_id : llmod_id. to_string ( ) ,
753
+ name : metadata_cgu_name,
751
754
source : ModuleSource :: Codegened ( ModuleLlvm {
752
755
llcx : metadata_llcx,
753
756
llmod : metadata_llmod,
@@ -810,26 +813,30 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
810
813
811
814
// Codegen an allocator shim, if any
812
815
let allocator_module = if let Some ( kind) = * tcx. sess . allocator_kind . get ( ) {
813
- unsafe {
814
- let llmod_id = "allocator" ;
815
- let ( llcx, llmod) =
816
- context:: create_context_and_module ( tcx. sess , llmod_id) ;
817
- let modules = ModuleLlvm {
818
- llmod,
819
- llcx,
820
- tm : create_target_machine ( tcx. sess , false ) ,
821
- } ;
822
- time ( tcx. sess , "write allocator module" , || {
816
+ let llmod_id = CodegenUnit :: build_cgu_name ( tcx,
817
+ LOCAL_CRATE ,
818
+ & [ "crate" ] ,
819
+ Some ( "allocator" ) ) . as_str ( )
820
+ . to_string ( ) ;
821
+ let ( llcx, llmod) = unsafe {
822
+ context:: create_context_and_module ( tcx. sess , & llmod_id)
823
+ } ;
824
+ let modules = ModuleLlvm {
825
+ llmod,
826
+ llcx,
827
+ tm : create_target_machine ( tcx. sess , false ) ,
828
+ } ;
829
+ time ( tcx. sess , "write allocator module" , || {
830
+ unsafe {
823
831
allocator:: codegen ( tcx, & modules, kind)
824
- } ) ;
832
+ }
833
+ } ) ;
825
834
826
- Some ( ModuleCodegen {
827
- name : link:: ALLOCATOR_MODULE_NAME . to_string ( ) ,
828
- llmod_id : llmod_id. to_string ( ) ,
829
- source : ModuleSource :: Codegened ( modules) ,
830
- kind : ModuleKind :: Allocator ,
831
- } )
832
- }
835
+ Some ( ModuleCodegen {
836
+ name : llmod_id,
837
+ source : ModuleSource :: Codegened ( modules) ,
838
+ kind : ModuleKind :: Allocator ,
839
+ } )
833
840
} else {
834
841
None
835
842
} ;
@@ -872,21 +879,10 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
872
879
// succeed it means that none of the dependencies has changed
873
880
// and we can safely re-use.
874
881
if let Some ( dep_node_index) = tcx. dep_graph . try_mark_green ( tcx, dep_node) {
875
- // Append ".rs" to LLVM module identifier.
876
- //
877
- // LLVM code generator emits a ".file filename" directive
878
- // for ELF backends. Value of the "filename" is set as the
879
- // LLVM module identifier. Due to a LLVM MC bug[1], LLVM
880
- // crashes if the module identifier is same as other symbols
881
- // such as a function name in the module.
882
- // 1. http://llvm.org/bugs/show_bug.cgi?id=11479
883
- let llmod_id = format ! ( "{}.rs" , cgu. name( ) ) ;
884
-
885
882
let module = ModuleCodegen {
886
883
name : cgu. name ( ) . to_string ( ) ,
887
884
source : ModuleSource :: Preexisting ( buf) ,
888
885
kind : ModuleKind :: Regular ,
889
- llmod_id,
890
886
} ;
891
887
tcx. dep_graph . mark_loaded_from_cache ( dep_node_index, true ) ;
892
888
write:: submit_codegened_module_to_llvm ( tcx, module, 0 ) ;
@@ -1195,21 +1191,8 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1195
1191
{
1196
1192
let cgu_name = cgu. name ( ) . to_string ( ) ;
1197
1193
1198
- // Append ".rs" to LLVM module identifier.
1199
- //
1200
- // LLVM code generator emits a ".file filename" directive
1201
- // for ELF backends. Value of the "filename" is set as the
1202
- // LLVM module identifier. Due to a LLVM MC bug[1], LLVM
1203
- // crashes if the module identifier is same as other symbols
1204
- // such as a function name in the module.
1205
- // 1. http://llvm.org/bugs/show_bug.cgi?id=11479
1206
- let llmod_id = format ! ( "{}-{}.rs" ,
1207
- cgu. name( ) ,
1208
- tcx. crate_disambiguator( LOCAL_CRATE )
1209
- . to_fingerprint( ) . to_hex( ) ) ;
1210
-
1211
1194
// Instantiate monomorphizations without filling out definitions yet...
1212
- let cx = CodegenCx :: new ( tcx, cgu, & llmod_id ) ;
1195
+ let cx = CodegenCx :: new ( tcx, cgu) ;
1213
1196
let module = {
1214
1197
let mono_items = cx. codegen_unit
1215
1198
. items_in_deterministic_order ( cx. tcx ) ;
@@ -1267,7 +1250,6 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1267
1250
name : cgu_name,
1268
1251
source : ModuleSource :: Codegened ( llvm_module) ,
1269
1252
kind : ModuleKind :: Regular ,
1270
- llmod_id,
1271
1253
}
1272
1254
} ;
1273
1255
0 commit comments