From 867b801601fb73813c9fcc9c78308833627e897d Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Sun, 11 Feb 2024 18:29:03 +0100 Subject: [PATCH] Get the handle from dlopen and not from debug infos --- src/gotcha_dl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gotcha_dl.c b/src/gotcha_dl.c index 9f1a82a..16e55b5 100644 --- a/src/gotcha_dl.c +++ b/src/gotcha_dl.c @@ -151,6 +151,7 @@ static void *dlopen_wrapper(const char *filename, int flags) { } static void *dlsym_wrapper(void *handle, const char *symbol_name) { + typeof(&dlopen_wrapper) orig_dlopen = gotcha_get_wrappee(orig_dlopen_handle); typeof(&dlsym_wrapper) orig_dlsym = gotcha_get_wrappee(orig_dlsym_handle); struct internal_binding_t *binding; debug_printf(1, "User called dlsym(%p, %s)\n", handle, symbol_name); @@ -161,7 +162,8 @@ static void *dlsym_wrapper(void *handle, const char *symbol_name) { struct link_map *lib = gotchas_dlsym_rtld_next_lookup( symbol_name, __builtin_return_address(0)); if (lib) { - void *symbol = orig_dlsym(lib, symbol_name); + void *handle = orig_dlopen(lib->l_name, RTLD_NOW); + void *symbol = orig_dlsym(handle, symbol_name); return symbol; } return NULL;