|
|
|
@ -31,110 +31,108 @@
@@ -31,110 +31,108 @@
|
|
|
|
|
# |
|
|
|
|
############################################################################ |
|
|
|
|
|
|
|
|
|
option(SANITIZE_ADDRESS "Enable AddressSanitizer" Off) |
|
|
|
|
option(SANITIZE_MEMORY "Enable MemorySanitizer" Off) |
|
|
|
|
option(SANITIZE_THREAD "Enable ThreadSanitizer" Off) |
|
|
|
|
option(SANITIZE_UNDEFINED "Enable UndefinedBehaviorSanitizer" Off) |
|
|
|
|
|
|
|
|
|
if(DEFINED ENV{PX4_ASAN}) |
|
|
|
|
set(SANITIZE_ADDRESS ON) |
|
|
|
|
elseif(DEFINED ENV{PX4_MSAN}) |
|
|
|
|
set(SANITIZE_MEMORY ON) |
|
|
|
|
elseif(DEFINED ENV{PX4_TSAN}) |
|
|
|
|
set(SANITIZE_THREAD ON) |
|
|
|
|
elseif(DEFINED ENV{PX4_UBSAN}) |
|
|
|
|
set(SANITIZE_UNDEFINED ON) |
|
|
|
|
endif() |
|
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL AddressSanitizer) |
|
|
|
|
message(STATUS "AddressSanitizer enabled") |
|
|
|
|
|
|
|
|
|
# environment variables |
|
|
|
|
# ASAN_OPTIONS=check_initialization_order=1,detect_stack_use_after_return=1 |
|
|
|
|
add_compile_options( |
|
|
|
|
-O1 |
|
|
|
|
-g3 |
|
|
|
|
|
|
|
|
|
-fsanitize=address |
|
|
|
|
|
|
|
|
|
-fno-omit-frame-pointer # Leave frame pointers. Allows the fast unwinder to function properly. |
|
|
|
|
-fno-common # Do not treat global variable in C as common variables (allows ASan to instrument them) |
|
|
|
|
-fno-optimize-sibling-calls # disable inlining and and tail call elimination for perfect stack traces |
|
|
|
|
) |
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address" CACHE INTERNAL "" FORCE) |
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address" CACHE INTERNAL "" FORCE) |
|
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address" CACHE INTERNAL "" FORCE) |
|
|
|
|
|
|
|
|
|
function(sanitizer_fail_test_on_error test_name) |
|
|
|
|
set_tests_properties(${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "ERROR: AddressSanitizer") |
|
|
|
|
set_tests_properties(${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "ERROR: LeakSanitizer") |
|
|
|
|
endfunction(sanitizer_fail_test_on_error) |
|
|
|
|
|
|
|
|
|
elseif (CMAKE_BUILD_TYPE STREQUAL MemorySanitizer) |
|
|
|
|
message(STATUS "MemorySanitizer enabled") |
|
|
|
|
|
|
|
|
|
add_compile_options( |
|
|
|
|
-O1 |
|
|
|
|
-g3 |
|
|
|
|
|
|
|
|
|
-fsanitize=memory |
|
|
|
|
-fsanitize-memory-track-origins |
|
|
|
|
|
|
|
|
|
if (SANITIZE_ADDRESS) |
|
|
|
|
message(STATUS "AddressSanitizer enabled") |
|
|
|
|
|
|
|
|
|
# environment variables |
|
|
|
|
# ASAN_OPTIONS=detect_stack_use_after_return=1 |
|
|
|
|
# ASAN_OPTIONS=check_initialization_order=1 |
|
|
|
|
add_compile_options( |
|
|
|
|
-g3 |
|
|
|
|
-fno-omit-frame-pointer |
|
|
|
|
-fsanitize=address |
|
|
|
|
#-fsanitize-address-use-after-scope |
|
|
|
|
-fno-optimize-sibling-calls |
|
|
|
|
) |
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address" CACHE INTERNAL "" FORCE) |
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address" CACHE INTERNAL "" FORCE) |
|
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address" CACHE INTERNAL "" FORCE) |
|
|
|
|
-fno-omit-frame-pointer # Leave frame pointers. Allows the fast unwinder to function properly. |
|
|
|
|
-fno-common # Do not treat global variable in C as common variables (allows ASan to instrument them) |
|
|
|
|
-fno-optimize-sibling-calls # disable inlining and and tail call elimination for perfect stack traces |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=memory" CACHE INTERNAL "" FORCE) |
|
|
|
|
|
|
|
|
|
function(sanitizer_fail_test_on_error test_name) |
|
|
|
|
set_tests_properties(${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "ERROR: AddressSanitizer") |
|
|
|
|
set_tests_properties(${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "ERROR: LeakSanitizer") |
|
|
|
|
endfunction(sanitizer_fail_test_on_error) |
|
|
|
|
|
|
|
|
|
elseif(SANITIZE_MEMORY) |
|
|
|
|
message(STATUS "MemorySanitizer enabled") |
|
|
|
|
|
|
|
|
|
add_compile_options( |
|
|
|
|
-g3 |
|
|
|
|
-fsanitize=memory |
|
|
|
|
) |
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=memory" CACHE INTERNAL "" FORCE) |
|
|
|
|
|
|
|
|
|
function(sanitizer_fail_test_on_error test_name) |
|
|
|
|
# TODO add right check here |
|
|
|
|
endfunction(sanitizer_fail_test_on_error) |
|
|
|
|
|
|
|
|
|
elseif(SANITIZE_THREAD) |
|
|
|
|
message(STATUS "ThreadSanitizer enabled") |
|
|
|
|
|
|
|
|
|
add_compile_options( |
|
|
|
|
-g3 |
|
|
|
|
-fsanitize=thread |
|
|
|
|
) |
|
|
|
|
# TODO add right check here |
|
|
|
|
endfunction(sanitizer_fail_test_on_error) |
|
|
|
|
|
|
|
|
|
elseif (CMAKE_BUILD_TYPE STREQUAL ThreadSanitizer) |
|
|
|
|
message(STATUS "ThreadSanitizer enabled") |
|
|
|
|
|
|
|
|
|
add_compile_options( |
|
|
|
|
-g3 |
|
|
|
|
-fsanitize=thread |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread" CACHE INTERNAL "" FORCE) |
|
|
|
|
|
|
|
|
|
function(sanitizer_fail_test_on_error test_name) |
|
|
|
|
# TODO add right check here |
|
|
|
|
endfunction(sanitizer_fail_test_on_error) |
|
|
|
|
function(sanitizer_fail_test_on_error test_name) |
|
|
|
|
# TODO add right check here |
|
|
|
|
endfunction(sanitizer_fail_test_on_error) |
|
|
|
|
|
|
|
|
|
elseif(SANITIZE_UNDEFINED) |
|
|
|
|
message(STATUS "UndefinedBehaviorSanitizer enabled") |
|
|
|
|
elseif (CMAKE_BUILD_TYPE STREQUAL UndefinedBehaviorSanitizer) |
|
|
|
|
message(STATUS "UndefinedBehaviorSanitizer enabled") |
|
|
|
|
|
|
|
|
|
add_compile_options( |
|
|
|
|
-g3 |
|
|
|
|
#-fsanitize=alignment |
|
|
|
|
-fsanitize=bool |
|
|
|
|
add_compile_options( |
|
|
|
|
-g3 |
|
|
|
|
|
|
|
|
|
#-fsanitize=alignment |
|
|
|
|
-fsanitize=bool |
|
|
|
|
#-fsanitize=builtin |
|
|
|
|
-fsanitize=bounds |
|
|
|
|
-fsanitize=enum |
|
|
|
|
-fsanitize=float-cast-overflow |
|
|
|
|
-fsanitize=float-divide-by-zero |
|
|
|
|
#-fsanitize=function |
|
|
|
|
-fsanitize=integer-divide-by-zero |
|
|
|
|
-fsanitize=nonnull-attribute |
|
|
|
|
-fsanitize=null |
|
|
|
|
-fsanitize=bounds |
|
|
|
|
-fsanitize=enum |
|
|
|
|
-fsanitize=float-cast-overflow |
|
|
|
|
-fsanitize=float-divide-by-zero |
|
|
|
|
#-fsanitize=function |
|
|
|
|
-fsanitize=integer-divide-by-zero |
|
|
|
|
-fsanitize=nonnull-attribute |
|
|
|
|
-fsanitize=null |
|
|
|
|
#-fsanitize=nullability-arg |
|
|
|
|
#-fsanitize=nullability-assign |
|
|
|
|
#-fsanitize=nullability-return |
|
|
|
|
-fsanitize=object-size |
|
|
|
|
-fsanitize=object-size |
|
|
|
|
#-fsanitize=pointer-overflow |
|
|
|
|
-fsanitize=return |
|
|
|
|
-fsanitize=returns-nonnull-attribute |
|
|
|
|
-fsanitize=shift |
|
|
|
|
-fsanitize=signed-integer-overflow |
|
|
|
|
-fsanitize=unreachable |
|
|
|
|
#-fsanitize=unsigned-integer-overflow |
|
|
|
|
-fsanitize=vla-bound |
|
|
|
|
-fsanitize=vptr |
|
|
|
|
-fsanitize=return |
|
|
|
|
-fsanitize=returns-nonnull-attribute |
|
|
|
|
-fsanitize=shift |
|
|
|
|
-fsanitize=signed-integer-overflow |
|
|
|
|
-fsanitize=unreachable |
|
|
|
|
#-fsanitize=unsigned-integer-overflow |
|
|
|
|
-fsanitize=vla-bound |
|
|
|
|
-fsanitize=vptr |
|
|
|
|
|
|
|
|
|
-fno-sanitize-recover=bounds,null |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined" CACHE INTERNAL "" FORCE) |
|
|
|
|
|
|
|
|
|
function(sanitizer_fail_test_on_error test_name) |
|
|
|
|
# TODO add right check here |
|
|
|
|
endfunction(sanitizer_fail_test_on_error) |
|
|
|
|
function(sanitizer_fail_test_on_error test_name) |
|
|
|
|
# TODO add right check here |
|
|
|
|
endfunction(sanitizer_fail_test_on_error) |
|
|
|
|
else() |
|
|
|
|
|
|
|
|
|
function(sanitizer_fail_test_on_error test_name) |
|
|
|
|
# default: don't do anything |
|
|
|
|
endfunction(sanitizer_fail_test_on_error) |
|
|
|
|
function(sanitizer_fail_test_on_error test_name) |
|
|
|
|
# default: don't do anything |
|
|
|
|
endfunction(sanitizer_fail_test_on_error) |
|
|
|
|
|
|
|
|
|
endif() |
|
|
|
|