Project Athena - Linux support
Contents
Project Athena - Linux support[edit]
Shutdown crash / issues with static libraries[edit]
Summary[edit]
The Linux interface inevitably crashes on shutdown due to an issue with linking. Upon investigation this turns out not to be a memory handling error in the code, and so is possibly harmless.
Avoiding the problem[edit]
A. Build with -DBUILD_SHARE_LIBS=on
B. Call _exit instead of exit, which sidesteps the problem by not cleaning up on exit. This may have undesirable effects (loss of data from buffers?)
C. Rewrite the code in a manner that avoids the issue. Using singletons appears to work.
D. Ignore the problem.
Technical explanation[edit]
The interface is made of multiple libraries, by default statically linked. There is a 'shared' library, which gets linked into other libraries, which get linked into plugins. The following situation happens:
1. A `static Foo foo;` is declared in libshared. This results in the compiler adding a constructor call.
2. libshared is linked into multiple libraries. With static linking this means copying the code, and so each of the libraries has its own copy of the constructor call.
3. When the linker links those libraries into a plugin, the plugin ends up with multiple constructor and destructor invocations.
4. The constructors and destructors get called on the same memory multiple times, resulting in things like multiple calls of free() on the same address.
Possible effects[edit]
Crash on exit. That's the common outcome.
Re-initialization of global data on plugin load. Since plugin loads trigger the constructor, it probably re-initializes the object and undoes any work done since the original initialization.