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.
This commit is contained in:
Audrey Dutcher 2025-03-06 22:24:27 -07:00
parent ac279d7e71
commit 86988bb5a8

View file

@ -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