Trying to use the AddressSanitizer tool (ASan) on my C++ project, I get a very verbose output full of undefined reference to '__asan_report_store8'
and undefined reference to '__asan_report_load8'
, and others like __asan_stack_malloc_2
. My project is built with CMake, and I've added the following line to my CMakeLists.txt:
add_definitions(-fsanitize=address -g3 -fno-omit-frame-pointer)
following these ASan examples:
Running the above makefile example I get the expected pretty output (which can also be seen in the video link). But for my project I'm getting a messy stack trace of those errors.
Notes:
ASAN_OPTIONS=symbolize=1
and ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-5.0/bin/llvm-symbolizer
in order to print the line numbers in the ASan outputWhen compiling code to be run with one of the LLVM Sanitizers, you have to pass the -fsanitize=...
flag to both the compiler and the linker. With CMake, you can do this by calling target_link_libraries
:
target_link_libraries(MyTarget
-fsanitize=address
)
Alternatively, if you aren't using modern CMake, you can do the same with the link_libraries
command
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With