@@ -32,6 +32,7 @@ use cc::windows_registry;
32
32
use object:: elf;
33
33
use object:: write:: Object ;
34
34
use object:: { Architecture , BinaryFormat , Endianness , FileFlags , SectionFlags , SectionKind } ;
35
+ use regex:: Regex ;
35
36
use tempfile:: Builder as TempFileBuilder ;
36
37
37
38
use std:: ffi:: OsString ;
@@ -672,6 +673,8 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
672
673
// Invoke the system linker
673
674
info ! ( "{:?}" , & cmd) ;
674
675
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 ( ) ;
675
678
let mut prog;
676
679
let mut i = 0 ;
677
680
loop {
@@ -688,16 +691,15 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
688
691
out. extend ( & output. stdout ) ;
689
692
let out = String :: from_utf8_lossy ( & out) ;
690
693
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.
697
700
if sess. target . linker_is_gnu
698
701
&& flavor != LinkerFlavor :: Ld
699
- && ( out. contains ( "unrecognized command line option" )
700
- || out. contains ( "unknown argument" ) )
702
+ && unknown_arg_regex. is_match ( & out)
701
703
&& out. contains ( "-no-pie" )
702
704
&& cmd. get_args ( ) . iter ( ) . any ( |e| e. to_string_lossy ( ) == "-no-pie" )
703
705
{
@@ -716,8 +718,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
716
718
// Fallback from '-static-pie' to '-static' in that case.
717
719
if sess. target . linker_is_gnu
718
720
&& flavor != LinkerFlavor :: Ld
719
- && ( out. contains ( "unrecognized command line option" )
720
- || out. contains ( "unknown argument" ) )
721
+ && unknown_arg_regex. is_match ( & out)
721
722
&& ( out. contains ( "-static-pie" ) || out. contains ( "--no-dynamic-linker" ) )
722
723
&& cmd. get_args ( ) . iter ( ) . any ( |e| e. to_string_lossy ( ) == "-static-pie" )
723
724
{
0 commit comments