Hi Jonathan & list, this is a follow-up on an email from mid-january - i had crashes when compiling my library with -O3. I fixed all warnings "dereferencing type-punned pointer will break > strict-aliasing rules" and got it running.
(at least i thought so - now i experience crashes again so maybe i just messed up my makefile and falsely thought that everything would work)... I fixed all warnings regarding dereferencing type-punned pointers and I compile with -O3 AND -fno-strict-aliasing. and i still get the same crash as earlier. it does not crash with -O2. >From what i understand the -fno-strict-aliasing should solve the problem, but it doesn't. The function which crashes basically is searching a bitmap for a pattern. When the search starts, it uses two pointers to the same memory location (u64 ptr for searching in 8byte-steps, char* ptr for searching byte-wise). If i understand the aliasing correctly then this might cause the problems. I just don't know how to rewrite the function - I want to use those two pointers for performance reasons. I don't even know if the problem is in this function or if it's somewhere else and the crash is just a side-effect of a completely different problem. To reproduce: wget http://crupp.de/hamsterdb-1.1.3.tar.gz tar -zxvf hamsterdb-1.1.3.tar.gz cd hamsterdb-1.1.3 ./configure make cd unittests ./test # <-- will segfault with a bad pointer Here's my gcc version: Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.1-4ubuntu9' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9) Thanks for any help, Christoph 2010/1/14 Jonathan Wakely <jwakely....@gmail.com>: > 2010/1/14 Christoph Rupp: >> >> To reproduce, these steps are necessary: >> >> wget http://crupp.de/dl/hamsterdb-1.1.1.tar.gz >> tar -zxvf hamsterdb-1.1.1.tar.gz >> cd hamsterdb-1.1.1 >> ./configure --enable-internal >> make > > There are lots of these warnings, which you ignore at your peril: > > freelist.c:3326: warning: dereferencing type-punned pointer will break > strict-aliasing rules > > ham_info.c:80: warning: dereferencing type-punned pointer will break > strict-aliasing rules > > env.cpp:1804: warning: dereferencing type-punned pointer will break > strict-aliasing rules > > You should probably either fix those warnings, avoid compiling at high > optimisation levels, or use -fno-strict-aliasing (which allows the > tests to run successfully.) >