Skip to content
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

Infer Lld::No linker hint when the linker stem is a generic compiler driver #114711

Merged
merged 2 commits into from
Aug 15, 2023

Conversation

lqd
Copy link
Member

@lqd lqd commented Aug 10, 2023

This PR basically reverts the temporary solution in #113631 to a more long-term solution.

r? @petrochenkov

In this comment, you had ideas about a long-term solution:

I wonder what a good non-temporary solution for the inference would look like.

* If the default is `(Cc::No, Lld::Yes)` (e.g. `rust-lld`)
  
  * and we switch to some specific platform compiler (e.g. `-C linker=arm-none-eabi-gcc`), should we change to `Lld::No`? Maybe yes?
  * and we switch to some non-default but generic compiler `-C linker=clang`? Then maybe not?

* If the default is `(Cc::Yes, Lld::Yes)` (e.g. future x86_64 linux with default LLD)
  
  * and we switch to some specific platform compiler (e.g. `-C linker=arm-none-eabi-gcc`), should we change to `Lld::No`? Maybe yes?
  * and we switch to some non-default but generic compiler `-C linker=clang`? Then maybe not?

I believe that we should infer the Lld::No linker hint for any -Clinker override, and all the cases above:

  • the linker drivers have their own defaults, so in my mind -Clinker is a signal to use its default linker / flavor, rather than ours or the target's. In the case of generic compilers, it's more likely than not going to be Lld::No. I would expect this to be the case in general, even when including platform-specific compilers.
  • the guess will be wrong if the linker driver uses lld by default (and we also don't want to search for -fuse-ld link args), but will work in the more common cases. And the minority of other cases can fix the wrong guess by opting into the precise linker flavor.
  • this also ensures backwards-compatibility: today, even on targets with an lld default and overriding the linker, rustc will not use lld. That includes thumbv6m-none-eabi where issue Regression when using linker=arm-none-eabi-gcc #113597 happened.

It looks like the simplest option, and the one with least churn: we maintain the current behavior in ambiguous cases.

I've tested that this works on #113597, as expected from the failure.

(I also have a no-std run-make test using a custom target json spec: basically simulating a future x86_64-unknown-linux-gnu using an lld flavor by default, to check that e.g. -Clinker=clang doesn't use lld. I could add that test to this PR, but IIUC such a custom target requires cargo -Z build-std and we have no tests depending on this cargo feature yet. Let me know if you want to add this test of the linker inference for such targets.)

What do you think ?

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 10, 2023
@rustbot
Copy link
Collaborator

rustbot commented Aug 10, 2023

These commits modify compiler targets.
(See the Target Tier Policy.)

@petrochenkov
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 15, 2023

📌 Commit 498d656 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 15, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 15, 2023
Infer `Lld::No` linker hint when the linker stem is a generic compiler driver

This PR basically reverts the temporary solution in rust-lang#113631 to a more long-term solution.

r? `@petrochenkov`

In [this comment](rust-lang#113631 (comment)), you had ideas about a long-term solution:

> I wonder what a good non-temporary solution for the inference would look like.
>
>     * If the default is `(Cc::No, Lld::Yes)` (e.g. `rust-lld`)
>
>       * and we switch to some specific platform compiler (e.g. `-C linker=arm-none-eabi-gcc`), should we change to `Lld::No`? Maybe yes?
>       * and we switch to some non-default but generic compiler `-C linker=clang`? Then maybe not?
>
>     * If the default is `(Cc::Yes, Lld::Yes)` (e.g. future x86_64 linux with default LLD)
>
>       * and we switch to some specific platform compiler (e.g. `-C linker=arm-none-eabi-gcc`), should we change to `Lld::No`? Maybe yes?
>       * and we switch to some non-default but generic compiler `-C linker=clang`? Then maybe not?
>

I believe that we should infer the `Lld::No` linker hint for any `-Clinker` override, and all the cases above:
- the linker drivers have their own defaults, so in my mind `-Clinker` is a signal to use its default linker / flavor, rather than ours or the target's. In the case of generic compilers, it's more likely than not going to be `Lld::No`. I would expect this to be the case in general, even when including platform-specific compilers.
- the guess will be wrong if the linker driver uses lld by default (and we also don't want to search for `-fuse-ld` link args), but will work in the more common cases. And the minority of other cases can fix the wrong guess by opting into the precise linker flavor.
- this also ensures backwards-compatibility: today, even on targets with an lld default and overriding the linker, rustc will not use lld. That includes `thumbv6m-none-eabi` where issue rust-lang#113597 happened.

It looks like the simplest option, and the one with least churn: we maintain the current behavior in ambiguous cases.

I've tested that this works on rust-lang#113597, as expected from the failure.

(I also have a no-std `run-make` test using a custom target json spec: basically simulating a future `x86_64-unknown-linux-gnu` using an lld flavor by default, to check that  e.g. `-Clinker=clang` doesn't use lld. I could add that test to this PR, but IIUC such a custom target requires `cargo -Z build-std` and we have no tests depending on this cargo feature yet. Let me know if you want to add this test of the linker inference for such targets.)

What do you think ?
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 15, 2023
…llaumeGomez

Rollup of 10 pull requests

Successful merges:

 - rust-lang#114711 (Infer `Lld::No` linker hint when the linker stem is a generic compiler driver)
 - rust-lang#114772 (Add `{Local}ModDefId` to more strongly type DefIds`)
 - rust-lang#114800 (std: add some missing repr(transparent))
 - rust-lang#114820 (Add test for unknown_lints from another file.)
 - rust-lang#114825 (Upgrade std to gimli 0.28.0)
 - rust-lang#114827 (Only consider object candidates for object-safe dyn types in new solver)
 - rust-lang#114828 (Probe when assembling upcast candidates so they don't step on eachother's toes in new solver)
 - rust-lang#114829 (Separate `consider_unsize_to_dyn_candidate` from other unsize candidates)
 - rust-lang#114830 (Clean up some bad UI testing annotations)
 - rust-lang#114831 (Check projection args before substitution in new solver)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f929741 into rust-lang:master Aug 15, 2023
11 checks passed
@rustbot rustbot added this to the 1.73.0 milestone Aug 15, 2023
@lqd lqd deleted the linker-inference branch August 15, 2023 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants