From cecd169cde3ccb072dbbcf1cbbf76c5e19145371 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 12 Apr 2022 17:22:18 -0500 Subject: [PATCH] Collate ASAN setup, move generated/instlist into generated/unstripped, use $UNSTRIPPED variable in more places and move definition to ./configure. --- configure | 6 +----- scripts/change.sh | 4 ++-- scripts/install.sh | 6 +++--- scripts/make.sh | 2 +- scripts/portability.sh | 7 +++---- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/configure b/configure index 1149fbf8..edaa3dad 100755 --- a/configure +++ b/configure @@ -16,17 +16,13 @@ CFLAGS="$CFLAGS -Wall -Wundef -Wno-char-subscripts -Werror=implicit-function-dec # Set default values if variable not already set : ${CC:=cc} ${HOSTCC:=cc} ${GENDIR:=generated} ${KCONFIG_CONFIG:=.config} -: ${OUTNAME:=toybox${TARGET:+-$TARGET}} +: ${UNSTRIPPED:=$GENDIR/unstripped} ${OUTNAME:=toybox${TARGET:+-$TARGET}} : ${OPTIMIZE:=-Os -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables -fno-strict-aliasing} -# set ASAN=1 to enable "address sanitizer" and debuggable backtraces -[ -z "$ASAN" ] || { CFLAGS="$CFLAGS -O1 -g -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize=address"; NOSTRIP=1; } - # We accept LDFLAGS, but by default don't have anything in it if [ "$(uname)" == "Darwin" ] then : ${LDOPTIMIZE:=-Wl,-dead_strip} ${STRIP:=strip} else : ${LDOPTIMIZE:=-Wl,--gc-sections -Wl,--as-needed} ${STRIP:=strip -s -R .note* -R .comment} -# LDASNEEDED="-Wl,--as-needed" # must go at end of compiler command line fi diff --git a/scripts/change.sh b/scripts/change.sh index 99dcfde9..ad01ba24 100755 --- a/scripts/change.sh +++ b/scripts/change.sh @@ -3,7 +3,7 @@ # build each command as a standalone executable NOBUILD=1 scripts/make.sh > /dev/null && -${HOSTCC:-cc} -I . scripts/install.c -o generated/instlist && +${HOSTCC:-cc} -I . scripts/install.c -o "$UNSTRIPPED"/instlist && export PREFIX=${PREFIX:-change/} && mkdir -p "$PREFIX" || exit 1 @@ -12,7 +12,7 @@ mkdir -p "$PREFIX" || exit 1 # sh - shell builtins like "cd" and "exit" need the multiplexer # help - needs to know what other commands are enabled (use command --help) -for i in $(generated/instlist | egrep -vw "sh|help") +for i in $("$UNSTRIPPED"/instlist | egrep -vw "sh|help") do echo -n " $i" && scripts/single.sh $i > /dev/null 2>$PREFIX/${i}.bad && diff --git a/scripts/install.sh b/scripts/install.sh index 56213ade..842ff9b0 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -2,7 +2,7 @@ # Grab default values for $CFLAGS and such. -source ./configure +source scripts/portability.sh [ -z "$PREFIX" ] && PREFIX="$PWD/install" @@ -32,8 +32,8 @@ done echo "Compile instlist..." NOBUILD=1 scripts/make.sh -$DEBUG $HOSTCC -I . scripts/install.c -o generated/instlist || exit 1 -COMMANDS="$(generated/instlist $LONG_PATH)" +$DEBUG $HOSTCC -I . scripts/install.c -o "$UNSTRIPPED"/instlist || exit 1 +COMMANDS="$("$UNSTRIPPED"/instlist $LONG_PATH)" echo "${UNINSTALL:-Install} commands..." diff --git a/scripts/make.sh b/scripts/make.sh index d850cd61..b7bb6930 100755 --- a/scripts/make.sh +++ b/scripts/make.sh @@ -26,7 +26,7 @@ isnewer() echo "Generate headers from toys/*/*.c..." -mkdir -p "${UNSTRIPPED:=$GENDIR/unstripped}" +mkdir -p "$UNSTRIPPED" if isnewer "$GENDIR"/Config.in toys || isnewer "$GENDIR"/Config.in Config.in then diff --git a/scripts/portability.sh b/scripts/portability.sh index 50793ade..3e86c36c 100644 --- a/scripts/portability.sh +++ b/scripts/portability.sh @@ -13,15 +13,14 @@ then [ ! -z "$(command -v gsed 2>/dev/null)" ] && SED=gsed || SED=sed fi -# Extra debug plumbing the Android guys want +# Address Sanitizer if [ ! -z "$ASAN" ]; then - echo "Enabling ASan..." # Turn ASan on and disable most optimization to get more readable backtraces. # (Technically ASAN is just "-fsanitize=address" and the rest is optional.) ASAN_FLAGS="-fsanitize=address -O1 -g -fno-omit-frame-pointer -fno-optimize-sibling-calls" - CFLAGS="$ASAN_FLAGS $CFLAGS" - # Run this nonsense against temporary build tools that don't ship too + CFLAGS="$CFLAGS $ASAN_FLAGS" HOSTCC="$HOSTCC $ASAN_FLAGS" + NOSTRIP=1 # Ignore leaks on exit. TODO export ASAN_OPTIONS="detect_leaks=0" fi -- 2.39.2