@@ -131,17 +131,22 @@ pub struct GccLinker<'a> {
131
131
impl < ' a > GccLinker < ' a > {
132
132
/// Argument that must be passed *directly* to the linker
133
133
///
134
- /// These arguments need to be prepended with '-Wl,' when a gcc-style linker is used
134
+ /// These arguments need to be preceded by '-Xlinker' when a gcc-style
135
+ /// linker is used.
135
136
fn linker_arg < S > ( & mut self , arg : S ) -> & mut Self
136
137
where S : AsRef < OsStr >
137
138
{
138
139
if !self . is_ld {
139
- let mut os = OsString :: from ( "-Wl," ) ;
140
- os. push ( arg. as_ref ( ) ) ;
141
- self . cmd . arg ( os) ;
142
- } else {
143
- self . cmd . arg ( arg) ;
140
+ self . cmd . arg ( "-Xlinker" ) ;
144
141
}
142
+ self . cmd . arg ( arg) ;
143
+ self
144
+ }
145
+
146
+ fn add_lib < S : AsRef < OsStr > > ( & mut self , lib : S ) -> & mut Self {
147
+ let mut os = OsString :: from ( "-l" ) ;
148
+ os. push ( lib. as_ref ( ) ) ;
149
+ self . cmd . arg ( os) ;
145
150
self
146
151
}
147
152
@@ -171,8 +176,8 @@ impl<'a> GccLinker<'a> {
171
176
}
172
177
173
178
impl < ' a > Linker for GccLinker < ' a > {
174
- fn link_dylib ( & mut self , lib : & str ) { self . hint_dynamic ( ) ; self . cmd . arg ( "-l" ) . arg ( lib) ; }
175
- fn link_staticlib ( & mut self , lib : & str ) { self . hint_static ( ) ; self . cmd . arg ( "-l" ) . arg ( lib) ; }
179
+ fn link_dylib ( & mut self , lib : & str ) { self . hint_dynamic ( ) ; self . add_lib ( lib) ; }
180
+ fn link_staticlib ( & mut self , lib : & str ) { self . hint_static ( ) ; self . add_lib ( lib) ; }
176
181
fn link_rlib ( & mut self , lib : & Path ) { self . hint_static ( ) ; self . cmd . arg ( lib) ; }
177
182
fn include_path ( & mut self , path : & Path ) { self . cmd . arg ( "-L" ) . arg ( path) ; }
178
183
fn framework_path ( & mut self , path : & Path ) { self . cmd . arg ( "-F" ) . arg ( path) ; }
@@ -182,11 +187,15 @@ impl<'a> Linker for GccLinker<'a> {
182
187
fn partial_relro ( & mut self ) { self . linker_arg ( "-z,relro" ) ; }
183
188
fn full_relro ( & mut self ) { self . linker_arg ( "-z,relro,-z,now" ) ; }
184
189
fn build_static_executable ( & mut self ) { self . cmd . arg ( "-static" ) ; }
185
- fn args ( & mut self , args : & [ String ] ) { self . cmd . args ( args) ; }
190
+ fn args ( & mut self , args : & [ String ] ) {
191
+ for arg in args {
192
+ self . linker_arg ( arg) ;
193
+ }
194
+ }
186
195
187
196
fn link_rust_dylib ( & mut self , lib : & str , _path : & Path ) {
188
197
self . hint_dynamic ( ) ;
189
- self . cmd . arg ( "-l" ) . arg ( lib) ;
198
+ self . add_lib ( lib) ;
190
199
}
191
200
192
201
fn link_framework ( & mut self , framework : & str ) {
@@ -202,25 +211,22 @@ impl<'a> Linker for GccLinker<'a> {
202
211
// functions, etc.
203
212
fn link_whole_staticlib ( & mut self , lib : & str , search_path : & [ PathBuf ] ) {
204
213
self . hint_static ( ) ;
205
- let target = & self . sess . target . target ;
206
- if !target. options . is_like_osx {
207
- self . linker_arg ( "--whole-archive" ) . cmd . arg ( "-l" ) . arg ( lib) ;
208
- self . linker_arg ( "--no-whole-archive" ) ;
214
+ if self . sess . target . target . options . is_like_osx {
215
+ self . linker_arg ( "-force_load" ) ;
216
+ // let-binding needed to appease borrowck.
217
+ let lib = archive:: find_library ( lib, search_path, & self . sess ) ;
218
+ self . linker_arg ( lib) ;
209
219
} else {
210
- // -force_load is the macOS equivalent of --whole-archive, but it
211
- // involves passing the full path to the library to link.
212
- let mut v = OsString :: from ( "-force_load," ) ;
213
- v. push ( & archive:: find_library ( lib, search_path, & self . sess ) ) ;
214
- self . linker_arg ( & v) ;
220
+ self . linker_arg ( "--whole-archive" ) . add_lib ( lib) ;
221
+ self . linker_arg ( "--no-whole-archive" ) ;
215
222
}
216
223
}
217
224
218
225
fn link_whole_rlib ( & mut self , lib : & Path ) {
219
226
self . hint_static ( ) ;
220
227
if self . sess . target . target . options . is_like_osx {
221
- let mut v = OsString :: from ( "-force_load," ) ;
222
- v. push ( lib) ;
223
- self . linker_arg ( & v) ;
228
+ self . linker_arg ( "-force_load" ) ;
229
+ self . linker_arg ( lib) ;
224
230
} else {
225
231
self . linker_arg ( "--whole-archive" ) . cmd . arg ( lib) ;
226
232
self . linker_arg ( "--no-whole-archive" ) ;
@@ -282,16 +288,16 @@ impl<'a> Linker for GccLinker<'a> {
282
288
fn build_dylib ( & mut self , out_filename : & Path ) {
283
289
// On mac we need to tell the linker to let this library be rpathed
284
290
if self . sess . target . target . options . is_like_osx {
285
- self . cmd . arg ( "-dynamiclib" ) ;
286
291
self . linker_arg ( "-dylib" ) ;
287
292
288
293
// Note that the `osx_rpath_install_name` option here is a hack
289
294
// purely to support rustbuild right now, we should get a more
290
295
// principled solution at some point to force the compiler to pass
291
- // the right `-Wl,- install_name` with an `@rpath` in it.
296
+ // the right `-install_name` with an `@rpath` in it.
292
297
if self . sess . opts . cg . rpath ||
293
298
self . sess . opts . debugging_opts . osx_rpath_install_name {
294
- let mut v = OsString :: from ( "-install_name,@rpath/" ) ;
299
+ self . linker_arg ( "-install_name" ) ;
300
+ let mut v = OsString :: from ( "@rpath/" ) ;
295
301
v. push ( out_filename. file_name ( ) . unwrap ( ) ) ;
296
302
self . linker_arg ( & v) ;
297
303
}
@@ -313,7 +319,6 @@ impl<'a> Linker for GccLinker<'a> {
313
319
return
314
320
}
315
321
316
- let mut arg = OsString :: new ( ) ;
317
322
let path = tmpdir. join ( "list" ) ;
318
323
319
324
debug ! ( "EXPORTED SYMBOLS:" ) ;
@@ -349,24 +354,16 @@ impl<'a> Linker for GccLinker<'a> {
349
354
}
350
355
351
356
if self . sess . target . target . options . is_like_osx {
352
- if !self . is_ld {
353
- arg. push ( "-Wl," )
354
- }
355
- arg. push ( "-exported_symbols_list," ) ;
357
+ self . linker_arg ( "-exported_symbols_list" ) ;
358
+ self . linker_arg ( & path) ;
356
359
} else if self . sess . target . target . options . is_like_solaris {
357
- if !self . is_ld {
358
- arg. push ( "-Wl," )
359
- }
360
- arg. push ( "-M," ) ;
360
+ self . linker_arg ( "-M" ) ;
361
+ self . linker_arg ( & path) ;
361
362
} else {
362
- if !self . is_ld {
363
- arg. push ( "-Wl," )
364
- }
365
- arg. push ( "--version-script=" ) ;
363
+ let mut arg = OsString :: from ( "--version-script=" ) ;
364
+ arg. push ( & path) ;
365
+ self . linker_arg ( & arg) ;
366
366
}
367
-
368
- arg. push ( & path) ;
369
- self . cmd . arg ( arg) ;
370
367
}
371
368
372
369
fn subsystem ( & mut self , subsystem : & str ) {
0 commit comments