@@ -531,19 +531,37 @@ fn check_for_buggy_ld_version(sess: &Session,
531
531
532
532
debug ! ( "check_for_buggy_ld_version out: {:?}" , out) ;
533
533
534
- let parse = |first_line : & str | -> Option < ( u32 , u32 ) > {
535
- let suffix = first_line. splitn ( 2 , "GNU ld version " ) . last ( ) ?;
536
- let version_components: Vec < _ > = suffix. split ( '.' ) . collect ( ) ;
537
- let major: u32 = version_components. get ( 0 ) ?. parse ( ) . ok ( ) ?;
538
- let minor: u32 = version_components. get ( 1 ) ?. parse ( ) . ok ( ) ?;
539
- Some ( ( major, minor) )
534
+ let first_line = match out. lines ( ) . next ( ) {
535
+ Some ( line) => line,
536
+ None => {
537
+ sess. warn ( & format ! ( "Linker version inspection had no lines of output: `{}`" ,
538
+ version_check_invocation) ) ;
539
+ return ;
540
+ }
540
541
} ;
541
-
542
- let first_line = out. lines ( ) . next ( ) ;
543
-
544
542
debug ! ( "check_for_buggy_ld_version first_line: {:?}" , first_line) ;
545
543
546
- let ( major, minor) = match first_line. and_then ( parse) {
544
+ let version_suffix_start = match first_line. find ( " 2." ) {
545
+ None => {
546
+ // if we cannot find ` 2.`, then assume that this an ld version that
547
+ // does not have the bug; no need for warning.
548
+ return ;
549
+ }
550
+ Some ( space_version_start) => {
551
+ // skip the space character so we are looking at "2.x.y-zzz"
552
+ space_version_start + 1
553
+ }
554
+ } ;
555
+ let version_suffix = & first_line[ version_suffix_start..] ;
556
+ debug ! ( "check_for_buggy_ld_version version_suffix: {:?}" , version_suffix) ;
557
+
558
+ let parse = |suffix : & str | -> Option < ( u32 , u32 ) > {
559
+ let mut components = suffix. split ( '.' ) ;
560
+ let major: u32 = components. next ( ) ?. parse ( ) . ok ( ) ?;
561
+ let minor: u32 = components. next ( ) ?. parse ( ) . ok ( ) ?;
562
+ Some ( ( major, minor) )
563
+ } ;
564
+ let ( major, minor) = match parse ( version_suffix) {
547
565
None => {
548
566
sess. warn ( & format ! ( "Linker version inspection failed to parse: `{}`, output: {}" ,
549
567
version_check_invocation, out) ) ;
@@ -558,7 +576,7 @@ fn check_for_buggy_ld_version(sess: &Session,
558
576
if is_old_buggy_version {
559
577
let diag = sess. diagnostic ( ) ;
560
578
diag. warn ( & format ! ( "Using linker `{}` with Rust dynamic libraries has known bugs." ,
561
- first_line. unwrap ( ) ) ) ;
579
+ first_line) ) ;
562
580
diag. note_without_error (
563
581
"Consider upgrading to GNU ld version 2.29 or newer, or using a different linker." ) ;
564
582
diag. note_without_error (
0 commit comments