@@ -196,6 +196,14 @@ pub trait Linker {
196
196
fn add_no_exec ( & mut self ) { }
197
197
fn add_as_needed ( & mut self ) { }
198
198
fn reset_per_library_state ( & mut self ) { }
199
+ fn linker_arg ( & mut self , arg : & OsStr , verbatim : bool ) {
200
+ self . linker_args ( & [ arg] , verbatim) ;
201
+ }
202
+ fn linker_args ( & mut self , args : & [ & OsStr ] , _verbatim : bool ) {
203
+ args. into_iter ( ) . for_each ( |a| {
204
+ self . cmd ( ) . arg ( a) ;
205
+ } ) ;
206
+ }
199
207
}
200
208
201
209
impl dyn Linker + ' _ {
@@ -223,38 +231,12 @@ pub struct GccLinker<'a> {
223
231
}
224
232
225
233
impl < ' a > GccLinker < ' a > {
226
- /// Passes an argument directly to the linker.
227
- ///
228
- /// When the linker is not ld-like such as when using a compiler as a linker, the argument is
229
- /// prepended by `-Wl,`.
230
- fn linker_arg ( & mut self , arg : impl AsRef < OsStr > ) -> & mut Self {
231
- self . linker_args ( & [ arg] ) ;
232
- self
234
+ fn linker_arg ( & mut self , arg : impl AsRef < OsStr > ) {
235
+ Linker :: linker_arg ( self , arg. as_ref ( ) , false ) ;
233
236
}
234
-
235
- /// Passes a series of arguments directly to the linker.
236
- ///
237
- /// When the linker is ld-like, the arguments are simply appended to the command. When the
238
- /// linker is not ld-like such as when using a compiler as a linker, the arguments are joined by
239
- /// commas to form an argument that is then prepended with `-Wl`. In this situation, only a
240
- /// single argument is appended to the command to ensure that the order of the arguments is
241
- /// preserved by the compiler.
242
- fn linker_args ( & mut self , args : & [ impl AsRef < OsStr > ] ) -> & mut Self {
243
- if self . is_ld {
244
- args. into_iter ( ) . for_each ( |a| {
245
- self . cmd . arg ( a) ;
246
- } ) ;
247
- } else {
248
- if !args. is_empty ( ) {
249
- let mut s = OsString :: from ( "-Wl" ) ;
250
- for a in args {
251
- s. push ( "," ) ;
252
- s. push ( a) ;
253
- }
254
- self . cmd . arg ( s) ;
255
- }
256
- }
257
- self
237
+ fn linker_args ( & mut self , args : & [ impl AsRef < OsStr > ] ) {
238
+ let args_vec: Vec < & OsStr > = args. iter ( ) . map ( |x| x. as_ref ( ) ) . collect ( ) ;
239
+ Linker :: linker_args ( self , & args_vec, false ) ;
258
240
}
259
241
260
242
fn takes_hints ( & self ) -> bool {
@@ -361,6 +343,30 @@ impl<'a> GccLinker<'a> {
361
343
}
362
344
363
345
impl < ' a > Linker for GccLinker < ' a > {
346
+ /// Passes a series of arguments directly to the linker.
347
+ ///
348
+ /// When the linker is ld-like, the arguments are simply appended to the command. When the
349
+ /// linker is not ld-like such as when using a compiler as a linker, the arguments are joined by
350
+ /// commas to form an argument that is then prepended with `-Wl`. In this situation, only a
351
+ /// single argument is appended to the command to ensure that the order of the arguments is
352
+ /// preserved by the compiler.
353
+ fn linker_args ( & mut self , args : & [ & OsStr ] , verbatim : bool ) {
354
+ if self . is_ld || verbatim {
355
+ args. into_iter ( ) . for_each ( |a| {
356
+ self . cmd . arg ( a) ;
357
+ } ) ;
358
+ } else {
359
+ if !args. is_empty ( ) {
360
+ let mut s = OsString :: from ( "-Wl" ) ;
361
+ for a in args {
362
+ s. push ( "," ) ;
363
+ s. push ( a) ;
364
+ }
365
+ self . cmd . arg ( s) ;
366
+ }
367
+ }
368
+ }
369
+
364
370
fn cmd ( & mut self ) -> & mut Command {
365
371
& mut self . cmd
366
372
}
@@ -531,7 +537,7 @@ impl<'a> Linker for GccLinker<'a> {
531
537
self . linker_arg ( "-force_load" ) ;
532
538
self . linker_arg ( & lib) ;
533
539
} else {
534
- self . linker_arg ( "--whole-archive" ) . cmd . arg ( lib ) ;
540
+ self . linker_args ( & [ OsString :: from ( "--whole-archive" ) , lib . into ( ) ] ) ;
535
541
self . linker_arg ( "--no-whole-archive" ) ;
536
542
}
537
543
}
0 commit comments