@@ -32,6 +32,7 @@ use cc::windows_registry;
3232use object:: elf;
3333use object:: write:: Object ;
3434use object:: { Architecture , BinaryFormat , Endianness , FileFlags , SectionFlags , SectionKind } ;
35+ use regex:: Regex ;
3536use tempfile:: Builder as TempFileBuilder ;
3637
3738use 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