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).


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:

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.

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:

and because:

r? @ghost