Skip to content

Commit 05cc0b8

Browse files
committed
Add build flag to enable the Undefined Behavior Sanitizer
The flag can be enabled in CMake using -DENABLE_UB_SANITIZER=ON Signed-off-by: Björn Svensson <[email protected]>
1 parent 1f549a6 commit 05cc0b8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ if (LEGACY_BUILD)
4545
option(ANDROID_BUILD_ZLIB "When building for Android, should Zlib be built as well" ON)
4646
option(FORCE_CURL "Forces usage of the Curl client rather than the default OS-specific api" OFF)
4747
option(ENABLE_ADDRESS_SANITIZER "Flags to enable/disable Address Sanitizer for gcc or clang" OFF)
48+
option(ENABLE_UB_SANITIZER "Flags to enable/disable Undefined Behavior Sanitizer for gcc or clang" OFF)
4849
option(BYPASS_DEFAULT_PROXY "Bypass the machine's default proxy settings when using IXmlHttpRequest2" ON)
4950
option(BUILD_DEPS "Build third-party dependencies" ON)
5051
option(USE_OPENSSL "Set this if you want to use your system's OpenSSL 1.0.2/1.1.1 compatible libcrypto" ON)
@@ -241,6 +242,10 @@ if (LEGACY_BUILD)
241242
set(BUILD_SHARED_LIBS OFF)
242243
endif ()
243244
set(CRT_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
245+
if (ENABLE_UB_SANITIZER)
246+
set(ENABLE_SANITIZERS ON CACHE BOOL "Enable sanitizers in dependencies")
247+
set(SANITIZERS "undefined" CACHE STRING "List of sanitizers to build with")
248+
endif ()
244249
add_subdirectory(crt/aws-crt-cpp)
245250
set(BUILD_TESTING ${BUILD_TESTING_PREV})
246251
if (ENABLE_OPENSSL_ENCRYPTION)
@@ -322,6 +327,10 @@ if (LEGACY_BUILD)
322327
endif ()
323328
endif ()
324329

330+
if (ENABLE_UB_SANITIZER)
331+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -g -fno-omit-frame-pointer")
332+
endif ()
333+
325334
include(CheckCXXSymbolExists)
326335

327336
check_cxx_symbol_exists("pathconf" "unistd.h" HAS_PATHCONF)

docs/CMake_Parameters.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ For more information, see the CMake documentation for your platform.
8888
### ENABLE_ADDRESS_SANITIZER
8989
(Defaults to OFF) Flags to enable/disable Address Sanitizer for gcc or clang
9090

91+
### ENABLE_UB_SANITIZER
92+
(Defaults to OFF) Flags to enable/disable Undefined Behavior Sanitizer for gcc or clang
93+
9194
### BYPASS_DEFAULT_PROXY
9295
(Defaults to ON) Bypass the machine's default proxy settings when using IXmlHttpRequest2
9396

0 commit comments

Comments
 (0)