-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Support -Clink-self-contained=+linker
for ld.lld
linker flavor
#140813
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
base: master
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Support `-Clink-self-contained=+linker` for `ld.lld` linker flavor When using an `ld.lld` linker flavor, rustc will invoke lld directly. This PR adds support to choose `rust-lld` instead of the system lld when the self-contained linker is enabled (on the CLI or by the target). There's some slight wrinkle/cycle here: inferring whether self-contained linking is enabled needs to know the linker (on mingw), but to choose the linker (rust-lld instead of lld) we need to know if the self-contained linker is enabled... So I only check for explicit self-contained linking components in the target (without the inference implied by the `LinkSelfContainedDefault` infra), as well as the CLI. That seems fine?. The linker command and binary is usually hidden by rustc so while I'm not enamored by the test, it feels slightly cleaner than parsing rustc's debug logs looking for the linker that is invoked. r? ghost try-job: dist-x86_64-linux
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
@bors try |
Support `-Clink-self-contained=+linker` for `ld.lld` linker flavor When using an `ld.lld` linker flavor, rustc will invoke lld directly. This PR adds support to choose `rust-lld` instead of the system lld when the self-contained linker is enabled (on the CLI or by the target). There's some slight wrinkle/cycle here: inferring whether self-contained linking is enabled needs to know the linker (on mingw), but to choose the linker (rust-lld instead of lld) we need to know if the self-contained linker is enabled... So I only check for explicit self-contained linking components in the target (without the inference implied by the `LinkSelfContainedDefault` infra), as well as the CLI. That seems fine? The linker command and binary is usually hidden by rustc so while I'm not enamored with the test looking for the linker name from a forced linking error, it feels cleaner/easier/more sensible/more stable than parsing rustc's _debug logs_ looking for the linker that is invoked in the command we log. Since this is somewhat of a stabilization concern for x64 linux, I focused on the `Gnu(Cc::No, Lld::Yes)` flavor, where we know it works, and not the other target-specific `Lld::Yes` flavors. We already support extending the $PATH with the needed directories when the linker is `rust-lld` so this makes use of that, and it should work on more targets (that we're not stabilizing). r? ghost try-job: x86_64-gnu try-job: x86_64-gnu-stable try-job: x86_64-gnu-aux try-job: x86_64-gnu-debug
☀️ Try build successful - checks-actions |
Some changes occurred in compiler/rustc_codegen_ssa This PR modifies cc @jieyouxu |
I don't think changing the linker name to I would expect I'd also want to migrate all the bare metal targets from using |
let self_contained_linker = (self_contained_cli.is_linker_enabled() | ||
|| self_contained_target) | ||
&& !self_contained_cli.is_linker_disabled(); | ||
if self_contained_linker { "rust-lld" } else { "lld" } |
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.
With mingw in particular this logic + logic in detect_self_contained_mingw
mean that self-contained=+linker
always turns into self-contained=yes
:D
Updating |
I don't see how that would work since rustc calls the |
Ah, right we are using UPD: Calling (There's also always an option to keep the non-default option combinations unstable to avoid changes before stabilization.) |
Yeah also changing the normal linker invocation last minute feels a bit rushed. We can take more time for analysis and tests to do that. Here, it felt acceptable because it starts from an unstable situation and most things still internally still rely on rust-lld (to the detriment of possibly breaking mingw as you pointed out above).
That's interesting. Something like only stabilizing (I guess there's also the option of only stabilizing the opt-outs, to go back to the pre-stabilization state, but not the opt-ins. That's a bit less appealing than the previous idea.) |
When using an
ld.lld
linker flavor, rustc will invoke lld directly. This PR adds support to chooserust-lld
instead of the system lld when the self-contained linker is enabled (on the CLI or by the target).There's some slight wrinkle/cycle here: inferring whether self-contained linking is enabled needs to know the linker (on mingw), but to choose the linker (rust-lld instead of lld) we need to know if the self-contained linker is enabled... So I only check for explicit self-contained linking components in the target (without the inference implied by the
LinkSelfContainedDefault
infra), as well as the CLI. That seems fine?The linker command and binary is usually hidden by rustc so while I'm not enamored with the test looking for the linker name from a forced linking error, it feels cleaner/easier/more sensible/more stable than parsing rustc's debug logs looking for the linker that is invoked in the command we log.
Since this is somewhat of a stabilization concern for x64 linux, I focused on the
Gnu(Cc::No, Lld::Yes)
flavor, where we know it works, and not the other target-specificLld::Yes
flavors. We already support extending the $PATH with the needed directories when the linker isrust-lld
so this makes use of that, and it should work on more targets (that we're not stabilizing).r? @petrochenkov
try-job: x86_64-gnu
try-job: x86_64-gnu-stable
try-job: x86_64-gnu-aux
try-job: x86_64-gnu-debug