Using sanitizers
You might have used tools such as Valgrind for memory debugging. LLVM also provides us with tools for memory debugging, such as the address sanitizer, memory sanitizer, and so on. These tools are very fast compared to Valgrind, even though they are not as mature as Valgrind. Most of these tools are in their experimental stage, so if you want, you can contribute to the open source development of these tools.
Getting ready
To make use of these sanitizers, we need to check out the code for compiler-rt
from the LLVM SVN:
cd llvm/projects svn co http://llvm.org/svn/llvm-project/compiler-rt/trunkĀ compiler-rt
Build LLVM as we did in Chapter 1, LLVM Design and Use. By doing so, we get the runtime libraries required.
How to do itā¦
Now, we will test the address sanitizer on a test code.
Write a test case to check the address sanitizer:
$ cat asan.c int main() { int a[5]; int index = 6; int retval = a[index]; return retval; }
Compile the test code using the
fsanitize=address
command-line...