LTO turns weak linkage into a miscompile (identified via `gettid` segfault on x86_64-unknown-linux-musl)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
This is a very strange one. Since 289fe36d373 (I bisected; cc @tgross35), my program that calls libc's gettid segfaults when built for x86_64-unknown-linux-musl. However, I can only reproduce this when the call to gettid is in a library crate, and only when it has a certain name, and only when not using -C target-feature=-crt-static, only when using LTO.
Code
dep.rs
unsafe extern "C" {
safe fn gettid() -> i32;
}
pub fn print_tid() {
println!("{}", gettid());
}
main.rs
fn main() {
vmm::print_tid();
}
Reproduction commands
rustc --crate-name vmm --edition=2024 dep.rs --crate-type lib -C opt-level=3 -C linker-plugin-lto --target x86_64-unknown-linux-musl -C linker=/nix/store/nz3n5wy8zadq73kkql2xn485l7xdmv46-x86_64-unknown-linux-musl-gcc-wrapper-15.2.0/bin/x86_64-unknown-linux-musl-cc
rustc --edition=2024 main.rs --crate-type bin -C opt-level=3 -C lto --target x86_64-unknown-linux-musl -C linker=/nix/store/nz3n5wy8zadq73kkql2xn485l7xdmv46-x86_64-unknown-linux-musl-gcc-wrapper-15.2.0/bin/x86_64-unknown-linux-musl-cc --extern vmm=libvmm.rlib
./main
Happy to provide LLVM IR or anything else that helps!
@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied dep.rs and main.rs reproduction commands for x86_64-unknown-linux-musl, comparing LTO with and without -C target-feature=-crt-static. Inspect regression commit 289fe36d373 and the generated LLVM IR around the gettid call and weak linkage. Done means the reproducer no longer segfaults under LTO and the regression is covered by a compiler test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100