-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from h-vetinari/tzdb
tzdb integration
- Loading branch information
Showing
9 changed files
with
213 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ches/0002-cross-compile-older-glibc.patch → ...ches/0001-cross-compile-older-glibc.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...003-allow-commands-in-main-specfile.patch → ...002-allow-commands-in-main-specfile.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
recipe/patches/0003-patch-zoneinfo_dir_override-to-point-to-our-tzdata.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
From 364f9fd8505a162a6cacd0223c3b55927804981c Mon Sep 17 00:00:00 2001 | ||
From: "H. Vetinari" <h.vetinari@gmx.com> | ||
Date: Fri, 21 Jun 2024 12:41:07 +1100 | ||
Subject: [PATCH 3/5] patch zoneinfo_dir_override to point to our tzdata | ||
|
||
--- | ||
libstdc++-v3/src/c++20/tzdb.cc | 78 ++++++++++++++++++++++++++++------ | ||
1 file changed, 65 insertions(+), 13 deletions(-) | ||
|
||
diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc | ||
index c7c7cc9de..1596a77b2 100644 | ||
--- a/libstdc++-v3/src/c++20/tzdb.cc | ||
+++ b/libstdc++-v3/src/c++20/tzdb.cc | ||
@@ -37,8 +37,12 @@ | ||
#include <mutex> // mutex | ||
#include <filesystem> // filesystem::read_symlink | ||
|
||
-#ifndef _AIX | ||
-# include <cstdlib> // getenv | ||
+#if defined(__linux__) | ||
+# include <dlfcn.h> // dladdr | ||
+# include <cstdlib> // free, malloc, realpath | ||
+# include <cstring> // memcpy, strlen | ||
+#else defined(_WIN32) | ||
+# include <windows.h> | ||
#endif | ||
|
||
#if defined __GTHREADS && ATOMIC_POINTER_LOCK_FREE == 2 | ||
@@ -64,25 +68,73 @@ | ||
|
||
namespace __gnu_cxx | ||
{ | ||
-#ifdef _AIX | ||
- // Cannot override weak symbols on AIX. | ||
- const char* (*zoneinfo_dir_override)() = nullptr; | ||
-#else | ||
- [[gnu::weak]] const char* zoneinfo_dir_override(); | ||
- | ||
-#if defined(__APPLE__) || defined(__hpux__) \ | ||
- || (defined(__VXWORKS__) && !defined(__RTP__)) | ||
- // Need a weak definition for Mach-O et al. | ||
[[gnu::weak]] const char* zoneinfo_dir_override() | ||
{ | ||
+#ifdef _GLIBCXX_SHARED | ||
+ // get path to library we're in, to determine our location relative to $PREFIX; | ||
+ // with help from the MIT-licensed https://github.com/gpakosz/whereami | ||
+ void* addr = __builtin_extract_return_addr(__builtin_return_address(0)); | ||
+ char* this_lib; | ||
+ int i; | ||
+ // <string> is included through <chrono> | ||
+ static std::string tz_dir; | ||
+ if (!tz_dir.empty()) { | ||
+ return tz_dir.c_str(); | ||
+ } | ||
+#ifdef _WIN32 | ||
+ // we're in %PREFIX%\Library\bin\libstdc++-6.dll | ||
+# define TO_PREFIX "/../.." | ||
+ // needs single quotes for character (not string) literal | ||
+# define PATH_SEP '\\' | ||
+ wchar_t buffer[MAX_PATH]; | ||
+ HMODULE hm = NULL; | ||
+ // non-zero return means success | ||
+ if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | | ||
+ GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, | ||
+ (LPCSTR) addr, &hm)) { | ||
+ // returns length of string (not counting null byte), see | ||
+ // https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamew#return-value | ||
+ DWORD total_length = GetModuleFileNameW(hm, buffer, sizeof(buffer)); | ||
+ if (total_length) { | ||
+ this_lib = (char*)malloc(total_length + 1); | ||
+ memcpy(this_lib, buffer, total_length); | ||
+#else | ||
+ // we're in $PREFIX/lib/libstdcxx.so | ||
+# define TO_PREFIX "/.." | ||
+# define PATH_SEP '/' | ||
+ char buffer[PATH_MAX]; | ||
+ Dl_info info; | ||
+ | ||
+ if (dladdr(addr, &info)) { | ||
+ char* resolved = realpath(info.dli_fname, buffer); | ||
+ if (resolved) { | ||
+ int total_length = (int)strlen(resolved); | ||
+ this_lib = (char*)malloc(total_length + 1); | ||
+ memcpy(this_lib, resolved, total_length); | ||
+#endif | ||
+ | ||
+ for (i = (int)total_length - 1; i >= 0; --i) { | ||
+ if (this_lib[i] == PATH_SEP) { | ||
+ // set to null byte so the string ends before the basename | ||
+ this_lib[i] = '\0'; | ||
+ break; | ||
+ } | ||
+ } | ||
+ tz_dir = {this_lib}; | ||
+ tz_dir += TO_PREFIX; | ||
+ tz_dir += "/share/zoneinfo"; | ||
+ // std::string constructor for tz_dir deep-copies | ||
+ free(this_lib); | ||
+ return tz_dir.c_str(); | ||
+ } | ||
+ } | ||
+#endif // _GLIBCXX_SHARED | ||
#ifdef _GLIBCXX_ZONEINFO_DIR | ||
return _GLIBCXX_ZONEINFO_DIR; | ||
#else | ||
return nullptr; | ||
#endif | ||
} | ||
-#endif | ||
-#endif | ||
} | ||
|
||
#if ! defined _GLIBCXX_ZONEINFO_DIR && ! defined _GLIBCXX_STATIC_TZDATA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
From 47b93186270f8f72a8a0229c08871b7a613484a4 Mon Sep 17 00:00:00 2001 | ||
From: "H. Vetinari" <h.vetinari@gmx.com> | ||
Date: Mon, 15 Jul 2024 19:16:05 +1100 | ||
Subject: [PATCH 4/5] add `-ldl` to libstdc___la_LDFLAGS | ||
|
||
we want to link static-only here, to avoid having to add | ||
`-ldl` everytime something links against libstdc++.so | ||
|
||
Co-Authored-By: Isuru Fernando <isuruf@gmail.com> | ||
--- | ||
libstdc++-v3/src/Makefile.am | 2 +- | ||
libstdc++-v3/src/Makefile.in | 2 +- | ||
2 files changed, 2 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am | ||
index 37ba1491d..5b69f43ec 100644 | ||
--- a/libstdc++-v3/src/Makefile.am | ||
+++ b/libstdc++-v3/src/Makefile.am | ||
@@ -161,7 +161,7 @@ libstdc___darwin_rpath += -Wl,-rpath,@loader_path | ||
endif | ||
|
||
libstdc___la_LDFLAGS = \ | ||
- -version-info $(libtool_VERSION) ${version_arg} -lm $(libstdc___darwin_rpath) | ||
+ -version-info $(libtool_VERSION) ${version_arg} -lm -Bstatic -ldl -Bdynamic -Wl,--exclude-libs,libdl.a $(libstdc___darwin_rpath) | ||
|
||
libstdc___la_LINK = $(CXXLINK) $(libstdc___la_LDFLAGS) $(lt_host_flags) | ||
|
||
diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in | ||
index 1bdf0daa8..ab28e1480 100644 | ||
--- a/libstdc++-v3/src/Makefile.in | ||
+++ b/libstdc++-v3/src/Makefile.in | ||
@@ -566,7 +566,7 @@ libstdc___la_DEPENDENCIES = \ | ||
@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wc,-nodefaultrpaths \ | ||
@ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path | ||
libstdc___la_LDFLAGS = \ | ||
- -version-info $(libtool_VERSION) ${version_arg} -lm $(libstdc___darwin_rpath) | ||
+ -version-info $(libtool_VERSION) ${version_arg} -lm -Bstatic -ldl -Bdynamic -Wl,--exclude-libs,libdl.a $(libstdc___darwin_rpath) | ||
|
||
libstdc___la_LINK = $(CXXLINK) $(libstdc___la_LDFLAGS) $(lt_host_flags) | ||
@GLIBCXX_LDBL_ALT128_COMPAT_FALSE@@GLIBCXX_LDBL_COMPAT_TRUE@LTCXXCOMPILE64 = $(LTCXXCOMPILE) |
4 changes: 2 additions & 2 deletions
4
...GNED_ALLOC-1-in-libstdc-v3-configur.patch → ...GNED_ALLOC-1-in-libstdc-v3-configur.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// We are using a weak symbol in linux and windows using a patch | ||
// while upstream only has the definition and no implementation. | ||
// Check that overriding works. | ||
|
||
// adapted from upstream tests | ||
// https://github.com/gcc-mirror/gcc/blob/releases/gcc-14.1.0/libstdc%2B%2B-v3/testsuite/std/time/tzdb/1.cc | ||
// https://github.com/gcc-mirror/gcc/blob/releases/gcc-14.1.0/libstdc%2B%2B-v3/testsuite/std/time/tzdb/leap_seconds.cc | ||
|
||
#include <chrono> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
static bool override_used = false; | ||
|
||
namespace __gnu_cxx | ||
{ | ||
const char* zoneinfo_dir_override() { | ||
override_used = true; | ||
return "./"; | ||
} | ||
} | ||
|
||
using namespace std::chrono; | ||
|
||
int main() | ||
{ | ||
auto &a = get_tzdb(); | ||
return !override_used; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ sed | |
findutils | ||
make | ||
file | ||
strace |