* Full disable of C++20 time zone support @ 2023-06-28 18:42 Alexey Lapshin 2023-06-28 19:33 ` Jonathan Wakely 0 siblings, 1 reply; 9+ messages in thread From: Alexey Lapshin @ 2023-06-28 18:42 UTC (permalink / raw) To: gcc-help; +Cc: jwakely Hi! I faced an issue with compiling libstdc++-v3/src/c++20/tzdb.cc: [ERROR] gcc/libstdc++-v3/src/c++20/tzdb.cc:110:21: error: 'constinit' variable 'std::chrono::{anonymous}::list_mutex' does not have a constant initializer [ERROR] gcc/libstdc++-v3/src/c++20/tzdb.cc:110:21: error: call to non-'constexpr' function 'std::mutex::mutex()' Any plans to create a configure option to disable tzdb from build? Or at least make it compilable? Tried --with-libstdcxx-zoneinfo=no but it does not take effect, because it does not cover line with the bug. For now using workaround with changes in libstdc++-v3/src/c++20/Makefile* Thanks ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Full disable of C++20 time zone support 2023-06-28 18:42 Full disable of C++20 time zone support Alexey Lapshin @ 2023-06-28 19:33 ` Jonathan Wakely 2023-06-28 19:40 ` Jonathan Wakely 0 siblings, 1 reply; 9+ messages in thread From: Jonathan Wakely @ 2023-06-28 19:33 UTC (permalink / raw) To: Alexey Lapshin; +Cc: gcc-help [-- Attachment #1: Type: text/plain, Size: 880 bytes --] On Wed, 28 Jun 2023 at 19:42, Alexey Lapshin wrote: > Hi! > > I faced an issue with compiling libstdc++-v3/src/c++20/tzdb.cc: > > > [ERROR] gcc/libstdc++-v3/src/c++20/tzdb.cc:110:21: error: 'constinit' > variable 'std::chrono::{anonymous}::list_mutex' does not have a constant > initializer > [ERROR] gcc/libstdc++-v3/src/c++20/tzdb.cc:110:21: error: call to > non-'constexpr' function 'std::mutex::mutex()' > > Which target are you building for? > > Any plans to create a configure option to disable tzdb from build? Or at > least make it compilable? > > Tried --with-libstdcxx-zoneinfo=no but it does not take effect, because it > does not cover line with the bug. > Well then we should fix that. We don't want *another* configure option when we already have two for tzdb. > > For now using workaround with changes in libstdc++-v3/src/c++20/Makefile* > > Thanks > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Full disable of C++20 time zone support 2023-06-28 19:33 ` Jonathan Wakely @ 2023-06-28 19:40 ` Jonathan Wakely 2023-06-29 9:15 ` Alexey Lapshin 0 siblings, 1 reply; 9+ messages in thread From: Jonathan Wakely @ 2023-06-28 19:40 UTC (permalink / raw) To: Alexey Lapshin; +Cc: gcc-help [-- Attachment #1: Type: text/plain, Size: 1376 bytes --] On Wed, 28 Jun 2023 at 20:33, Jonathan Wakely <jwakely@redhat.com> wrote: > On Wed, 28 Jun 2023 at 19:42, Alexey Lapshin wrote: > >> Hi! >> >> I faced an issue with compiling libstdc++-v3/src/c++20/tzdb.cc: >> >> >> [ERROR] gcc/libstdc++-v3/src/c++20/tzdb.cc:110:21: error: 'constinit' >> variable 'std::chrono::{anonymous}::list_mutex' does not have a constant >> initializer >> [ERROR] gcc/libstdc++-v3/src/c++20/tzdb.cc:110:21: error: call to >> non-'constexpr' function 'std::mutex::mutex()' >> >> > Which target are you building for? > > > >> >> Any plans to create a configure option to disable tzdb from build? Or at >> least make it compilable? >> >> Tried --with-libstdcxx-zoneinfo=no but it does not take effect, because >> it does not cover line with the bug. >> > > Well then we should fix that. We don't want *another* configure option > when we already have two for tzdb. > I think this should fix it: --- a/libstdc++-v3/src/c++20/tzdb.cc +++ b/libstdc++-v3/src/c++20/tzdb.cc @@ -43,8 +43,8 @@ #ifndef __GTHREADS # define USE_ATOMIC_SHARED_PTR 0 -#elif _WIN32 -// std::mutex cannot be constinit, so Windows must use atomic<shared_ptr<>>. +#elif ! defined __GTHREAD_MUTEX_INIT +// std::mutex cannot be constinit, so must use atomic<shared_ptr<>>. # define USE_ATOMIC_SHARED_PTR 1 #elif ATOMIC_POINTER_LOCK_FREE < 2 # define USE_ATOMIC_SHARED_PTR 0 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Full disable of C++20 time zone support 2023-06-28 19:40 ` Jonathan Wakely @ 2023-06-29 9:15 ` Alexey Lapshin 2023-06-29 9:23 ` Jonathan Wakely 0 siblings, 1 reply; 9+ messages in thread From: Alexey Lapshin @ 2023-06-29 9:15 UTC (permalink / raw) To: jwakely; +Cc: gcc-help > Which target are you building for? riscv32-esp-elf build with gcc v4.9.2 > I think this should fix it: This brings next errors: gcc/libstdc++-v3/src/c++20/tzdb.cc:157:27: error: 'list_mutex' was not declared in this scope gcc/libstdc++-v3/src/c++20/tzdb.cc:158:28: error: 'using std::chrono::tzdb_list::_Node::head_ptr = class std::atomic<std::shared_ptr<std::chrono::tzdb_list::_Node> >' {aka 'class std::atomic<std::shared_ptr<std::chrono::tzdb_list::_Node> >'} has no member named 'get' Why it could not be disabled at all? like this: --- a/libstdc++-v3/src/c++20/tzdb.cc +++ b/libstdc++-v3/src/c++20/tzdb.cc @@ -22,6 +22,8 @@ // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // <http://www.gnu.org/licenses/>. +#ifndef TZDB_DISABLED + // The -Wabi warnings in this file are all for non-exported symbols. #pragma GCC diagnostic ignored "-Wabi" @@ -2037,3 +2039,5 @@ namespace std::chrono } // namespace #endif // TZDB_DISABLED } // namespace std::chrono + +#endif On Wed, 2023-06-28 at 20:40 +0100, Jonathan Wakely wrote: > [External: This email originated outside Espressif] > > > On Wed, 28 Jun 2023 at 20:33, Jonathan Wakely <jwakely@redhat.com> wrote: > > On Wed, 28 Jun 2023 at 19:42, Alexey Lapshin wrote: > > > Hi! > > > > > > I faced an issue with compiling libstdc++-v3/src/c++20/tzdb.cc: > > > > > > > > > [ERROR] gcc/libstdc++-v3/src/c++20/tzdb.cc:110:21: error: 'constinit' variable 'std::chrono::{anonymous}::list_mutex' does not have a constant initializer > > > [ERROR] gcc/libstdc++-v3/src/c++20/tzdb.cc:110:21: error: call to non-'constexpr' function 'std::mutex::mutex()' > > > > > > > > > > > > Which target are you building for? > > > > > > > > > > Any plans to create a configure option to disable tzdb from build? Or at least make it compilable? > > > > > > Tried --with-libstdcxx-zoneinfo=no but it does not take effect, because it does not cover line with the bug. > > > > > > > > > Well then we should fix that. We don't want *another* configure option when we already have two for tzdb. > > > > > I think this should fix it: > > --- a/libstdc++-v3/src/c++20/tzdb.cc > +++ b/libstdc++-v3/src/c++20/tzdb.cc > @@ -43,8 +43,8 @@ > > #ifndef __GTHREADS > # define USE_ATOMIC_SHARED_PTR 0 > -#elif _WIN32 > -// std::mutex cannot be constinit, so Windows must use atomic<shared_ptr<>>. > +#elif ! defined __GTHREAD_MUTEX_INIT > +// std::mutex cannot be constinit, so must use atomic<shared_ptr<>>. > # define USE_ATOMIC_SHARED_PTR 1 > #elif ATOMIC_POINTER_LOCK_FREE < 2 > # define USE_ATOMIC_SHARED_PTR 0 > > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Full disable of C++20 time zone support 2023-06-29 9:15 ` Alexey Lapshin @ 2023-06-29 9:23 ` Jonathan Wakely 2023-06-29 9:27 ` Alexey Lapshin 0 siblings, 1 reply; 9+ messages in thread From: Jonathan Wakely @ 2023-06-29 9:23 UTC (permalink / raw) To: Alexey Lapshin; +Cc: jwakely, gcc-help On Thu, 29 Jun 2023 at 10:16, Alexey Lapshin via Gcc-help <gcc-help@gcc.gnu.org> wrote: > > > Which target are you building for? > > riscv32-esp-elf > > build with gcc v4.9.2 > > > I think this should fix it: > > This brings next errors: > > > gcc/libstdc++-v3/src/c++20/tzdb.cc:157:27: error: 'list_mutex' was not declared in this scope > gcc/libstdc++-v3/src/c++20/tzdb.cc:158:28: error: 'using std::chrono::tzdb_list::_Node::head_ptr = class std::atomic<std::shared_ptr<std::chrono::tzdb_list::_Node> >' {aka 'class std::atomic<std::shared_ptr<std::chrono::tzdb_list::_Node> >'} has no member named 'get' > > > > Why it could not be disabled at all? like this: > > > --- a/libstdc++-v3/src/c++20/tzdb.cc > +++ b/libstdc++-v3/src/c++20/tzdb.cc > @@ -22,6 +22,8 @@ > // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see > // <http://www.gnu.org/licenses/>. > > +#ifndef TZDB_DISABLED That macro isn't even defined until later in the file, so would never be defined at this point. But more importantly, that would give linker errors when including <chrono>. The point of that macro is to disable trying to process tzdata, not to create a broken libstdc++ with missing parts of the C++20 library. It should always be possible to call std::chrono::get_tzdb() even if the tzdb only contains the UTC time zone. > + > // The -Wabi warnings in this file are all for non-exported symbols. > #pragma GCC diagnostic ignored "-Wabi" > > @@ -2037,3 +2039,5 @@ namespace std::chrono > } // namespace > #endif // TZDB_DISABLED > } // namespace std::chrono > + > +#endif > > > > On Wed, 2023-06-28 at 20:40 +0100, Jonathan Wakely wrote: > > [External: This email originated outside Espressif] > > > > > > On Wed, 28 Jun 2023 at 20:33, Jonathan Wakely <jwakely@redhat.com> wrote: > > > On Wed, 28 Jun 2023 at 19:42, Alexey Lapshin wrote: > > > > Hi! > > > > > > > > I faced an issue with compiling libstdc++-v3/src/c++20/tzdb.cc: > > > > > > > > > > > > [ERROR] gcc/libstdc++-v3/src/c++20/tzdb.cc:110:21: error: 'constinit' variable 'std::chrono::{anonymous}::list_mutex' does not have a constant initializer > > > > [ERROR] gcc/libstdc++-v3/src/c++20/tzdb.cc:110:21: error: call to non-'constexpr' function 'std::mutex::mutex()' > > > > > > > > > > > > > > > > > Which target are you building for? > > > > > > > > > > > > > > Any plans to create a configure option to disable tzdb from build? Or at least make it compilable? > > > > > > > > Tried --with-libstdcxx-zoneinfo=no but it does not take effect, because it does not cover line with the bug. > > > > > > > > > > > > > Well then we should fix that. We don't want *another* configure option when we already have two for tzdb. > > > > > > > > > I think this should fix it: > > > > --- a/libstdc++-v3/src/c++20/tzdb.cc > > +++ b/libstdc++-v3/src/c++20/tzdb.cc > > @@ -43,8 +43,8 @@ > > > > #ifndef __GTHREADS > > # define USE_ATOMIC_SHARED_PTR 0 > > -#elif _WIN32 > > -// std::mutex cannot be constinit, so Windows must use atomic<shared_ptr<>>. > > +#elif ! defined __GTHREAD_MUTEX_INIT > > +// std::mutex cannot be constinit, so must use atomic<shared_ptr<>>. > > # define USE_ATOMIC_SHARED_PTR 1 > > #elif ATOMIC_POINTER_LOCK_FREE < 2 > > # define USE_ATOMIC_SHARED_PTR 0 > > > > > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Full disable of C++20 time zone support 2023-06-29 9:23 ` Jonathan Wakely @ 2023-06-29 9:27 ` Alexey Lapshin 2023-06-29 9:39 ` Jonathan Wakely 0 siblings, 1 reply; 9+ messages in thread From: Alexey Lapshin @ 2023-06-29 9:27 UTC (permalink / raw) To: jwakely.gcc; +Cc: jwakely, gcc-help On Thu, 2023-06-29 at 10:23 +0100, Jonathan Wakely wrote: > That macro isn't even defined until later in the file, so would never > be defined at this point. Was a simplified example. Why do you still need to have some mutexes or whatever in case TZDB_DISABLED? > It should always be possible to call std::chrono::get_tzdb() even if the tzdb only contains the UTC time zone. Just return NULL in case TZDB_DISABLED? Thanks ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Full disable of C++20 time zone support 2023-06-29 9:27 ` Alexey Lapshin @ 2023-06-29 9:39 ` Jonathan Wakely 2023-06-29 12:11 ` Jonathan Wakely 0 siblings, 1 reply; 9+ messages in thread From: Jonathan Wakely @ 2023-06-29 9:39 UTC (permalink / raw) To: Alexey Lapshin; +Cc: jwakely, gcc-help On Thu, 29 Jun 2023 at 10:27, Alexey Lapshin <alexey.lapshin@espressif.com> wrote: > > On Thu, 2023-06-29 at 10:23 +0100, Jonathan Wakely wrote: > > That macro isn't even defined until later in the file, so would never > > be defined at this point. > > Was a simplified example. > > > Why do you still need to have some mutexes or whatever in case TZDB_DISABLED? Because there is still a global object that needs to be lazily constructed, and multiple threads can try to access it concurrently. > > It should always be possible to call > std::chrono::get_tzdb() even if the tzdb only contains the UTC time > zone. > > Just return NULL in case TZDB_DISABLED? It returns a reference. As I said (and you quoted above), the intention is to return a valid object that contains the UTC time zone. That is a graceful failure for missing tzdata, not a crash. > > Thanks ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Full disable of C++20 time zone support 2023-06-29 9:39 ` Jonathan Wakely @ 2023-06-29 12:11 ` Jonathan Wakely 2023-06-29 13:51 ` Alexey Lapshin 0 siblings, 1 reply; 9+ messages in thread From: Jonathan Wakely @ 2023-06-29 12:11 UTC (permalink / raw) To: Alexey Lapshin; +Cc: jwakely, gcc-help [-- Attachment #1: Type: text/plain, Size: 627 bytes --] On Thu, 29 Jun 2023 at 10:39, Jonathan Wakely wrote: > > On Thu, 29 Jun 2023 at 10:27, Alexey Lapshin > <alexey.lapshin@espressif.com> wrote: > > > > On Thu, 2023-06-29 at 10:23 +0100, Jonathan Wakely wrote: > > > That macro isn't even defined until later in the file, so would never > > > be defined at this point. > > > > Was a simplified example. > > > > > > Why do you still need to have some mutexes or whatever in case TZDB_DISABLED? > > Because there is still a global object that needs to be lazily > constructed, and multiple threads can try to access it concurrently. The attached patch should work for your target. [-- Attachment #2: patch.txt --] [-- Type: text/plain, Size: 5030 bytes --] commit 881299967d8778e29f803d8801af9a0b1a5bd1bd Author: Jonathan Wakely <jwakely@redhat.com> Date: Thu Jun 29 11:40:32 2023 libstdc++: Fix src/c++20/tzdb.cc for non-constexpr std::mutex Building libstdc++ reportedly fails for targets without lock-free std::atomic<T*> which don't define __GTHREAD_MUTEX_INIT: src/c++20/tzdb.cc:110:21: error: 'constinit' variable 'std::chrono::{anonymous}::list_mutex' does not have a constant initializer src/c++20/tzdb.cc:110:21: error: call to non-'constexpr' function 'std::mutex::mutex()' The solution implemented by this commit is to use a local static mutex when it can't be constinit, so that it's constructed on first use. With this change, we can also simplify the preprocessor logic for defining USE_ATOMIC_SHARED_PTR. It now depends on the same conditions as USE_ATOMIC_LIST_HEAD, so in theory we could have a single macro. Keeping them separate would allow us to replace the use of atomic<shared_ptr<T>> with a mutex if that performs better, without having to give up on the lock-free cache for fast access to the list head. libstdc++-v3/ChangeLog: * src/c++20/tzdb.cc (USE_ATOMIC_SHARED_PTR): Define consistently with USE_ATOMIC_LIST_HEAD. (list_mutex): Replace global object with function. Use local static object when std::mutex constructor isn't constexpr. diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc index a43b4f33eba..8d27726016e 100644 --- a/libstdc++-v3/src/c++20/tzdb.cc +++ b/libstdc++-v3/src/c++20/tzdb.cc @@ -41,22 +41,17 @@ # include <cstdlib> // getenv #endif -#ifndef __GTHREADS -# define USE_ATOMIC_SHARED_PTR 0 -#elif _WIN32 -// std::mutex cannot be constinit, so Windows must use atomic<shared_ptr<>>. -# define USE_ATOMIC_SHARED_PTR 1 -#elif ATOMIC_POINTER_LOCK_FREE < 2 -# define USE_ATOMIC_SHARED_PTR 0 -#else -// TODO benchmark atomic<shared_ptr<>> vs mutex. -# define USE_ATOMIC_SHARED_PTR 1 -#endif - #if defined __GTHREADS && ATOMIC_POINTER_LOCK_FREE == 2 # define USE_ATOMIC_LIST_HEAD 1 +// TODO benchmark atomic<shared_ptr<>> vs mutex. +# define USE_ATOMIC_SHARED_PTR 1 #else # define USE_ATOMIC_LIST_HEAD 0 +# define USE_ATOMIC_SHARED_PTR 0 +#endif + +#if USE_ATOMIC_SHARED_PTR && ! USE_ATOMIC_LIST_HEAD +# error Unsupported combination #endif #if ! __cpp_constinit @@ -106,9 +101,18 @@ namespace std::chrono // Dummy no-op mutex type for single-threaded targets. struct mutex { void lock() { } void unlock() { } }; #endif - /// XXX std::mutex::mutex() not constexpr on Windows, so can't be constinit - constinit mutex list_mutex; + inline mutex& list_mutex() + { +#ifdef __GTHREAD_MUTEX_INIT + constinit static mutex m; +#else + // Cannot use a constinit mutex, so use a local static. + alignas(mutex) constinit static char buf[sizeof(mutex)]; + static mutex& m = *::new(buf) mutex(); #endif + return m; + } +#endif // ! USE_ATOMIC_SHARED_PTR struct Rule; } @@ -154,7 +158,7 @@ namespace std::chrono static _Node* _S_list_head(memory_order) { - lock_guard<mutex> l(list_mutex); + lock_guard<mutex> l(list_mutex()); return _S_head_owner.get(); } @@ -1279,7 +1283,7 @@ namespace std::chrono } // XXX small window here where _S_head_cache still points to previous tzdb. #else - lock_guard<mutex> l(list_mutex); + lock_guard<mutex> l(list_mutex()); if (const _Node* h = _S_head_owner.get()) { if (h->db.version == new_head_ptr->db.version) @@ -1406,11 +1410,12 @@ namespace std::chrono #else if (Node::_S_list_head(memory_order::relaxed) != nullptr) [[likely]] { - lock_guard<mutex> l(list_mutex); + lock_guard<mutex> l(list_mutex()); const tzdb& current = Node::_S_head_owner->db; if (current.version == version) return current; } + shared_ptr<Node> head; // Passed as unused arg to _S_replace_head. #endif auto [leaps, leaps_ok] = Node::_S_read_leap_seconds(); @@ -1499,9 +1504,6 @@ namespace std::chrono ranges::sort(node->db.links, {}, &time_zone_link::name); ranges::stable_sort(node->rules, {}, &Rule::name); -#if ! USE_ATOMIC_SHARED_PTR - shared_ptr<Node> head; -#endif return Node::_S_replace_head(std::move(head), std::move(node)); #else __throw_disabled(); @@ -1526,7 +1528,7 @@ namespace std::chrono #if USE_ATOMIC_SHARED_PTR return const_iterator{_Node::_S_head_owner.load()}; #else - lock_guard<mutex> l(list_mutex); + lock_guard<mutex> l(list_mutex()); return const_iterator{_Node::_S_head_owner}; #endif } @@ -1539,7 +1541,7 @@ namespace std::chrono if (p._M_node) [[likely]] { #if ! USE_ATOMIC_SHARED_PTR - lock_guard<mutex> l(list_mutex); + lock_guard<mutex> l(list_mutex()); #endif if (auto next = p._M_node->next) [[likely]] return const_iterator{p._M_node->next = std::move(next->next)}; ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Full disable of C++20 time zone support 2023-06-29 12:11 ` Jonathan Wakely @ 2023-06-29 13:51 ` Alexey Lapshin 0 siblings, 0 replies; 9+ messages in thread From: Alexey Lapshin @ 2023-06-29 13:51 UTC (permalink / raw) To: jwakely.gcc; +Cc: jwakely, gcc-help The patch does work. Thank you for a quick fix! ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-06-29 13:51 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-06-28 18:42 Full disable of C++20 time zone support Alexey Lapshin 2023-06-28 19:33 ` Jonathan Wakely 2023-06-28 19:40 ` Jonathan Wakely 2023-06-29 9:15 ` Alexey Lapshin 2023-06-29 9:23 ` Jonathan Wakely 2023-06-29 9:27 ` Alexey Lapshin 2023-06-29 9:39 ` Jonathan Wakely 2023-06-29 12:11 ` Jonathan Wakely 2023-06-29 13:51 ` Alexey Lapshin
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).