Skip to content

Commit 357542f

Browse files
committed
revised version parsing to handle arbitrary leading strings, rather than assuming it starts with "GNU ld version "
1 parent a29d805 commit 357542f

File tree

1 file changed

+29
-11
lines changed
  • src/librustc_codegen_ssa/back

1 file changed

+29
-11
lines changed

src/librustc_codegen_ssa/back/link.rs

+29-11
Original file line numberDiff line numberDiff line change
@@ -531,19 +531,37 @@ fn check_for_buggy_ld_version(sess: &Session,
531531

532532
debug!("check_for_buggy_ld_version out: {:?}", out);
533533

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+
}
540541
};
541-
542-
let first_line = out.lines().next();
543-
544542
debug!("check_for_buggy_ld_version first_line: {:?}", first_line);
545543

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) {
547565
None => {
548566
sess.warn(&format!("Linker version inspection failed to parse: `{}`, output: {}",
549567
version_check_invocation, out));
@@ -558,7 +576,7 @@ fn check_for_buggy_ld_version(sess: &Session,
558576
if is_old_buggy_version {
559577
let diag = sess.diagnostic();
560578
diag.warn(&format!("Using linker `{}` with Rust dynamic libraries has known bugs.",
561-
first_line.unwrap()));
579+
first_line));
562580
diag.note_without_error(
563581
"Consider upgrading to GNU ld version 2.29 or newer, or using a different linker.");
564582
diag.note_without_error(

0 commit comments

Comments
 (0)