aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTijl Coosemans <tijl@FreeBSD.org>2023-07-17 13:06:02 +0000
committerTijl Coosemans <tijl@FreeBSD.org>2023-07-17 18:53:17 +0000
commitfb889ca82944e04d4b3dfa2a13c51456bbde0094 (patch)
tree026700efa75a093fe78cb7f46b3dc9447f1f4518
parent70528428672cb3c386ae3dcfd36694c5dfde11fc (diff)
downloadports-fb889ca82944e04d4b3dfa2a13c51456bbde0094.tar.gz
ports-fb889ca82944e04d4b3dfa2a13c51456bbde0094.zip
devel/gettext-runtime: Fix crash triggered by libgpg-error
Libgpg-error has an initialisation function with __attribute__((constructor)) that calls a libintl function that calls pthread_rwlock_wrlock that segfaults if libpthread wasn't initialised yet. This can happen because libintl doesn't link to libpthread to avoid the overhead for non-threaded programs. To fix this, add an initialisation function to libintl that triggers initialisation of libpthread. RTLD_NOLOAD suggested by kib. dlopen was fixed to work during initialisation in https://cgit.FreeBSD.org/src/commit/?id=1005d3d05362 PR: 272472, 272517
-rw-r--r--Mk/Uses/gettext-runtime.mk5
-rw-r--r--devel/gettext-runtime/Makefile2
-rw-r--r--devel/gettext-runtime/files/patch-intl_osdep.c28
3 files changed, 32 insertions, 3 deletions
diff --git a/Mk/Uses/gettext-runtime.mk b/Mk/Uses/gettext-runtime.mk
index 374a19b45ec4..1d0f0b8900b9 100644
--- a/Mk/Uses/gettext-runtime.mk
+++ b/Mk/Uses/gettext-runtime.mk
@@ -14,13 +14,14 @@ gettext-runtime_ARGS= lib
. endif
. if ${gettext-runtime_ARGS:Mlib}
+BUILD_DEPENDS+= gettext-runtime>=0.22_1:devel/gettext-runtime
LIB_DEPENDS+= libintl.so:devel/gettext-runtime
. endif
. if ${gettext-runtime_ARGS:Mbuild}
-BUILD_DEPENDS+= gettext:devel/gettext-runtime
+BUILD_DEPENDS+= gettext-runtime>=0.22_1:devel/gettext-runtime
. endif
. if ${gettext-runtime_ARGS:Mrun}
-RUN_DEPENDS+= gettext:devel/gettext-runtime
+RUN_DEPENDS+= gettext-runtime>=0.22_1:devel/gettext-runtime
. endif
.endif
diff --git a/devel/gettext-runtime/Makefile b/devel/gettext-runtime/Makefile
index 618340e867f9..1e57b4fb24d7 100644
--- a/devel/gettext-runtime/Makefile
+++ b/devel/gettext-runtime/Makefile
@@ -3,7 +3,7 @@
# discretion.
PORTNAME= gettext-runtime
-PORTREVISION= 0
+PORTREVISION= 1
COMMENT= GNU gettext runtime libraries and programs
WWW= https://www.gnu.org/software/gettext/
diff --git a/devel/gettext-runtime/files/patch-intl_osdep.c b/devel/gettext-runtime/files/patch-intl_osdep.c
new file mode 100644
index 000000000000..1f1825303b65
--- /dev/null
+++ b/devel/gettext-runtime/files/patch-intl_osdep.c
@@ -0,0 +1,28 @@
+--- intl/osdep.c.orig 2019-05-11 11:29:32 UTC
++++ intl/osdep.c
+@@ -18,6 +18,25 @@
+ # include "intl-exports.c"
+ #elif defined __EMX__ && !defined __KLIBC__
+ # include "os2compat.c"
++#elif defined __FreeBSD__
++#include <config.h>
++#include <sys/param.h>
++#include <dlfcn.h>
++#include <pthread.h>
++static __attribute__((constructor)) void
++libintl_init (void)
++{
++#if __FreeBSD_version >= 1400094
++ /* We don't link with libpthread in order to avoid the overhead for
++ non-threaded programs. Instead we dlopen it with RTLD_NOLOAD here
++ to ensure it is initialised when present. */
++ (void) dlopen ("libpthread.so", RTLD_LAZY | RTLD_GLOBAL | RTLD_NOLOAD);
++#else
++ /* For older versions this hack also triggers libpthread
++ initialisation. */
++ (void) pthread_self ();
++#endif
++}
+ #else
+ /* Avoid AIX compiler warning. */
+ typedef int dummy;