https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95722
Bug ID: 95722 Summary: libatomic crashes on __atomic_load of const object Product: gcc Version: 10.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: luis at luismarques dot eu Target Milestone: --- With this code in `test.c`: ``` struct S { int x; int y; int z; }; int main() { __attribute__((aligned(16))) static const _Atomic struct S a; struct S b; b = a; } ``` On x86_64 I get: ``` $ gcc test.c -latomic && ./a.out Segmentation fault (core dumped) ``` It crashes on a `lock cmpxchg16b` with the address of `a`, so I imagine the libatomic implementation is dispatching to an optimized __atomic_load case where the code assumes it can get a (mutable) lock from the object itself, and when it tries to acquire that lock it writes to `.rodata`, causing the crash.