<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61770>61770</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[AArch64]: 128-bit Const Atomic Load implemented using Store Pair instruction, induces Runtime Crash on Arm AArch64
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
lukeg101
</td>
</tr>
</table>
<pre>
Consider the following C test:
```
// test.c - fails when compiled and run with either LLVM or GCC
#include <stdatomic.h>
const _Atomic __int128 x = 0;
int main() {
__int128_t y = atomic_load_explicit(&x,memory_order_seq_cst);
}
// Fails when run as x is put into read-only section // $ clang -O0 test.c -o test.o
// $ ./test.o
/ / [1] 55891 bus error ./test.o
```
When compiled and run with clang (observed using apple clang on an M1 machine) targeting Arm AArch64, we observe a run-time crash.
As far as I can tell this fault is due to the fact that `const`-qualified data is stored in read-only section, and the compare-and-swap loop (https://godbolt.org/z/GaGKhT4f9) implemented using the `LDAXP`, `STLXP`, and `CBNZ` emits a store to the read-only memory.
It appears this issue is fixed by the patch [1] when targeting armv8.4-a and above, but it is not clear there is a (lock-free) fix for this crash for Armv8.3-a or below (or for any Arm arch that doesn't implement single-copy atomicity for 16-byte aligned 128-bit loads or stores). GCC emits a function call [2] instead. Is it possible to emit a function call in LLVM in a similar way without an ABI break?
[1] https://reviews.llvm.org/rG13aa102e07695297fd17f68913c343c95a7c56ad
[2] https://godbolt.org/z/7nqPW6Yb6
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VVFz4jYQ_jXiZceMLWODH3ggUDKZ5tqb3k2v7QuzltZYPVniJDmE_vqOZEIul3YmASTtrna_79sVeq-OhmjNqjtW7WY4ht66tR6_0rHIi1lr5WW9tcYrSQ5CT9BZre1ZmSNsIZAPrNywfMfyDavz69-05HvG98lkLiCDDpX2cO7JgLDDSWmSgEaCGw2cVe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