Linker-plugin-based LTO: give an explanation how to use linker-plugin-lto with full LTO by foxtran · Pull Request #151933 · rust-lang/rust

@rustbot added the S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

label

Feb 1, 2026

nnethercote

bjorn3

bjorn3

@rustbot rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

and removed S-waiting-on-author

Status: This is awaiting some action (such as code changes or more information) from the author.

labels

Feb 6, 2026

nnethercote

@rustbot rustbot added T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.

T-libs

Relevant to the library team, which will review and decide on the PR/issue.

labels

Feb 7, 2026

@foxtran

@rust-bors rust-bors bot added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Feb 7, 2026

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request

Feb 7, 2026
…-lto, r=nnethercote

Linker-plugin-based LTO: give an explanation how to use linker-plugin-lto with full LTO

Closes rust-lang#138910

The existing linker-plugin-based LTO documentation does not describe the correct usage of full LTO. Specifically, when invoking `rustc` with full LTO, the `-C lto` flag must be passed in addition to `-C linker-plugin-lto`.

Also, this PR documents the use of full LTO when linking Rust with Fortran. Unfortunately, LLVM `flang` does not currently support ThinLTO, so full LTO is the only viable option in this case.

Toolchain combinations were slightly updated.

TODO:
- [x] check swiftc compiler. Almost unusable.
- [x] check how std lib is actually compiled
- [x] add note about LLD and bitcode
- [x] report bug to LLVM: llvm/llvm-project#179800

<details>
  <summary>Swiftc is unusable</summary>

https://www.swift.org/install/ gave me LLVM-17. During playing with swift main + rust static library, LLVM-23 removed main :D

```console
# thin LTO Rust:
rustc --crate-type=staticlib -Clinker-plugin-lto -Copt-level=3 ./ftn.rs
# full LTO swift:
swiftc -static libftn.a main.swift -lto=llvm-full -O -use-ld=/tmp/test/llvm-project/install/bin/ld.lld -Xlinker --gc-sections -Xlinker --as-needed -o sr
 ./sr
> ftn() returned: 77
# thin LTO swift:
swiftc -static libftn.a main.swift -lto=llvm-thin -O -use-ld=/tmp/test/llvm-project/install/bin/ld.lld -Xlinker --gc-sections -Xlinker --as-needed -o sr
./sr
> No output
```

</details>

This was referenced

Feb 7, 2026

rust-bors bot pushed a commit that referenced this pull request

Feb 7, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #148590 (Stabilize `atomic_try_update`and deprecate `fetch_update` starting 1.99.0)
 - #150522 (Stabilize new inclusive range type and iterator type)
 - #152235 (Convert to inline diagnostics in `rustc_parse`)
 - #152267 (feat: Implement `int_from_ascii` for `NonZero<T>`)
 - #151576 (Stabilize `core::hint::cold_path`)
 - #151933 (Linker-plugin-based LTO: give an explanation how to use linker-plugin-lto with full LTO)
 - #152010 (Ignore all debuginfo tests for LLDB that we do not run in CI)
 - #152199 (Move `rustc_query_system::cache`.)

rust-timer added a commit that referenced this pull request

Feb 7, 2026
Rollup merge of #151933 - foxtran:doc/linker-plugin-lto-full-lto, r=nnethercote

Linker-plugin-based LTO: give an explanation how to use linker-plugin-lto with full LTO

Closes #138910

The existing linker-plugin-based LTO documentation does not describe the correct usage of full LTO. Specifically, when invoking `rustc` with full LTO, the `-C lto` flag must be passed in addition to `-C linker-plugin-lto`.

Also, this PR documents the use of full LTO when linking Rust with Fortran. Unfortunately, LLVM `flang` does not currently support ThinLTO, so full LTO is the only viable option in this case.

Toolchain combinations were slightly updated.

TODO:
- [x] check swiftc compiler. Almost unusable.
- [x] check how std lib is actually compiled
- [x] add note about LLD and bitcode
- [x] report bug to LLVM: llvm/llvm-project#179800

<details>
  <summary>Swiftc is unusable</summary>

https://www.swift.org/install/ gave me LLVM-17. During playing with swift main + rust static library, LLVM-23 removed main :D

```console
# thin LTO Rust:
rustc --crate-type=staticlib -Clinker-plugin-lto -Copt-level=3 ./ftn.rs
# full LTO swift:
swiftc -static libftn.a main.swift -lto=llvm-full -O -use-ld=/tmp/test/llvm-project/install/bin/ld.lld -Xlinker --gc-sections -Xlinker --as-needed -o sr
 ./sr
> ftn() returned: 77
# thin LTO swift:
swiftc -static libftn.a main.swift -lto=llvm-thin -O -use-ld=/tmp/test/llvm-project/install/bin/ld.lld -Xlinker --gc-sections -Xlinker --as-needed -o sr
./sr
> No output
```

</details>

@foxtran foxtran deleted the doc/linker-plugin-lto-full-lto branch

February 9, 2026 12:18