@@ -10,7 +10,6 @@ use std::io::{self, BufWriter};
10
10
use std:: path:: { Path , PathBuf } ;
11
11
use std:: { env, mem, str} ;
12
12
13
- use rustc_data_structures:: fx:: FxHashMap ;
14
13
use rustc_hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
15
14
use rustc_middle:: middle:: dependency_format:: Linkage ;
16
15
use rustc_middle:: ty:: TyCtxt ;
@@ -36,28 +35,6 @@ pub fn disable_localization(linker: &mut Command) {
36
35
linker. env ( "VSLANG" , "1033" ) ;
37
36
}
38
37
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
-
61
38
// The third parameter is for env vars, used on windows to set up the
62
39
// path for MSVC to find its DLLs, and gcc to find its bundled
63
40
// toolchain
@@ -66,7 +43,7 @@ pub fn get_linker<'a>(
66
43
linker : & Path ,
67
44
flavor : LinkerFlavor ,
68
45
self_contained : bool ,
69
- info : & ' a LinkerInfo ,
46
+ target_cpu : & ' a str ,
70
47
) -> Box < dyn Linker + ' a > {
71
48
let msvc_tool = windows_registry:: find_tool ( & sess. opts . target_triple . triple ( ) , "link.exe" ) ;
72
49
@@ -153,40 +130,26 @@ pub fn get_linker<'a>(
153
130
154
131
match flavor {
155
132
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 >
157
134
}
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 >
160
139
}
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 > ,
169
140
170
141
LinkerFlavor :: Lld ( LldFlavor :: Ld )
171
142
| 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 >
183
146
}
184
147
148
+ LinkerFlavor :: Lld ( LldFlavor :: Wasm ) => Box :: new ( WasmLd :: new ( cmd, sess) ) as Box < dyn Linker > ,
149
+
185
150
LinkerFlavor :: PtxLinker => Box :: new ( PtxLinker { cmd, sess } ) as Box < dyn Linker > ,
186
151
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 > ,
190
153
}
191
154
}
192
155
@@ -222,7 +185,7 @@ pub trait Linker {
222
185
fn debuginfo ( & mut self , strip : Strip ) ;
223
186
fn no_crt_objects ( & mut self ) ;
224
187
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 ] ) ;
226
189
fn subsystem ( & mut self , subsystem : & str ) ;
227
190
fn group_start ( & mut self ) ;
228
191
fn group_end ( & mut self ) ;
@@ -250,7 +213,6 @@ impl dyn Linker + '_ {
250
213
pub struct GccLinker < ' a > {
251
214
cmd : Command ,
252
215
sess : & ' a Session ,
253
- exports : & ' a FxHashMap < CrateType , Vec < String > > ,
254
216
target_cpu : & ' a str ,
255
217
hinted_static : bool , // Keeps track of the current hinting mode.
256
218
// Link as ld
@@ -655,7 +617,7 @@ impl<'a> Linker for GccLinker<'a> {
655
617
}
656
618
}
657
619
658
- fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType ) {
620
+ fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType , symbols : & [ String ] ) {
659
621
// Symbol visibility in object files typically takes care of this.
660
622
if crate_type == CrateType :: Executable && self . sess . target . override_export_symbols . is_none ( )
661
623
{
@@ -684,7 +646,7 @@ impl<'a> Linker for GccLinker<'a> {
684
646
// Write a plain, newline-separated list of symbols
685
647
let res: io:: Result < ( ) > = try {
686
648
let mut f = BufWriter :: new ( File :: create ( & path) ?) ;
687
- for sym in self . exports [ & crate_type ] . iter ( ) {
649
+ for sym in symbols {
688
650
debug ! ( " _{}" , sym) ;
689
651
writeln ! ( f, "_{}" , sym) ?;
690
652
}
@@ -699,7 +661,7 @@ impl<'a> Linker for GccLinker<'a> {
699
661
// .def file similar to MSVC one but without LIBRARY section
700
662
// because LD doesn't like when it's empty
701
663
writeln ! ( f, "EXPORTS" ) ?;
702
- for symbol in self . exports [ & crate_type ] . iter ( ) {
664
+ for symbol in symbols {
703
665
debug ! ( " _{}" , symbol) ;
704
666
writeln ! ( f, " {}" , symbol) ?;
705
667
}
@@ -712,9 +674,9 @@ impl<'a> Linker for GccLinker<'a> {
712
674
let res: io:: Result < ( ) > = try {
713
675
let mut f = BufWriter :: new ( File :: create ( & path) ?) ;
714
676
writeln ! ( f, "{{" ) ?;
715
- if !self . exports [ & crate_type ] . is_empty ( ) {
677
+ if !symbols . is_empty ( ) {
716
678
writeln ! ( f, " global:" ) ?;
717
- for sym in self . exports [ & crate_type ] . iter ( ) {
679
+ for sym in symbols {
718
680
debug ! ( " {};" , sym) ;
719
681
writeln ! ( f, " {};" , sym) ?;
720
682
}
@@ -814,7 +776,6 @@ impl<'a> Linker for GccLinker<'a> {
814
776
pub struct MsvcLinker < ' a > {
815
777
cmd : Command ,
816
778
sess : & ' a Session ,
817
- exports : & ' a FxHashMap < CrateType , Vec < String > > ,
818
779
}
819
780
820
781
impl < ' a > Linker for MsvcLinker < ' a > {
@@ -988,7 +949,7 @@ impl<'a> Linker for MsvcLinker<'a> {
988
949
// crates. Upstream rlibs may be linked statically to this dynamic library,
989
950
// in which case they may continue to transitively be used and hence need
990
951
// 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 ] ) {
992
953
// Symbol visibility takes care of this typically
993
954
if crate_type == CrateType :: Executable {
994
955
return ;
@@ -1002,7 +963,7 @@ impl<'a> Linker for MsvcLinker<'a> {
1002
963
// straight to exports.
1003
964
writeln ! ( f, "LIBRARY" ) ?;
1004
965
writeln ! ( f, "EXPORTS" ) ?;
1005
- for symbol in self . exports [ & crate_type ] . iter ( ) {
966
+ for symbol in symbols {
1006
967
debug ! ( " _{}" , symbol) ;
1007
968
writeln ! ( f, " {}" , symbol) ?;
1008
969
}
@@ -1055,7 +1016,6 @@ impl<'a> Linker for MsvcLinker<'a> {
1055
1016
pub struct EmLinker < ' a > {
1056
1017
cmd : Command ,
1057
1018
sess : & ' a Session ,
1058
- exports : & ' a FxHashMap < CrateType , Vec < String > > ,
1059
1019
}
1060
1020
1061
1021
impl < ' a > Linker for EmLinker < ' a > {
@@ -1167,9 +1127,7 @@ impl<'a> Linker for EmLinker<'a> {
1167
1127
self . cmd . args ( & [ "-s" , "DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[]" ] ) ;
1168
1128
}
1169
1129
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 ] ) {
1173
1131
debug ! ( "EXPORTED SYMBOLS:" ) ;
1174
1132
1175
1133
self . cmd . arg ( "-s" ) ;
@@ -1211,15 +1169,10 @@ impl<'a> Linker for EmLinker<'a> {
1211
1169
pub struct WasmLd < ' a > {
1212
1170
cmd : Command ,
1213
1171
sess : & ' a Session ,
1214
- exports : & ' a FxHashMap < CrateType , Vec < String > > ,
1215
1172
}
1216
1173
1217
1174
impl < ' 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 > {
1223
1176
// If the atomics feature is enabled for wasm then we need a whole bunch
1224
1177
// of flags:
1225
1178
//
@@ -1252,7 +1205,7 @@ impl<'a> WasmLd<'a> {
1252
1205
cmd. arg ( "--export=__tls_align" ) ;
1253
1206
cmd. arg ( "--export=__tls_base" ) ;
1254
1207
}
1255
- WasmLd { cmd, sess, exports }
1208
+ WasmLd { cmd, sess }
1256
1209
}
1257
1210
}
1258
1211
@@ -1368,8 +1321,8 @@ impl<'a> Linker for WasmLd<'a> {
1368
1321
1369
1322
fn no_default_libraries ( & mut self ) { }
1370
1323
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 {
1373
1326
self . cmd . arg ( "--export" ) . arg ( & sym) ;
1374
1327
}
1375
1328
@@ -1392,7 +1345,7 @@ impl<'a> Linker for WasmLd<'a> {
1392
1345
}
1393
1346
}
1394
1347
1395
- fn exported_symbols ( tcx : TyCtxt < ' _ > , crate_type : CrateType ) -> Vec < String > {
1348
+ pub ( crate ) fn exported_symbols ( tcx : TyCtxt < ' _ > , crate_type : CrateType ) -> Vec < String > {
1396
1349
if let Some ( ref exports) = tcx. sess . target . override_export_symbols {
1397
1350
return exports. clone ( ) ;
1398
1351
}
@@ -1521,7 +1474,7 @@ impl<'a> Linker for PtxLinker<'a> {
1521
1474
1522
1475
fn control_flow_guard ( & mut self ) { }
1523
1476
1524
- fn export_symbols ( & mut self , _tmpdir : & Path , _crate_type : CrateType ) { }
1477
+ fn export_symbols ( & mut self , _tmpdir : & Path , _crate_type : CrateType , _symbols : & [ String ] ) { }
1525
1478
1526
1479
fn subsystem ( & mut self , _subsystem : & str ) { }
1527
1480
@@ -1535,7 +1488,6 @@ impl<'a> Linker for PtxLinker<'a> {
1535
1488
pub struct BpfLinker < ' a > {
1536
1489
cmd : Command ,
1537
1490
sess : & ' a Session ,
1538
- exports : & ' a FxHashMap < CrateType , Vec < String > > ,
1539
1491
}
1540
1492
1541
1493
impl < ' a > Linker for BpfLinker < ' a > {
@@ -1622,11 +1574,11 @@ impl<'a> Linker for BpfLinker<'a> {
1622
1574
1623
1575
fn control_flow_guard ( & mut self ) { }
1624
1576
1625
- fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType ) {
1577
+ fn export_symbols ( & mut self , tmpdir : & Path , _crate_type : CrateType , symbols : & [ String ] ) {
1626
1578
let path = tmpdir. join ( "symbols" ) ;
1627
1579
let res: io:: Result < ( ) > = try {
1628
1580
let mut f = BufWriter :: new ( File :: create ( & path) ?) ;
1629
- for sym in self . exports [ & crate_type ] . iter ( ) {
1581
+ for sym in symbols {
1630
1582
writeln ! ( f, "{}" , sym) ?;
1631
1583
}
1632
1584
} ;
0 commit comments