dlopen 是否重新加载已经加载的依赖项?如果是这样,有什么影响?

Does dlopen re-load already loaded dependencies? If so, what are the implications?

我有一个程序,代号为foofoo 依赖于 common.so 并以正常方式链接到它(抱歉,我不知道从技术角度来说)。当 foo 为 运行 时,它会使用 dlopen() 动态加载 bar.so。到目前为止一切顺利。

但是,bar.so 也依赖于 common.sodlopen() 会重新加载 common.so (根据我的阅读,它会递归加载任何必需的依赖项),还是会检测到它已经加载?如果它确实重新加载它,这会导致我的程序出现问题吗? foobar.so 都需要查看 common.so 中的任何一个对静态变量所做的更改。

也许我的设计需要更改或需要使用 -rdynamic(我也不太理解)?

POSIX spec for dlopen() 说:

Only a single copy of an executable object file shall be brought into the address space, even if dlopen() is invoked multiple times in reference to the executable object file, and even if different pathnames are used to reference the executable object file.

在Linux,这是使用引用计数实现的;在 dlclose 被调用相同次数之前,共享对象将保持驻留。

[更新]

我知道你问的是作为依赖项隐式加载的共享对象,但同样的原则适用。否则,很多事情都会崩溃......特别是,共享对象中的全局构造函数会 运行 多次,这会造成严重破坏。