Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Riztazz/f6297978ccc6b3e9cb475e69022694d4 to your computer and use it in GitHub Desktop.
Save Riztazz/f6297978ccc6b3e9cb475e69022694d4 to your computer and use it in GitHub Desktop.
GCC sanitizer with CMake

Build in CMake with these params:

CMAKE_CXX_FLAGS:STRING= -fsanitize=address  -fsanitize=leak -g
CMAKE_C_FLAGS:STRING=-fsanitize=address  -fsanitize=leak -g
CMAKE_EXE_LINKER_FLAGS:STRING=-fsanitize=address  -fsanitize=leak
CMAKE_MODULE_LINKER_FLAGS:STRING=-fsanitize=address  -fsanitize=leak

Which can be done with:

cmake .. -DCMAKE_CXX_FLAGS="-fsanitize=address  -fsanitize=leak -g" -DCMAKE_C_FLAGS="-fsanitize=address  -fsanitize=leak -g" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address  -fsanitize=leak" -DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=address  -fsanitize=leak"

Then run with:

export ASAN_OPTIONS=fast_unwind_on_malloc=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment