Sanitizer: Add in build environment support

configure --enable-sanitizer
cmake -DENABLE_SANITIZER=ON
This commit is contained in:
Jon Shallow committed 2026-03-25 08:53:41 +00:00
1 parent 0cd597ab82
commit d7b1827287
2 files changed
+35

No files matched your search

+16
View File
@@ -72,6 +72,17 @@ if(CMAKE_GENERATOR MATCHES "Visual Studio")
endif()
endif()
if(ENABLE_SANITIZER)
if(MSVC)
add_compile_options(/fsanitize=address,undefined)
add_link_options(/fsanitize=address,undefined)
else()
add_compile_options(-fsanitize=address,undefined -fno-omit-frame-pointer -fsanitize-address-use-after-scope)
add_link_options(-fsanitize=address,undefined)
endif()
message(STATUS "AddressSanitizer (ASan) and UndefinedBehaviorSanitizer (UBSan) enabled")
endif()
#
# The libcoap library
#
@@ -201,6 +212,10 @@ option(
WARNING_TO_ERROR
"force all compiler warnings to be errors"
OFF)
option(
ENABLE_SANITIZER
"enable AddressSanitizer (ASan) and UndefinedBehaviorSanitizer (UBSan)"
OFF)
set(MAX_LOGGING_LEVEL
"8"
CACHE
@@ -687,6 +702,7 @@ message(STATUS "ENABLE_THREAD_SAFE:..............${ENABLE_THREAD_SAFE}")
message(STATUS "ENABLE_THREAD_RECURSIVE_CHECK....${ENABLE_THREAD_RECURSIVE_LOCK_CHECK}")
message(STATUS "ENABLE_DOCS:.....................${ENABLE_DOCS}")
message(STATUS "ENABLE_EXAMPLES:.................${ENABLE_EXAMPLES}")
message(STATUS "ENABLE_SANITIZER:................${ENABLE_SANITIZER}")
message(STATUS "DTLS_BACKEND:....................${DTLS_BACKEND}")
message(STATUS "WITH_GNUTLS:.....................${WITH_GNUTLS}")
message(STATUS "WITH_TINYDTLS:...................${WITH_TINYDTLS}")
+19
View File
@@ -943,6 +943,20 @@ if test "x$build_gcov" = "xyes"; then
fi
fi
# configure options
# __sanitize__
AC_ARG_ENABLE([sanitize],
[AS_HELP_STRING([--enable-sanitize],
[Enable building with sanitize=address,undefined coverage support [default=no]])],
[build_sanitize="$enableval"],
[build_sanitize="no"])
if test "x$build_sanitize" = "xyes"; then
AX_CHECK_COMPILE_FLAG([-fsanitize=address,undefined], [CFLAGS="$CFLAGS -fsanitize=address,undefined"])
AX_CHECK_COMPILE_FLAG([-fno-omit-frame-pointer], [CFLAGS="$CFLAGS -fno-omit-frame-pointer"])
AX_CHECK_COMPILE_FLAG([-fsanitize-address-use-after-scope], [CFLAGS="$CFLAGS -fsanitize-address-use-after-scope"])
fi
# configure options
# __license-install__
AC_ARG_ENABLE([license-install],
@@ -1556,6 +1570,11 @@ if test "x$enable_static" = "xyes"; then
else
AC_MSG_RESULT([ build static library : "no"])
fi
if test "x$enable_sanitize" = "xyes"; then
AC_MSG_RESULT([ build with sanitize : "yes"])
else
AC_MSG_RESULT([ build with sanitize : "no"])
fi
mkdir -p include/coap$LIBCOAP_API_VERSION
LT_TEMP=`grep -B2 " COAP_" coap_config.h > include/coap$LIBCOAP_API_VERSION/coap_defines.h`