[PATCH] libstdc++: Use #embed for static tzdata.zi file

Jonathan Wakely jwakely@redhat.com
Tue May 19 20:32:34 GMT 2026


This doesn't make much difference to the time taken to compile tzdb.cc
but it is simpler and more maintainable than generating a header in the
makefile.

libstdc++-v3/ChangeLog:

	* src/c++20/Makefile.am [USE_STATIC_TZDATA]: Remove targets for
	tzdata.zi.h, tzdb.lo and tzdb.o.
	* src/c++20/Makefile.in: Regenerate.
	* src/c++20/tzdb.cc (tzdata_chars): Use #embed.
	(tzdata_stream::ispanbuf): Remove adjustment for extra newline
	inserted by the Makefile recipe for tzdata.zi.h.
---

Tested aarch64-linux.

 libstdc++-v3/src/c++20/Makefile.am | 13 -------------
 libstdc++-v3/src/c++20/Makefile.in | 11 -----------
 libstdc++-v3/src/c++20/tzdb.cc     |  8 +++++---
 3 files changed, 5 insertions(+), 27 deletions(-)

diff --git a/libstdc++-v3/src/c++20/Makefile.am b/libstdc++-v3/src/c++20/Makefile.am
index 5182d51b9faa..cfd09bddffcb 100644
--- a/libstdc++-v3/src/c++20/Makefile.am
+++ b/libstdc++-v3/src/c++20/Makefile.am
@@ -54,19 +54,6 @@ if ENABLE_DUAL_ABI
 cow-string-inst.lo cow-string-inst.o: string-inst.cc
 endif
 
-if USE_STATIC_TZDATA
-tzdata.zi.h: $(top_srcdir)/src/c++20/tzdata.zi
-	echo 'static const char tzdata_chars[] = R"__libstdcxx__(' > $@.tmp
-	cat $^ >> $@.tmp
-	echo ')__libstdcxx__";' >> $@.tmp
-	mv $@.tmp $@
-
-tzdb.lo: tzdb.cc tzdata.zi.h
-	$(LTCXXCOMPILE) -I. -c $<
-tzdb.o: tzdb.cc tzdata.zi.h
-	$(CXXCOMPILE) -I. -c $<
-endif
-
 # This needs access to std::text_encoding and to the internals of std::locale.
 format.lo: format.cc
 	$(LTCXXCOMPILE) -std=gnu++26 -fno-access-control -c $<
diff --git a/libstdc++-v3/src/c++20/Makefile.in b/libstdc++-v3/src/c++20/Makefile.in
index 33e3ba21b522..067419d2e485 100644
--- a/libstdc++-v3/src/c++20/Makefile.in
+++ b/libstdc++-v3/src/c++20/Makefile.in
@@ -758,17 +758,6 @@ vpath % $(top_srcdir)/src/c++20
 # These files should be rebuilt if the .cc prerequisite changes.
 @ENABLE_DUAL_ABI_TRUE@cow-string-inst.lo cow-string-inst.o: string-inst.cc
 
-@USE_STATIC_TZDATA_TRUE@tzdata.zi.h: $(top_srcdir)/src/c++20/tzdata.zi
-@USE_STATIC_TZDATA_TRUE@	echo 'static const char tzdata_chars[] = R"__libstdcxx__(' > $@.tmp
-@USE_STATIC_TZDATA_TRUE@	cat $^ >> $@.tmp
-@USE_STATIC_TZDATA_TRUE@	echo ')__libstdcxx__";' >> $@.tmp
-@USE_STATIC_TZDATA_TRUE@	mv $@.tmp $@
-
-@USE_STATIC_TZDATA_TRUE@tzdb.lo: tzdb.cc tzdata.zi.h
-@USE_STATIC_TZDATA_TRUE@	$(LTCXXCOMPILE) -I. -c $<
-@USE_STATIC_TZDATA_TRUE@tzdb.o: tzdb.cc tzdata.zi.h
-@USE_STATIC_TZDATA_TRUE@	$(CXXCOMPILE) -I. -c $<
-
 # This needs access to std::text_encoding and to the internals of std::locale.
 format.lo: format.cc
 	$(LTCXXCOMPILE) -std=gnu++26 -fno-access-control -c $<
diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc
index 183a0c61a616..5793155b6d89 100644
--- a/libstdc++-v3/src/c++20/tzdb.cc
+++ b/libstdc++-v3/src/c++20/tzdb.cc
@@ -1208,8 +1208,10 @@ namespace std::chrono
     const string_view leaps_file = "/leapseconds";
 
 #ifdef _GLIBCXX_STATIC_TZDATA
-// Static copy of tzdata.zi embedded in the library as tzdata_chars[]
-#include "tzdata.zi.h"
+// Static copy of tzdata.zi embedded in the library.
+static constexpr char tzdata_chars[] = {
+#embed "tzdata.zi"
+};
 #endif
 
     // An istream type that can read from a file or from a string.
@@ -1222,7 +1224,7 @@ namespace std::chrono
 	{
 #ifdef _GLIBCXX_STATIC_TZDATA
 	  char* p = const_cast<char*>(tzdata_chars);
-	  this->setg(p, p, p + std::size(tzdata_chars) - 1);
+	  this->setg(p, p, p + std::size(tzdata_chars));
 #endif
 	}
 
-- 
2.54.0



More information about the Libstdc++ mailing list