Implement -Zgcc-ld=lld
stabilization MCP by lqd · Pull Request #96401 · rust-lang/rust (original) (raw)
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
. Iflinker
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 iflinker
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 ascrt,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 (LinkerFlavor
s) 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-wrapper
s 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 iflinker
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 (andrust-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