By default, in a function like this,
void foo() { Eigen::Quaternionf q; //... }
GCC assumes that the stack is already 16-byte-aligned so that the object q will be created at a 16-byte-aligned location. For this reason, it doesn't take any special care to explicitly align the object q, as Eigen requires.
The problem is that, in some particular cases, this assumption can be wrong on Windows, where the stack is only guaranteed to have 4-byte alignment. Indeed, even though GCC takes care of aligning the stack in the main function and does its best to keep it aligned, when a function is called from another thread or from a binary compiled with another compiler, the stack alignment can be corrupted. This results in the object 'q' being created at an unaligned location, making your program crash with the assertion on unaligned arrays. So far we found the three following solutions.
__attribute__((force_align_arg_pointer)) void foo() { Eigen::Quaternionf q; //... }
-mincoming-stack-boundary=2
Another global solution is to pass this option to gcc:
-mstackrealign
force_align_arg_pointer
attribute to all functions.These global solutions are easy to use, but note that they may slowdown your program because they lead to extra prologue/epilogue instructions for every function.