How to use AddressSanitizer with GCC?

别等时光非礼了梦想. 提交于 2019-11-26 09:36:27

问题


I\'m trying to build my project with

g++ -O0 -g -fsanitize=address -fno-omit-frame-pointer

but get lots of errors like:

/home/user/libs/opencv/include/opencv2/core/mat.hpp:715: undefined reference to `__asan_report_load8\'

How to compile project with AddressSanitize support?

My gcc version is 4.8.4.


回答1:


You need to add the switch -lasan to your compile/link command line to link the correct library.




回答2:


You need to add -fsanitize=address to both compiler flags (CFLAGS, CXXFLAGS) and linker flags (LDFLAGS). You've probably added it to your compiler flags only.

Note that using explicit -lasan option has been widely discouraged by ASan developers (e.g. here) as it misses some other important linker flags. The only recommended way to link is to use -fsanitize=address.

As a side note, for more aggressive verification flags check Asan FAQ (look for "more aggressive diagnostics").




回答3:


Make sure you have libasan installed. For example, in Fedora:

dnf install libasan libasan-static



来源:https://stackoverflow.com/questions/37970758/how-to-use-addresssanitizer-with-gcc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!