Book Image

LLVM Cookbook

Book Image

LLVM Cookbook

Overview of this book

Table of Contents (16 chapters)
LLVM Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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.

  1. 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;
    }
    
  2. Compile the test code using the fsanitize=address command-line...