# HG changeset patch # User Mike Becker # Date 1747660173 -7200 # Node ID c7b37d5e26cfeadf7aa6ff54de08bdb1e0ebee6f # Parent c1046605091a39a8d6b738cf045275803bf5b42e add asan and ubsan features diff -r c1046605091a -r c7b37d5e26cf configure --- a/configure Mon May 19 15:09:16 2025 +0200 +++ b/configure Mon May 19 15:09:33 2025 +0200 @@ -112,6 +112,8 @@ Optional Features: --enable-static statically link libstdc++ + --enable-asan compile with address sanitizer + --enable-ubsan compile with undefined behavior sanitizer __EOF__ } @@ -179,6 +181,10 @@ "--release") BUILD_TYPE="release" ;; "--enable-static") FEATURE_STATIC=on ;; "--disable-static") unset FEATURE_STATIC ;; + "--enable-asan") FEATURE_ASAN=on ;; + "--disable-asan") unset FEATURE_ASAN ;; + "--enable-ubsan") FEATURE_UBSAN=on ;; + "--disable-ubsan") unset FEATURE_UBSAN ;; "-"*) echo "unknown option: $ARG"; abort_configure ;; esac done @@ -295,25 +301,33 @@ fi } +dependency_error_asan() +{ + print_check_msg "$dep_checked_asan" "checking for asan... " + # dependency asan toolchain="gnuc" + while true + do + if notistoolchain "gnuc"; then + break + fi + TEMP_CXXFLAGS="$TEMP_CXXFLAGS -fsanitize=address" + TEMP_LDFLAGS="$TEMP_LDFLAGS -fsanitize=address" + print_check_msg "$dep_checked_asan" "yes\n" + dep_checked_asan=1 + return 1 + done + + print_check_msg "$dep_checked_asan" "no\n" + dep_checked_asan=1 + return 0 +} dependency_error_static() { print_check_msg "$dep_checked_static" "checking for static... " - # dependency static toolchain="gcc" + # dependency static toolchain="gnuc" while true do - if notistoolchain "gcc"; then - break - fi - TEMP_LDFLAGS="$TEMP_LDFLAGS -static" - print_check_msg "$dep_checked_static" "yes\n" - dep_checked_static=1 - return 1 - done - - # dependency static toolchain="clang" - while true - do - if notistoolchain "clang"; then + if notistoolchain "gnuc"; then break fi TEMP_LDFLAGS="$TEMP_LDFLAGS -static" @@ -326,6 +340,26 @@ dep_checked_static=1 return 0 } +dependency_error_ubsan() +{ + print_check_msg "$dep_checked_ubsan" "checking for ubsan... " + # dependency ubsan toolchain="gnuc" + while true + do + if notistoolchain "gnuc"; then + break + fi + TEMP_CXXFLAGS="$TEMP_CXXFLAGS -fsanitize=undefined" + TEMP_LDFLAGS="$TEMP_LDFLAGS -fsanitize=undefined" + print_check_msg "$dep_checked_ubsan" "yes\n" + dep_checked_ubsan=1 + return 1 + done + + print_check_msg "$dep_checked_ubsan" "no\n" + dep_checked_ubsan=1 + return 0 +} # start collecting dependency information echo > "$TEMP_DIR/flags.mk" @@ -410,6 +444,46 @@ else : fi +if [ -n "$FEATURE_ASAN" ]; then + # check dependency + if dependency_error_asan ; then + # "auto" features can fail and are just disabled in this case + if [ "$FEATURE_ASAN" = "auto" ]; then + DISABLE_FEATURE_ASAN=1 + else + DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED asan " + ERROR=1 + fi + fi + if [ -n "$DISABLE_FEATURE_ASAN" ]; then + unset FEATURE_ASAN + fi +fi +if [ -n "$FEATURE_ASAN" ]; then + : +else + : +fi +if [ -n "$FEATURE_UBSAN" ]; then + # check dependency + if dependency_error_ubsan ; then + # "auto" features can fail and are just disabled in this case + if [ "$FEATURE_UBSAN" = "auto" ]; then + DISABLE_FEATURE_UBSAN=1 + else + DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ubsan " + ERROR=1 + fi + fi + if [ -n "$DISABLE_FEATURE_UBSAN" ]; then + unset FEATURE_UBSAN + fi +fi +if [ -n "$FEATURE_UBSAN" ]; then + : +else + : +fi if [ -n "${TEMP_CFLAGS}" ] && [ -n "$lang_c" ]; then @@ -500,6 +574,16 @@ else echo " static: off" fi +if [ -n "$FEATURE_ASAN" ]; then +echo " asan: on" +else +echo " asan: off" +fi +if [ -n "$FEATURE_UBSAN" ]; then +echo " ubsan: on" +else +echo " ubsan: off" +fi echo # generate the config.mk file diff -r c1046605091a -r c7b37d5e26cf make/project.xml --- a/make/project.xml Mon May 19 15:09:16 2025 +0200 +++ b/make/project.xml Mon May 19 15:09:33 2025 +0200 @@ -4,17 +4,30 @@ cpp -std=c++23 - + -static - - -static + + -fsanitize=address + -fsanitize=address + + + -fsanitize=undefined + -fsanitize=undefined statically link libstdc++ static + + compile with address sanitizer + asan + + + compile with undefined behavior sanitizer + ubsan +