问题
I'm using dlopen / dlclose to load lib with glibc 2.21.
Is there a C++ call to check a lib as a DF_1_NODELETE flag set ? readelf seems to be able to do it.
or at least if a lib has unique symbol defined in it ? nm is definitely able to do it.
ideally i would like something like :
CloseLib( libHandle lib)
{
if( checkIfLibIsClosable(lib) )
{
dlclose(lib)
}
}
This is in order to avoid calling dlclose on lib with DF_1_NODELETE flag, as calling it will fails with an assert error :
Inconsistency detected by ld.so: dl-close.c: 764: _dl_close: Assertion `map->l_init_called' failed!
which is caused by DF_1_NODELETE flag set in dl-close.c:762, The flag is set in dl-lookup.c:332
Info about DF_1_NODELETE flag and unique symbol :
DF_1_NODELETE
Unique Symbol
回答1:
This is in order to avoid calling dlclose on lib with DF_1_NODELETE flag, as calling it will fails with an assert error :
Inconsistency detected by ld.so: dl-close.c: 764: _dl_close: \
Assertion `map->l_init_called' failed!
If calling dlclose
on such a library causes above assertion, that is a bug in GLIBC and you should report it in glibc bugzilla.
As for detecting whether the DF_1_NODELETE
(or any other) flag, yes you can do it by read
ing the Elf{32,64}_Ehdr
from the start of the library, then reading Elf{32,64}_Phdr
s from .e_phoff
offset until you find one with .p_type == PT_DYNAMIC
, then reading Elf{32,64}_Dyn
s from its .p_offset
until you find one with .d_type == DT_FLAGS
, and finally checking whether its .d_un.d_val & DF_1_NODELETE
is non-zero.
来源:https://stackoverflow.com/questions/31826309/glibc-test-if-lib-as-df-1-nodelete-flag-or-if-lib-has-unique-symbol