@@ -10,7 +10,6 @@ use std::io::{self, BufWriter};
1010use std:: path:: { Path , PathBuf } ;
1111use std:: { env, mem, str} ;
1212
13- use rustc_data_structures:: fx:: FxHashMap ;
1413use rustc_hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
1514use rustc_middle:: middle:: dependency_format:: Linkage ;
1615use rustc_middle:: ty:: TyCtxt ;
@@ -36,28 +35,6 @@ pub fn disable_localization(linker: &mut Command) {
3635 linker. env ( "VSLANG" , "1033" ) ;
3736}
3837
39- /// For all the linkers we support, and information they might
40- /// need out of the shared crate context before we get rid of it.
41- #[ derive( Debug , Encodable , Decodable ) ]
42- pub struct LinkerInfo {
43- pub ( super ) target_cpu : String ,
44- exports : FxHashMap < CrateType , Vec < String > > ,
45- }
46-
47- impl LinkerInfo {
48- pub fn new ( tcx : TyCtxt < ' _ > , target_cpu : String ) -> LinkerInfo {
49- LinkerInfo {
50- target_cpu,
51- exports : tcx
52- . sess
53- . crate_types ( )
54- . iter ( )
55- . map ( |& c| ( c, exported_symbols ( tcx, c) ) )
56- . collect ( ) ,
57- }
58- }
59- }
60-
6138// The third parameter is for env vars, used on windows to set up the
6239// path for MSVC to find its DLLs, and gcc to find its bundled
6340// toolchain
@@ -66,7 +43,7 @@ pub fn get_linker<'a>(
6643 linker : & Path ,
6744 flavor : LinkerFlavor ,
6845 self_contained : bool ,
69- info : & ' a LinkerInfo ,
46+ target_cpu : & ' a str ,
7047) -> Box < dyn Linker + ' a > {
7148 let msvc_tool = windows_registry:: find_tool ( & sess. opts . target_triple . triple ( ) , "link.exe" ) ;
7249
@@ -153,40 +130,26 @@ pub fn get_linker<'a>(
153130
154131 match flavor {
155132 LinkerFlavor :: Lld ( LldFlavor :: Link ) | LinkerFlavor :: Msvc => {
156- Box :: new ( MsvcLinker { cmd, sess, exports : & info . exports } ) as Box < dyn Linker >
133+ Box :: new ( MsvcLinker { cmd, sess } ) as Box < dyn Linker >
157134 }
158- LinkerFlavor :: Em => {
159- Box :: new ( EmLinker { cmd, sess, exports : & info. exports } ) as Box < dyn Linker >
135+ LinkerFlavor :: Em => Box :: new ( EmLinker { cmd, sess } ) as Box < dyn Linker > ,
136+ LinkerFlavor :: Gcc => {
137+ Box :: new ( GccLinker { cmd, sess, target_cpu, hinted_static : false , is_ld : false } )
138+ as Box < dyn Linker >
160139 }
161- LinkerFlavor :: Gcc => Box :: new ( GccLinker {
162- cmd,
163- sess,
164- exports : & info. exports ,
165- target_cpu : & info. target_cpu ,
166- hinted_static : false ,
167- is_ld : false ,
168- } ) as Box < dyn Linker > ,
169140
170141 LinkerFlavor :: Lld ( LldFlavor :: Ld )
171142 | LinkerFlavor :: Lld ( LldFlavor :: Ld64 )
172- | LinkerFlavor :: Ld => Box :: new ( GccLinker {
173- cmd,
174- sess,
175- exports : & info. exports ,
176- target_cpu : & info. target_cpu ,
177- hinted_static : false ,
178- is_ld : true ,
179- } ) as Box < dyn Linker > ,
180-
181- LinkerFlavor :: Lld ( LldFlavor :: Wasm ) => {
182- Box :: new ( WasmLd :: new ( cmd, sess, & info. exports ) ) as Box < dyn Linker >
143+ | LinkerFlavor :: Ld => {
144+ Box :: new ( GccLinker { cmd, sess, target_cpu, hinted_static : false , is_ld : true } )
145+ as Box < dyn Linker >
183146 }
184147
148+ LinkerFlavor :: Lld ( LldFlavor :: Wasm ) => Box :: new ( WasmLd :: new ( cmd, sess) ) as Box < dyn Linker > ,
149+
185150 LinkerFlavor :: PtxLinker => Box :: new ( PtxLinker { cmd, sess } ) as Box < dyn Linker > ,
186151
187- LinkerFlavor :: BpfLinker => {
188- Box :: new ( BpfLinker { cmd, sess, exports : & info. exports } ) as Box < dyn Linker >
189- }
152+ LinkerFlavor :: BpfLinker => Box :: new ( BpfLinker { cmd, sess } ) as Box < dyn Linker > ,
190153 }
191154}
192155
@@ -222,7 +185,7 @@ pub trait Linker {
222185 fn debuginfo ( & mut self , strip : Strip ) ;
223186 fn no_crt_objects ( & mut self ) ;
224187 fn no_default_libraries ( & mut self ) ;
225- fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType ) ;
188+ fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType , symbols : & [ String ] ) ;
226189 fn subsystem ( & mut self , subsystem : & str ) ;
227190 fn group_start ( & mut self ) ;
228191 fn group_end ( & mut self ) ;
@@ -250,7 +213,6 @@ impl dyn Linker + '_ {
250213pub struct GccLinker < ' a > {
251214 cmd : Command ,
252215 sess : & ' a Session ,
253- exports : & ' a FxHashMap < CrateType , Vec < String > > ,
254216 target_cpu : & ' a str ,
255217 hinted_static : bool , // Keeps track of the current hinting mode.
256218 // Link as ld
@@ -655,7 +617,7 @@ impl<'a> Linker for GccLinker<'a> {
655617 }
656618 }
657619
658- fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType ) {
620+ fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType , symbols : & [ String ] ) {
659621 // Symbol visibility in object files typically takes care of this.
660622 if crate_type == CrateType :: Executable && self . sess . target . override_export_symbols . is_none ( )
661623 {
@@ -684,7 +646,7 @@ impl<'a> Linker for GccLinker<'a> {
684646 // Write a plain, newline-separated list of symbols
685647 let res: io:: Result < ( ) > = try {
686648 let mut f = BufWriter :: new ( File :: create ( & path) ?) ;
687- for sym in self . exports [ & crate_type ] . iter ( ) {
649+ for sym in symbols {
688650 debug ! ( " _{}" , sym) ;
689651 writeln ! ( f, "_{}" , sym) ?;
690652 }
@@ -699,7 +661,7 @@ impl<'a> Linker for GccLinker<'a> {
699661 // .def file similar to MSVC one but without LIBRARY section
700662 // because LD doesn't like when it's empty
701663 writeln ! ( f, "EXPORTS" ) ?;
702- for symbol in self . exports [ & crate_type ] . iter ( ) {
664+ for symbol in symbols {
703665 debug ! ( " _{}" , symbol) ;
704666 writeln ! ( f, " {}" , symbol) ?;
705667 }
@@ -712,9 +674,9 @@ impl<'a> Linker for GccLinker<'a> {
712674 let res: io:: Result < ( ) > = try {
713675 let mut f = BufWriter :: new ( File :: create ( & path) ?) ;
714676 writeln ! ( f, "{{" ) ?;
715- if !self . exports [ & crate_type ] . is_empty ( ) {
677+ if !symbols . is_empty ( ) {
716678 writeln ! ( f, " global:" ) ?;
717- for sym in self . exports [ & crate_type ] . iter ( ) {
679+ for sym in symbols {
718680 debug ! ( " {};" , sym) ;
719681 writeln ! ( f, " {};" , sym) ?;
720682 }
@@ -814,7 +776,6 @@ impl<'a> Linker for GccLinker<'a> {
814776pub struct MsvcLinker < ' a > {
815777 cmd : Command ,
816778 sess : & ' a Session ,
817- exports : & ' a FxHashMap < CrateType , Vec < String > > ,
818779}
819780
820781impl < ' a > Linker for MsvcLinker < ' a > {
@@ -988,7 +949,7 @@ impl<'a> Linker for MsvcLinker<'a> {
988949 // crates. Upstream rlibs may be linked statically to this dynamic library,
989950 // in which case they may continue to transitively be used and hence need
990951 // their symbols exported.
991- fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType ) {
952+ fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType , symbols : & [ String ] ) {
992953 // Symbol visibility takes care of this typically
993954 if crate_type == CrateType :: Executable {
994955 return ;
@@ -1002,7 +963,7 @@ impl<'a> Linker for MsvcLinker<'a> {
1002963 // straight to exports.
1003964 writeln ! ( f, "LIBRARY" ) ?;
1004965 writeln ! ( f, "EXPORTS" ) ?;
1005- for symbol in self . exports [ & crate_type ] . iter ( ) {
966+ for symbol in symbols {
1006967 debug ! ( " _{}" , symbol) ;
1007968 writeln ! ( f, " {}" , symbol) ?;
1008969 }
@@ -1055,7 +1016,6 @@ impl<'a> Linker for MsvcLinker<'a> {
10551016pub struct EmLinker < ' a > {
10561017 cmd : Command ,
10571018 sess : & ' a Session ,
1058- exports : & ' a FxHashMap < CrateType , Vec < String > > ,
10591019}
10601020
10611021impl < ' a > Linker for EmLinker < ' a > {
@@ -1167,9 +1127,7 @@ impl<'a> Linker for EmLinker<'a> {
11671127 self . cmd . args ( & [ "-s" , "DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[]" ] ) ;
11681128 }
11691129
1170- fn export_symbols ( & mut self , _tmpdir : & Path , crate_type : CrateType ) {
1171- let symbols = & self . exports [ & crate_type] ;
1172-
1130+ fn export_symbols ( & mut self , _tmpdir : & Path , _crate_type : CrateType , symbols : & [ String ] ) {
11731131 debug ! ( "EXPORTED SYMBOLS:" ) ;
11741132
11751133 self . cmd . arg ( "-s" ) ;
@@ -1211,15 +1169,10 @@ impl<'a> Linker for EmLinker<'a> {
12111169pub struct WasmLd < ' a > {
12121170 cmd : Command ,
12131171 sess : & ' a Session ,
1214- exports : & ' a FxHashMap < CrateType , Vec < String > > ,
12151172}
12161173
12171174impl < ' a > WasmLd < ' a > {
1218- fn new (
1219- mut cmd : Command ,
1220- sess : & ' a Session ,
1221- exports : & ' a FxHashMap < CrateType , Vec < String > > ,
1222- ) -> WasmLd < ' a > {
1175+ fn new ( mut cmd : Command , sess : & ' a Session ) -> WasmLd < ' a > {
12231176 // If the atomics feature is enabled for wasm then we need a whole bunch
12241177 // of flags:
12251178 //
@@ -1252,7 +1205,7 @@ impl<'a> WasmLd<'a> {
12521205 cmd. arg ( "--export=__tls_align" ) ;
12531206 cmd. arg ( "--export=__tls_base" ) ;
12541207 }
1255- WasmLd { cmd, sess, exports }
1208+ WasmLd { cmd, sess }
12561209 }
12571210}
12581211
@@ -1368,8 +1321,8 @@ impl<'a> Linker for WasmLd<'a> {
13681321
13691322 fn no_default_libraries ( & mut self ) { }
13701323
1371- fn export_symbols ( & mut self , _tmpdir : & Path , crate_type : CrateType ) {
1372- for sym in self . exports [ & crate_type ] . iter ( ) {
1324+ fn export_symbols ( & mut self , _tmpdir : & Path , _crate_type : CrateType , symbols : & [ String ] ) {
1325+ for sym in symbols {
13731326 self . cmd . arg ( "--export" ) . arg ( & sym) ;
13741327 }
13751328
@@ -1392,7 +1345,7 @@ impl<'a> Linker for WasmLd<'a> {
13921345 }
13931346}
13941347
1395- fn exported_symbols ( tcx : TyCtxt < ' _ > , crate_type : CrateType ) -> Vec < String > {
1348+ pub ( crate ) fn exported_symbols ( tcx : TyCtxt < ' _ > , crate_type : CrateType ) -> Vec < String > {
13961349 if let Some ( ref exports) = tcx. sess . target . override_export_symbols {
13971350 return exports. clone ( ) ;
13981351 }
@@ -1521,7 +1474,7 @@ impl<'a> Linker for PtxLinker<'a> {
15211474
15221475 fn control_flow_guard ( & mut self ) { }
15231476
1524- fn export_symbols ( & mut self , _tmpdir : & Path , _crate_type : CrateType ) { }
1477+ fn export_symbols ( & mut self , _tmpdir : & Path , _crate_type : CrateType , _symbols : & [ String ] ) { }
15251478
15261479 fn subsystem ( & mut self , _subsystem : & str ) { }
15271480
@@ -1535,7 +1488,6 @@ impl<'a> Linker for PtxLinker<'a> {
15351488pub struct BpfLinker < ' a > {
15361489 cmd : Command ,
15371490 sess : & ' a Session ,
1538- exports : & ' a FxHashMap < CrateType , Vec < String > > ,
15391491}
15401492
15411493impl < ' a > Linker for BpfLinker < ' a > {
@@ -1622,11 +1574,11 @@ impl<'a> Linker for BpfLinker<'a> {
16221574
16231575 fn control_flow_guard ( & mut self ) { }
16241576
1625- fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType ) {
1577+ fn export_symbols ( & mut self , tmpdir : & Path , _crate_type : CrateType , symbols : & [ String ] ) {
16261578 let path = tmpdir. join ( "symbols" ) ;
16271579 let res: io:: Result < ( ) > = try {
16281580 let mut f = BufWriter :: new ( File :: create ( & path) ?) ;
1629- for sym in self . exports [ & crate_type ] . iter ( ) {
1581+ for sym in symbols {
16301582 writeln ! ( f, "{}" , sym) ?;
16311583 }
16321584 } ;
0 commit comments