From 68a064ec64dab22d353dcde0b3208fa067abed51 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Kristensen Date: Sat, 13 Feb 2016 12:34:22 -0800 Subject: aubdump: Don't use .so constructors for initializing This doesn't seem to work when mixed with constructors in other shared objects or other creative uses of the linker. Let's stick with a simpler mechanism, where we look up the libc functions when our hooks are called for the first time. --- tools/aubdump.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'tools/aubdump.c') diff --git a/tools/aubdump.c b/tools/aubdump.c index 6327b87e..01ecf0c5 100644 --- a/tools/aubdump.c +++ b/tools/aubdump.c @@ -43,8 +43,11 @@ #include "intel_aub.h" #include "intel_chipset.h" -static int (*libc_close)(int fd); -static int (*libc_ioctl)(int fd, unsigned long request, void *argp); +static int close_init_helper(int fd); +static int ioctl_init_helper(int fd, unsigned long request, ...); + +static int (*libc_close)(int fd) = close_init_helper; +static int (*libc_ioctl)(int fd, unsigned long request, ...) = ioctl_init_helper; static int drm_fd = -1; static char *filename; @@ -528,7 +531,7 @@ ioctl(int fd, unsigned long request, ...) } } -static void __attribute__ ((constructor)) +static void init(void) { const char *args = getenv("INTEL_AUBDUMP_ARGS"); @@ -553,6 +556,27 @@ init(void) fail_if(file == NULL, "intel_aubdump: failed to open file '%s'\n", filename); } +static int +close_init_helper(int fd) +{ + init(); + return libc_close(fd); +} + +static int +ioctl_init_helper(int fd, unsigned long request, ...) +{ + va_list args; + void *argp; + + va_start(args, request); + argp = va_arg(args, void *); + va_end(args); + + init(); + return libc_ioctl(fd, request, argp); +} + static void __attribute__ ((destructor)) fini(void) { -- cgit v1.2.3