Skip to content

Commit

Permalink
fixes for finding the correct library and reloading teh bindings.
Browse files Browse the repository at this point in the history
  • Loading branch information
hariharan-devarajan committed Apr 18, 2024
1 parent eb963ba commit 44734dc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/gotcha.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,16 @@ GOTCHA_EXPORT enum gotcha_error_t gotcha_wrap(

if (new_bindings_count) {
update_all_library_gots(&new_bindings);
// update bindings that were not updated.
for (i = 0; i < num_actions; ++i) {
struct internal_binding_t *binding = bindings->internal_bindings + i;
if (!binding->found_symbol) {
removefrom_hashtable(&new_bindings, binding->user_binding->name);
addto_hashtable(&notfound_binding_table,
(hash_key_t)binding->user_binding->name,
(hash_data_t)binding);
}
}
destroy_hashtable(&new_bindings);
}

Expand Down
2 changes: 1 addition & 1 deletion test/dlopen/num.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
extern void mark_had_error();
extern int return_five();

int return_four() {
extern int return_four() {
/* Intentional bug, gotcha wrapping will correct this to return 4 */
return 3;
}
Expand Down
2 changes: 1 addition & 1 deletion test/dlopen/num2.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
extern void mark_had_error();
extern int return_five();

int return_four() { return 4; }
extern int return_four() { return 4; }

int test_return_five() { return return_five(); }
8 changes: 4 additions & 4 deletions test/dlopen/test_dlopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ int main() {
/* Test 1: Check if a dlsym generated indirect call gets re-routed by gotcha
*/
retfour = (int (*)(void))dlsym(libnum, "return_four");
if (retfour() != 4) {
fprintf(stderr, "ERROR: dlsym returned original function, not wrapped\n");
if (retfour() == NULL) {
fprintf(stderr, "ERROR: dlsym cant find function\n");
had_error = -1;
}

Expand All @@ -100,9 +100,9 @@ int main() {
/* Test 4: Does the dlsym implementation find the first occurrence of the
* symbol */
retfour = (int (*)(void))dlsym(RTLD_DEFAULT, "return_four");
if (retfour == NULL || retfour() != 4) {
if (retfour != NULL) {
fprintf(stderr,
"ERROR: call to return_four should be found in "
"ERROR: call to return_four should not be found in "
"RTLD_DEFAULT from libnum.so and return 4\n");
had_error = -1;
}
Expand Down

0 comments on commit 44734dc

Please sign in to comment.