joakimkarlsson / igloo

A framework for unit testing in C++
Boost Software License 1.0
153 stars 32 forks source link

igloo-tests Segfaults with Clang 3.4.0 #14

Closed umireon closed 10 years ago

umireon commented 10 years ago

1.1.1 builds, but master doesn't.

Here is the log. (Ubuntu 14.04 x64 in DigitalOcean)

root@klang:~/klang/lib/igloo/build# cmake ..
-- The C compiler identification is Clang 3.4.0
-- The CXX compiler identification is Clang 3.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- cotire 1.4.1 loaded.
-- CXX target igloo-tests cotired.
-- CXX target snowhouse-tests cotired.
-- Configuring done
-- Generating done
-- Build files have been written to: /root/klang/lib/igloo/build

root@klang:~/klang/lib/igloo/build# make
[  2%] Generating cotire/igloo-tests_CXX_prefix.hxx
[  5%] Building CXX precompiled header cotire/igloo-tests_CXX_prefix.hxx.gch
Scanning dependencies of target igloo-tests
[  7%] Building CXX object CMakeFiles/igloo-tests.dir/tests/abstract_tests.cpp.o
[ 10%] Building CXX object CMakeFiles/igloo-tests.dir/tests/bdd_tests.cpp.o
[ 12%] Building CXX object CMakeFiles/igloo-tests.dir/tests/ignoring_specs_tests.cpp.o
[ 15%] Building CXX object CMakeFiles/igloo-tests.dir/tests/xmlwritter_tests.cpp.o
[ 17%] Building CXX object CMakeFiles/igloo-tests.dir/tests/igloo_tests.cpp.o
[ 20%] Building CXX object CMakeFiles/igloo-tests.dir/tests/testfixtures.cpp.o
[ 23%] Building CXX object CMakeFiles/igloo-tests.dir/tests/running_subsets_of_tests.cpp.o
[ 25%] Building CXX object CMakeFiles/igloo-tests.dir/tests/testresults_tests.cpp.o
[ 28%] Building CXX object CMakeFiles/igloo-tests.dir/tests/coloredconsoletestresultsoutput_tests.cpp.o
[ 30%] Building CXX object CMakeFiles/igloo-tests.dir/tests/context_error_handling.cpp.o
[ 33%] Building CXX object CMakeFiles/igloo-tests.dir/tests/main.cpp.o
[ 35%] Building CXX object CMakeFiles/igloo-tests.dir/tests/visualstudiotestresultsoutput_tests.cpp.o
[ 38%] Building CXX object CMakeFiles/igloo-tests.dir/tests/xunittestresultsoutput_tests.cpp.o
[ 41%] Building CXX object CMakeFiles/igloo-tests.dir/tests/context_metadata.cpp.o
[ 43%] Building CXX object CMakeFiles/igloo-tests.dir/tests/testresultfactory_tests.cpp.o
[ 46%] Building CXX object CMakeFiles/igloo-tests.dir/tests/alternative_registration.cpp.o
[ 48%] Building CXX object CMakeFiles/igloo-tests.dir/tests/defaulttestresultsoutput_tests.cpp.o
[ 51%] Building CXX object CMakeFiles/igloo-tests.dir/tests/testlistener_tests.cpp.o
[ 53%] Building CXX object CMakeFiles/igloo-tests.dir/tests/nested_contexts.cpp.o
[ 56%] Building CXX object CMakeFiles/igloo-tests.dir/tests/context_registry/static_setup_teardown_tests.cpp.o
[ 58%] Building CXX object CMakeFiles/igloo-tests.dir/tests/context_registry/specs_marked_as_only_tests.cpp.o
[ 61%] Building CXX object CMakeFiles/igloo-tests.dir/tests/context_provider/marked_as_only_tests.cpp.o
Linking CXX executable bin/igloo-tests
Segmentation fault (core dumped)
make[2]: *** [bin/igloo-tests] Error 139
make[1]: *** [CMakeFiles/igloo-tests.dir/all] Error 2
make: *** [all] Error 2

