But strangely the link failed because it cannot find libclang_rt.san-x86_64.a.
Yes, make install does not install some of the things that are needed. In other cases, he installs them in non-standard places.
Other things that it does not install include asan_symbolize.py , which is used to indicate dumps with Address Sanitizer (ASan).
But what is libclang_rt.san-x86_64.a? And how can I get it?
Its one of the disinfection libraries. You probably have it, you just don't understand it, because it is in a non-standard place. For example, on my system (where I create LLVM / Clang myself):
$ find /usr -name libclang_rt.san-x86_64.a 2>/dev/null /usr/local/lib/clang/3.5.0/lib/linux/libclang_rt.san-x86_64.a
So you need to use either LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (OS X) to make sure that the compiler driver can find it. You should never manually add various sanitizer libraries - the compiler driver should always add them for you.
For completeness, Clang 3.4 installed sanitizers libraries in /usr/local/lib/clang/3.4/lib/linux/ on Linux; and Clang 3.3 installed them in /usr/local/lib/clang/3.3/lib/darwin/ on OS X.
In fact, you can change the search directories in the source code, and they will be automatically loaded by the compiler driver. I think I had to change the actual sources because I could not find the configure parameter to add places like /usr/local/lib/clang/<version>/lib/linux/ . Take a look at tools/clang/lib/Frontend/InitHeaderSearch.cpp and friends. What comes from paths like .../include/c++/4.2.1 .
By the way, here's how to use Address Sanitizer and asan_symbolize.py . First run 2to3 and asan_symbolize.py to fix what Python people have broken related to basic I / O:
$ find Clang-3.5/ -name asan_symbolize.py Clang-3.5/llvm/projects/compiler-rt/lib/asan/scripts/asan_symbolize.py 2to3 -w Clang-3.5/llvm/projects/compiler-rt/lib/asan/scripts/asan_symbolize.py echo "" | Clang-3.5/llvm/projects/compiler-rt/lib/asan/scripts/asan_symbolize.py
Then copy it to a known place (or put it on the path):
sudo cp Clang-3.5/llvm/projects/compiler-rt/lib/asan/scripts/asan_symbolize.py /usr/local/bin
Then for your project:
export CPPFLAGS="-fsanitze=undefined -fsanitize=address" export CFLAGS="-fsanitze=undefined -fsanitize=address" export CXXFLAGS="-fsanitze=undefined -fsanitize=address -fno-sanitize=vptr" export CC=/usr/local/bin/clang export CXX=/usr/local/bin/clang++ export LD_LIBRARY_PATH=/usr/local/lib/clang/3.5.0/lib/linux ./configure make make check 2>&1 | asan_symbolize.py
CPPFLAGS is actually very important for the Autotools project. Otherwise, you get a scary C compiler that cannot create an executable error.
If you have an ASan error, you will see similar ones:
make test 2>&1 | asan_symbolize.py ... /usr/local/bin/clang -fsanitize=address -Xlinker -export-dynamic -o python Modules/python.o libpython3.3m.a -ldl -lutil /usr/local/ssl/lib/libssl.a /usr/local/ssl/lib/libcrypto.a -lm ./python -E -S -m sysconfig --generate-posix-vars ================================================================= ==24064==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x619000004020 at pc 0x4ed4b2 bp 0x7fff80fff010 sp 0x7fff80fff008 READ of size 4 at 0x619000004020 thread T0
There is a more complete record of the LLVM / Clang build process and the use of santizers in Python Dynamic Analysis with Clang . I wrote this a while ago, so the version and recipe are out of date. But the concepts are the same.