From d9c56bfd49c1b2935b6e1431a7ab946df50ed1cc Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Wed, 30 Aug 2023 04:06:49 -0400 Subject: [PATCH] Workaround upstream FreeBSD issue #272992 FreeBSD does not support looking up WEAK symbols in its libc via `dlsym` if you're using a library-specific handle. It will give you the empty stub in libc instead of, e.g., the strong implementation in ld-elf.so This fix and the one that was merged upstream are pretty conspicuously incomplete, since `dlsym`, `dladdr` and a ton of other symbols still have stubs with no trampoline in libc: https://cgit.freebsd.org/src/tree/lib/libc/gen/dlfcn.c?id=21a52f99440c9bec7679f3b0c5c9d888901c3694 Thankfully, this appears to be the only function that we directly `ccall` from Julia's Libdl so we can leave this fix incomplete for now. --- src/dlload.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/dlload.c b/src/dlload.c index ffa9a053d5f1c..8124605880b5e 100644 --- a/src/dlload.c +++ b/src/dlload.c @@ -435,6 +435,13 @@ JL_DLLEXPORT int jl_dlsym(void *handle, const char *symbol, void ** value, int t // Look for symbols in internal libraries JL_DLLEXPORT const char *jl_dlfind(const char *f_name) { +#ifdef _OS_FREEBSD_ + // This is a workaround for FreeBSD <= 13.2 which do not have + // https://cgit.freebsd.org/src/commit/?id=21a52f99440c9bec7679f3b0c5c9d888901c3694 + // (See https://github.com/JuliaLang/julia/issues/50846) + if (strcmp(f_name, "dl_iterate_phdr") == 0) + return JL_EXE_LIBNAME; +#endif void * dummy; if (jl_dlsym(jl_libjulia_internal_handle, f_name, &dummy, 0)) return JL_LIBJULIA_INTERNAL_DL_LIBNAME;