@@ -799,7 +799,8 @@ fn write_metadata(cx: &SharedCrateContext,
799
799
/// Find any symbols that are defined in one compilation unit, but not declared
800
800
/// in any other compilation unit. Give these symbols internal linkage.
801
801
fn internalize_symbols < ' a , ' tcx > ( sess : & Session ,
802
- ccxs : & CrateContextList < ' a , ' tcx > ,
802
+ scx : & SharedCrateContext < ' a , ' tcx > ,
803
+ llvm_modules : & [ ModuleLlvm ] ,
803
804
symbol_map : & SymbolMap < ' tcx > ,
804
805
exported_symbols : & ExportedSymbols ) {
805
806
let export_threshold =
@@ -814,7 +815,6 @@ fn internalize_symbols<'a, 'tcx>(sess: &Session,
814
815
. map ( |& ( ref name, _) | & name[ ..] )
815
816
. collect :: < FxHashSet < & str > > ( ) ;
816
817
817
- let scx = ccxs. shared ( ) ;
818
818
let tcx = scx. tcx ( ) ;
819
819
820
820
let incr_comp = sess. opts . debugging_opts . incremental . is_some ( ) ;
@@ -829,8 +829,8 @@ fn internalize_symbols<'a, 'tcx>(sess: &Session,
829
829
// incremental compilation, we don't need to collect. See below for more
830
830
// information.
831
831
if !incr_comp {
832
- for ccx in ccxs . iter_need_trans ( ) {
833
- for val in iter_globals ( ccx . llmod ( ) ) . chain ( iter_functions ( ccx . llmod ( ) ) ) {
832
+ for ll in llvm_modules {
833
+ for val in iter_globals ( ll . llmod ) . chain ( iter_functions ( ll . llmod ) ) {
834
834
let linkage = llvm:: LLVMRustGetLinkage ( val) ;
835
835
// We only care about external declarations (not definitions)
836
836
// and available_externally definitions.
@@ -866,8 +866,8 @@ fn internalize_symbols<'a, 'tcx>(sess: &Session,
866
866
// Examine each external definition. If the definition is not used in
867
867
// any other compilation unit, and is not reachable from other crates,
868
868
// then give it internal linkage.
869
- for ccx in ccxs . iter_need_trans ( ) {
870
- for val in iter_globals ( ccx . llmod ( ) ) . chain ( iter_functions ( ccx . llmod ( ) ) ) {
869
+ for ll in llvm_modules {
870
+ for val in iter_globals ( ll . llmod ) . chain ( iter_functions ( ll . llmod ) ) {
871
871
let linkage = llvm:: LLVMRustGetLinkage ( val) ;
872
872
873
873
let is_externally_visible = ( linkage == llvm:: Linkage :: ExternalLinkage ) ||
@@ -926,33 +926,34 @@ fn internalize_symbols<'a, 'tcx>(sess: &Session,
926
926
// when using MSVC linker. We do this only for data, as linker can fix up
927
927
// code references on its own.
928
928
// See #26591, #27438
929
- fn create_imps ( cx : & CrateContextList ) {
929
+ fn create_imps ( sess : & Session ,
930
+ llvm_modules : & [ ModuleLlvm ] ) {
930
931
// The x86 ABI seems to require that leading underscores are added to symbol
931
932
// names, so we need an extra underscore on 32-bit. There's also a leading
932
933
// '\x01' here which disables LLVM's symbol mangling (e.g. no extra
933
934
// underscores added in front).
934
- let prefix = if cx . shared ( ) . sess ( ) . target . target . target_pointer_width == "32" {
935
+ let prefix = if sess. target . target . target_pointer_width == "32" {
935
936
"\x01 __imp__"
936
937
} else {
937
938
"\x01 __imp_"
938
939
} ;
939
940
unsafe {
940
- for ccx in cx . iter_need_trans ( ) {
941
- let exported: Vec < _ > = iter_globals ( ccx . llmod ( ) )
941
+ for ll in llvm_modules {
942
+ let exported: Vec < _ > = iter_globals ( ll . llmod )
942
943
. filter ( |& val| {
943
944
llvm:: LLVMRustGetLinkage ( val) ==
944
945
llvm:: Linkage :: ExternalLinkage &&
945
946
llvm:: LLVMIsDeclaration ( val) == 0
946
947
} )
947
948
. collect ( ) ;
948
949
949
- let i8p_ty = Type :: i8p ( & ccx ) ;
950
+ let i8p_ty = Type :: i8p_llcx ( ll . llcx ) ;
950
951
for val in exported {
951
952
let name = CStr :: from_ptr ( llvm:: LLVMGetValueName ( val) ) ;
952
953
let mut imp_name = prefix. as_bytes ( ) . to_vec ( ) ;
953
954
imp_name. extend ( name. to_bytes ( ) ) ;
954
955
let imp_name = CString :: new ( imp_name) . unwrap ( ) ;
955
- let imp = llvm:: LLVMAddGlobal ( ccx . llmod ( ) ,
956
+ let imp = llvm:: LLVMAddGlobal ( ll . llmod ,
956
957
i8p_ty. to_ref ( ) ,
957
958
imp_name. as_ptr ( ) as * const _ ) ;
958
959
let init = llvm:: LLVMConstBitCast ( val, i8p_ty. to_ref ( ) ) ;
@@ -1244,11 +1245,23 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1244
1245
let exported_symbols = ExportedSymbols :: compute_from ( & shared_ccx,
1245
1246
& symbol_map) ;
1246
1247
1248
+ // Get the list of llvm modules we created. We'll do a few wacky
1249
+ // transforms on them now.
1250
+
1251
+ let llvm_modules: Vec < _ > =
1252
+ modules. iter ( )
1253
+ . filter_map ( |module| match module. source {
1254
+ ModuleSource :: Translated ( llvm) => Some ( llvm) ,
1255
+ _ => None ,
1256
+ } )
1257
+ . collect ( ) ;
1258
+
1247
1259
// Now that we have all symbols that are exported from the CGUs of this
1248
1260
// crate, we can run the `internalize_symbols` pass.
1249
1261
time ( shared_ccx. sess ( ) . time_passes ( ) , "internalize symbols" , || {
1250
1262
internalize_symbols ( sess,
1251
- & crate_context_list,
1263
+ & shared_ccx,
1264
+ & llvm_modules,
1252
1265
& symbol_map,
1253
1266
& exported_symbols) ;
1254
1267
} ) ;
@@ -1259,7 +1272,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1259
1272
1260
1273
if sess. target . target . options . is_like_msvc &&
1261
1274
sess. crate_types . borrow ( ) . iter ( ) . any ( |ct| * ct == config:: CrateTypeRlib ) {
1262
- create_imps ( & crate_context_list ) ;
1275
+ create_imps ( sess , & llvm_modules ) ;
1263
1276
}
1264
1277
1265
1278
let linker_info = LinkerInfo :: new ( & shared_ccx, & exported_symbols) ;
0 commit comments