我正在尝试创建一个多次重新加载共享库的应用程序.但在某个时间点,dlmopen失败并出现错误
/usr/lib/libc.so.6: cannot allocate memory in static TLS block
以下是重现此问题的最小代码:
#include <dlfcn.h>
#include <cstdio>
#include <vector>
int main() {
for (int i = 0; i < 100; ++i) {
void *lib_so = dlmopen(LM_ID_NEWLM, "lib.so", RTLD_LAZY | RTLD_LOCAL);
if (lib_so == NULL) {
printf("Iteration %i loading failed: %s\n", i, dlerror());
return 1;
}
dlclose(lib_so);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
并清空lib.cpp,用.编译
g++ -rdynamic -ldl -Wl,-R . -o test main.cpp
g++ -fPIC -shared lib.cpp -o lib.so
Run Code Online (Sandbox Code Playgroud)
它似乎即使用一个线程也会崩溃.问题是:如何强制库卸载或销毁使用的未使用的命名空间LM_ID_NEWLM?