[Bug libstdc++/86846] [9 Regression] ld: (Warning) Unsatisfied symbol "__atomic_exchange_8" in libstdc++.sl
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 Jonathan Wakely changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution|--- |FIXED --- Comment #11 from Jonathan Wakely --- Should be fixed now.
[Bug libstdc++/86846] [9 Regression] ld: (Warning) Unsatisfied symbol "__atomic_exchange_8" in libstdc++.sl
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 --- Comment #10 from Jonathan Wakely --- Author: redi Date: Tue Aug 14 13:13:37 2018 New Revision: 263536 URL: https://gcc.gnu.org/viewcvs?rev=263536=gcc=rev Log: PR libstdc++/86846 Alternative to pointer-width atomics Define a class using std::mutex for when std::atomic cannot be used to implement the default memory resource. When std::mutex constructor is not constexpr the constant_init trick won't work, so just define a global and use init_priority for it. The compiler warns about using reserved priority, so put the definition in a header file using #pragma GCC system_header to suppress the warning. PR libstdc++/86846 * src/c++17/default_resource.h: New file, defining default_res. * src/c++17/memory_resource.cc [ATOMIC_POINTER_LOCK_FREE != 2] (atomic_mem_res): Define alternative for atomic using a mutex instead of atomics. Added: trunk/libstdc++-v3/src/c++17/default_resource.h Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/src/c++17/memory_resource.cc
[Bug libstdc++/86846] [9 Regression] ld: (Warning) Unsatisfied symbol "__atomic_exchange_8" in libstdc++.sl
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 --- Comment #9 from Jonathan Wakely --- OK, thanks. The second patch might not be needed for hppa64-hp-hpux11.11 but would be for targets without pointer-width atomics and without PTHREAD_MUTEX_INITIALIZER, so I'll commit that version.
[Bug libstdc++/86846] [9 Regression] ld: (Warning) Unsatisfied symbol "__atomic_exchange_8" in libstdc++.sl
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 --- Comment #8 from dave.anglin at bell dot net --- On 2018-08-11 8:04 PM, redi at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 > > --- Comment #5 from Jonathan Wakely --- > This should do it: The testsuite isn't quite finished but it's clear this fixes the bug on hppa64-hp-hpux11.11. Don't know about second patch. > > --- a/libstdc++-v3/src/c++17/memory_resource.cc > +++ b/libstdc++-v3/src/c++17/memory_resource.cc > @@ -25,6 +25,7 @@ > #include > #include > #include > +#include > > namespace std _GLIBCXX_VISIBILITY(default) > { > @@ -81,7 +82,31 @@ namespace pmr > > constant_init newdel_res{}; > constant_init null_res{}; > +#if ATOMIC_POINTER_LOCK_FREE == 2 > constant_init> default_res{_res.obj}; > +#else > +struct locking_atomic > +{ > + constexpr locking_atomic(memory_resource* r) : val(r) { } > + mutex mx; > + memory_resource* val; > + > + memory_resource* load() > + { > + lock_guard lock(mx); > + return val; > + } > + > + memory_resource* exchange(memory_resource* r) > + { > + lock_guard lock(mx); > + auto prev = val; > + val = r; > + return prev; > + } > +}; > +constant_init default_res{_res.obj}; > +#endif > } // namespace > > memory_resource* > Thanks, Dave
[Bug libstdc++/86846] [9 Regression] ld: (Warning) Unsatisfied symbol "__atomic_exchange_8" in libstdc++.sl
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 --- Comment #7 from Jonathan Wakely --- Ah, that patch assumes this is defined: #ifdef __GTHREAD_MUTEX_INIT __native_type _M_mutex = __GTHREAD_MUTEX_INIT; constexpr __mutex_base() noexcept = default; i.e. PTHREAD_MUTEX_INITIALIZER. If that's not available we might just need to use a global mutex, without the constant_init<> wrapper that makes the object immortal. In that case it will be risky to use the default memory resource functions after static destructors start (which is bad practice anyway). So this would be a bit more robust: --- a/libstdc++-v3/src/c++17/memory_resource.cc +++ b/libstdc++-v3/src/c++17/memory_resource.cc @@ -25,6 +25,10 @@ #include #include #include +#if ATOMIC_POINTER_LOCK_FREE != 2 +# include // std::mutex, std::lock_guard +# include // std::exchange +#endif namespace std _GLIBCXX_VISIBILITY(default) { @@ -81,7 +85,39 @@ namespace pmr constant_init newdel_res{}; constant_init null_res{}; +#if ATOMIC_POINTER_LOCK_FREE == 2 constant_init> default_res{_res.obj}; +#else +struct locking_atomic +{ +#ifdef __GTHREAD_MUTEX_INIT + // std::mutex has constexpr constructor + constexpr +#endif + locking_atomic(memory_resource* r) : val(r) { } + mutex mx; + memory_resource* val; + + memory_resource* load() + { + lock_guard lock(mx); + return val; + } + + memory_resource* exchange(memory_resource* r) + { + lock_guard lock(mx); + return std::exchange(val, r); + } +}; +#ifdef __GTHREAD_MUTEX_INIT +constant_init default_res{_res.obj}; +#else +struct { + locking_atomic obj = _res.obj; +} default_res __attribute__ ((init_priority (100))); +#endif +#endif } // namespace memory_resource* Unfortunately this produces a warning for targets without pointer-width atomics and without PTHREAD_MUTEX_INITIALIZER: /home/jwakely/src/gcc/gcc/libstdc++-v3/src/c++17/memory_resource.cc:119:55: warning: requested init_priority is reserved for internal use } default_res __attribute__ ((init_priority (100))); ^
[Bug libstdc++/86846] [9 Regression] ld: (Warning) Unsatisfied symbol "__atomic_exchange_8" in libstdc++.sl
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 --- Comment #6 from dave.anglin at bell dot net --- On 2018-08-11 8:04 PM, redi at gcc dot gnu.org wrote: > This should do it: I'll give it a test on my next build. Thanks, Dave
[Bug libstdc++/86846] [9 Regression] ld: (Warning) Unsatisfied symbol "__atomic_exchange_8" in libstdc++.sl
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 --- Comment #5 from Jonathan Wakely --- This should do it: --- a/libstdc++-v3/src/c++17/memory_resource.cc +++ b/libstdc++-v3/src/c++17/memory_resource.cc @@ -25,6 +25,7 @@ #include #include #include +#include namespace std _GLIBCXX_VISIBILITY(default) { @@ -81,7 +82,31 @@ namespace pmr constant_init newdel_res{}; constant_init null_res{}; +#if ATOMIC_POINTER_LOCK_FREE == 2 constant_init> default_res{_res.obj}; +#else +struct locking_atomic +{ + constexpr locking_atomic(memory_resource* r) : val(r) { } + mutex mx; + memory_resource* val; + + memory_resource* load() + { + lock_guard lock(mx); + return val; + } + + memory_resource* exchange(memory_resource* r) + { + lock_guard lock(mx); + auto prev = val; + val = r; + return prev; + } +}; +constant_init default_res{_res.obj}; +#endif } // namespace memory_resource*
[Bug libstdc++/86846] [9 Regression] ld: (Warning) Unsatisfied symbol "__atomic_exchange_8" in libstdc++.sl
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 --- Comment #4 from dave.anglin at bell dot net --- On 2018-08-11 4:08 PM, redi at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 > > --- Comment #3 from Jonathan Wakely --- > N.B. this doesn't need compare and exchange, just exchange. There also isn't exchange operation. :-(
[Bug libstdc++/86846] [9 Regression] ld: (Warning) Unsatisfied symbol "__atomic_exchange_8" in libstdc++.sl
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 --- Comment #3 from Jonathan Wakely --- N.B. this doesn't need compare and exchange, just exchange. I'll fix this early next week.
[Bug libstdc++/86846] [9 Regression] ld: (Warning) Unsatisfied symbol "__atomic_exchange_8" in libstdc++.sl
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 --- Comment #2 from dave.anglin at bell dot net --- On 2018-08-11 3:31 PM, redi at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 > > --- Comment #1 from Jonathan Wakely --- > Does hppa64 really not have native atomic ops for sizeof(void*) ? Sadly, it lacks an atomic compare and exchange operation. The mutex support might have some form of kernel support but I don't know what it is. I've been working on atomic load and store support. > > I guess we need to use a mutex here, as I don't want libstdc++ to depend on > libatomic. > Yes. Dave
[Bug libstdc++/86846] [9 Regression] ld: (Warning) Unsatisfied symbol "__atomic_exchange_8" in libstdc++.sl
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 Jonathan Wakely changed: What|Removed |Added Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org Target Milestone|--- |9.0
[Bug libstdc++/86846] [9 Regression] ld: (Warning) Unsatisfied symbol "__atomic_exchange_8" in libstdc++.sl
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 --- Comment #1 from Jonathan Wakely --- Does hppa64 really not have native atomic ops for sizeof(void*) ? I guess we need to use a mutex here, as I don't want libstdc++ to depend on libatomic.
[Bug libstdc++/86846] [9 Regression] ld: (Warning) Unsatisfied symbol "__atomic_exchange_8" in libstdc++.sl
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86846 Jonathan Wakely changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2018-08-03 Ever confirmed|0 |1