-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[WIP] Infer linker-flavor from the selected linker #50359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ use syntax::{ast, codemap}; | |
use syntax::feature_gate::AttributeType; | ||
use syntax_pos::{MultiSpan, Span}; | ||
|
||
use rustc_target::spec::{LinkerFlavor, PanicStrategy}; | ||
use rustc_target::spec::{LldFlavor, LinkerFlavor, PanicStrategy}; | ||
use rustc_target::spec::{Target, TargetTriple}; | ||
use rustc_data_structures::flock; | ||
use jobserver::Client; | ||
|
@@ -600,11 +600,51 @@ impl Session { | |
.panic | ||
.unwrap_or(self.target.target.options.panic_strategy) | ||
} | ||
pub fn linker_flavor(&self) -> LinkerFlavor { | ||
|
||
fn linker(&self) -> &str { | ||
self.opts | ||
.debugging_opts | ||
.linker_flavor | ||
.unwrap_or(self.target.target.linker_flavor) | ||
.cg | ||
.linker | ||
.as_ref() | ||
.and_then(|l| l.file_name()) | ||
.and_then(|l| l.to_str()) | ||
.unwrap_or_else(|| { | ||
self.target.target.options.linker.as_ref().map(|l| &**l).unwrap_or_else(|| { | ||
"cc" | ||
}) | ||
}) | ||
} | ||
|
||
pub fn linker_flavor(&self) -> LinkerFlavor { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the main change but the logic probably doesn't work correctly on Windows because of the .exe suffix. |
||
self.opts.debugging_opts.linker_flavor.unwrap_or_else(|| { | ||
let linker = self.linker(); | ||
|
||
if linker.ends_with("gcc") { // e.g. `arm-none-eabi-gcc` | ||
LinkerFlavor::Gcc | ||
} else if linker == "lld" || linker == "rustc-lld" { | ||
let flavor = if self.target.target.target_os == "macos" { | ||
LldFlavor::Ld64 | ||
} else if self.target.target.target_env == "msvc" { | ||
LldFlavor::Link | ||
} else if self.target.target.arch.starts_with("wasm") { | ||
LldFlavor::Wasm | ||
} else { | ||
// most likely ELF output | ||
LldFlavor::Ld | ||
}; | ||
|
||
LinkerFlavor::Lld(flavor) | ||
} else if linker.ends_with("ld") || // e.g. `arm-none-eabi-ld` | ||
linker.starts_with("ld.") { // e.g. `ld.lld` or `ld.gold` | ||
LinkerFlavor::Ld | ||
} else if linker == "emcc" { | ||
LinkerFlavor::Em | ||
} else if linker == "link.exe" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
LinkerFlavor::Msvc | ||
} else { | ||
LinkerFlavor::Gcc | ||
} | ||
}) | ||
} | ||
|
||
pub fn fewer_names(&self) -> bool { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK there's not actually any reason these methods have to live in librustc, if you'd like feel free to delete them here and move the wholesale into librustc_trans
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think this method looks mostly correct except for the last part. We'll probably want to rename this to something like
linker_file_stem
and then make sure you use thefile_stem
method ofPath
at the end to remove bat/exe suffixes