Calling __asan_describe_address after unloading any library through
dlclose or FreeLibrary currently results in a crash due to accessing
unmapped memory (the Global structure in list_of_all_globals).
As list_of_all_globals is only accessed under a lock, it is safe to
remove items in UnregisterGlobal.
To prevent a significant slowdown (0.8 secs before this patch, 5.2 secs
for an initial O(n^2) version that naively walks the list), optimize it:
- Reverse the loop (reduces time to 1.0 sec), 2. Cache the start of the
loop (restores original performance). Both changes make O(n) possible.
The above test was performed on a project that starts with 881337
globals. It would load 24125 additional globals through 14 plugins.
I confirmed through gdb that the size of list_of_all_globals indeed
shrinks (the size at exit matches with the size at startup).
Fixes https://github.com/google/sanitizers/issues/741
Fixes https://github.com/google/sanitizers/issues/963