Instrumenting an application with sanitizers
LLVM comes with a couple of sanitizers. These are passes that instrument the Intermediate Representation (IR) in a way to check for certain misbehaviors of an application. Usually, they require library support, which is part of the compiler-rt
project. Sanitizers can be enabled in Clang, which makes them very comfortable to use. In the following sections, we will have a look at the available sanitizers, namely, address
, memory
, and thread
. We will first look at the address
sanitizer.
Detecting memory access problems with the address sanitizer
You use the address
sanitizer to detect a couple of memory access bugs in an application. This includes common errors such as using dynamically allocated memory after freeing it, or writing to dynamically allocated memory outside the boundaries of the allocated memory.
When enabled, the address
sanitizer replaces calls to the malloc()
and free()
functions with its own version, and instruments...