@@ -276,18 +276,27 @@ impl<'a> Linker for GccLinker<'a> {
276276 fn set_output_kind ( & mut self , output_kind : LinkOutputKind , out_filename : & Path ) {
277277 match output_kind {
278278 LinkOutputKind :: DynamicNoPicExe => {
279- if !self . is_ld && self . sess . target . linker_is_gnu {
279+ if !self . is_ld
280+ && self . sess . target . linker_is_gnu
281+ && !self . sess . target . is_like_windows
282+ {
280283 self . cmd . arg ( "-no-pie" ) ;
281284 }
282285 }
283286 LinkOutputKind :: DynamicPicExe => {
284- // `-pie` works for both gcc wrapper and ld.
285- self . cmd . arg ( "-pie" ) ;
287+ // noop on windows w/ gcc & ld, error w/ lld
288+ if !self . sess . target . is_like_windows {
289+ // `-pie` works for both gcc wrapper and ld
290+ self . cmd . arg ( "-pie" ) ;
291+ }
286292 }
287293 LinkOutputKind :: StaticNoPicExe => {
288294 // `-static` works for both gcc wrapper and ld.
289295 self . cmd . arg ( "-static" ) ;
290- if !self . is_ld && self . sess . target . linker_is_gnu {
296+ if !self . is_ld
297+ && self . sess . target . linker_is_gnu
298+ && !self . sess . target . is_like_windows
299+ {
291300 self . cmd . arg ( "-no-pie" ) ;
292301 }
293302 }
@@ -347,7 +356,7 @@ impl<'a> Linker for GccLinker<'a> {
347356 // has -needed-l{} / -needed_library {}
348357 // but we have no way to detect that here.
349358 self . sess . warn ( "`as-needed` modifier not implemented yet for ld64" ) ;
350- } else if self . sess . target . linker_is_gnu {
359+ } else if self . sess . target . linker_is_gnu && ! self . sess . target . is_like_windows {
351360 self . linker_arg ( "--no-as-needed" ) ;
352361 } else {
353362 self . sess . warn ( "`as-needed` modifier not supported for current linker" ) ;
@@ -358,7 +367,7 @@ impl<'a> Linker for GccLinker<'a> {
358367 if !as_needed {
359368 if self . sess . target . is_like_osx {
360369 // See above FIXME comment
361- } else if self . sess . target . linker_is_gnu {
370+ } else if self . sess . target . linker_is_gnu && ! self . sess . target . is_like_windows {
362371 self . linker_arg ( "--as-needed" ) ;
363372 }
364373 }
@@ -690,7 +699,7 @@ impl<'a> Linker for GccLinker<'a> {
690699 }
691700
692701 fn add_as_needed ( & mut self ) {
693- if self . sess . target . linker_is_gnu {
702+ if self . sess . target . linker_is_gnu && ! self . sess . target . is_like_windows {
694703 self . linker_arg ( "--as-needed" ) ;
695704 } else if self . sess . target . is_like_solaris {
696705 // -z ignore is the Solaris equivalent to the GNU ld --as-needed option
0 commit comments