Skip to content

Commit edd613c

Browse files
authored
Add temporary gotcha build workaround for glibc 2.34+ (LLNL#405)
1 parent 9cf3821 commit edd613c

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

ext/gotcha/src/gotcha_dl.c

+20-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
#include "elf_ops.h"
66
#include <dlfcn.h>
77

8+
#if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 34
9+
# define GOTCHA_DL_SYM_WORKAROUND 1
10+
#endif
11+
12+
#ifndef GOTCHA_DL_SYM_WORKAROUND
813
void* _dl_sym(void* handle, const char* name, void* where);
14+
#endif
915

1016
gotcha_wrappee_handle_t orig_dlopen_handle;
1117
gotcha_wrappee_handle_t orig_dlsym_handle;
@@ -17,13 +23,13 @@ static int per_binding(hash_key_t key, hash_data_t data, void *opaque KNOWN_UNUS
1723

1824
debug_printf(3, "Trying to re-bind %s from tool %s after dlopen\n",
1925
binding->user_binding->name, binding->associated_binding_table->tool->tool_name);
20-
26+
2127
while (binding->next_binding) {
2228
binding = binding->next_binding;
2329
debug_printf(3, "Selecting new innermost version of binding %s from tool %s.\n",
2430
binding->user_binding->name, binding->associated_binding_table->tool->tool_name);
2531
}
26-
32+
2733
result = prepare_symbol(binding);
2834
if (result == -1) {
2935
debug_printf(3, "Still could not prepare binding %s after dlopen\n", binding->user_binding->name);
@@ -45,7 +51,7 @@ static void* dlopen_wrapper(const char* filename, int flags) {
4551

4652
debug_printf(2, "Updating GOT entries for new dlopened libraries\n");
4753
update_all_library_gots(&function_hash_table);
48-
54+
4955
return handle;
5056
}
5157

@@ -55,13 +61,17 @@ static void* dlsym_wrapper(void* handle, const char* symbol_name){
5561
int result;
5662
debug_printf(1, "User called dlsym(%p, %s)\n", handle, symbol_name);
5763

58-
if(handle == RTLD_NEXT){
59-
return _dl_sym(RTLD_NEXT, symbol_name ,__builtin_return_address(0));
60-
}
61-
if(handle == RTLD_DEFAULT) {
62-
return _dl_sym(RTLD_DEFAULT, symbol_name,__builtin_return_address(0));
64+
if (handle == RTLD_DEFAULT || handle == RTLD_NEXT) {
65+
#if defined GOTCHA_DL_SYM_WORKAROUND
66+
/* Workaround as _dl_sym isn't exported in glibc 2.34+ anymore.
67+
This probably breaks dlsym() wrapping for RTLD_NEXT: need to
68+
wait for real fix in Gotcha.
69+
*/
70+
return orig_dlsym(handle, symbol_name);
71+
#else
72+
return _dl_sym(handle, symbol_name ,__builtin_return_address(0));
73+
#endif
6374
}
64-
6575
result = lookup_hashtable(&function_hash_table, (hash_key_t) symbol_name, (hash_data_t *) &binding);
6676
if (result == -1)
6777
return orig_dlsym(handle, symbol_name);
@@ -72,7 +82,7 @@ static void* dlsym_wrapper(void* handle, const char* symbol_name){
7282
struct gotcha_binding_t dl_binds[] = {
7383
{"dlopen", dlopen_wrapper, &orig_dlopen_handle},
7484
{"dlsym", dlsym_wrapper, &orig_dlsym_handle}
75-
};
85+
};
7686
void handle_libdl(){
7787
gotcha_wrap(dl_binds, 2, "gotcha");
7888
}

0 commit comments

Comments
 (0)