Say I have an application foo
that is linked against bar.so
. I have another library, buzz.so
that the application does not directly link, but that I use when I run the application with LD_PRELOAD
like so: LD_PRELOAD=buzz.so ./foo
. Now I want buzz.so
to be able to use dlsym
to find a symbol inside bar.so
. My question is: what is the earliest point in time the dlsym call can succeed and how do run a function at that time?
GCC/Clang support annotating functions with the __constructor__((priority))
attribute to make them run before main
, but AFAIK there isn’t any priority number that corresponds to being sure that all shared libraries are loaded.