Skip to content

Commit 6648385

Browse files
committed
rustc: Update linker flavor inference from filename
This commit fixes what is believed to be a preexisting bug in the linker flavor inference and additionally adds a new features. Previously if the linker didn't end in `exe` the entire file name was compared to infer the linker's flavor. This commit fixes the code to instead unconditionally inspect `file_stem()` which is the relevant part we're looking at to figure out what the linker flavor is. Additionally this commit now also adds recognition of `clang` and clang wrappers that end in `-clang` (which look like gcc wrappers). This should allow clang-specific wrappers to get correctly inferred to the `Gcc` linker flavor rather than the default linker flavor configured for a target.
1 parent 7a4df3b commit 6648385

File tree

1 file changed

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

1 file changed

+11
-8
lines changed

Diff for: src/librustc_codegen_ssa/back/link.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,20 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
152152
LinkerFlavor::PtxLinker => "rust-ptx-linker",
153153
}), flavor)),
154154
(Some(linker), None) => {
155-
let stem = if linker.extension().and_then(|ext| ext.to_str()) == Some("exe") {
156-
linker.file_stem().and_then(|stem| stem.to_str())
157-
} else {
158-
linker.to_str()
159-
}.unwrap_or_else(|| {
160-
sess.fatal("couldn't extract file stem from specified linker");
161-
}).to_owned();
155+
let stem = linker
156+
.file_stem()
157+
.and_then(|stem| stem.to_str())
158+
.unwrap_or_else(|| {
159+
sess.fatal("couldn't extract file stem from specified linker")
160+
});
162161

163162
let flavor = if stem == "emcc" {
164163
LinkerFlavor::Em
165-
} else if stem == "gcc" || stem.ends_with("-gcc") {
164+
} else if stem == "gcc"
165+
|| stem.ends_with("-gcc")
166+
|| stem == "clang"
167+
|| stem.ends_with("-clang")
168+
{
166169
LinkerFlavor::Gcc
167170
} else if stem == "ld" || stem == "ld.lld" || stem.ends_with("-ld") {
168171
LinkerFlavor::Ld

0 commit comments

Comments
 (0)