diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-01-13 19:16:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-13 19:16:42 +0100 |
| commit | f9dde54a11e166a8d217db9190f6bb59e54924ad (patch) | |
| tree | 749284a011a3fcc50b0b8a90f3ccca56feccba49 /compiler/rustc_codegen_ssa/src | |
| parent | 1dc43b2e8b5faba0a5a5c7eb899e6f63e654e46c (diff) | |
| parent | 3bc2970a2e5f80f04ac2c1b1c1e4ec06a001f151 (diff) | |
| download | rust-f9dde54a11e166a8d217db9190f6bb59e54924ad.tar.gz rust-f9dde54a11e166a8d217db9190f6bb59e54924ad.zip | |
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
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/link.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 8ca7103ed48..342abf81f6a 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1231,12 +1231,21 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) { 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" { LinkerFlavor::EmCc } else if stem == "gcc" || stem.ends_with("-gcc") + || stem == "g++" + || stem.ends_with("-g++") || stem == "clang" - || stem.ends_with("-clang") + || stem == "clang++" { LinkerFlavor::from_cli(LinkerFlavorCli::Gcc, &sess.target) } else if stem == "wasm-ld" || stem.ends_with("-wasm-ld") { |
