@@ -113,6 +113,7 @@ static int per_binding(hash_key_t key, hash_data_t data,
113
113
binding -> user_binding -> name ,
114
114
binding -> associated_binding_table -> tool -> tool_name );
115
115
116
+ if (!binding -> user_binding -> name ) return 0 ;
116
117
while (binding -> next_binding ) {
117
118
binding = binding -> next_binding ; // GCOVR_EXCL_START
118
119
debug_printf (3 ,
@@ -157,7 +158,18 @@ static void *dlsym_wrapper(void *handle, const char *symbol_name) {
157
158
debug_printf (1 , "User called dlsym(%p, %s)\n" , handle , symbol_name );
158
159
int result = lookup_hashtable (& function_hash_table , (hash_key_t )symbol_name ,
159
160
(hash_data_t * )& binding );
160
- if (result != -1 ) return binding -> user_binding -> wrapper_pointer ;
161
+ void * val = orig_dlsym (handle , symbol_name );
162
+ if (result != -1 ) {
163
+ void * * wrappee_ptr = getInternalBindingAddressPointer (
164
+ (struct internal_binding_t * * )binding -> user_binding -> function_handle );
165
+ if (val == NULL || * wrappee_ptr == val ) {
166
+ // if the wrapper is found and the wrappee is the function requested.
167
+ // This is needed in cases where we wrap a function F1 from library A and
168
+ // we dynamically load function F1 from library B. As name is same, we
169
+ // need to make sure the wrappee are the same as well
170
+ return binding -> user_binding -> wrapper_pointer ;
171
+ }
172
+ }
161
173
if (handle == RTLD_NEXT ) {
162
174
struct link_map * lib = gotchas_dlsym_rtld_next_lookup (
163
175
symbol_name , __builtin_return_address (0 ));
@@ -168,7 +180,7 @@ static void *dlsym_wrapper(void *handle, const char *symbol_name) {
168
180
}
169
181
return NULL ;
170
182
} else {
171
- return orig_dlsym ( handle , symbol_name ) ;
183
+ return val ;
172
184
}
173
185
}
174
186
0 commit comments