-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Linking a Rust staticlib unexpectedly changes C math functions from libm to bundled ones from compiler-builtins #142119
Copy link
Copy link
Open
Labels
A-compiler-builtinsArea: compiler-builtins (https://github.com/rust-lang/compiler-builtins)Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins)A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.Category: This is a bug.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
Metadata
Metadata
Assignees
Labels
A-compiler-builtinsArea: compiler-builtins (https://github.com/rust-lang/compiler-builtins)Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins)A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.Category: This is a bug.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Code
Given a staticlib with the source:
compiled as
crate-type = ["staticlib"]and the C program:When linking the program like this:
$(CC) main.o as-crate/target/debug/libas_crate.a -lm -o out/tgt-from-cratethe resulting binary ends up usingceilffrom compiler-builtins rather than libm.I expected to see this happen: The binary should still get ceilf from libm, eg
Instead, this happened: Instead, the ceilf symbol was satisfied by the matching symbol in compiler-builtins, and so the C call was surprise-migrated to a different implementation.
Version it worked on
1.86
rustc --version --verbose:Version with regression
1.87
rustc --version --verbose:Additional information
I suspect this is related to some work tracked in #137578. I also found out Chromium has already stumbled on this: https://issues.chromium.org/issues/419258012#comment5 and for them it caused observable behavior changes. Apologies for not catching this sooner - we hadn't upgraded compiler-builtins for a while and didn't notice until a couple of weeks ago. :(