LD_PRELOAD is specified by ld.so as (my emphasis):
LD_PRELOAD
A list of additional, user-specified, ELF shared objects to be
loaded *BEFORE* all others.
Does this happen ? Let's find out with a simple program that links a shared library and then we add another with LD_PRELOAD.
Build with mulle-make or alternatively :
(
mkdir build &&
cd build &&
cmake .. &&
make
)
LD_PRELOAD="${PWD}/build/libld-preload.so" ./build/main
load_linked
load_preload
LD_PRELOAD's constructor is certainly run AFTER all others.
Looking at it with ldd
(See: Issue #1) one can see that load_preload
is actually loaded ahead of linked
, which is fine. According to the ELF spec, the initialization order
of non-related shared objects is non-defined (maybe to support parallel loading). So this could be technically OK on
the ELF side. But I still think, this violates LD_PRELOAD
s purpose.