libsanitizer: ldso: track _dl_load_adds/_dl_load_subs counters
glibc populates dl_phdr_info::dlpi_adds and dlpi_subs with monotonic
counters of object load / unload events. Callers of dl_iterate_phdr
use these to cache the iteration result across calls ("if both
counters are unchanged, the loaded-module list is unchanged too").
libgcc_s, libstdc++ exception unwinding, valgrind and similar tools
depend on this contract.
uClibc-ng never tracked these counters, so patch 0001 left them at
zero -- functionally fine for libsanitizer (which does not read
them on Linux) but degenerate for the rest of the ecosystem.
Add two unsigned-long-long globals next to _dl_loaded_modules in
dl-symbols.c. Increment _dl_load_adds at the end of
_dl_add_elf_hash_table() (the central spot where every loaded
object hits the chain, both at startup and via dlopen) and
_dl_load_subs in do_dlclose() right after the chain unlink. Wire
the values into dl_iterate_phdr's per-module callback.
For statically-linked programs the counters live in dl-symbols.c
included via libc/misc/elf/dl-core.c and stay at zero, since static
binaries never load or unload anything -- which matches the glibc
behaviour.
Signed-off-by: Ramin Moussavi <ramin.moussavi@yacoub.de>