Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Enabling Address Sanitizer for OpenCV builds

Is there a way to enable Address Sanitizer for OpenCV builds?

I've tried adding OPENCV_EXTRA_CXX_FLAGS="-fsanitize=address"; however, I receive configuration errors claiming:

Compiler doesn't support baseline optimization flags

I've also tried adding custom build configs like the below:

# AddressSanitize
set(CMAKE_C_FLAGS_ASAN
    "-fsanitize=address -g -O1"
    CACHE STRING "Flags used by the C compiler during AddressSanitizer builds."
    FORCE)
set(CMAKE_CXX_FLAGS_ASAN
    "-fsanitize=address -g -O1"
    CACHE STRING "Flags used by the C++ compiler during AddressSanitizer builds."
    FORCE)

This makes it further, but upon linking libopencv_core.so I get the following error:

`_ZZN2cv10AutoBufferIiLm4EEixEmE19__PRETTY_FUNCTION__' referenced in section `.data.rel.local..LASAN0' of CMakeFiles/opencv_core.dir/src/umatrix.cpp.o: defined in discarded section `.rodata._ZZN2cv10AutoBufferIiLm4EEixEmE19__PRETTY_FUNC
TION__[_ZZN2cv10AutoBufferIiLm4EEixEmE15__cv_check__137]' of CMakeFiles/opencv_core.dir/src/umatrix.cpp.o
`_ZZN2cv10AutoBufferINS_5RangeELm136EEixEmE19__PRETTY_FUNCTION__' referenced in section `.data.rel.local..LASAN0' of CMakeFiles/opencv_core.dir/src/umatrix.cpp.o: defined in discarded section `.rodata._ZZN2cv10AutoBufferINS_5RangeELm136
EEixEmE19__PRETTY_FUNCTION__[_ZZN2cv10AutoBufferINS_5RangeELm136EEixEmE15__cv_check__137]' of CMakeFiles/opencv_core.dir/src/umatrix.cpp.o
collect2: error: ld returned 1 exit status
modules/core/CMakeFiles/opencv_core.dir/build.make:1614: recipe for target 'lib/libopencv_core.so.3.4.10' failed
make[2]: *** [lib/libopencv_core.so.3.4.10] Error 1
CMakeFiles/Makefile2:2258: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

Thanks for your time!