Skip to content

Commit a981113

Browse files
committed
expand documentation with x64 linux implementation notes
1 parent 3a16ffa commit a981113

File tree

1 file changed

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

1 file changed

+22
-4
lines changed

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,16 @@ 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.
257+
251258
## linker
252259

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

269276
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).
277+
- `lld`: to toggle trying to use the lld linker, either the system-installed binary, or the self-contained
278+
`rust-lld` linker (via the [`-Clink-self-contained=+linker`][#link-self-contained] flag).
272279

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

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

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

0 commit comments

Comments
 (0)