Skip to content

Commit 94f25a1

Browse files
committed
document -Zlinker-features in the unstable book
1 parent f0b98ab commit 94f25a1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# `linker-features`
2+
3+
--------------------
4+
5+
The `-Zlinker-features` compiler flag allows enabling or disabling specific features used during
6+
linking, and is intended to be stabilized under the codegen options as `-Clinker-features`.
7+
8+
These feature flags are a flexible extension mechanism that is complementary to linker flavors,
9+
designed to avoid the combinatorial explosion of having to create a new set of flavors for each
10+
linker feature we'd want to use.
11+
12+
For example, this design allows:
13+
- default feature sets for principal flavors, or for specific targets.
14+
- flavor-specific features: for example, clang offers automatic cross-linking with `--target`, which
15+
gcc-style compilers don't support. The *flavor* is still a C/C++ compiler, and we don't want to
16+
multiply the number of flavors for this use-case. Instead, we can have a single `+target` feature.
17+
- umbrella features: for example, if clang accumulates more features in the future than just the
18+
`+target` above. That could be modeled as `+clang`.
19+
- niche features for resolving specific issues: for example, on Apple targets the linker flag
20+
implementing the `as-needed` native link modifier (#99424) is only possible on sufficiently recent
21+
linker versions.
22+
- still allows for discovery and automation, for example via feature detection. This can be useful
23+
in exotic environments/build systems.
24+
25+
The flag accepts a comma-separated list of features, individually enabled (`+features`) or disabled
26+
(`-features`), though currently only one is exposed on the CLI:
27+
- `lld`: to toggle using the lld linker, either the system-installed binary, or the self-contained
28+
`rust-lld` linker.
29+
30+
As described above, this list is intended to grow in the future.
31+
32+
One of the most common uses of this flag will be to toggle self-contained linking with `rust-lld` on
33+
and off: `-Clinker-features=+lld -Clink-self-contained=+linker` will use the toolchain's `rust-lld`
34+
as the linker. Inversely, `-Clinker-features=-lld` would opt out of that, if the current target had
35+
self-contained linking enabled by default.

0 commit comments

Comments
 (0)