gpt4 book ai didi

c++ - glibc : Test if lib as DF_1_NODELETE flag or if lib has unique symbol

转载 作者:太空狗 更新时间:2023-10-29 23:14:50 25 4
gpt4 key购买 nike

我正在使用 dlopen/dlclose 加载带有 glibc 2.21 的库。

是否有 C++ 调用来检查库是否设置了 DF_1_NODELETE 标志?readelf 似乎可以做到。

或者至少如果一个库中定义了唯一的符号?nm 绝对可以做到。

理想情况下我想要这样的东西:

CloseLib( libHandle lib)
{
if( checkIfLibIsClosable(lib) )
{
dlclose(lib)
}
}

这是为了避免在带有 DF_1_NODELETE 标志的 lib 上调用 dlclose,因为调用它会失败并出现断言错误:

Inconsistency detected by ld.so: dl-close.c: 764: _dl_close: Assertion `map->l_init_called' failed!

这是由 dl-close.c:762 中设置的 DF_1_NODELETE 标志引起的,该标志在 dl-lookup.c:332 中设置

关于 DF_1_NODELETE 标志和唯一符号的信息:

DF_1_NODELETE

Unique Symbol

最佳答案

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!

如果在这样的库上调用 dlclose 导致上述断言,那是 GLIBC 中的错误,您应该在 glibc bugzilla 中报告它.

至于检测 DF_1_NODELETE(或任何其他)标志,是的,您可以通过读取Elf{32,64}_Ehdr 从库的开头开始,然后从 .e_phoff 偏移量读取 Elf{32,64}_Phdr,直到找到 .p_type == PT_DYNAMIC,然后从它的 .p_offset 中读取 Elf{32,64}_Dyn,直到找到一个 .d_type == DT_FLAGS,最后检查其 .d_un.d_val & DF_1_NODELETE 是否非零。

关于c++ - glibc : Test if lib as DF_1_NODELETE flag or if lib has unique symbol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31826309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com