static link stdc++ without STB_GNU_UNIQUE cause memory leak when dlclose

送分小仙女□ 提交于 2019-12-02 03:32:49

问题


I have to make a dso that static link stdc++ and need can unload from memory dynamic. So I tried with compile gcc with --disable-gnu-unique-object and use gold link with -Wl,--no-gnu-unique options. But both contains memory leak issue even I do nothing except call dlopen() dlclose() in main. The test code like:

int main()
{
    for(int i=0;i<1000;i++)
    {
        void * h=dlopen(filepath);
        if(h)
             dlclose(h);
    }
    return 0;
}

Than I checked the memory cat /proc/pid/maps before and after I found only heap changes bigger and bigger every time. About 90M after 1000 time call dlopen & dlclose to me 90M is still too big.

026fb000-0274e000 rw-p 00000000 00:00 0                                  [heap]

after googled about 2 weeks but nothing helpful for this issue. Only find a document said as below here.

-fno-gnu-unique On systems with recent GNU assembler and C library, the C++ compiler uses the "STB_GNU_UNIQUE" binding to make sure that definitions of template static data members and static local variables in inline functions are unique even in the presence of "RTLD_LOCAL"; this is necessary to avoid problems with a library used by two different "RTLD_LOCAL" plugins depending on a definition in one of them and therefore disagreeing with the other one about the binding of the symbol. But this causes "dlclose" to be ignored for affected DSOs; if your program relies on reinitialization of a DSO via "dlclose" and "dlopen", you can use -fno-gnu-unique.

Is this a linux bug? Is there anyone can help me on this issue? thanks. The environment is gcc 5.3.1. I linked with definitions _GLIBCXX_USE_CXX11_ABI.

来源:https://stackoverflow.com/questions/50402314/static-link-stdc-without-stb-gnu-unique-cause-memory-leak-when-dlclose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!