Skip to content

Commit 3ee8719

Browse files
committed
expand documentation with x64 linux implementation notes
1 parent be8e2d1 commit 3ee8719

File tree

1 file changed

+23
-4
lines changed
  • src/doc/rustc/src/codegen-options

1 file changed

+23
-4
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,17 @@ It is also possible to enable or disable specific self-contained components in a
249249
You can pass a comma-separated list of self-contained components, individually enabled
250250
(`+component`) or disabled (`-component`).
251251

252-
Currently, only the `linker` granular option is stabilized:
252+
Currently, only the `linker` granular option is stabilized, and only on the `x86_64-unknown-linux-gnu` target:
253253
- `linker`: toggle the usage of self-contained linker binaries (linker, dlltool, and their necessary libraries)
254254

255+
#### Implementation notes
256+
257+
On the `x86_64-unknown-linux-gnu` target, when using the default linker flavor (using `cc` as the
258+
linker driver) and linker features (to try using `lld`), `rustc` will try to use the self-contained
259+
linker by passing a `-B /path/to/sysroot/` link argument to the driver to find `rust-lld` in the
260+
sysroot. For backwards-compatibility, and to limit name and `PATH` collisions, this is done using a
261+
shim executable (the `lld-wrapper` tool) that forwards execution to the `rust-lld` executable itself.
262+
255263
## linker
256264

257265
This flag controls which linker `rustc` invokes to link your code. It takes a
@@ -275,13 +283,24 @@ The flag accepts a comma-separated list of features, individually enabled (`+fea
275283
(`-feature`).
276284

277285
Currently only one is stable, and only on the `x86_64-unknown-linux-gnu` target:
278-
- `lld`: to toggle using the lld linker, either the system-installed binary, or the self-contained
279-
`rust-lld` linker (via the `-Clink-self-contained=+linker` flag).
286+
- `lld`: to toggle trying to use the lld linker, either the system-installed binary, or the self-contained
287+
`rust-lld` linker (via the [`-Clink-self-contained=+linker`](#link-self-contained) flag).
280288

281289
For example, use:
282-
- `-Clinker-features=+lld` to opt in to using the `lld` linker
290+
- `-Clinker-features=+lld` to opt into using the `lld` linker, when possible (see the Implementation notes below)
283291
- `-Clinker-features=-lld` to opt out instead, for targets where it is configured as the default linker
284292

293+
#### Implementation notes
294+
295+
On the `x86_64-unknown-linux-gnu` target, when using the default linker flavor (using `cc` as the
296+
linker driver), `rustc` will try to use lld by passing a `-fuse-ld=lld` link argument to the driver.
297+
`rustc` will also try to detect if that _causes_ an error during linking (for example, if GCC is too
298+
old to understand the flag, and returns an error) and will then retry linking without this argument,
299+
as a fallback.
300+
301+
If the user _also_ passes a `-Clink-arg=-fuse-ld=$value`, both will be given to the linker
302+
driver but the user's will be passed last, and would generally have priority over `rustc`'s.
303+
285304
## linker-flavor
286305

287306
This flag controls the linker flavor used by `rustc`. If a linker is given with

0 commit comments

Comments
 (0)