diff --git a/arch/posix/CMakeLists.txt b/arch/posix/CMakeLists.txt index df88a9df85f..b32fc855117 100644 --- a/arch/posix/CMakeLists.txt +++ b/arch/posix/CMakeLists.txt @@ -27,6 +27,10 @@ if (CONFIG_ASAN) toolchain_cc_asan() endif () +if (CONFIG_UBSAN) + toolchain_cc_ubsan() +endif () + zephyr_compile_definitions(_POSIX_C_SOURCE=200809 _XOPEN_SOURCE=600 _XOPEN_SOURCE_EXTENDED) zephyr_ld_options( diff --git a/cmake/compiler/clang/target_sanitizers.cmake b/cmake/compiler/clang/target_sanitizers.cmake index 9baa653e3f3..091b6d274d1 100644 --- a/cmake/compiler/clang/target_sanitizers.cmake +++ b/cmake/compiler/clang/target_sanitizers.cmake @@ -6,3 +6,10 @@ zephyr_compile_options(-fsanitize=address) zephyr_ld_options(-fsanitize=address) endmacro() + +macro(toolchain_cc_ubsan) + +zephyr_compile_options(-fsanitize=undefined) +zephyr_ld_options(-fsanitize=undefined) + +endmacro() diff --git a/cmake/compiler/gcc/target_sanitizers.cmake b/cmake/compiler/gcc/target_sanitizers.cmake index c7273547987..1661307feb4 100644 --- a/cmake/compiler/gcc/target_sanitizers.cmake +++ b/cmake/compiler/gcc/target_sanitizers.cmake @@ -7,3 +7,10 @@ zephyr_link_libraries(-lasan) zephyr_ld_options(-fsanitize=address) endmacro() + +macro(toolchain_cc_ubsan) + +zephyr_compile_options(-fsanitize=undefined) +zephyr_ld_options(-fsanitize=undefined) + +endmacro() diff --git a/subsys/debug/Kconfig b/subsys/debug/Kconfig index 27ce9fa9579..08a563c7e0d 100644 --- a/subsys/debug/Kconfig +++ b/subsys/debug/Kconfig @@ -45,14 +45,24 @@ config TRACING help Enable system tracing. This requires a backend such as SEGGER Systemview to be enabled as well. + config ASAN bool "Build with address sanitizer" depends on ARCH_POSIX help - Builds Zephyr with Address Sanitizer enabled. This is currently - only supported by the native_posix port, and requires a recent-ish - compiler with the ``-fsanitize=address`` command line option, and - the libasan library. + Builds Zephyr with Address Sanitizer enabled. This is currently + only supported by boards based on the posix architecture, and requires a + recent-ish compiler with the ``-fsanitize=address`` command line option, + and the libasan library. + +config UBSAN + bool "Build with undefined behavior sanitizer" + depends on ARCH_POSIX + help + Builds Zephyr with Undefined Behavior Sanitizer enabled. + This is currently only supported by boards based on the posix + architecture, and requires a recent-ish compiler with the + ``-fsanitize=undefined`` command line option. config STACK_USAGE bool "Generate stack usage information"