Skip to content

Commit 3e70747

Browse files
committed
testsuite: Have libtestinger run main() from the non-shared copy of the 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.
1 parent 87fb442 commit 3e70747

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

testsuite/build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ cp external/libgotcha/libgotcha_repl.h "target/$buildtype"
4141
objcopy -Wsignal --globalize-symbol libgotcha_dlsym --globalize-symbol libgotcha_signal "target/$buildtype/deps/libgotcha-"*.rlib 2>/dev/null
4242
rm "target/$buildtype/deps/libinger.so"
4343
cd -
44-
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
44+
c99 $cflags -Wall -Wextra -Wpedantic -Werror "$@" -c -fpic -fno-optimize-sibling-calls -D_GNU_SOURCE -Wno-missing-attributes -I"$OLDPWD/target/$buildtype" testinger.c
4545
cd -
4646
cargo rustc $cargoflags --lib -- -Clink-arg="$OLDPWD/testinger.o"
4747
cd -

testsuite/testinger.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#include <sys/select.h>
66
#include <sys/types.h>
77
#include <assert.h>
8-
#include <dlfcn.h>
98
#include <errno.h>
109
#include <fcntl.h>
10+
#include <link.h>
1111
#include <stdio.h>
1212
#include <stdlib.h>
1313
#include <string.h>
@@ -38,12 +38,18 @@ static int testinger(int argc, char **argv, char **envp) {
3838
}
3939

4040
#pragma weak libtestinger_libc_start_main = __libc_start_main
41-
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) {
41+
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) {
4242
const char *skiplist = getenv("LIBGOTCHA_SKIP");
4343
if(skiplist && strstr(skiplist, *argv))
4444
return __libc_start_main(main, argc, argv, init, fini, rtld_fini, stack_end);
4545

46-
mainfunc = main;
46+
struct link_map *lm = dlmopen(1, *argv, RTLD_LAZY);
47+
dlclose(lm);
48+
49+
const struct link_map *l = dlopen(NULL, RTLD_LAZY);
50+
uintptr_t offset = (uintptr_t) main - l->l_addr;
51+
mainfunc = (int (*)(int, char **, char **)) (lm->l_addr + offset);
52+
4753
return __libc_start_main(testinger, argc, argv, init, fini, rtld_fini, stack_end);
4854
}
4955

0 commit comments

Comments
 (0)