#!/bin/bash # # Usage: # ./asan.sh # # Trigger ASAN failures like this: # # int *array = malloc(100); # free(array); # fprintf(stderr, "C = %c\n", array[0]); set -o nounset set -o pipefail set -o errexit CFLAGS='-Wno-uninitialized -g' #CFLAGS="$CFLAGS -g" # for debugging # On Ubuntu Trusty # You can get things like this if versions don't match. # # clang 3.4: # Segmentation Fault # clang 3.6: # # $ ./toybox # ==14123==Your application is linked against incompatible ASan runtimes. # # Do I have to build my own clang? That's annoying. It's up to 3.9 though. install-clang() { sudo apt install clang libasan0 } readonly CLANG_DIR=~/install/clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-14.04 readonly CLANG=$CLANG_DIR/bin/clang clang-version() { $CLANG --version } # clang-3.6 is called clang-3.6 for some reason #readonly CLANG=clang build-clang() { make CC=$CLANG CFLAGS="$CFLAGS" } build-asan() { # tons of -Wuninitialized stuff make CC=$CLANG CFLAGS="-fsanitize=address $CFLAGS" V=1 # LDFLAGS='-lasan' #V=1 } test-command() { local cmd=${1:-sed} # OOPS, TEST_HOST tests the GNU stuff! Whatever is on the host. # We need another mode. # # But this reveals differences with GNU sed! # This invokes scripts/test.sh sed. # scripts/single.sh sed -- Why does this configure a single command? # And this calls "make" # Woohoo! This works. Ig et line numbers. export ASAN_SYMBOLIZER_PATH=$CLANG_DIR/bin/llvm-symbolizer ls -l $ASAN_SYMBOLIZER_PATH # NOTE: This requires my patch to scripts/single.sh make VERBOSE=fail CC=$CLANG CFLAGS="-fsanitize=address $CFLAGS" test_$cmd } sed-cases() { # toybox transforms abc -> db\f # GNU sed transforms abc -> de\f -- this seems wrong because \b is an # escape? echo --- echo -ne 'abc' | "$@" 'y/a\bc/de\f/' # This seems to be on purpose? # commit 2081ec658cdedc7bc6693c8353874dcaf48e9b1b # Author: Rob Landley # Date: Thu Jan 21 13:04:51 2016 -0600 # # Add a sed test from the posix mailing list. echo --- echo -ne 'a\nb\n' | "$@" -e n -e '1,2s/b/c/' } sed-compare() { echo TOYBOX sed-cases ./toybox sed echo echo GNU sed-cases sed # Same results #echo GNU posix #sed-cases sed --posix } "$@"