-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
rustc emits calls to __sync_
when using load/store with +forced-atomics
#101300
Comments
Related to (possibly dupe of) #99668. |
Yeah, this shouldn't be happening. Based on the symbol names, the atomic load or store seems to get lowered to atomic CAS at some point. |
There's no __sync equivalent to plain load/store, so I believe this is to force going through libcalls on targets where you'd need to take a global lock around all access to support RMWs (which I guess LLVM assumes we might want to support). |
This is a lot like the current situation for compiler_fence -- on some embedded targets llvm seems to consider __sync to be a good fallback: https://github.com/llvm/llvm-project/blob/9905dae5e18cd55ee6bb8678c95fed940ded1ef9/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp#L3937-L3939 |
Ah, I see the problem. These are seq_cst atomic load/stores, but apparently thumbv4t has no dmb instruction, so it's not possible to lower atomic load/store with stronger than monotonic ordering natively. Thus we get libcalls even with the This does look correct to me, and it also looks like this is not new LLVM 15 behavior either. So to clarify, did this code (using these atomic orderings) work previously? I think this means that we do need to declare atomics as completely unsupported for thumbv4t targets. |
Ah, I should be more clear: This code is all new code, and I have never before even attempted to use However, I was told by both Ralf and m-ou-se that plain loads are stores are "effectively atomic". So when the Forced Atomic stuff was put in I went to try it out, and it did not work as expected. What I expected, given that it's an ARMv4T, is that all atomic orderings will lower to plain What I am really after is a way for the main program (just one thread) to communicate with the interrupt handler.
So, if you think that everything here is working as far as you expect, then I might have to tell Ralf and Mo-us-e that there's no "effective atomics" after all and they need to go back to the drawing board. |
On advice
|
So yeah, atomics are completely broken on this target at the moment. In the mean time it can be worked around with inline_asm, but then i either have to make every access a macro call (to get good register allocation) or wrap it in a method that gets inlined but then every access will always be fighting for |
FWIW, (when you use core::sync::atomic's atomics) whether this works or not actually seems to depend on compiler optimizations. (In cases where |
Ah yes, i hadn't considered. For this platform, I always use opt-level = 3 for all builds. |
I went to start a new branch for the
gba
crate and things were going well until LLVM demanded that I add a bunch of definitions for atomic intrinsics:These are all part of LLVM's sync function set, and they are probably caused by the atomic accesses I'm using:
Now the GBA is using the ARMv4T architecture, which does not have atomic instructions at the CPU level, but the
+forced-atomic
feature was recently added to many target definitions for older targets. My understanding of how this was supposed to work is that an aligned atomic load/store will just use the normal load/store instruction, and then the "advanced" atomic actions like fetch_add would call a function. However, it seems to be the cast that (using thethumbv4t-none-eabi
target) LLVM still wants to call functions for plain load/store.The text was updated successfully, but these errors were encountered: