-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
u128 atomic compare_and_set (cxchg) emits linker error #56798
Comments
I was initially confused by this issue: of course 128 bit compare-exchange doesn't exist so it has to be emulated in libatomic. But it appears that x86_64 has a 128 bit version of CMPXCHG. To clarify, is the issue that the compiler doesn't emit that instruction? |
@rkruppe Yes, the compiler (at least on x86) doesnt emit cmpxchg16b. instead it emits what seems to be a call to __sync_val_compare_and_swap_16 which should be a libatomic function but that doesnt get linked into the executable. |
This is still an issue with nightly-2019-11-20. I see the same thing when trying to use @kprotty : __sync_val_compare_and_swap_16 is not from libatomic; it's a gcc/llvm intrinsic. I tried setting target-cpu=skylake and/or target-feature=cx16, but it didn't help. |
Perhaps the label is wrong? Even though the error appears at the linker, it should have been resolved during the compile. "A-intrinsics", perhaps? |
Quick C example (this is the whole file):
Compiling on x86_64 (
gcc behaves the same. I take that as evidence that LLVM does consider this an intrinsic or builtin (at least on x86_64) I think the question is, since llvm is building for the same arch/cpu/feature-set, why did it not replace this symbol with the same inline code, when building rust programs? |
I wonder if this is relevant?
How would I find out if rust is doing all those things? |
Those are controlled by the LLVM backend, not rustc |
Yeah, I think that that snippet was off-topic anyway. Earlier in that page it says
That threw me off... but I think this part of the hypothesis is still true: llvm has a builtin for this, but isn't using it for some reason. |
I think this is user error. I figured out how to make it work, both for my code and the original example. All you need is to run rustc with the right cpu feature enabled. Either of these will work: My mistake was trying to do both, but missing the Most target-feature typos are caught by rustc, but this one makes it all the way to the llvm-ir, where it does ... nothing helpful? Anyway, putting the right |
Seems like there should be a But...
I guess because libstd and stdarch are pre-compiled they already made it past the gate; but if those functions get inlined then rustc emits llvm-ir that llvm won't process correctly if the cpu/features aren't set correctly. |
I think this is a legitimate error when using runtime feature detection and compiling a specific method with |
On Rust 1.32.0 nightly for both x86_64-pc-linux-gnu & x86_64-pc-windows-gnu.
undefined reference to '__sync_val_compare_and_swap_16'
while also failing to link to libatomic if provided. Example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=9aeb9e2d8ce7e5b2cac9cdeaadd03ee2The text was updated successfully, but these errors were encountered: