Add option to add -lc++abi flag to TSan lit tests
| Bugzilla Link | 22690 |
| Resolution | WONTFIX |
| Resolved on | Mar 18, 2016 14:58 |
| Version | unspecified |
| OS | Linux |
| Reporter | LLVM Bugzilla Contributor |
| CC | @KernelAddress,@eugenis |
Extended Description
When using libc++ with libc++abi on Linux (Debian Testing for me) it becomes necessary to manually link to libc++abi by adding -lc++abi when linking against libc++. (Though some changes may happen regarding this, see http://lists.cs.uiuc.edu/pipermail/cfe-dev/2015-February/041674.html).
The problem is I see 128 test case failures all within ThreadSanitizer. All of the failures look like:
FAIL: ThreadSanitizer :: write_in_reader_lock.cc (182 of 268) ******************** TEST 'ThreadSanitizer :: write_in_reader_lock.cc' FAILED ******************** Script:
/home/will/Repos/llvm_projects/build/./bin/clang --driver-mode=g++ -fsanitize=thread -Wall -m64 -gline-tables-only -std=c++11 -I/home/will/Repos/llvm_projects/build/projects/compiler-rt/lib/tsan/libcxx_tsan/include/c++/v1 /home/will/Repos/llvm_projects/build/projects/compiler-rt/lib/tsan/libcxx_tsan/lib/libc++.so -Wl,-rpath=/home/will/Repos/llvm_projects/build/projects/compiler-rt/lib/tsan/libcxx_tsan/lib -O1 /home/will/Repos/llvm_projects/compiler-rt/test/tsan/write_in_reader_lock.cc -o /home/will/Repos/llvm_projects/build/projects/compiler-rt/test/tsan/Output/write_in_reader_lock.cc.tmp && /home/will/Repos/llvm_projects/llvm/projects/compiler-rt/test/tsan/deflake.bash /home/will/Repos/llvm_projects/build/projects/compiler-rt/test/tsan/Output/write_in_reader_lock.cc.tmp | FileCheck /home/will/Repos/llvm_projects/compiler-rt/test/tsan/write_in_reader_lock.cc
Exit Code: 1
Command Output (stderr):
/home/will/Repos/llvm_projects/build/projects/compiler-rt/lib/tsan/libcxx_tsan/lib/libc++.so: undefined reference to std::bad_alloc::bad_alloc()' /home/will/Repos/llvm_projects/build/projects/compiler-rt/lib/tsan/libcxx_tsan/lib/libc++.so: undefined reference to __cxa_current_primary_exception'
/home/will/Repos/llvm_projects/build/projects/compiler-rt/lib/tsan/libcxx_tsan/lib/libc++.so: undefined reference to __cxa_uncaught_exception' /home/will/Repos/llvm_projects/build/projects/compiler-rt/lib/tsan/libcxx_tsan/lib/libc++.so: undefined reference to __cxa_increment_exception_refcount'
/home/will/Repos/llvm_projects/build/projects/compiler-rt/lib/tsan/libcxx_tsan/lib/libc++.so: undefined reference to std::bad_cast::bad_cast()' /home/will/Repos/llvm_projects/build/projects/compiler-rt/lib/tsan/libcxx_tsan/lib/libc++.so: undefined reference to __cxa_decrement_exception_refcount'
/home/will/Repos/llvm_projects/build/projects/compiler-rt/lib/tsan/libcxx_tsan/lib/libc++.so: undefined reference to `__cxa_rethrow_primary_exception'
clang-3.7: error: linker command failed with exit code 1 (use -v to see invocation)
--
These are all because libc++abi isn't being linked into the TSan test cases.
I have checked out the git repos of clang, clang-tools-extra, compiler-rt, libcxx, libcxxabi, lldb, and llvm. Appropriate symlinks are set up to build everything with cmake, with libcxx, libcxxabi, and compiler-rt in particular symlinked out of llvm/projects.
I'm configuring cmake as: CC=clang CXX=clang++ cmake ../llvm -G Ninja -DCMAKE_BUILD_TYPE=Release -DLIBCXX_CXX_ABI=libcxxabi -DLIBCXX_LIBCXXABI_INCLUDE_PATHS=../libcxxabi/include
and building by: ninja && ninja check-all
I have verified that adding -lc++abi fixes these errors by applying the following patch:
diff --git a/test/lit.common.cfg b/test/lit.common.cfg index 0a55186..1c76ccf 100644 --- a/test/lit.common.cfg +++ b/test/lit.common.cfg @@ -22,7 +22,7 @@ if (not compiler_path) or (not os.path.exists(compiler_path)): compiler_id = getattr(config, 'compiler_id', None) if compiler_id == "Clang": if platform.system() != 'Windows':
- config.cxx_mode_flags = ["--driver-mode=g++"]
- config.cxx_mode_flags = ["--driver-mode=g++ -lc++abi"] else: config.cxx_mode_flags = []
We assume that sanitizers should provide good enough error
Of course this patch is completely wrong as it is the wrong place to add the flag, but it was the first obvious place I saw that would propogate through to building the tests to verify the problem/solution.
It seems to me the correct fix is to add a CMake option of something like COMPILER_RT_LINK_LIBCXXABI, but I don't understand lit well enough to provide a patch. It might also be that this option should be in LLVM's CMake, but as far as I can see only TSan currently runs tests that use the standard library.
OK, thanks for checking!
I apologize for missing Dimitry's first ping. My dissertation research has been consuming all of my time and I haven't had time to keep up with the latest developments. There have quite obviously been quite some changes with the CMake files since I last looked at them.
I am no longer able to replicate the issue that I first reported. Since reporting I have a new laptop, though still Debian Testing, and have rebuilt my development environment. So I cannot confirm that this was necessarily fixed versus something different about my environment that I am unaware of. In either event since I can no longer replicate, this bug should probably be closed.
Will, is this still an issue for you?
Will, any updates on this? Evgeniy, how does it work with msan?
The patches mentioned above landed as r231075 and r231076. However they don't quite fix this bug. As I've looked into this more my current understanding is that the libc++ instrumented TSan isn't statically linked to libc++abi (or other ABI). Eric Fiselier's patch to libc++ making libc++ statically linked to libc++abi is one way to fix this, the other being to add the -lc++abi flag. Eric's patch works for the general libc++, but not the instrumented ones built by compiler-rt. Moreover it is not just the TSan instrumented libc++.It just happened to be the only one turned up when I ran "ninja check-all". I have checked this as follows:
will@gauss:~/Repos/llvm_projects/build$ for i in projects/compiler-rt/lib///lib/libc++.so; do echo $i; nm -D -C $i | grep '__cxa_current_primary_exception'; done projects/compiler-rt/lib/msan/libcxx_msan/lib/libc++.so U __cxa_current_primary_exception projects/compiler-rt/lib/msan/libcxx_msan-with-call/lib/libc++.so U __cxa_current_primary_exception projects/compiler-rt/lib/tsan/libcxx_tsan/lib/libc++.so U __cxa_current_primary_exception will@gauss:~/Repos/llvm_projects/build$
Note each .so has the ABI symbol __cxa_current_primary_exception undefined.
Individually calling "ninja check-tsan" will fail, but "ninja check-msan" will not, indicating some gap of testing coverage. I'm not sure how that should be addressed.
The building of the instrumented libc++ comes from the macro add_custom_libcxx defined in compiler-rt/cmake/Modules/AddCompilerRT.cmake. I haven't worked through exactly how yet, but I suspect the correct thing to do is tie into the LIBCXX_ENABLE_STATIC_ABI_LIBRARY option that Eric added in this location.
I believe that the proposed patches by Eric Fiselier (http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150302/124591.html and http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150302/124569.html) and the related bug of http://llvm.org/bugs/show_bug.cgi?id=22731 would fix this bug.