From dc37ee2226fc16afa8edf179aba658e64799fc8e Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Mon, 7 Dec 2015 21:53:59 +0000 Subject: [PATCH] [TSan] Port check_memcpy.sh script to a regular lit test. Check that TSan runtime doesn't contain compiler-inserted calls to memset/memmove functions. In future, we may consider moving this test to test/sanitizer_common, as we don't want to have compiler-inserted memcpy/memmove calls in any sanitizer runtime. llvm-svn: 254955 --- compiler-rt/lib/tsan/Makefile.old | 2 -- compiler-rt/lib/tsan/check_memcpy.sh | 31 ----------------------------- compiler-rt/test/tsan/Linux/check_memcpy.cc | 11 ++++++++++ compiler-rt/test/tsan/Linux/check_memcpy.sh | 26 ++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 33 deletions(-) delete mode 100755 compiler-rt/lib/tsan/check_memcpy.sh create mode 100644 compiler-rt/test/tsan/Linux/check_memcpy.cc create mode 100755 compiler-rt/test/tsan/Linux/check_memcpy.sh diff --git a/compiler-rt/lib/tsan/Makefile.old b/compiler-rt/lib/tsan/Makefile.old index 79f5d8a..d91a3df 100644 --- a/compiler-rt/lib/tsan/Makefile.old +++ b/compiler-rt/lib/tsan/Makefile.old @@ -71,14 +71,12 @@ presubmit: # Release build with clang. $(MAKE) -f Makefile.old clean $(MAKE) -f Makefile.old run DEBUG=0 -j 16 CC=$(CLANG) CXX=$(CLANG)++ - ./check_memcpy.sh # Debug build with gcc $(MAKE) -f Makefile.old clean $(MAKE) -f Makefile.old run DEBUG=1 -j 16 CC=gcc CXX=g++ # Release build with gcc $(MAKE) -f Makefile.old clean $(MAKE) -f Makefile.old run DEBUG=0 -j 16 CC=gcc CXX=g++ - ./check_memcpy.sh # Sanity check for Go runtime (cd go && ./buildgo.sh) # Check cmake build diff --git a/compiler-rt/lib/tsan/check_memcpy.sh b/compiler-rt/lib/tsan/check_memcpy.sh deleted file mode 100755 index 101df11..0000000 --- a/compiler-rt/lib/tsan/check_memcpy.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -# Ensure that tsan runtime does not contain compiler-emitted memcpy and memset calls. - -set -eu - -ROOTDIR=$(dirname $0) -TEST_DIR=$ROOTDIR/../../test/tsan - -: ${CXX:=clang++} -CFLAGS="-fsanitize=thread -fPIE -O1 -g" -LDFLAGS="-pie -lpthread -ldl -lrt -lm -Wl,--whole-archive $ROOTDIR/rtl/libtsan.a -Wl,--no-whole-archive" - -SRC=$TEST_DIR/simple_race.cc -OBJ=$SRC.o -EXE=$SRC.exe -$CXX $SRC $CFLAGS -c -o $OBJ -$CXX $OBJ $LDFLAGS -o $EXE - -NCALL=$(objdump -d $EXE | egrep "callq .*<__interceptor_mem(cpy|set)>" | wc -l) -if [ "$NCALL" != "0" ]; then - echo FAIL: found $NCALL memcpy/memset calls - exit 1 -fi - -# tail calls -NCALL=$(objdump -d $EXE | egrep "jmpq .*<__interceptor_mem(cpy|set)>" | wc -l) -if [ "$NCALL" != "0" ]; then - echo FAIL: found $NCALL memcpy/memset calls - exit 1 -fi diff --git a/compiler-rt/test/tsan/Linux/check_memcpy.cc b/compiler-rt/test/tsan/Linux/check_memcpy.cc new file mode 100644 index 0000000..86f2455 --- /dev/null +++ b/compiler-rt/test/tsan/Linux/check_memcpy.cc @@ -0,0 +1,11 @@ +// Test that verifies TSan runtime doesn't contain compiler-emitted +// memcpy/memmove calls. It builds the binary with TSan and passes it to +// check_memcpy.sh script. + +// RUN: %clangxx_tsan -O1 %s -o %t +// RUN: %S/check_memcpy.sh %t + +int main() { + return 0; +} + diff --git a/compiler-rt/test/tsan/Linux/check_memcpy.sh b/compiler-rt/test/tsan/Linux/check_memcpy.sh new file mode 100755 index 0000000..2b5f21f --- /dev/null +++ b/compiler-rt/test/tsan/Linux/check_memcpy.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Script that ensures that TSan runtime does not contain compiler-emitted +# memcpy and memset calls. + +set -eu + +if [[ "$#" != 1 ]]; then + echo "Usage: $0 /path/to/binary/built/with/tsan" + exit 1 +fi + +EXE=$1 + +NCALL=$(objdump -d $EXE | egrep "callq .*<__interceptor_mem(cpy|set)>" | wc -l) +if [ "$NCALL" != "0" ]; then + echo FAIL: found $NCALL memcpy/memset calls + exit 1 +fi + +# tail calls +NCALL=$(objdump -d $EXE | egrep "jmpq .*<__interceptor_mem(cpy|set)>" | wc -l) +if [ "$NCALL" != "0" ]; then + echo FAIL: found $NCALL memcpy/memset calls + exit 1 +fi -- 2.7.4