Skip to content

Commit

Permalink
testsuite: Have libtestinger run main() from the non-shared copy of t…
Browse files Browse the repository at this point in the history
…he executable

This reenables selective relinking when preloaded, despite the libgotcha exit analysis optimization.
It is useful for assessing the performance effects of timer signals *and* selective relinking on
compatible applications without modifying them.  Note that it causes more Gnulib tests to fail.
  • Loading branch information
solb committed Feb 24, 2022
1 parent 87fb442 commit 3e70747
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion testsuite/build
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cp external/libgotcha/libgotcha_repl.h "target/$buildtype"
objcopy -Wsignal --globalize-symbol libgotcha_dlsym --globalize-symbol libgotcha_signal "target/$buildtype/deps/libgotcha-"*.rlib 2>/dev/null
rm "target/$buildtype/deps/libinger.so"
cd -
c99 $cflags -Wall -Wextra -Wpedantic -Werror "$@" -c -fpic -fno-optimize-sibling-calls -D_DEFAULT_SOURCE -D_XOPEN_SOURCE -Wno-missing-attributes -I"$OLDPWD/target/$buildtype" testinger.c
c99 $cflags -Wall -Wextra -Wpedantic -Werror "$@" -c -fpic -fno-optimize-sibling-calls -D_GNU_SOURCE -Wno-missing-attributes -I"$OLDPWD/target/$buildtype" testinger.c
cd -
cargo rustc $cargoflags --lib -- -Clink-arg="$OLDPWD/testinger.o"
cd -
Expand Down
12 changes: 9 additions & 3 deletions testsuite/testinger.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <sys/select.h>
#include <sys/types.h>
#include <assert.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <link.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -38,12 +38,18 @@ static int testinger(int argc, char **argv, char **envp) {
}

#pragma weak libtestinger_libc_start_main = __libc_start_main
int __libc_start_main(int (*main)(int, char **, char **), int argc, char**argv, int (*init)(int, char **, char **), void (*fini)(void), void (*rtld_fini)(void), void *stack_end) {
int __libc_start_main(int (*main)(int, char **, char **), int argc, char **argv, int (*init)(int, char **, char **), void (*fini)(void), void (*rtld_fini)(void), void *stack_end) {
const char *skiplist = getenv("LIBGOTCHA_SKIP");
if(skiplist && strstr(skiplist, *argv))
return __libc_start_main(main, argc, argv, init, fini, rtld_fini, stack_end);

mainfunc = main;
struct link_map *lm = dlmopen(1, *argv, RTLD_LAZY);
dlclose(lm);

const struct link_map *l = dlopen(NULL, RTLD_LAZY);
uintptr_t offset = (uintptr_t) main - l->l_addr;
mainfunc = (int (*)(int, char **, char **)) (lm->l_addr + offset);

return __libc_start_main(testinger, argc, argv, init, fini, rtld_fini, stack_end);
}

Expand Down

0 comments on commit 3e70747

Please sign in to comment.