System: ubuntu14.04
Compiler: gcc4.8.2
Problem Description: Work needs, use Libnids, so the latest version of the 1.24, after compiling the installation, found that the TCP message reorganization work can not be completed, specifically, although the NIDS_REGISTER_TCP function registered a callback function, but the function can not be executed, By tracing the Libnids execution process, it is found that there is a problem in the calculation of the checksum, the value of checksum is not zero, which leads to libnids that the datagram is corrupted.
Unknown so, but through thinking, think the problem should be on the compiler, is not the problem of 64-bit and 32? The source code does not use a long and other data types that can cause problems. Later thought of the compilation optimization, this is really the problem: when the high version of the GCC compiled with-O2 and above optimization level, The length of the structure may change (in order to speed up the addressing speed, the compiler optimizes the alignment), this time cannot use the manually calculated address offset, there is a problem.
Solution: Compile-time plus-fno-strict-aliasing option
Some of the connections you can refer to are:
https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1072650
http://edeca.net/wp/2014/03/libnids-on-64-bit-architecture-machines/
[Original] High version of GCC compilation Yo optimization may cause problems