From: Evgeny Vereshchagin Date: Wed, 1 Jul 2020 19:52:51 +0000 (+0000) Subject: build-sys: add --enable-ubsan to make it possible to build util-linux with UBSan X-Git-Tag: v2.36-rc2~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e6a4d8cc06f26f01b9e1ef80b11138624b2e9dce;p=thirdparty%2Futil-linux.git build-sys: add --enable-ubsan to make it possible to build util-linux with UBSan mostly to prepare for https://github.com/karelzak/util-linux/pull/1068 but it's useful even without fuzzing. Signed-off-by: Karel Zak --- diff --git a/Makefile.am b/Makefile.am index 75964bab31..f4f0ab44b3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,7 +11,7 @@ AM_CPPFLAGS += \ endif AM_CFLAGS = -fsigned-char $(WARN_CFLAGS) -AM_LDFLAGS = $(ASAN_LDFLAGS) +AM_LDFLAGS = $(ASAN_LDFLAGS) $(UBSAN_LDFLAGS) # Add gettext stuff to the global LDADD for systems with separate libintl # library. The LTLIBINTL is generated by AM_GNU_GETTEXT macro. diff --git a/configure.ac b/configure.ac index 77ac3634c1..b40fcd0ff6 100644 --- a/configure.ac +++ b/configure.ac @@ -179,6 +179,16 @@ AS_IF([test "x$enable_asan" = xyes], [ ]) AC_SUBST([ASAN_LDFLAGS]) +AC_ARG_ENABLE([ubsan], + AS_HELP_STRING([--enable-ubsan], [compile with UBsan]), + [], [enable_ubsan=no] +) +AS_IF([test "x$enable_ubsan" = xyes], [ + UL_WARN_ADD([-fsanitize=undefined]) + UBSAN_LDFLAGS="-fsanitize=undefined" +]) +AC_SUBST([UBSAN_LDFLAGS]) + dnl libtool-2 LT_INIT diff --git a/tests/functions.sh b/tests/functions.sh index 60bef734ef..b73889e64d 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -262,8 +262,9 @@ function ts_init_env { LC_ALL="POSIX" CHARSET="UTF-8" ASAN_OPTIONS="detect_leaks=0" + UBSAN_OPTIONS="print_stacktrace=1:print_summary=1:halt_on_error=1" - export LANG LANGUAGE LC_ALL CHARSET ASAN_OPTIONS + export LANG LANGUAGE LC_ALL CHARSET ASAN_OPTIONS UBSAN_OPTIONS mydir=$(ts_canonicalize "$mydir") @@ -339,6 +340,10 @@ function ts_init_env { if [ "$tmp" == "yes" ]; then TS_ENABLE_ASAN="yes" fi + tmp=$( ts_has_option "memcheck-ubsan" "$*") + if [ "$tmp" == "yes" ]; then + TS_ENABLE_UBSAN="yes" + fi BLKID_FILE="$TS_OUTDIR/${TS_TESTNAME}.blkidtab" @@ -441,8 +446,14 @@ function ts_run { # # ASAN mode # - if [ "$TS_ENABLE_ASAN" == "yes" ]; then - args+=(env ASAN_OPTIONS=detect_leaks=1) + if [ "$TS_ENABLE_ASAN" == "yes" -o "$TS_ENABLE_UBSAN" == "yes" ]; then + args+=(env) + if [ "$TS_ENABLE_ASAN" == "yes" ]; then + args+=(ASAN_OPTIONS=detect_leaks=1) + fi + if [ "$TS_ENABLE_UBSAN" == "yes" ]; then + args+=(UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1) + fi fi # diff --git a/tests/run.sh b/tests/run.sh index 29588fa03d..f74bdefaa6 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -26,6 +26,7 @@ top_srcdir= top_builddir= paraller_jobs=1 has_asan_opt= +has_ubsan_opt= function num_cpus() { @@ -74,6 +75,10 @@ while [ -n "$1" ]; do OPTS="$OPTS $1" has_asan_opt="yes" ;; + --memcheck-ubsan) + OPTS="$OPTS $1" + has_ubsan_opt="yes" + ;; --use-system-commands) OPTS="$OPTS $1" SYSCOMMANDS="yes" @@ -161,6 +166,13 @@ if [ -z "$has_asan_opt" ]; then fi fi +if [ -z "$has_ubsan_opt" ]; then + ubsan=$(awk '/^UBSAN_LDFLAGS/ { print $3 }' $top_builddir/Makefile) + if [ -n "$ubsan" ]; then + OPTS="$OPTS --memcheck-ubsan" + fi +fi + declare -a comps if [ -n "$SUBTESTS" ]; then # selected tests only