1
yanqiyu 17 天前
我觉得最简单的办法是在你的动态库里面加一个构造和析构会打 log 的对象看看这东西被析构了吗,如果不是的话去 gdb 给 dlopen 打断点看看是不是有别的没注意到的地方 dlopen 了
另外确定你们的环境不是 musl ?这东西的 dlclose 我记得是假的 |
![]() |
3
ysc3839 17 天前 via Android
还是提供初始化和卸载函数吧
|
![]() |
4
seers 17 天前 via Android
dlclose 后检查下 soinfo 链,看看是不是确实关闭了
|
![]() |
5
Noicdi 16 天前
> 可以定义一个或多个在共享库被加载和卸载时自动执行的函数,这样在使用共享库时就能够完成一些初始化和终止工作了。不管库是自动被加载还是使用 dlopen 接口(参见 42.1 节)显式加载的,初始化函数和终止函数都会被执行。
> > 《 Linux/Unix 系统编程手册》 42.2 初始化和终止函数 那我的第一反应就是你提供全局变量的析构函数,注册到终止函数里,库被卸载的时候去析构。但是又考虑到库没被卸载。 > Shared objects may export functions using the __attribute__((constructor)) and __attribute__((destructor)) function attributes. Constructor functions are executed before dlopen() returns, and destructor functions are executed before dlclose() returns. A shared object may export multiple constructors and destructors, and priorities can be associated with each function to determine the order in which they are executed. See the gcc info pages (under "Function attributes") for further information. > > man dlopen 但是这里又说 `destructor functions are executed before dlclose() returns`,那试一试? |
![]() |
6
Noicdi 16 天前
|
7
Ainokiseki OP |
![]() |
8
passive 16 天前 via Android
计数器只是一个原因
dlclose 并不会卸载 so ,前两天 hackernews 上刚有讨论 |
9
iceheart 16 天前 via Android
dlclose 之后 cat /proc/[pid]/maps 确认有没有卸载。
|
![]() |
10
Noicdi 14 天前
所以那个链接里提到的内容是有用的?那我也细看一下,对你提出的问题还挺感兴趣的。
话说是 RTLD_LOCAL 还是 RTLF_LOCAL ? |
11
hwdq0012 14 天前
我的动态库加载和卸载都是基于我自己定义的接口, 安装时 ioc 注册, 卸载时 ioc 手动清除, 上周也遇到个程序退出后静态资源没析构导致进程没退出的问题, 把那静态变量放 ioc 容器里就解决了
|
12
Ainokiseki OP @Noicdi 通过实验,编译的时候带上-fno-gnu-unique 是真正起作用的做法。RTLD_LOCAL 没用
|