Skip to content

Commit 49b687f

Browse files
committed
expand documentation with x64 linux implementation notes
1 parent e65f271 commit 49b687f

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
@@ -245,9 +245,17 @@ It is also possible to enable or disable specific self-contained components in a
245245
You can pass a comma-separated list of self-contained components, individually enabled
246246
(`+component`) or disabled (`-component`).
247247

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)