public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/101439] New: std::atomic<__uint128_t>::load() crashes - possible fix with mutable
@ 2021-07-13 15:43 doodspav at gmail dot com
2021-08-28 20:55 ` [Bug libstdc++/101439] std::atomic<sixteen_byte_struct>::load() " pinskia at gcc dot gnu.org
2021-08-28 21:10 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: doodspav at gmail dot com @ 2021-07-13 15:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101439
Bug ID: 101439
Summary: std::atomic<__uint128_t>::load() crashes - possible
fix with mutable
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: doodspav at gmail dot com
Target Milestone: ---
The following code will cause a segfault on x86 from g++4.8 up to g++11.1
(currently the latest non-trunk version on Godbolt):
```
#include <atomic>
struct S { long i, j; };
const std::atomic<S> x{ {0, 0} };
int f(const std::atomic<S>* p) {
S y = *p;
return y.i;
}
int main() {
return f(&x);
}
```
(demonstrated here: https://godbolt.org/z/eWcTv5fdY for however long the link
remains alive)
Loading the value from `x` causes libatomic to use `lock cmpxchg16b` on
read-only memory, crashing the program (since `lock cmpxchg16b` always performs
a write).
This has been reported in bug report 95722 (and touched upon in 70490), however
those treat it as a libatomic bug (which it technically is), whereas here I
seek to treat it as a libstdc++ bug.
A "simple" workaround for C++ that doesn't involve changing anything in
libatomic would be to mark all members in any 16 byte specialisation of
`std::atomic` as `mutable`, preventing the compiler from placing it in
read-only memory. This is what MSVC does in their implementation (as does
Boost.Atomic I think). This shouldn't break anything as far as I can tell.
This code (using `_Atomic`) also causes a segfault in C. I can't really think
of a similar fix there (maybe just act as if DR459 never happened?).
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/101439] std::atomic<sixteen_byte_struct>::load() crashes - possible fix with mutable
2021-07-13 15:43 [Bug libstdc++/101439] New: std::atomic<__uint128_t>::load() crashes - possible fix with mutable doodspav at gmail dot com
@ 2021-08-28 20:55 ` pinskia at gcc dot gnu.org
2021-08-28 21:10 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ 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=101439
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 95722.
*** This bug has been marked as a duplicate of bug 95722 ***
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/101439] std::atomic<sixteen_byte_struct>::load() crashes - possible fix with mutable
2021-07-13 15:43 [Bug libstdc++/101439] New: std::atomic<__uint128_t>::load() crashes - possible fix with mutable doodspav at gmail dot com
2021-08-28 20:55 ` [Bug libstdc++/101439] std::atomic<sixteen_byte_struct>::load() " pinskia at gcc dot gnu.org
@ 2021-08-28 21:10 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-28 21:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101439
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|DUPLICATE |---
Status|RESOLVED |NEW
Last reconfirmed| |2021-08-28
Ever confirmed|0 |1
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
LLVM's libc++ does:
template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp,
bool>::value>
struct __atomic_base
{
mutable __cxx_atomic_impl<_Tp> __a_;
...
template <class _Tp>
struct __atomic_base<_Tp, true>
: public __atomic_base<_Tp, false>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-08-28 21:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-13 15:43 [Bug libstdc++/101439] New: std::atomic<__uint128_t>::load() crashes - possible fix with mutable doodspav at gmail dot com
2021-08-28 20:55 ` [Bug libstdc++/101439] std::atomic<sixteen_byte_struct>::load() " pinskia at gcc dot gnu.org
2021-08-28 21:10 ` 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).