From 86988bb5a8024854a91e27361b35af410019cdc4 Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Thu, 6 Mar 2025 22:24:27 -0700 Subject: [PATCH] background_thread: add fallback for pthread_create dlsym If jemalloc is linked into a shared library, the RTLD_NEXT dlsym call may fail since RTLD_NEXT is only specified to search all objects after the current one in the loading order, and the pthread library may be earlier in the load order. Instead of failing immediately, attempt one more time to find pthread_create via RTLD_GLOBAL. Errors cascading from this were observed on FreeBSD 14.1. --- src/background_thread.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/background_thread.c b/src/background_thread.c index 30c3111c..511febac 100644 --- a/src/background_thread.c +++ b/src/background_thread.c @@ -63,6 +63,9 @@ pthread_create_fptr_init(void) { */ #ifdef JEMALLOC_HAVE_DLSYM pthread_create_fptr = dlsym(RTLD_NEXT, "pthread_create"); + if (pthread_create_fptr == NULL) { + pthread_create_fptr = dlsym(RTLD_DEFAULT, "pthread_create"); + } #else pthread_create_fptr = NULL; #endif