Skip to content

Linker plugin LTO broken? #163652

Description

@bjorn3

I tried this code:

echo '#[unsafe(no_mangle)] fn foo() {}' | rustc +1.95 - --crate-type staticlib -Clinker-plugin-lto
echo 'void foo(); int main() { foo(); }' | clang -flto -O3 librust_out.a -x c - -fuse-ld=lld
objdump -dr a.out

I expected to see this happen: foo gets inlined.

Instead, this happened: foo does not get inlined.

[...]
0000000000001730 <main>:
    1730:	50                   	push   %rax
    1731:	31 c0                	xor    %eax,%eax
    1733:	e8 08 00 00 00       	call   1740 <foo>
    1738:	31 c0                	xor    %eax,%eax
    173a:	59                   	pop    %rcx
    173b:	c3                   	ret
    173c:	cc                   	int3
    173d:	cc                   	int3
    173e:	cc                   	int3
    173f:	cc                   	int3

0000000000001740 <foo>:
    1740:	c3                   	ret
[...]

Also if I understood correctly in #159924 (comment), lld would ignore the standard library even if linker-plugin-lto was working due to us putting bitcode in the wrong section for -Cembed-bitcode=yes.

Meta

rustc --version --verbose:

rustc 1.95.0 (59807616e 2026-04-14)
binary: rustc
commit-hash: 59807616e1fa2540724bfbac14d7976d7e4a3860
commit-date: 2026-04-14
host: x86_64-unknown-linux-musl
release: 1.95.0
LLVM version: 22.1.2

clang --version:

Alpine clang version 22.1.3
Target: x86_64-alpine-linux-musl
Thread model: posix
InstalledDir: /usr/lib/llvm22/bin
Configuration file: /etc/clang22/x86_64-alpine-linux-musl.cfg

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-LTOArea: Link-time optimization (LTO)C-bugCategory: This is a bug.needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions