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
This commit is contained in:
Matthias Krüger 2023-01-13 19:16:42 +01:00 committed by GitHub
commit f9dde54a11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1231,12 +1231,21 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
sess.emit_fatal(errors::LinkerFileStem); sess.emit_fatal(errors::LinkerFileStem);
}); });
// Remove any version postfix.
let stem = stem
.rsplit_once('-')
.and_then(|(lhs, rhs)| rhs.chars().all(char::is_numeric).then_some(lhs))
.unwrap_or(stem);
// GCC can have an optional target prefix.
let flavor = if stem == "emcc" { let flavor = if stem == "emcc" {
LinkerFlavor::EmCc LinkerFlavor::EmCc
} else if stem == "gcc" } else if stem == "gcc"
|| stem.ends_with("-gcc") || stem.ends_with("-gcc")
|| stem == "g++"
|| stem.ends_with("-g++")
|| stem == "clang" || stem == "clang"
|| stem.ends_with("-clang") || stem == "clang++"
{ {
LinkerFlavor::from_cli(LinkerFlavorCli::Gcc, &sess.target) LinkerFlavor::from_cli(LinkerFlavorCli::Gcc, &sess.target)
} else if stem == "wasm-ld" || stem.ends_with("-wasm-ld") { } else if stem == "wasm-ld" || stem.ends_with("-wasm-ld") {