@@ -2,14 +2,15 @@ use super::link::{self, ensure_removed};
2
2
use super :: lto:: { self , SerializedModule } ;
3
3
use super :: symbol_export:: symbol_name_for_instance_in_crate;
4
4
5
+ use crate :: back:: archive:: read_archive_file_undefined_symbols;
5
6
use crate :: errors;
6
7
use crate :: traits:: * ;
7
8
use crate :: {
8
9
CachedModuleCodegen , CodegenResults , CompiledModule , CrateInfo , ModuleCodegen , ModuleKind ,
9
10
} ;
10
11
use jobserver:: { Acquired , Client } ;
11
12
use rustc_ast:: attr;
12
- use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
13
+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap } ;
13
14
use rustc_data_structures:: memmap:: Mmap ;
14
15
use rustc_data_structures:: profiling:: { SelfProfilerRef , VerboseTimingGuard } ;
15
16
use rustc_data_structures:: sync:: Lrc ;
@@ -327,6 +328,7 @@ pub struct CodegenContext<B: WriteBackendMethods> {
327
328
pub fewer_names : bool ,
328
329
pub time_trace : bool ,
329
330
pub exported_symbols : Option < Arc < ExportedSymbols > > ,
331
+ pub undefined_symbols_from_ignored_for_lto : Option < FxHashSet < String > > ,
330
332
pub opts : Arc < config:: Options > ,
331
333
pub crate_types : Vec < CrateType > ,
332
334
pub each_linked_rlib_for_lto : Vec < ( CrateNum , PathBuf ) > ,
@@ -989,13 +991,36 @@ fn start_executing_work<B: ExtraBackendMethods>(
989
991
let sess = tcx. sess ;
990
992
991
993
let mut each_linked_rlib_for_lto = Vec :: new ( ) ;
994
+ let mut ignored_cnum_for_lto = Vec :: new ( ) ;
992
995
drop ( link:: each_linked_rlib ( crate_info, None , & mut |cnum, path| {
993
996
if link:: ignored_for_lto ( sess, crate_info, cnum) {
997
+ ignored_cnum_for_lto. push ( cnum) ;
994
998
return ;
995
999
}
996
1000
each_linked_rlib_for_lto. push ( ( cnum, path. to_path_buf ( ) ) ) ;
997
1001
} ) ) ;
998
1002
1003
+ let undefined_symbols_from_ignored_for_lto = {
1004
+ match sess. lto ( ) {
1005
+ Lto :: Fat | Lto :: Thin => {
1006
+ let mut undefined_symbols_from_ignored_for_lto = FxHashSet :: default ( ) ;
1007
+ if !sess. target . is_like_wasm {
1008
+ // FIXME: Add an undefined symbol lookup for wasm. https://github.com/WebAssembly/tool-conventions/blob/main/Linking.md
1009
+ for cnum in ignored_cnum_for_lto {
1010
+ let c_src = tcx. used_crate_source ( cnum) ;
1011
+ if let Some ( ( path, _) ) = & c_src. rlib {
1012
+ let undefined_symbols = read_archive_file_undefined_symbols ( path)
1013
+ . expect ( "failed to read undefined symbols" ) ;
1014
+ undefined_symbols_from_ignored_for_lto. extend ( undefined_symbols) ;
1015
+ }
1016
+ }
1017
+ }
1018
+ Some ( undefined_symbols_from_ignored_for_lto)
1019
+ }
1020
+ Lto :: No | Lto :: ThinLocal => None ,
1021
+ }
1022
+ } ;
1023
+
999
1024
// Compute the set of symbols we need to retain when doing LTO (if we need to)
1000
1025
let exported_symbols = {
1001
1026
let mut exported_symbols = FxHashMap :: default ( ) ;
@@ -1049,6 +1074,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
1049
1074
backend : backend. clone ( ) ,
1050
1075
crate_types : sess. crate_types ( ) . to_vec ( ) ,
1051
1076
each_linked_rlib_for_lto,
1077
+ undefined_symbols_from_ignored_for_lto,
1052
1078
lto : sess. lto ( ) ,
1053
1079
fewer_names : sess. fewer_names ( ) ,
1054
1080
save_temps : sess. opts . cg . save_temps ,
0 commit comments