Mon, 19 May 2025 15:09:33 +0200
add asan and ubsan features
configure | file | annotate | diff | comparison | revisions | |
make/project.xml | file | annotate | diff | comparison | revisions |
--- 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
--- 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 @@ <lang>cpp</lang> <cxxflags>-std=c++23</cxxflags> </dependency> - <dependency name="static" toolchain="gcc"> + <dependency name="static" toolchain="gnuc"> <ldflags>-static</ldflags> </dependency> - <dependency name="static" toolchain="clang"> - <ldflags>-static</ldflags> + <dependency name="asan" toolchain="gnuc"> + <cxxflags>-fsanitize=address</cxxflags> + <ldflags>-fsanitize=address</ldflags> + </dependency> + <dependency name="ubsan" toolchain="gnuc"> + <cxxflags>-fsanitize=undefined</cxxflags> + <ldflags>-fsanitize=undefined</ldflags> </dependency> <target> <feature name="static"> <desc>statically link libstdc++</desc> <dependencies>static</dependencies> </feature> + <feature name="asan"> + <desc>compile with address sanitizer</desc> + <dependencies>asan</dependencies> + </feature> + <feature name="ubsan"> + <desc>compile with undefined behavior sanitizer</desc> + <dependencies>ubsan</dependencies> + </feature> </target> </project>