Just use `ASAN=1 make test_grep` or whatever. You'll probably want to set $ASAN_SYMBOLIZER_PATH to point to llvm-symbolizer, but Debian makes that annoying by calling the symbolizer /usr/bin/llvm-symbolizer-4.0 or whatever, and ASan refuses to use it:
==43370==ERROR: External symbolizer path is set to '/usr/bin/llvm-symbolizer-4.0' which isn't a known symbolizer. Please set the path to the llvm-symbolizer binary or other known tool. My usual workaround for this is to drop an llvm-symbolizer symlink in the current directory, and I'm happy to automate that in the script to make it require no knowledge of any of this nonsense, but haven't done so in this initial patch. This patch also fixes the -Wstring-plus-int check, because ASan requires clang, and clang defaults to having that warning on, so things get quite noisy. I've also fixed (and modernized) the "are we root?" check in the hostname test, found when I manually ran through all the existing tests checking that we don't have any other memory issues covered by existing tests. I wasn't expecting to find any, because the HWASan build should have found them already, but you never know... I tested that this is actually working by reverting the grep fix and running `ASAN=1 make test_grep`. --- scripts/genconfig.sh | 2 +- scripts/make.sh | 10 ++++++++++ tests/hostname.test | 8 +------- 3 files changed, 12 insertions(+), 8 deletions(-)
From 182f1d90974e0b27ee38f3a4581b9ee7573d4524 Mon Sep 17 00:00:00 2001 From: Elliott Hughes <[email protected]> Date: Thu, 18 Jul 2019 18:46:35 -0700 Subject: [PATCH] Add ASAN=1 to the build system. Just use `ASAN=1 make test_grep` or whatever. You'll probably want to set $ASAN_SYMBOLIZER_PATH to point to llvm-symbolizer, but Debian makes that annoying by calling the symbolizer /usr/bin/llvm-symbolizer-4.0 or whatever, and ASan refuses to use it: ==43370==ERROR: External symbolizer path is set to '/usr/bin/llvm-symbolizer-4.0' which isn't a known symbolizer. Please set the path to the llvm-symbolizer binary or other known tool. My usual workaround for this is to drop an llvm-symbolizer symlink in the current directory, and I'm happy to automate that in the script to make it require no knowledge of any of this nonsense, but haven't done so in this initial patch. This patch also fixes the -Wstring-plus-int check, because ASan requires clang, and clang defaults to having that warning on, so things get quite noisy. I've also fixed (and modernized) the "are we root?" check in the hostname test, found when I manually ran through all the existing tests checking that we don't have any other memory issues covered by existing tests. I wasn't expecting to find any, because the HWASan build should have found them already, but you never know... I tested that this is actually working by reverting the grep fix and running `ASAN=1 make test_grep`. --- scripts/genconfig.sh | 2 +- scripts/make.sh | 10 ++++++++++ tests/hostname.test | 8 +------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/scripts/genconfig.sh b/scripts/genconfig.sh index e1eff09f..e386e427 100755 --- a/scripts/genconfig.sh +++ b/scripts/genconfig.sh @@ -28,7 +28,7 @@ probeconfig() # llvm produces its own really stupid warnings about things that aren't wrong, # and although you can turn the warning off, gcc reacts badly to command line # arguments it doesn't understand. So probe. - [ -z "$(probecc -Wno-string-plus-int <<< \#warn warn 2>&1 | grep string-plus-int)" ] && + [ -z "$(probecc -Werror -Wno-string-plus-int <<< \#warn warn 2>&1 | grep string-plus-int)" ] && echo -Wno-string-plus-int >> generated/cflags # Probe for container support on target diff --git a/scripts/make.sh b/scripts/make.sh index 2a78844d..2f972635 100755 --- a/scripts/make.sh +++ b/scripts/make.sh @@ -2,6 +2,16 @@ # Grab default values for $CFLAGS and such. +if [ ! -z "$ASAN" ]; then + # ASan isn't hard to set up, but it's a lot of little things... + # First, it's clang-only. + CC="clang" + # And you need to turn it on, obviously. + CFLAGS="-fsanitize=address $CFLAGS" + # These are strictly optional, but we want useful backtraces. + CFLAGS="-O1 -g -fno-omit-frame-pointer -fno-optimize-sibling-calls $CFLAGS" +fi + export LANG=c export LC_ALL=C set -o pipefail diff --git a/tests/hostname.test b/tests/hostname.test index ba65a398..263c60b5 100755 --- a/tests/hostname.test +++ b/tests/hostname.test @@ -7,11 +7,5 @@ HOST="$(cat /proc/sys/kernel/hostname)" testing "get" "hostname" "$HOST\n" "" "" -if [ "$(id -u)" -ne 0 ] -then - echo "$SHOWSKIP: groupdel (not root)" - return 2>/dev/null - exit -fi - +skipnot [ $(id -u) -eq 0 ] testing "set" 'hostname "2>&1 | tee"; hostname; hostname "$HOST"' "2>&1 | tee\n" "" "" -- 2.22.0.657.g960e92d24f-goog
_______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
