File tree 1 file changed +28
-11
lines changed
compiler/rustc_codegen_ssa/src/back
1 file changed +28
-11
lines changed Original file line number Diff line number Diff line change @@ -219,19 +219,36 @@ pub struct GccLinker<'a> {
219
219
}
220
220
221
221
impl < ' a > GccLinker < ' a > {
222
- /// Argument that must be passed * directly* to the linker
222
+ /// Passes an argument directly to the linker.
223
223
///
224
- /// These arguments need to be prepended with `-Wl`, when a GCC-style linker is used.
225
- fn linker_arg < S > ( & mut self , arg : S ) -> & mut Self
226
- where
227
- S : AsRef < OsStr > ,
228
- {
229
- if !self . is_ld {
230
- let mut os = OsString :: from ( "-Wl," ) ;
231
- os. push ( arg. as_ref ( ) ) ;
232
- self . cmd . arg ( os) ;
224
+ /// When the linker is not ld-like such as when using a compiler as a linker, the argument is
225
+ /// prepended by `-Wl,`.
226
+ fn linker_arg ( & mut self , arg : impl AsRef < OsStr > ) -> & mut Self {
227
+ self . linker_args ( & [ arg] ) ;
228
+ self
229
+ }
230
+
231
+ /// Passes a series of arguments directly to the linker.
232
+ ///
233
+ /// When the linker is ld-like, the arguments are simply appended to the command. When the
234
+ /// linker is not ld-like such as when using a compiler as a linker, the arguments are joined by
235
+ /// commas to form an argument that is then prepended with `-Wl`. In this situation, only a
236
+ /// single argument is appended to the command to ensure that the order of the arguments is
237
+ /// preserved by the compiler.
238
+ fn linker_args ( & mut self , args : & [ impl AsRef < OsStr > ] ) -> & mut Self {
239
+ if self . is_ld {
240
+ args. into_iter ( ) . for_each ( |a| {
241
+ self . cmd . arg ( a) ;
242
+ } ) ;
233
243
} else {
234
- self . cmd . arg ( arg) ;
244
+ if !args. is_empty ( ) {
245
+ let mut s = OsString :: from ( "-Wl" ) ;
246
+ for a in args {
247
+ s. push ( "," ) ;
248
+ s. push ( a) ;
249
+ }
250
+ self . cmd . arg ( s) ;
251
+ }
235
252
}
236
253
self
237
254
}
You can’t perform that action at this time.
0 commit comments