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

Implement -Zgcc-ld=lld stabilization MCP #96401

Closed
wants to merge 18 commits into from
Closed

Conversation

lqd
Copy link
Member

@lqd lqd commented Apr 25, 2022

This PR is a draft implementation of MCP #510 to stabilize -Zgcc-ld=lld as -Clink-self-contained=linker -Clinker-flavor=gcc:lld.

The changes to the -Clink-self-contained and -Clinker-flavor flags described below are tentative, currently protected by -Z unstable-options to gather feedback on nightly, and subject to FCP (either in this PR or when they are truly stabilized when removing the -Z unstable-options check).


1. -C link-self-contained

Today, -C link-self-contained is a tristate bool, whose default value is determined by the current target spec. The on and off values force the rust-provided CRT objects to be linked.

The way to choose the target-defined behavior is to omit the flag, there is no value one can use.

Proposed behavior: to model using a rust-provided linker (like rust-lld), a new value -C link-self-contained=linker is added. This flag becomes a bit more complex, controlling two facets: the CRT linking, and the use of a rustup linker.

In order to not change stable behavior:

  • -C link-self-contained=y still targets only the CRT linking (although it can be argued that this could opt in to both)
  • -C link-self-contained=n disables both
  • -C link-self-contained=linker turns on the linker facet, but keeps the default CRT facet
  • a value reifying the current default, to make it explicit for the future: -C link-self-contained=auto. If linker ever becomes a default, this would allow to turn off the linker facet while still keeping the target-defined CRT-linking behavior. Otherwise, the fact that this value is only available when the flag is absent will prevent picking it explicitly.
  • depending on whether we'd want -C link-self-contained=y to mean a single or both facets, a value like -C link-self-contained=crt would be useful if linker ever became the default: this would allow to turn off the linker facet while opting into the CRT-linking.
  • turning both on with -C link-self-contained=all. We had discussed e.g. -C link-self-contained=crt,linker, but without a way or need to turn off CRT-linking while enabling the linker (a use-case -C link-self-contained=linker would serve most of the time, as the CRT-linking is only enabled in a very limited number or targets) it doesn't seem that useful to specify both as crt,linker. If we need a way to do so, then -C link-self-contained=crt,linker and e.g. -C link-self-contained=no-crt,linker could be used.
2. -C linker-flavor

Today, -C linker-flavor is a list of flavor mappings (LinkerFlavors) that target specs can use.

Proposed behavior: these stable values are retained, but a new extensible one is added for the gcc flavor: gcc:*. The gcc: prefix would allow to specify a linker for cc to use, much like one would add a -fuse-ld link-arg today: -C linker-flavor=gcc:lld would be a thin wrapper over that, and pass -fuse-ld=lld to the cc process.

3. -C linker-flavor=gcc:lld -C link-self-contained=linker

This is the combination that allows using rust-lld, by providing either -fuse-ld or -B with the sysroot path containing the lld-wrappers that will launch rust-lld.


Opening as draft for discussion about:

  • the naming of the options and structures, for the two flags
  • the new behavior of -Clink-self-contained described above: the individual and aggregate opt-ins and opt-outs, making sure that stable behavior is preserved, and that there are adequate options to keep the stable behavior if linker becomes a default one day
  • the zulip thread mentioned opportunities for cleanups but I'm not 100% sure what they are, but they can probably be done in follow-up PRs.

and because:

  • I wonder what should we do on windows gnu ? Since IIUC it supports a gcc linker-flavor (and rust-lld already with -C linker=rust-lld). Maybe nothing in particular
  • and how/if we need to mention the unstable values in the --help text or wait for when we'll drop the -Z unstable-options requirement ?
  • I'm not sure about some of the run-make tests, maybe some need to be more constrained (e.g. linux only), and would love feedback about them

r? @ghost

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 25, 2022
@lqd lqd force-pushed the lld_mcp branch 2 times, most recently from 16f42bb to 56dee54 Compare April 26, 2022 22:06
@rust-log-analyzer

This comment was marked as resolved.

lqd added 14 commits April 27, 2022 22:03
Distro builds don't distribute it by default, and can't use
`-Clink-self-contained=linker -Clinker-flavor=gcc:lld` to
enable it.
only the stable values for `-Clinker-flavor` and `-Clink-self-contained`
can be used on stable until we have more feedback on the interface
These values require using `-Z unstable options`
…` match

currently only "lld" is usable in this context
ensures that the wrapped linker is indeed passed straight to cc
using the `-C linker-flavor=gcc:lld -C link-self-contained=linker` stable flags
@petrochenkov
Copy link
Contributor

I understand that the PR is intended to show the final state of the feature, but for actually landing this I'd strongly prefer to implement the orthogonal parts as separate PRs, the -C linker-flavor part first, and then -C self-contained second, then I'll be able to review these parts.

@lqd
Copy link
Member Author

lqd commented May 6, 2022

Thanks a bunch @petrochenkov, I will separate these in different PRs.

@lqd
Copy link
Member Author

lqd commented May 7, 2022

I've extracted the -Clinker-flavor=gcc:* changes into #96827.

@lqd
Copy link
Member Author

lqd commented May 9, 2022

I've now extracted the -Clink-self-contained changes into #96884. It's sill not the +/- list you'd like to see, but I figured we would finalize these details, and some possible target-specific behavior, on the PR.

Would you prefer I add the change that make use of both flags to trigger using rust-lld in these other PRs, or rather update this one with the remaining commits and tests, once the other 2 PRs land ?

@bors
Copy link
Contributor

bors commented May 21, 2022

☔ The latest upstream changes (presumably #97239) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 21, 2022
@Dylan-DPC
Copy link
Member

@lqd @petrochenkov any updates on this?

@Dylan-DPC
Copy link
Member

Closing this pr as inactive

@Dylan-DPC

This comment was marked as off-topic.

@Dylan-DPC Dylan-DPC closed this May 13, 2023
@Dylan-DPC Dylan-DPC added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. 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.

6 participants