However, I have a linking problem when I try to extend the example.
When I try to call the function "dfsan_get_label_info", the linker
can't find it. This is a bit of a surprise, because it does appear to
be defined in my LLVM build:
When I build it without the dataflow sanitizer, things work fine:
/home/cconvey/dw/clang-llvm-git/build/bin/clang++ -std=c++11 foo2.cpp
However, when I enable the sanitizer, there are a lot of unmet
dependencies. Any idea if I'm doing something wrong on the command
cconvey@spaceman /tmp $
/tmp/foo2-8b9f0f.o: In function `main':
foo2.cpp:(.text+0xb): undefined reference to
foo2.cpp:(.text+0x44): undefined reference to
foo2.cpp:(.text+0x6a): undefined reference to `dfs$_ZNSolsEPFRSoS_E'
/tmp/foo2-8b9f0f.o: In function `dfs$__cxx_global_var_init':
foo2.cpp:(.text.startup+0x1d): undefined reference to
foo2.cpp:(.text.startup+0x24): undefined reference to
clang-3.6: error: linker command failed with exit code 1 (use -v to
If you wish to compile C++ programs with DFSan, you will first need to
compile the C++ standard library with DFSan. Unfortunately, the way to do
this is quite painful at the moment, and needs to be simplified and documented
better. This way worked for me:
1. Check out the libcxx and libcxxabi projects into the LLVM projects directory.
2. Use cmake to configure a separate build directory in which to build libcxx
and libcxxabi with DFSan:
# assuming that your LLVM source directory is ~/src/llvm and build directory is ~/src/llvm-build
CC=~/src/llvm-build/bin/clang CXX=~/src/llvm-build/bin/clang++ cmake -G Ninja ../llvm -DCMAKE_C_FLAGS=-fsanitize=dataflow -DCMAKE_CXX_FLAGS=-fsanitize=dataflow -DLIBCXXABI_ENABLE_SHARED=NO -DLIBCXX_ENABLE_SHARED=NO -DLLVM_FORCE_USE_OLD_TOOLCHAIN=YES -DLIBCXX_CXX_ABI=libcxxabi
3. Build only libc++ and libc++abi in the just-configured build directory:
ninja cxx cxxabi
3. To compile your program, pass the following flags to clang++:
Are you sure that you have checked out libcxx and libcxxabi into llvm/projects
(i.e. alongside compiler-rt)? Once you have done so, it may be necessary
to run CMake again to pick up the new projects (the safest thing to do is
probably to delete the llvm-build-dfsan directory and redo step 2).