Skip to content

Instantly share code, notes, and snippets.

@antmd
Last active March 1, 2022 21:14
Show Gist options
  • Save antmd/893fdae85e10e5f6c8c87505c5561add to your computer and use it in GitHub Desktop.
Save antmd/893fdae85e10e5f6c8c87505c5561add to your computer and use it in GitHub Desktop.
AddressSanitizer for GCC

https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer

CMAKE Flags

If you haven't got the ASAN libraries installed on the run host, or you are going to use another LD_PRELOAD'd lib like onload, you'll have to build 'static-libasan':

Static LibASAN build

cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CXX_FLAGS='-fsanitize=address -fno-omit-frame-pointer' -DCMAKE_MODULE_LINKER_FLAGS='-fsanitize=address -static-libasan' -DCMAKE_EXE_LINKER_FLAGS='-fsanitize=address -static-libasan'

Running with ASAN

  • Virtual memory must not be limited by ulimit -v or by LimitAS in a systemd unit file
  • Output from the address sanitizer will be printed to stderr, and available in the journal
  • Preventing LeaK Detector exiting a process with non-zero code for tests, export LSAN_OPTIONS=exitcode=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment