@@ -37,12 +37,14 @@ pub fn disable_localization(linker: &mut Command) {
37
37
/// need out of the shared crate context before we get rid of it.
38
38
#[ derive( Encodable , Decodable ) ]
39
39
pub struct LinkerInfo {
40
+ target_cpu : String ,
40
41
exports : FxHashMap < CrateType , Vec < String > > ,
41
42
}
42
43
43
44
impl LinkerInfo {
44
- pub fn new ( tcx : TyCtxt < ' _ > ) -> LinkerInfo {
45
+ pub fn new ( tcx : TyCtxt < ' _ > , target_cpu : String ) -> LinkerInfo {
45
46
LinkerInfo {
47
+ target_cpu,
46
48
exports : tcx
47
49
. sess
48
50
. crate_types ( )
@@ -57,38 +59,31 @@ impl LinkerInfo {
57
59
cmd : Command ,
58
60
sess : & ' a Session ,
59
61
flavor : LinkerFlavor ,
60
- target_cpu : & ' a str ,
61
62
) -> Box < dyn Linker + ' a > {
62
63
match flavor {
63
64
LinkerFlavor :: Lld ( LldFlavor :: Link ) | LinkerFlavor :: Msvc => {
64
65
Box :: new ( MsvcLinker { cmd, sess, info : self } ) as Box < dyn Linker >
65
66
}
66
67
LinkerFlavor :: Em => Box :: new ( EmLinker { cmd, sess, info : self } ) as Box < dyn Linker > ,
67
- LinkerFlavor :: Gcc => Box :: new ( GccLinker {
68
- cmd,
69
- sess,
70
- info : self ,
71
- hinted_static : false ,
72
- is_ld : false ,
73
- target_cpu,
74
- } ) as Box < dyn Linker > ,
68
+ LinkerFlavor :: Gcc => {
69
+ Box :: new ( GccLinker { cmd, sess, info : self , hinted_static : false , is_ld : false } )
70
+ as Box < dyn Linker >
71
+ }
75
72
76
73
LinkerFlavor :: Lld ( LldFlavor :: Ld )
77
74
| LinkerFlavor :: Lld ( LldFlavor :: Ld64 )
78
- | LinkerFlavor :: Ld => Box :: new ( GccLinker {
79
- cmd,
80
- sess,
81
- info : self ,
82
- hinted_static : false ,
83
- is_ld : true ,
84
- target_cpu,
85
- } ) as Box < dyn Linker > ,
75
+ | LinkerFlavor :: Ld => {
76
+ Box :: new ( GccLinker { cmd, sess, info : self , hinted_static : false , is_ld : true } )
77
+ as Box < dyn Linker >
78
+ }
86
79
87
80
LinkerFlavor :: Lld ( LldFlavor :: Wasm ) => {
88
81
Box :: new ( WasmLd :: new ( cmd, sess, self ) ) as Box < dyn Linker >
89
82
}
90
83
91
- LinkerFlavor :: PtxLinker => Box :: new ( PtxLinker { cmd, sess } ) as Box < dyn Linker > ,
84
+ LinkerFlavor :: PtxLinker => {
85
+ Box :: new ( PtxLinker { cmd, sess, info : self } ) as Box < dyn Linker >
86
+ }
92
87
}
93
88
}
94
89
}
@@ -157,7 +152,6 @@ pub struct GccLinker<'a> {
157
152
hinted_static : bool , // Keeps track of the current hinting mode.
158
153
// Link as ld
159
154
is_ld : bool ,
160
- target_cpu : & ' a str ,
161
155
}
162
156
163
157
impl < ' a > GccLinker < ' a > {
@@ -229,8 +223,7 @@ impl<'a> GccLinker<'a> {
229
223
} ;
230
224
231
225
self . linker_arg ( & format ! ( "-plugin-opt={}" , opt_level) ) ;
232
- let target_cpu = self . target_cpu ;
233
- self . linker_arg ( & format ! ( "-plugin-opt=mcpu={}" , target_cpu) ) ;
226
+ self . linker_arg ( & format ! ( "-plugin-opt=mcpu={}" , self . info. target_cpu) ) ;
234
227
}
235
228
236
229
fn build_dylib ( & mut self , out_filename : & Path ) {
@@ -1336,6 +1329,7 @@ fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
1336
1329
pub struct PtxLinker < ' a > {
1337
1330
cmd : Command ,
1338
1331
sess : & ' a Session ,
1332
+ info : & ' a LinkerInfo ,
1339
1333
}
1340
1334
1341
1335
impl < ' a > Linker for PtxLinker < ' a > {
@@ -1381,10 +1375,7 @@ impl<'a> Linker for PtxLinker<'a> {
1381
1375
1382
1376
fn finalize ( & mut self ) {
1383
1377
// Provide the linker with fallback to internal `target-cpu`.
1384
- self . cmd . arg ( "--fallback-arch" ) . arg ( match self . sess . opts . cg . target_cpu {
1385
- Some ( ref s) => s,
1386
- None => & self . sess . target . cpu ,
1387
- } ) ;
1378
+ self . cmd . arg ( "--fallback-arch" ) . arg ( & self . info . target_cpu ) ;
1388
1379
}
1389
1380
1390
1381
fn link_dylib ( & mut self , _lib : Symbol , _verbatim : bool , _as_needed : bool ) {
0 commit comments