Skip to content

Commit f9dde54

Browse files
authored
Rollup merge of #106489 - jschwe:fix_linker_detection, r=petrochenkov
Fix linker detection for linker (drivers) with a version postfix (e.g. clang-12 instead of clang) Linker (drivers) such as clang / gcc or lld often have a version postfix matching the regex "-\d+$". Previously, linker detection did not account for the possible version postfix and the fallback value was used, which can cause linker errors due to wrong arguments. Also remove the check for `-clang`, since there are no architecture specific variants of clang (to my knowledge). Fixes #106454
2 parents 1dc43b2 + 3bc2970 commit f9dde54

File tree

1 file changed

+10
-1
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+10
-1
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1231,12 +1231,21 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
12311231
sess.emit_fatal(errors::LinkerFileStem);
12321232
});
12331233

1234+
// Remove any version postfix.
1235+
let stem = stem
1236+
.rsplit_once('-')
1237+
.and_then(|(lhs, rhs)| rhs.chars().all(char::is_numeric).then_some(lhs))
1238+
.unwrap_or(stem);
1239+
1240+
// GCC can have an optional target prefix.
12341241
let flavor = if stem == "emcc" {
12351242
LinkerFlavor::EmCc
12361243
} else if stem == "gcc"
12371244
|| stem.ends_with("-gcc")
1245+
|| stem == "g++"
1246+
|| stem.ends_with("-g++")
12381247
|| stem == "clang"
1239-
|| stem.ends_with("-clang")
1248+
|| stem == "clang++"
12401249
{
12411250
LinkerFlavor::from_cli(LinkerFlavorCli::Gcc, &sess.target)
12421251
} else if stem == "wasm-ld" || stem.ends_with("-wasm-ld") {

0 commit comments

Comments
 (0)