In some cases unloading a module with dlclose can fail to update the symbol search list for the remaining modules, leading to a situation where symbols are referenced after the library has been removed from the symbol map. The most commonly encountered example of this is the error_category destructor in libstdc++ not getting called until the exit finalizers are run, resulting in: symbol lookup error: /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/libstdc++.so.6: undefined symbol: _ZNSt14error_categoryD2Ev, version GLIBCXX_3.4.15 https://bugs.gentoo.org/364077 https://bugzilla.redhat.com/593675 http://sourceware.org/ml/libc-hacker/2010-05/msg00007.html http://gcc.gnu.org/ml/gcc-help/2011-07/msg00099.html 2010-05-26 Andreas Schwab * elf/dl-close.c (_dl_close_worker): Reset private search list if it wasn't used. --- a/elf/dl-close.c +++ b/elf/dl-close.c @@ -421,6 +421,13 @@ _dl_close_worker (struct link_map *map) imap->l_scope_max = new_size; } + else if (new_list != NULL) + { + /* We didn't change the scope array, so reset the search + list. */ + imap->l_searchlist.r_list = NULL; + imap->l_searchlist.r_nlist = 0; + } /* The loader is gone, so mark the object as not having one. Note: l_idx != IDX_STILL_USED -> object will be removed. */