Skip to content

Commit 2a76340

Browse files
committed
Auto merge of rust-lang#119024 - lqd:linker-docs, r=petrochenkov
Document unstable linker flags in the unstable book This PR: - removes the unstable linker flavors from the stable documentation - documents the unstable `-C linker-flavor` values in the unstable book (including the ones previously described as stable) - documents the unstable `-C link-self-contained` components in the unstable book I don't know if these have some common reviewers, but if not r? `@petrochenkov` as the most knowledgeable person in this area. Please feel free to reassign, I know that you are quite busy.
2 parents a7690a3 + 3006e62 commit 2a76340

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

src/doc/rustc/src/codegen-options/index.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ metrics.
221221
## link-self-contained
222222

223223
On `windows-gnu`, `linux-musl`, and `wasi` targets, this flag controls whether the
224-
linker will use libraries and objects shipped with Rust instead or those in the system.
224+
linker will use libraries and objects shipped with Rust instead of those in the system.
225225
It takes one of the following values:
226226

227227
* no value: rustc will use heuristic to disable self-contained mode if system has necessary tools.
@@ -249,9 +249,6 @@ flavor. Valid options are:
249249
* `gcc`: use the `cc` executable, which is typically gcc or clang on many systems.
250250
* `ld`: use the `ld` executable.
251251
* `msvc`: use the `link.exe` executable from Microsoft Visual Studio MSVC.
252-
* `ptx`: use [`rust-ptx-linker`](https://github.com/denzp/rust-ptx-linker)
253-
for Nvidia NVPTX GPGPU support.
254-
* `bpf`: use [`bpf-linker`](https://github.com/alessandrod/bpf-linker) for eBPF support.
255252
* `wasm-ld`: use the [`wasm-ld`](https://lld.llvm.org/WebAssembly.html)
256253
executable, a port of LLVM `lld` for WebAssembly.
257254
* `ld64.lld`: use the LLVM `lld` executable with the [`-flavor darwin`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Unstable codegen options
2+
3+
All of these options are passed to `rustc` via the `-C` flag, short for "codegen". The flags are
4+
stable but some of their values are individually unstable, and also require using `-Z
5+
unstable-options` to be accepted.
6+
7+
## linker-flavor
8+
9+
In addition to the stable set of linker flavors, the following unstable values also exist:
10+
- `ptx`: use [`rust-ptx-linker`](https://github.com/denzp/rust-ptx-linker)
11+
for Nvidia NVPTX GPGPU support.
12+
- `bpf`: use [`bpf-linker`](https://github.com/alessandrod/bpf-linker) for eBPF support.
13+
14+
Additionally, a set of more precise linker flavors also exists, for example allowing targets to
15+
declare that they use the LLD linker by default. The following values are currently unstable, and
16+
the goal is for them to become stable, and preferred in practice over the existing stable values:
17+
- `gnu`: unix-like linker with GNU extensions
18+
- `gnu-lld`: `gnu` using LLD
19+
- `gnu-cc`: `gnu` using a C/C++ compiler as the linker driver
20+
- `gnu-lld-cc`: `gnu` using LLD and a C/C++ compiler as the linker driver
21+
- `darwin`: unix-like linker for Apple targets
22+
- `darwin-lld`: `darwin` using LLD
23+
- `darwin-cc`: `darwin` using a C/C++ compiler as the linker driver
24+
- `darwin-lld-cc`: `darwin` using LLD and a C/C++ compiler as the linker driver
25+
- `wasm-lld`: unix-like linker for Wasm targets, with LLD
26+
- `wasm-lld-cc`: unix-like linker for Wasm targets, with LLD and a C/C++ compiler as the linker
27+
driver
28+
- `unix`: basic unix-like linker for "any other Unix" targets (Solaris/illumos, L4Re, MSP430, etc),
29+
not supported with LLD.
30+
- `unix-cc`: `unix` using a C/C++ compiler as the linker driver
31+
- `msvc-lld`: MSVC-style linker for Windows and UEFI, with LLD
32+
- `em-cc`: emscripten compiler frontend, similar to `wasm-lld-cc` with a different interface
33+
34+
## link-self-contained
35+
36+
This flag generally controls whether the linker will use libraries and objects shipped with Rust
37+
instead of those in the system. The stable boolean values for this flag are coarse-grained
38+
(everything or nothing), but there exists a set of unstable values with finer-grained control,
39+
`-Clink-self-contained` can accept a comma-separated list of components, individually enabled
40+
(`+component`) or disabled (`-component`):
41+
- `crto`: CRT objects (e.g. on `windows-gnu`, `musl`, `wasi` targets)
42+
- `libc`: libc static library (e.g. on `musl`, `wasi` targets)
43+
- `unwind`: libgcc/libunwind (e.g. on `windows-gnu`, `fuchsia`, `fortanix`, `gnullvm` targets)
44+
- `linker`: linker, dlltool, and their necessary libraries (e.g. on `windows-gnu` and for
45+
`rust-lld`)
46+
- `sanitizers`: sanitizer runtime libraries
47+
- `mingw`: other MinGW libs and Windows import libs
48+
49+
Out of the above self-contained linking components, `linker` is the only one currently implemented
50+
(beyond parsing the CLI options).
51+
52+
It refers to the LLD linker, built from the same LLVM revision used by rustc (named `rust-lld` to
53+
avoid naming conflicts), that is distributed via `rustup` with the compiler (and is used by default
54+
for the wasm targets). One can also opt-in to use it by combining this flag with an appropriate
55+
linker flavor: for example, `-Clinker-flavor=gnu-lld-cc -Clink-self-contained=+linker` will use the
56+
toolchain's `rust-lld` as the linker.

0 commit comments

Comments
 (0)