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.
pull/504/head
rofl0r 2023-03-20 20:07:21 +00:00
parent 66f99b19dd
commit 2d265582a2
1 changed files with 7 additions and 7 deletions

View File

@ -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