Skip to content

Commit d4ad1cf

Browse files
committed
Auto merge of #87641 - HackAttack:expand-unknown-option-message, r=wesleywiser
Allow more "unknown argument" strings from linker Some toolchains emit slightly different errors, e.g. ppc-vle-gcc: error: unrecognized option '-no-pie'
2 parents 25b7648 + 3299235 commit d4ad1cf

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3649,6 +3649,7 @@ dependencies = [
36493649
"libc",
36503650
"object 0.25.2",
36513651
"pathdiff",
3652+
"regex",
36523653
"rustc_apfloat",
36533654
"rustc_ast",
36543655
"rustc_attr",

compiler/rustc_codegen_ssa/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobserver = "0.1.22"
1616
tempfile = "3.2"
1717
pathdiff = "0.2.0"
1818
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
19+
regex = "1.4"
1920

2021
rustc_serialize = { path = "../rustc_serialize" }
2122
rustc_ast = { path = "../rustc_ast" }

compiler/rustc_codegen_ssa/src/back/link.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use cc::windows_registry;
3232
use object::elf;
3333
use object::write::Object;
3434
use object::{Architecture, BinaryFormat, Endianness, FileFlags, SectionFlags, SectionKind};
35+
use regex::Regex;
3536
use tempfile::Builder as TempFileBuilder;
3637

3738
use std::ffi::OsString;
@@ -672,6 +673,8 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
672673
// Invoke the system linker
673674
info!("{:?}", &cmd);
674675
let retry_on_segfault = env::var("RUSTC_RETRY_LINKER_ON_SEGFAULT").is_ok();
676+
let unknown_arg_regex =
677+
Regex::new(r"(unknown|unrecognized) (command line )?(option|argument)").unwrap();
675678
let mut prog;
676679
let mut i = 0;
677680
loop {
@@ -688,16 +691,15 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
688691
out.extend(&output.stdout);
689692
let out = String::from_utf8_lossy(&out);
690693

691-
// Check to see if the link failed with "unrecognized command line option:
692-
// '-no-pie'" for gcc or "unknown argument: '-no-pie'" for clang. If so,
693-
// reperform the link step without the -no-pie option. This is safe because
694-
// if the linker doesn't support -no-pie then it should not default to
695-
// linking executables as pie. Different versions of gcc seem to use
696-
// different quotes in the error message so don't check for them.
694+
// Check to see if the link failed with an error message that indicates it
695+
// doesn't recognize the -no-pie option. If so, reperform the link step
696+
// without it. This is safe because if the linker doesn't support -no-pie
697+
// then it should not default to linking executables as pie. Different
698+
// versions of gcc seem to use different quotes in the error message so
699+
// don't check for them.
697700
if sess.target.linker_is_gnu
698701
&& flavor != LinkerFlavor::Ld
699-
&& (out.contains("unrecognized command line option")
700-
|| out.contains("unknown argument"))
702+
&& unknown_arg_regex.is_match(&out)
701703
&& out.contains("-no-pie")
702704
&& cmd.get_args().iter().any(|e| e.to_string_lossy() == "-no-pie")
703705
{
@@ -716,8 +718,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
716718
// Fallback from '-static-pie' to '-static' in that case.
717719
if sess.target.linker_is_gnu
718720
&& flavor != LinkerFlavor::Ld
719-
&& (out.contains("unrecognized command line option")
720-
|| out.contains("unknown argument"))
721+
&& unknown_arg_regex.is_match(&out)
721722
&& (out.contains("-static-pie") || out.contains("--no-dynamic-linker"))
722723
&& cmd.get_args().iter().any(|e| e.to_string_lossy() == "-static-pie")
723724
{

0 commit comments

Comments
 (0)