From c65901171a30b261f063c6a56c4a58a36d492be0 Mon Sep 17 00:00:00 2001 From: Cody Tapscott <84105208+topolarity@users.noreply.github.com> Date: Wed, 30 Aug 2023 21:58:57 -0400 Subject: [PATCH] Workaround upstream FreeBSD issue #272992 (#51114) ELF doesn't handle WEAK symbols dynamically the way it handles them statically. Looking up overloaded WEAK symbols via a library-specific handle will often give you the empty stub (in `libc.so.7` in this case) instead of the strong implementation elsewhere (`ld-elf.so.1` here). Even after the [upstream fix](https://cgit.freebsd.org/src/commit/?id=21a52f99440c9bec7679f3b0c5c9d888901c3694), `dlsym`, `dladdr` and a ton of other symbols still have stubs with no trampoline in FreeBSD's libc: https://cgit.freebsd.org/src/tree/lib/libc/gen/dlfcn.c?id=21a52f99440c9bec7679f3b0c5c9d888901c3694 Thankfully `dl_iterate_phdr` appears to be the only function that we directly `ccall` from Julia's Libdl so we can leave this fix incomplete for now. Resolves #50846. --- 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;