Skip to content

Commit

Permalink
Get the handle from dlopen and not from debug infos
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Cornu committed Feb 11, 2024
1 parent 365d638 commit 867b801
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/gotcha_dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 867b801

Please sign in to comment.