public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/95722] New: libatomic crashes on __atomic_load of const object
@ 2020-06-17 14:55 luis at luismarques dot eu
2020-06-17 19:10 ` [Bug target/95722] " foom at fuhm dot net
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: luis at luismarques dot eu @ 2020-06-17 14:55 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/95722] libatomic crashes on __atomic_load of const object
2020-06-17 14:55 [Bug other/95722] New: libatomic crashes on __atomic_load of const object luis at luismarques dot eu
@ 2020-06-17 19:10 ` foom at fuhm dot net
2020-06-18 8:30 ` [Bug c/95722] " rguenth at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: foom at fuhm dot net @ 2020-06-17 19:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95722
James Y Knight <foom at fuhm dot net> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |foom at fuhm dot net
--- Comment #1 from James Y Knight <foom at fuhm dot net> ---
The fix would be to have libatomic use a lock instead of the lock-free
cmpxchg16b instruction to implement atomic_load. But I think this is impossible
without causing incompatibility with older GCCs.
Older versions of GCC (before GCC 7), and Clang to this day, emitted cmpxchg16b
inline for a 16-byte atomic load when you compile with -mcx16.
And thus, unfortunately, I think if libatomic switched to a lock now, it would
not be compatible with those older programs.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/95722] libatomic crashes on __atomic_load of const object
2020-06-17 14:55 [Bug other/95722] New: libatomic crashes on __atomic_load of const object luis at luismarques dot eu
2020-06-17 19:10 ` [Bug target/95722] " foom at fuhm dot net
@ 2020-06-18 8:30 ` rguenth at gcc dot gnu.org
2020-06-18 16:16 ` joseph at codesourcery dot com
2021-08-28 20:55 ` [Bug target/95722] " pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-06-18 8:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95722
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|target |c
CC| |jsm28 at gcc dot gnu.org
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think _Atomic can be ignored on const qualified objects? Or maybe should
even be ill-formed?
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/95722] libatomic crashes on __atomic_load of const object
2020-06-17 14:55 [Bug other/95722] New: libatomic crashes on __atomic_load of const object luis at luismarques dot eu
2020-06-17 19:10 ` [Bug target/95722] " foom at fuhm dot net
2020-06-18 8:30 ` [Bug c/95722] " rguenth at gcc dot gnu.org
@ 2020-06-18 16:16 ` joseph at codesourcery dot com
2021-08-28 20:55 ` [Bug target/95722] " pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: joseph at codesourcery dot com @ 2020-06-18 16:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95722
--- Comment #3 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
See bugs 70490 and 84563 regarding atomic_load of const.
The atomic_load generic function takes a pointer-to-const-atomic argument
just like any other library function that takes an argument it does not
modify. It's certainly valid to do an atomic load through such a pointer
in a case where the original object was not defined as const but a pointer
to const was passed to the function doing the load.
The question is whether it is or should be valid in the case where the
object was defined as const. If it is, that would constrain code
sequences used in any case where the compiler cannot see that the object
definitely isn't in read-only memory, including for other operations that
might only be valid for writable memory but need to interact correctly
with atomic_load.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/95722] libatomic crashes on __atomic_load of const object
2020-06-17 14:55 [Bug other/95722] New: libatomic crashes on __atomic_load of const object luis at luismarques dot eu
` (2 preceding siblings ...)
2020-06-18 16:16 ` joseph at codesourcery dot com
@ 2021-08-28 20:55 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-28 20:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95722
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |doodspav at gmail dot com
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 101439 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-08-28 20:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-17 14:55 [Bug other/95722] New: libatomic crashes on __atomic_load of const object luis at luismarques dot eu
2020-06-17 19:10 ` [Bug target/95722] " foom at fuhm dot net
2020-06-18 8:30 ` [Bug c/95722] " rguenth at gcc dot gnu.org
2020-06-18 16:16 ` joseph at codesourcery dot com
2021-08-28 20:55 ` [Bug target/95722] " pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).