From 2d265582a27dd358052d2644c9d736450f63b9c9 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Mon, 20 Mar 2023 20:07:21 +0000 Subject: [PATCH] disable lazy init if compiler supports GCC constructor attribute before we started to use the gcc constructor attribute to load our initialization code, each function hook used to check whether the initialization was already done, and if not, do it at that point. this workaround is quite ugly, and creates a circular reference if the startup code calls any of the hooked functions. now we only do the lazy init if the compiler used is not GCC compatible. --- src/libproxychains.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libproxychains.c b/src/libproxychains.c index 575e439..64dd2a8 100644 --- a/src/libproxychains.c +++ b/src/libproxychains.c @@ -105,9 +105,6 @@ static void* load_sym(char* symname, void* proxyfunc, int is_mandatory) { return funcptr; } -#define INIT() init_lib_wrapper(__FUNCTION__) - - #include "allocator_thread.h" const char *proxychains_get_version(void); @@ -165,16 +162,19 @@ static void init_lib_wrapper(const char* caller) { pthread_once(&init_once, do_init); } -/* if we use gcc >= 3, we can instruct the dynamic loader +/* if we use gcc >= 3, we can instruct the dynamic loader * to call init_lib at link time. otherwise it gets loaded * lazily, which has the disadvantage that there's a potential - * race condition if 2 threads call it before init_l is set + * race condition if 2 threads call it before init_l is set * and PTHREAD support was disabled */ -#if __GNUC__ > 2 +#if __GNUC__+0 > 2 __attribute__((constructor)) static void gcc_init(void) { - INIT(); + init_lib_wrapper(__FUNCTION__); } +#define INIT() do {} while(0) +#else +#define INIT() init_lib_wrapper(__FUNCTION__) #endif