From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 6366F3858D1E for ; Sat, 14 Jan 2023 18:26:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6366F3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673720797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xVjgSnJg3F/4tCDpyEnfLvCEZosnB0JmK4nDNFfgbsM=; b=befndLkwbTFYHRVUEPDJCFcMcgjG0huHtwu0lwv/Liqsei1HQQXjHEQdxjheBobNmgGG7y X9E3u2MxZlvKudGeiN6fqTtdhQ0erbokyIM/Hx/fWPo9FBOE5YFJXaNJr/CTvDzBovBzbh Xr3J2KvH4ehB1I4WKAhpWuLw2kbbm1c= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-414-H82UMl4gPp-PXfvlm2sGUw-1; Sat, 14 Jan 2023 13:26:35 -0500 X-MC-Unique: H82UMl4gPp-PXfvlm2sGUw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8CCF185A588; Sat, 14 Jan 2023 18:26:35 +0000 (UTC) Received: from localhost (unknown [10.33.36.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F2AF492B05; Sat, 14 Jan 2023 18:26:35 +0000 (UTC) Date: Sat, 14 Jan 2023 18:26:34 +0000 From: Jonathan Wakely To: iain@sandoe.co.uk Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org, Iain Sandoe Subject: Re: [PATCH] libstdc++, configure: Fix GLIBCXX_ZONEINFO_DIR configuration macro. Message-ID: References: <20221223170619.38428-1-iain@sandoe.co.uk> MIME-Version: 1.0 In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 14/01/23 18:24 +0000, Jonathan Wakely wrote: >On 23/12/22 17:06 +0000, Iain Sandoe wrote: >>This is a patch for comment on the approach - tested on x86_64-darwi21 >>thoughts? >>Iain >> >>--- 8< --- >> >>Testing on Darwin revealed that the GLIBCXX_ZONEINFO_DIR was not doing quite >>the right thing (we ended up with ${withval} in the config.h file). >> >>This patch proposes revising the behaviour of the configure flag thus: >> >>--with-libstdcxx-zoneinfo-dir= >>unspecified : Set _GLIBCXX_ZONEINFO_DIR to a default suitable for $host >> yes : Set _GLIBCXX_ZONEINFO_DIR to a default suitable for $host >> no : Do not set _GLIBCXX_ZONEINFO_DIR >>/some/path : set _GLIBCXX_ZONEINFO_DIR = "/some/path" > >Here's what I've pushed to trunk now, after discussion with Iain. This is a small follow-up to elide most of the code in src/c++20/tzdb.cc when the library is configured with --with-libstdcxx-zoneinfo=no Tested x86_64-linux and powerpc64le-linux. Pushed to trunk. -- >8 -- commit c47dcb95666ce0b48f0ff09aa99483fd12df8714 Author: Jonathan Wakely Date: Sat Jan 14 13:39:48 2023 libstdc++: Disable unwanted code for --with-libstdcxx-zoneinfo=no This allows most of the tzdb functionality to be disabled by configuring with --with-libstdcxx-zoneinfo=no. This might be desirable for small targets that don't need the time zone support. libstdc++-v3/ChangeLog: * src/c++20/tzdb.cc (TZDB_DISABLED): Disable all code for loading tzdb. * testsuite/std/time/tzdb/leap_seconds.cc: Require tzdb effective target. * testsuite/std/time/tzdb_list/1.cc: Likewise. diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc index 94fb0436091..a37859dffdb 100644 --- a/libstdc++-v3/src/c++20/tzdb.cc +++ b/libstdc++-v3/src/c++20/tzdb.cc @@ -82,6 +82,14 @@ namespace __gnu_cxx #endif } +#if ! defined _GLIBCXX_ZONEINFO_DIR && ! defined _GLIBCXX_STATIC_TZDATA +# define TZDB_DISABLED + [[noreturn]] void __throw_disabled() + { + std::__throw_runtime_error("tzdb: support for loading tzdata is disabled"); + } +#endif + namespace std::chrono { namespace @@ -105,7 +113,9 @@ namespace std::chrono { shared_ptr<_Node> next; tzdb db; +#ifndef TZDB_DISABLED vector rules; +#endif // The following static members are here because making them members // of this type gives them access to the private members of time_zone @@ -175,6 +185,7 @@ namespace std::chrono // assume that setting failbit will throw an exception, so individual // input operations are not always checked for success. +#ifndef TZDB_DISABLED namespace { // Used for reading a possibly-quoted string from a stream. @@ -582,6 +593,7 @@ namespace std::chrono #endif }; } // namespace +#endif // TZDB_DISABLED // Private constructor used by reload_tzdb() to create time_zone objects. time_zone::time_zone(unique_ptr<_Impl> __p) : _M_impl(std::move(__p)) { } @@ -591,6 +603,7 @@ namespace std::chrono // The opaque pimpl class stored in a time_zone object. struct time_zone::_Impl { +#ifndef TZDB_DISABLED explicit _Impl(weak_ptr node) : node(std::move(node)) { } @@ -677,11 +690,19 @@ namespace std::chrono } } }; -#endif +#endif // __GTHREADS && __cpp_lib_atomic_wait RulesCounter rules_counter; +#else // TZDB_DISABLED + _Impl(weak_ptr) { } + struct { + sys_info info; + void push_back(sys_info i) { info = std::move(i); } + } infos; +#endif // TZDB_DISABLED }; +#ifndef TZDB_DISABLED namespace { bool @@ -731,11 +752,13 @@ namespace std::chrono select_std_or_dst_abbrev(info.abbrev, info.save); } } +#endif // TZDB_DISABLED // Implementation of std::chrono::time_zone::get_info(const sys_time&) sys_info time_zone::_M_get_sys_info(sys_seconds tp) const { +#ifndef TZDB_DISABLED // This gives us access to the node->rules vector, but also ensures // that the tzdb node won't get erased while we're still using it. const auto node = _M_impl->node.lock(); @@ -934,17 +957,20 @@ namespace std::chrono // Decrement count of rule-based infos (might also release lock). _M_impl->rules_counter.decrement(); } - return info; +#else + return _M_impl->infos.info; +#endif // TZDB_DISABLED } // Implementation of std::chrono::time_zone::get_info(const local_time&) local_info time_zone::_M_get_local_info(local_seconds tp) const { + local_info info{}; +#ifndef TZDB_DISABLED const auto node = _M_impl->node.lock(); - local_info info{}; // Get sys_info assuming no offset between local time and UTC: info.first = _M_get_sys_info(sys_seconds(tp.time_since_epoch())); @@ -1007,9 +1033,13 @@ namespace std::chrono } // else tp is a unique local time, info.first is the correct sys_info. } +#else + info.first = _M_impl->infos.info; +#endif // TZDB_DISABLED return info; } +#ifndef TZDB_DISABLED namespace { // If a zoneinfo directory is defined (either when the library was built, @@ -1088,14 +1118,13 @@ namespace std::chrono bool using_static_data() const { return this->rdbuf() == &sb; } }; } +#endif // TZDB_DISABLED // Return leap_second values, and a bool indicating whether the values are // current (true), or potentially out of date (false). pair, bool> tzdb_list::_Node::_S_read_leap_seconds() { - const string filename = zoneinfo_file(leaps_file); - // This list is valid until at least 2023-06-28 00:00:00 UTC. auto expires = sys_days{2023y/6/28}; vector leaps @@ -1137,10 +1166,10 @@ namespace std::chrono return {std::move(leaps), true}; #endif - auto exp_year = year_month_day(expires).year(); - - if (ifstream ls{filename}) +#ifndef TZDB_DISABLED + if (ifstream ls{zoneinfo_file(leaps_file)}) { + auto exp_year = year_month_day(expires).year(); std::string s, w; s.reserve(80); // Avoid later reallocations. while (std::getline(ls, s)) @@ -1183,10 +1212,11 @@ namespace std::chrono } return {std::move(leaps), true}; } - else - return {std::move(leaps), false}; +#endif + return {std::move(leaps), false}; } +#ifndef TZDB_DISABLED namespace { // Read the version number from a tzdata.zi file. @@ -1213,12 +1243,17 @@ namespace std::chrono __throw_runtime_error("tzdb: no version found in tzdata.zi"); } } +#endif // Definition of std::chrono::remote_version() string remote_version() { +#ifndef TZDB_DISABLED tzdata_stream zif; return remote_version(zif); +#else + __throw_disabled(); +#endif } // Used by chrono::reload_tzdb() to add a new node to the front of the list. @@ -1255,11 +1290,13 @@ namespace std::chrono const tzdb& tzdb_list::_Node::_S_init_tzdb() { +#ifndef TZDB_DISABLED __try { return reload_tzdb(); } __catch (const std::exception&) +#endif { auto [leaps, ok] = _S_read_leap_seconds(); @@ -1349,6 +1386,7 @@ namespace std::chrono const tzdb& reload_tzdb() { +#ifndef TZDB_DISABLED using Node = tzdb_list::_Node; tzdata_stream zif; @@ -1458,6 +1496,9 @@ namespace std::chrono shared_ptr head; #endif return Node::_S_replace_head(std::move(head), std::move(node)); +#else + __throw_disabled(); +#endif // TZDB_DISABLED } // Any call to tzdb_list::front() or tzdb_list::begin() must follow @@ -1641,6 +1682,7 @@ namespace std::chrono return get_tzdb_list().begin()->current_zone(); } +#ifndef TZDB_DISABLED namespace { istream& operator>>(istream& in, abbrev_month& am) @@ -1933,5 +1975,5 @@ namespace std::chrono return in; } } // namespace - +#endif // TZDB_DISABLED } // namespace std::chrono diff --git a/libstdc++-v3/testsuite/std/time/tzdb/leap_seconds.cc b/libstdc++-v3/testsuite/std/time/tzdb/leap_seconds.cc index 2b289436583..d27038225c8 100644 --- a/libstdc++-v3/testsuite/std/time/tzdb/leap_seconds.cc +++ b/libstdc++-v3/testsuite/std/time/tzdb/leap_seconds.cc @@ -1,5 +1,6 @@ // { dg-options "-std=gnu++20" } // { dg-do run { target c++20 } } +// { dg-require-effective-target tzdb } // { dg-require-effective-target cxx11_abi } // { dg-xfail-run-if "no weak override on AIX" { powerpc-ibm-aix* } } diff --git a/libstdc++-v3/testsuite/std/time/tzdb_list/1.cc b/libstdc++-v3/testsuite/std/time/tzdb_list/1.cc index 4cbd656efbd..2b121ff219d 100644 --- a/libstdc++-v3/testsuite/std/time/tzdb_list/1.cc +++ b/libstdc++-v3/testsuite/std/time/tzdb_list/1.cc @@ -1,5 +1,6 @@ // { dg-options "-std=gnu++20" } // { dg-do run { target c++20 } } +// { dg-require-effective-target tzdb } // { dg-require-effective-target cxx11_abi } // { dg-xfail-run-if "no weak override on AIX" { powerpc-ibm-aix* } }