]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
build-sys: add --enable-ubsan to make it possible to build util-linux with UBSan
authorEvgeny Vereshchagin <evvers@ya.ru>
Wed, 1 Jul 2020 19:52:51 +0000 (19:52 +0000)
committerKarel Zak <kzak@redhat.com>
Fri, 3 Jul 2020 09:17:53 +0000 (11:17 +0200)
mostly to prepare for https://github.com/karelzak/util-linux/pull/1068
but it's useful even without fuzzing.

Signed-off-by: Karel Zak <kzak@redhat.com>
Makefile.am
configure.ac
tests/functions.sh
tests/run.sh

index 75964bab31d64666ac2eca8bfdbe5c82b0dfd562..f4f0ab44b364eeb8ee6603c614b69a3e09993ce4 100644 (file)
@@ -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.
index 77ac3634c19af056a69899a98ce9eed480395e4d..b40fcd0ff60f5e6af43e5948338eca9980bc2650 100644 (file)
@@ -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
 
index 60bef734ef19dabcbda4af0e4f07febd2cce8f99..b73889e64de1f4900728539cc688e5bf875e7873 100644 (file)
@@ -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
 
        #
index 29588fa03d5c239f5ae4772265416b65e2553c80..f74bdefaa6e8c44b069883e73074186284a7cf2a 100755 (executable)
@@ -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