root@klang:~/klang/lib/igloo/build# make VERBOSE=1
--- snip ---
[ 61%] Building CXX object CMakeFiles/igloo-tests.dir/tests/context_provider/marked_as_only_tests.cpp.o
/usr/bin/c++    -Wfatal-errors -Wall -W -Werror -Wfloat-equal -Wundef -Wendif-labels -Wshadow -pedantic-errors -I/root/klang/lib/igloo     -include "/root/klang/lib/igloo/build/cotire/igloo-tests_CXX_prefix.hxx" -Qunused-arguments  -o CMakeFiles/igloo-tests.dir/tests/context_provider/marked_as_only_tests.cpp.o -c /root/klang/lib/igloo/tests/context_provider/marked_as_only_tests.cpp
Linking CXX executable bin/igloo-tests
/usr/bin/cmake -E cmake_link_script CMakeFiles/igloo-tests.dir/link.txt --verbose=1
/usr/bin/c++    -Wfatal-errors -Wall -W -Werror -Wfloat-equal -Wundef -Wendif-labels -Wshadow -pedantic-errors    CMakeFiles/igloo-tests.dir/tests/abstract_tests.cpp.o CMakeFiles/igloo-tests.dir/tests/bdd_tests.cpp.o CMakeFiles/igloo-tests.dir/tests/ignoring_specs_tests.cpp.o CMakeFiles/igloo-tests.dir/tests/xmlwritter_tests.cpp.o CMakeFiles/igloo-tests.dir/tests/igloo_tests.cpp.o CMakeFiles/igloo-tests.dir/tests/testfixtures.cpp.o CMakeFiles/igloo-tests.dir/tests/running_subsets_of_tests.cpp.o CMakeFiles/igloo-tests.dir/tests/testresults_tests.cpp.o CMakeFiles/igloo-tests.dir/tests/coloredconsoletestresultsoutput_tests.cpp.o CMakeFiles/igloo-tests.dir/tests/context_error_handling.cpp.o CMakeFiles/igloo-tests.dir/tests/main.cpp.o CMakeFiles/igloo-tests.dir/tests/visualstudiotestresultsoutput_tests.cpp.o CMakeFiles/igloo-tests.dir/tests/xunittestresultsoutput_tests.cpp.o CMakeFiles/igloo-tests.dir/tests/context_metadata.cpp.o CMakeFiles/igloo-tests.dir/tests/testresultfactory_tests.cpp.o CMakeFiles/igloo-tests.dir/tests/alternative_registration.cpp.o CMakeFiles/igloo-tests.dir/tests/defaulttestresultsoutput_tests.cpp.o CMakeFiles/igloo-tests.dir/tests/testlistener_tests.cpp.o CMakeFiles/igloo-tests.dir/tests/nested_contexts.cpp.o CMakeFiles/igloo-tests.dir/tests/context_registry/static_setup_teardown_tests.cpp.o CMakeFiles/igloo-tests.dir/tests/context_registry/specs_marked_as_only_tests.cpp.o CMakeFiles/igloo-tests.dir/tests/context_provider/marked_as_only_tests.cpp.o  -o bin/igloo-tests -rdynamic 
cd /root/klang/lib/igloo/build/bin && /root/klang/lib/igloo/build/bin/igloo-tests
Segmentation fault (core dumped)
make[2]: *** [bin/igloo-tests] Error 139
make[2]: Leaving directory `/root/klang/lib/igloo/build'
make[1]: *** [CMakeFiles/igloo-tests.dir/all] Error 2
make[1]: Leaving directory `/root/klang/lib/igloo/build'
make: *** [all] Error 2
umireon commented 10 years ago

The actual commit that causes this issue is 033e714a72be60732ffdf1921cf34900106a22fe. Addressed by git bisect: https://gist.github.com/umireon/eeccd8f570a264f319da#file-gistfile1-sh

joakimkarlsson commented 10 years ago

Thanks for the investigation. Great detective work.

It seems that cotire isn't working. I've seen the same problem with bandit, where we changed to the latest version. I suspect this is the same thing. If it turns out to be a problem with cotire, I'll look into making cotire a submodule so we have an easier time updating it.

joakimkarlsson commented 10 years ago

Updating cotire still breaks the build on travis with the same symptom as described.

It builds fine on my machine with the following compiler:

Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4) Target: x86_64-pc-linux-gnu Thread model: posix

joakimkarlsson commented 10 years ago

Ha! After updating my ubuntu installation I get the same symptom on my machine.

joakimkarlsson commented 10 years ago

...and when I remove cotire from the build it starts working again!

umireon commented 10 years ago

Unfortunately, this issue is not so simple, because libstdc++ does something with the problem.

Stacktrace retrieved by lldb: https://gist.github.com/umireon/d6898c3b6cd3a72674da#file-igloo-test_stacktrace-txt

The result of executing strace igloo-tests: https://gist.github.com/umireon/3ff496edee4ad4ef434e#file-igloo-test_strace-c

My compiler:

Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix

libstdc++:

ii  libstdc++-4.8-dev:amd64             4.8.2-19ubuntu1                      amd64        GNU Standard C++ Library v3 (development files)
ii  libstdc++6:amd64                    4.8.2-19ubuntu1                      amd64        GNU Standard C++ Library v3
joakimkarlsson commented 10 years ago

Does this only happen when you're in lldb?

Do you get the same result when:

  1. Running without a debugger attached
  2. Running in gdb?
umireon commented 10 years ago

Thanks for reply.

  1. Yes, it faults
$ bin/igloo-tests 
fish: Job 1, “bin/igloo-tests ” terminated by signal SIGSEGV (Address boundary error)
  1. Yes. The stacktrace: https://gist.github.com/umireon/6d4298973ca4c8ac9087#file-igloo-test_gdb-txt

I suspect a static local variable “specs” in igloo/core/contextregistry.h as the cause.

Signed-Off-By: Udagawa Kaito umiiro.hacker@gmail.com

On 2014年5月13日 at 3:20:07, Joakim Karlsson (notifications@github.com) wrote:

Does this only happen when you're in lldb?

Do you get the same result when:

  1. Running without a debugger attached
  2. Running in gdb?

Reply to this email directly or view it on GitHub: https://github.com/joakimkarlsson/igloo/issues/14#issuecomment-42868266

umireon commented 10 years ago

Clang and LLVM has a problem with handling local static variables in .pch: http://permalink.gmane.org/gmane.comp.compilers.clang.scm/92157

umireon commented 10 years ago

With Clang and LLVM 3.3 or 3.5, everything goes right.

Using Clang 3.4 with precompiled headers(cotire) when the code has local static variable, actually causes this issue.

umireon commented 10 years ago

Sorry, local static variable IN A HEADER.

joakimkarlsson commented 10 years ago

Can you confirm that commit c03bc09 fixes this for you. I've commented out the use of cotire from CMakeLists.txt.

I think I'll remove cotire all together as it didn't have that much of an impact on build times for the self tests.

umireon commented 10 years ago

Yes, c03bc09 works like a charm!

clang version:

Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix
joakimkarlsson commented 10 years ago

Great.

Thanks for the excellent detective work!

umireon commented 10 years ago

I am very thankful for you. I can use your great product again without an anxiety!