How to compile and use MariaDB with AddressSanitizer (ASAN)

You are viewing an old version of this article. View the current version here.

What is AddressSantitizer (ASAN)

AddressSanitizer (aka ASan) is a memory error detector for C/C++. It finds a lot of the same things as valgrind, but with a lot less overhead.

  • Use after free (dangling pointer dereference)
  • Heap buffer overflow
  • Stack buffer overflow
  • Global buffer overflow
  • Use after return
  • Use after scope
  • Initialization order bugs
  • Memory leaks

To use ASAN you need a gcc version that supports ASAN. gcc 4.8.5 and up are known to work.

How to compile MariaDB for ASAN

ASAN is supported in MariaDB from 10.1 and up.

You can use one of the two following build commands: <<code> cmake . -DWITH_ASAN=ON <</code>> or from MariaDB 10.2 and up:

./BUILD/compile-pentium64-asan-max

Running a ASAN build

To run mysqld with instrumentation you have to set the ASAN_OPTIONS environment variable before starting mysqld. Either in your shell or in your mysqld_safe script.

export ASAN_OPTIONS=abort_on_error=1:leak_check_at_exit=0

The above command will abort mysqld if any errors are found, which is good for debugging. If you set abort_on_error=0 all errors are logged to your error log file (mysqld.err).

Other things

A side effect of using ASAN builds is that you will not get any core file if your server crashes.

See also

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.