GCC Compiler Bug Causes Crashes
This bug is relevant for configurations which satisfy all of the following conditions:
- Using GCC >= 4.9 and < 6.0 to compile.
- Using
-O3
compile flag. (This is default behavior for Release mode.) - Using
-std=c++11
(orc++0x
orc++14
) compile flags.
The compiler sometimes generates SSE instructions (which require 16 byte alignment) using memory addresses that are not 16-byte-aligned. Since these errors lead to segfaults, suggesting that you tried to access invalid memory addresses, they are extremely hard to recognize and debug.
Known workarounds:
- Use GCC <= 4.8 or >= 6.0.
- Use clang to compile.
- Use
-O2
instead of-O3
. - Use
-O3 -march=<architecture>
for an architecture that supports AVX. This way the compiler will generate AVX instead of SSE instructions which do allow unaligned memory access at a small performance penalty.
Also see the corresponding GCC bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66598