Skip to content

Instantly share code, notes, and snippets.

@springmeyer
Last active December 10, 2015 19:18
Show Gist options
  • Save springmeyer/4480481 to your computer and use it in GitHub Desktop.
Save springmeyer/4480481 to your computer and use it in GitHub Desktop.
Using clang++ 3.x -fsanitize
# Clang runtime checks
## gochas
- The compiler_rt code must be built (if compiling llvm/clang with
cmake you need cmake > 2.8.7)
- `-fsanitize=thread` and therefore the `tsan` symbols are not available on OS X
- Missing `asan` symbols can be solved on OS X by doing:
```
export DYLD_INSERT_LIBRARIES=/opt/llvm2/lib/clang/3.3/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
```
- Missing `ubsan` symbols like `Symbol not found: ___ubsan_handle_sub_overflow`
can be solved by statically linking the `libclang_rt.ubsan_osx.a` library.
- Both the above problems should be avoidable by doing export
`LD=clang++` and/or by ensuring that the `-fsanitize` option
is also included in the `LINKFLAGS` as well as the `CXXFLAGS`
but this did not work for me
- A missing symbol like `__ZTIN10__cxxabiv117__class_type_infoE`
can be avoided by not specifying `-fsanitize=vptr` (which is included if you do `-fsanitize=undefined`)
## build clang latest with cmake on OS X:
```sh
## docs:
# http://clang.llvm.org/get_started.html#build
# http://www.llvm.org/docs/CMake.html
# http://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summary
# http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
## requirements:
# make sure you have cmake > 2.8.7, otherwise compiler_rt will not be compiled
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm2
cd llvm2
cd tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd clang/tools
svn co http://include-what-you-use.googlecode.com/svn/trunk/ include-what-you-use
echo 'add_subdirectory(include-what-you-use)' >> CMakeLists.txt
svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra
cd ../../../
cd projects
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
# cmake approach
mkdir -p build
cd build
cmake ../ -DCMAKE_BUILD_TYPE:STRING=Release \
-DCMAKE_INSTALL_PREFIX:PATH=/opt/llvm2 \
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON ../
make
#cp ../tools/clang/tools/scan-build/scan-build/* /opt/llvm/bin/
#cp ../tools/clang/tools/scan-view/scan-view/* /opt/llvm/bin/
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment