There is a c ++ linux project consisting of a shell that loads various modules made in the form of shared libraries (in fact, they are plugins loaded via QPluginLoader, but essentially the same shared libraries). Modules, in turn, use each other's methods. Compiler clang 6, gold linker.

Found a strange problem with static variables. For example, we have three libraries L1, L2, L3. L1 and L2 use L3. A static variable is defined in one of the exported L3 classes:

test.h: class AAA { public: static QHash<int,int> data; }; test.cpp: QHash<int,int> AAA::data = {{1,2} , {2,3}}; 

If the project is linked without an option

-Wl, - as-needed

then when you close the application, the memory allocated for AAA :: data is deleted twice, and crash occurs naturally. It seems that the L1 and L2 libraries, when linked to L3, generate a memory free code twice. After activating -Wl, -as-needed, the crashes disappear. Is this generally normal behavior?

  • Bekreys kresha can be? - Fat-Zer
  • Now I can’t give out a detailed one, but there the MALLOC_CHECK check inside glibc works and gives out corrupted double-linked list - nrw
  • if there is a thread destructor QPluginLoader or something similar up there, then it is probably incorrectly used ... - Fat-Zer
  • No, there's one assembler on the stack. The bottom line is that the problem got out after changing the build system from qbs to cmake. On the same code, the build for qbs (or qmake) does not crash, but cmake does. I compared the command lines that generate qbs / cmake - the only difference is in this link parameter. - nrw
  • 2
    About the problem, you can read here and further on the links from there - avp

0