[TSan] Port check_memcpy.sh script to a regular lit test.
authorAlexey Samsonov <vonosmas@gmail.com>
Mon, 7 Dec 2015 21:53:59 +0000 (21:53 +0000)
committerAlexey Samsonov <vonosmas@gmail.com>
Mon, 7 Dec 2015 21:53:59 +0000 (21:53 +0000)
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
compiler-rt/lib/tsan/check_memcpy.sh [deleted file]
compiler-rt/test/tsan/Linux/check_memcpy.cc [new file with mode: 0644]
compiler-rt/test/tsan/Linux/check_memcpy.sh [new file with mode: 0755]

index 79f5d8a..d91a3df 100644 (file)
@@ -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 (executable)
index 101df11..0000000
+++ /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 (file)
index 0000000..86f2455
--- /dev/null
@@ -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 (executable)
index 0000000..2b5f21f
--- /dev/null
@@ -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