From aaec13b84cb8b7c8934bc883a5891a889177f9a7 Mon Sep 17 00:00:00 2001 From: mikkelfj Date: Wed, 25 Oct 2023 16:03:33 +0200 Subject: [PATCH] Make clang -fsanitize an option and fix setup script to add sanitize flag for clang --- CMakeLists.txt | 12 +++++++++--- README.md | 12 ++++++++++++ scripts/_user_build.in | 13 ++++++++++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ace0368e1..cb6715a9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,10 @@ option(FLATCC_TEST "enable tests" ON) # project. option(FLATCC_CXX_TEST "enable C++ tests" ON) +# Note that linking with flatcc debug libraries may require souce code to also use +# the sanitize flag. +option(FLATCC_DEBUG_CLANG_SANITIZE "enable clang sanitize flag for debug build" ON) + # Conditionally set project languages based on FLATCC_TEST, as C++ is # only necessary if building the tests. if (FLATCC_TEST AND FLATCC_CXX_TEST) @@ -188,9 +192,11 @@ if (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT "${CMAKE_CXX_SIMULATE_ID}" STREQ if (FLATCC_IGNORE_CONST_COND) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-tautological-constant-out-of-range-compare") endif() - if (CMAKE_BUILD_TYPE MATCHES Debug) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined") + if (FLATCC_DEBUG_CLANG_SANITIZE) + if (CMAKE_BUILD_TYPE MATCHES Debug) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined") + endif() endif() # Suppress warning relaxed in clang-6, see https://reviews.llvm.org/D28148 if (CMAKE_C_COMPILER_VERSION VERSION_LESS 6) diff --git a/README.md b/README.md index 95fe80866..501f40bb6 100644 --- a/README.md +++ b/README.md @@ -294,6 +294,13 @@ fi ## Status +Release 0.6.2 (in development) is primarily a bug fix release, refer +to CHANGELOG for details. +Note that for clang debug builds, -fsanitize=undefined has been +added and this may require dependent source code to also use +that flag to avoid missing linker symbols. The feature can be disabled +in CMakeLists.txt. + Release 0.6.1 contains primarily bug fixes and numerous contributions from the community to handle platform edge cases. Additionally, pendantic GCC warnings are disabled, relying instead on clang, since GCC @@ -390,6 +397,11 @@ different target platforms. ### Supported platforms (CI tested) +This list is somewhat outdated, more recent compiler versions are added and +some old ones are removed when CI platforms no longer supported but largely +the supported targets remain unchanged. MSVC 2010 might become deprecated +in the future. + The ci-more branch tests additional compilers: - Ubuntu Trusty gcc 4.4, 4.6-4.9, 5, 6, 7 and clang 3.6, 3.8 diff --git a/scripts/_user_build.in b/scripts/_user_build.in index dfcc40a62..7b8e0b59e 100644 --- a/scripts/_user_build.in +++ b/scripts/_user_build.in @@ -15,12 +15,21 @@ mkdir -p generated cd build +# we cannot link with debug library unless we use the sanitize flag. +SANFLAG_DEBUG="" +compiler_info="$($CC --version 2>&1)" +echo "using compiler: $compiler_info" +if echo $compiler_info | grep -q -i "clang"; then + SANFLAG_DEBUG="-fsanitize=undefined" + echo "sanitizer flag: $SANFLAG_DEBUG" +fi + if [[ "$FLATCC_PORTABLE" = "yes" ]]; then CFLAGS="$CFLAGS -DFLATCC_PORTABLE" fi CFLAGS="$CFLAGS -I ${ROOT}/include -I ${ROOT}/generated" -CFLAGS_DEBUG=${CFLAGS_DEBUG:--g} +CFLAGS_DEBUG=${CFLAGS_DEBUG:--g $SANFLAG_DEBUG} CFLAGS_RELEASE=${CFLAGS_RELEASE:--O2 -DNDEBUG} ${ROOT}/bin/flatcc -a -o ${ROOT}/generated ${ROOT}/src/*.fbs @@ -30,3 +39,5 @@ $CC $CFLAGS $CFLAGS_DEBUG ${ROOT}/src/*.c ${ROOT}/lib/libflatccrt_d.a -o ${NAME} echo "building '$NAME' for release" $CC $CFLAGS $CFLAGS_RELEASE ${ROOT}/src/*.c ${ROOT}/lib/libflatccrt.a -o ${NAME} + +echo using compiler $CC \ No newline at end of file