diff --git a/src/librustc_trans/back/command.rs b/src/librustc_trans/back/command.rs index 3b765a493e0e..0bccef1e62a8 100644 --- a/src/librustc_trans/back/command.rs +++ b/src/librustc_trans/back/command.rs @@ -109,6 +109,10 @@ impl Command { // extensions + pub fn get_args(&self) -> &[OsString] { + &self.args + } + pub fn take_args(&mut self) -> Vec { mem::replace(&mut self.args, Vec::new()) } diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index d15450212ae3..6f8b425ad56d 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -668,7 +668,9 @@ fn link_natively(sess: &Session, // is safe because if the linker doesn't support -no-pie then it should not // default to linking executables as pie. Different versions of gcc seem to // use different quotes in the error message so don't check for them. - if out.contains("unrecognized command line option") && out.contains("-no-pie") { + if out.contains("unrecognized command line option") && + out.contains("-no-pie") && + cmd.get_args().iter().any(|e| e.to_string_lossy() == "-no-pie") { info!("linker output: {:?}", out); warn!("Linker does not support -no-pie command line option. Retrying without."); for arg in cmd.take_args() {