Hello, I'm using the dataflow sanitizer in clang 3.6 for the first
time, I'm I'm running into some linker errors. I was wondering if
someone could point out my mistake?
I downloaded (today) from git the current llvm, clang, and compiler-rt
code. It built without any problem.
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
line?
cconvey@spaceman /tmp $
/home/cconvey/dw/clang-llvm-git/build/bin/clang++ -std=c++11
-fsanitize=dataflow foo2.cpp
/tmp/foo2-8b9f0f.o: In function `main':
foo2.cpp:(.text+0xb): undefined reference to
`dfs$_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_'
foo2.cpp:(.text+0x44): undefined reference to
`dfs$_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc'
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
`dfs$_ZNSt8ios_base4InitC1Ev'
foo2.cpp:(.text.startup+0x24): undefined reference to
`dfs$_ZNSt8ios_base4InitD1Ev'
clang-3.6: error: linker command failed with exit code 1 (use -v to
see invocation)
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
mkdir ~/src/llvm-build-dfsan
cd ~/src/llvm-build-dfsan
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++:
Sorry for the slow reply. I tried to following your instructions
precisely (since I think that was one of your main points), and I ran
into trouble on the "ninja" invocation:
cconvey@spaceman ~/dw/clang-llvm-git/llvm-build-dfsan $ ninja cxx cxxabi
ninja: error: unknown target 'cxx', did you mean 'lli'?
Please let me know if you'd like me to try something else.
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).