|
| 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