diff options
| author | Thomas Huth <huth@tuxfamily.org> | 2025-01-06 18:32:37 (GMT) |
|---|---|---|
| committer | Thomas Huth <huth@tuxfamily.org> | 2025-01-06 18:32:37 (GMT) |
| commit | 108c56a1cb71e78326f142f0d892a6cadf5460dc (patch) | |
| tree | deb9fca9eb73b9d0d08e0b497cabd3a7796ec346 | |
| parent | d68bdd7ee068676153e432150a7e5f722d422220 (diff) | |
| download | hatari-108c56a1cb71e78326f142f0d892a6cadf5460dc.zip hatari-108c56a1cb71e78326f142f0d892a6cadf5460dc.tar.gz | |
Add a switch to enable the undefined behavior sanitizer
| -rw-r--r-- | CMakeLists.txt | 15 | ||||
| -rwxr-xr-x | configure | 14 | ||||
| -rw-r--r-- | src/cpu/maccess.h | 2 |
3 files changed, 30 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1925b9b..57a2a0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,12 @@ if(ASAN_AVAILABLE) CACHE BOOL "Enable GCC/LLVM run-time stack/pointer debugging (~2x slowdown)") endif(ASAN_AVAILABLE) +CHECK_C_COMPILER_FLAG("-fsanitize=undefined" UBSAN_AVAILABLE) +if(UBSAN_AVAILABLE) + set(ENABLE_UBSAN 0 + CACHE BOOL "Enable GCC/LLVM run-time undefined behavior debugging") +endif(UBSAN_AVAILABLE) + find_program(GZIP gzip) if(UNIX AND GZIP) set(ENABLE_MAN_PAGES 1 CACHE BOOL "Built and install man pages") @@ -243,6 +249,15 @@ if(ENABLE_ASAN) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-common") endif(ENABLE_ASAN) +# GCC/Clang undefined behavior debugging +if(ENABLE_UBSAN) + # We assume twos-complement of modern CPUs, so use -fwrapv to + # silence related ubsan warnings: + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fwrapv") + add_definitions(-DENABLE_UBSAN=1) +endif(ENABLE_UBSAN) + + # GCC/Clang specific flags: if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") # We want to allow ‘for’-loop initial declarations a la for(int i=0; ...) @@ -14,10 +14,12 @@ print_help() echo "This is a simple configure script wrapper around cmake build system." echo "Parameters are:" echo " --prefix=<path> Set the install prefix to path" + echo " --enable-asan Enable address sanitizer debug build" echo " --enable-debug Enable debug (non-optimized) build" echo " --disable-dsp Disable DSP emulation for Falcon mode." echo " --disable-tracing Disable tracing messages for debugging" echo " --disable-osx-bundle Disable application bundling on macOS" + echo " --enable-ubsan Enable undefined behavior sanitizer debug build" echo " --enable-werror Use -Werror flag to stop on compiler warnings" echo " --cross-compile-win64_32 Build the 32 bit Windows version using mingw-w64" echo " --cross-compile-win64_64 Build the 64 bit Windows version using mingw-w64" @@ -42,6 +44,12 @@ do prefix=${1##*=} # get part after = cmake_args="$cmake_args -DCMAKE_INSTALL_PREFIX:PATH=$prefix" ;; + --enable-asan) + cmake_args="$cmake_args -DENABLE_ASAN:BOOL=1" + ;; + --disable-asan) + cmake_args="$cmake_args -DENABLE_ASAN:BOOL=0" + ;; --enable-debug) build_type="Debug" cmake_args="$cmake_args -DCMAKE_BUILD_TYPE:STRING=Debug" @@ -68,6 +76,12 @@ do --disable-osx-bundle) cmake_args="$cmake_args -DENABLE_OSX_BUNDLE:BOOL=0" ;; + --enable-ubsan) + cmake_args="$cmake_args -DENABLE_UBSAN:BOOL=1" + ;; + --disable-ubsan) + cmake_args="$cmake_args -DENABLE_UBSAN:BOOL=0" + ;; --enable-werror) cmake_args="$cmake_args -DENABLE_WERROR:BOOL=1" ;; diff --git a/src/cpu/maccess.h b/src/cpu/maccess.h index b53a7e6..0eb9c08 100644 --- a/src/cpu/maccess.h +++ b/src/cpu/maccess.h @@ -39,7 +39,7 @@ #endif /* If the CPU can access unaligned memory, use these accelerated functions: */ -#if CPU_CAN_ACCESS_UNALIGNED +#if CPU_CAN_ACCESS_UNALIGNED && !defined(ENABLE_UBSAN) static inline uae_u32 do_get_mem_long(void *a) { |
