-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Enabling LTO causes miscompilation on x86_64-apple-darwin #141306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
See tikv/tikv#18465 for another project that seems to have encountered the same error with the same unrecognized relocation type error on ARM64 Linux, using nightly-2025-04-04. |
The problem seems to be caused by LTO, as when I remove "lto = true" from the release profile in Cargo.toml, things are working. See https://github.com/briansmith/ring/actions/runs/15145798156. |
Rust 1.87 seems to miscompile the tests and/or *ring* itself when LTO is enabled. See rust-lang/rust#141306.
Can you bisect the PR causing this with cargo-bisect-rustc? Thanks! |
If you are asking me, then no. It is very unlikely I will get to it, though in normal circumstances I would try. |
The bisection should be helpful regardless of who's doing it, it doesn't have to be you, no worries. |
Rust 1.87 seems to miscompile the tests and/or *ring* itself when LTO is enabled. See rust-lang/rust#141306.
My guess is that, for the x86_64-apple-darwin miscompile, there may be two issues: #140686, which we believe to be a linker bug (not sure if that is a bug in a very old linker, or a bug that also affects the linker that is used b by default in macos-13 GitHub runners, which are x86-64) and a codegen change that causes the linker bug to be hit more often. If so, reducing and bisecting might be more difficult than typical. |
close #18465 downgrade rust toolchain to fix arm64 build(It's a workaround of rust bug rust-lang/rust#141306) Signed-off-by: glorv <[email protected]>
A minimum reproduction: https://rust.godbolt.org/z/vd4nTc3oj @rustbot label -E-needs-mcve |
As another data point, aws-lc-rs is seeing the same runtime failure on
However, we're not seeing any failures during linking on the other platforms. |
I have split out the linkage issue to #141737 This issue only tracks the miscompilation now. |
We investigated this during the T-compiler meeting on 2025-05-29 and determined
|
Let this be a reminder to everyone that every miscompilation issue is its own unique, sparkling star, and it is possible for two such stars, alike in dignity yet still standing in distinction, to fall from the heavenly tapestry of fate and strike the Rust toolchain at about the same time. |
Edit: All issues are temporarily resolved by llvm/llvm-project#142304, which will be included in the next LLVM update. I have documented everything about #140686, #141306 and #141737 on https://github.com/dianqk/rust-140686-141306-141737. @apiraino We can mention it at the next meeting. For #140686, I don't have any suggestion for cross-building for macOS on Linux. : |
@dianqk Are all issues here related to relative lookup tables? |
Is it easy? Many people are using macos-13 runners to ensure that Also, Xcode 15.2 is the default Xcode version on those runners. If we don't want to maintain compatibility with Xcode 15.2, that's fine. But, instead of people's code silently being miscompiled, we should at a minimum ensure that the build stops with an error when Xcode 15.2 (and earlier?) is used, or that LTO isn't used with its linker, or maybe something else. Anything other than silently miscompiling their code. |
Yes, you are right. Xcode 15.2 requires macOS 13.5+, but Xcode 15.3 requires macOS 14.0+. |
…REL relocations (#142304) Follow #72584 (comment), the patch will drop the `unnamed_addr` attribute when generating relative lookup tables. I'm not very confident about this patch, but it does resolve rust-lang/rust#140686, rust-lang/rust#141306 and rust-lang/rust#141737. But I don't think this will result in worse problems. > LLVM provides that the calculation of such a constant initializer will not overflow at link time under the medium code model if x is an unnamed_addr function. However, it does not provide this guarantee for a constant initializer folded into a function body. This intrinsic can be used to avoid the possibility of overflows when loading from such a constant. ([‘llvm.load.relative’ Intrinsic](https://llvm.org/docs/LangRef.html#id2592)) This is my concern. I'm not sure how unnamed_addr provides this guarantee, and I haven't found any test cases.
…ating GOTPCREL relocations (#142304) Follow llvm/llvm-project#72584 (comment), the patch will drop the `unnamed_addr` attribute when generating relative lookup tables. I'm not very confident about this patch, but it does resolve rust-lang/rust#140686, rust-lang/rust#141306 and rust-lang/rust#141737. But I don't think this will result in worse problems. > LLVM provides that the calculation of such a constant initializer will not overflow at link time under the medium code model if x is an unnamed_addr function. However, it does not provide this guarantee for a constant initializer folded into a function body. This intrinsic can be used to avoid the possibility of overflows when loading from such a constant. ([‘llvm.load.relative’ Intrinsic](https://llvm.org/docs/LangRef.html#id2592)) This is my concern. I'm not sure how unnamed_addr provides this guarantee, and I haven't found any test cases.
…REL relocations (llvm#142304) Follow llvm#72584 (comment), the patch will drop the `unnamed_addr` attribute when generating relative lookup tables. I'm not very confident about this patch, but it does resolve rust-lang/rust#140686, rust-lang/rust#141306 and rust-lang/rust#141737. But I don't think this will result in worse problems. > LLVM provides that the calculation of such a constant initializer will not overflow at link time under the medium code model if x is an unnamed_addr function. However, it does not provide this guarantee for a constant initializer folded into a function body. This intrinsic can be used to avoid the possibility of overflows when loading from such a constant. ([‘llvm.load.relative’ Intrinsic](https://llvm.org/docs/LangRef.html#id2592)) This is my concern. I'm not sure how unnamed_addr provides this guarantee, and I haven't found any test cases. (cherry picked from commit aa09dbb)
…REL relocations (llvm#142304) Follow llvm#72584 (comment), the patch will drop the `unnamed_addr` attribute when generating relative lookup tables. I'm not very confident about this patch, but it does resolve rust-lang/rust#140686, rust-lang/rust#141306 and rust-lang/rust#141737. But I don't think this will result in worse problems. > LLVM provides that the calculation of such a constant initializer will not overflow at link time under the medium code model if x is an unnamed_addr function. However, it does not provide this guarantee for a constant initializer folded into a function body. This intrinsic can be used to avoid the possibility of overflows when loading from such a constant. ([‘llvm.load.relative’ Intrinsic](https://llvm.org/docs/LangRef.html#id2592)) This is my concern. I'm not sure how unnamed_addr provides this guarantee, and I haven't found any test cases. (cherry picked from commit aa09dbb)
…ating GOTPCREL relocations (#142304) Follow llvm/llvm-project#72584 (comment), the patch will drop the `unnamed_addr` attribute when generating relative lookup tables. I'm not very confident about this patch, but it does resolve rust-lang/rust#140686, rust-lang/rust#141306 and rust-lang/rust#141737. But I don't think this will result in worse problems. > LLVM provides that the calculation of such a constant initializer will not overflow at link time under the medium code model if x is an unnamed_addr function. However, it does not provide this guarantee for a constant initializer folded into a function body. This intrinsic can be used to avoid the possibility of overflows when loading from such a constant. ([‘llvm.load.relative’ Intrinsic](https://llvm.org/docs/LangRef.html#id2592)) This is my concern. I'm not sure how unnamed_addr provides this guarantee, and I haven't found any test cases. (cherry picked from commit aa09dbb)
…REL relocations (llvm#142304) Follow llvm#72584 (comment), the patch will drop the `unnamed_addr` attribute when generating relative lookup tables. I'm not very confident about this patch, but it does resolve rust-lang/rust#140686, rust-lang/rust#141306 and rust-lang/rust#141737. But I don't think this will result in worse problems. > LLVM provides that the calculation of such a constant initializer will not overflow at link time under the medium code model if x is an unnamed_addr function. However, it does not provide this guarantee for a constant initializer folded into a function body. This intrinsic can be used to avoid the possibility of overflows when loading from such a constant. ([‘llvm.load.relative’ Intrinsic](https://llvm.org/docs/LangRef.html#id2592)) This is my concern. I'm not sure how unnamed_addr provides this guarantee, and I haven't found any test cases.
Uh oh!
There was an error while loading. Please reload this page.
This is from https://github.com/briansmith/ring 's CI, testing the tip of the main branch. The CI passes on 1.86 and fails on multiple targets when building with 1.87. In at least one case, building and linking passes but the test fails, indicating potentially the code (computing HMAC) or the test of the code is being miscompiled.
Unfortunately, I have limited access to systems that would help me reduce these today. I have noticed another project has run into a similar linker error recently. I apologize in advance for such a poor bug report. I hope I, or ideally others, could fill in the details, as I have limited availability today.
x86_64-apple-darwin
https://github.com/briansmith/ring/actions/runs/15143648178/job/42573984175
(The test is checking whether the output of the HMAC computation is correct.)
The text was updated successfully, but these errors were encountered: