mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 05:51:58 +00:00
Allow more "unknown argument" strings from linker
Some toolchains emit slightly different errors, e.g. ppc-vle-gcc: error: unrecognized option '-no-pie'
This commit is contained in:
parent
f3f8e758f2
commit
32992357eb
@ -3649,6 +3649,7 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"object 0.25.2",
|
"object 0.25.2",
|
||||||
"pathdiff",
|
"pathdiff",
|
||||||
|
"regex",
|
||||||
"rustc_apfloat",
|
"rustc_apfloat",
|
||||||
"rustc_ast",
|
"rustc_ast",
|
||||||
"rustc_attr",
|
"rustc_attr",
|
||||||
|
@ -17,6 +17,7 @@ jobserver = "0.1.22"
|
|||||||
tempfile = "3.2"
|
tempfile = "3.2"
|
||||||
pathdiff = "0.2.0"
|
pathdiff = "0.2.0"
|
||||||
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
|
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
|
||||||
|
regex = "1.4"
|
||||||
|
|
||||||
rustc_serialize = { path = "../rustc_serialize" }
|
rustc_serialize = { path = "../rustc_serialize" }
|
||||||
rustc_ast = { path = "../rustc_ast" }
|
rustc_ast = { path = "../rustc_ast" }
|
||||||
|
@ -32,6 +32,7 @@ use cc::windows_registry;
|
|||||||
use object::elf;
|
use object::elf;
|
||||||
use object::write::Object;
|
use object::write::Object;
|
||||||
use object::{Architecture, BinaryFormat, Endianness, FileFlags, SectionFlags, SectionKind};
|
use object::{Architecture, BinaryFormat, Endianness, FileFlags, SectionFlags, SectionKind};
|
||||||
|
use regex::Regex;
|
||||||
use tempfile::Builder as TempFileBuilder;
|
use tempfile::Builder as TempFileBuilder;
|
||||||
|
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
@ -672,6 +673,8 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||||||
// Invoke the system linker
|
// Invoke the system linker
|
||||||
info!("{:?}", &cmd);
|
info!("{:?}", &cmd);
|
||||||
let retry_on_segfault = env::var("RUSTC_RETRY_LINKER_ON_SEGFAULT").is_ok();
|
let retry_on_segfault = env::var("RUSTC_RETRY_LINKER_ON_SEGFAULT").is_ok();
|
||||||
|
let unknown_arg_regex =
|
||||||
|
Regex::new(r"(unknown|unrecognized) (command line )?(option|argument)").unwrap();
|
||||||
let mut prog;
|
let mut prog;
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
loop {
|
loop {
|
||||||
@ -688,16 +691,15 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||||||
out.extend(&output.stdout);
|
out.extend(&output.stdout);
|
||||||
let out = String::from_utf8_lossy(&out);
|
let out = String::from_utf8_lossy(&out);
|
||||||
|
|
||||||
// Check to see if the link failed with "unrecognized command line option:
|
// Check to see if the link failed with an error message that indicates it
|
||||||
// '-no-pie'" for gcc or "unknown argument: '-no-pie'" for clang. If so,
|
// doesn't recognize the -no-pie option. If so, reperform the link step
|
||||||
// reperform the link step without the -no-pie option. This is safe because
|
// without it. This is safe because if the linker doesn't support -no-pie
|
||||||
// if the linker doesn't support -no-pie then it should not default to
|
// then it should not default to linking executables as pie. Different
|
||||||
// linking executables as pie. Different versions of gcc seem to use
|
// versions of gcc seem to use different quotes in the error message so
|
||||||
// different quotes in the error message so don't check for them.
|
// don't check for them.
|
||||||
if sess.target.linker_is_gnu
|
if sess.target.linker_is_gnu
|
||||||
&& flavor != LinkerFlavor::Ld
|
&& flavor != LinkerFlavor::Ld
|
||||||
&& (out.contains("unrecognized command line option")
|
&& unknown_arg_regex.is_match(&out)
|
||||||
|| out.contains("unknown argument"))
|
|
||||||
&& out.contains("-no-pie")
|
&& out.contains("-no-pie")
|
||||||
&& cmd.get_args().iter().any(|e| e.to_string_lossy() == "-no-pie")
|
&& cmd.get_args().iter().any(|e| e.to_string_lossy() == "-no-pie")
|
||||||
{
|
{
|
||||||
@ -716,8 +718,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||||||
// Fallback from '-static-pie' to '-static' in that case.
|
// Fallback from '-static-pie' to '-static' in that case.
|
||||||
if sess.target.linker_is_gnu
|
if sess.target.linker_is_gnu
|
||||||
&& flavor != LinkerFlavor::Ld
|
&& flavor != LinkerFlavor::Ld
|
||||||
&& (out.contains("unrecognized command line option")
|
&& unknown_arg_regex.is_match(&out)
|
||||||
|| out.contains("unknown argument"))
|
|
||||||
&& (out.contains("-static-pie") || out.contains("--no-dynamic-linker"))
|
&& (out.contains("-static-pie") || out.contains("--no-dynamic-linker"))
|
||||||
&& cmd.get_args().iter().any(|e| e.to_string_lossy() == "-static-pie")
|
&& cmd.get_args().iter().any(|e| e.to_string_lossy() == "-static-pie")
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user