From a8bf5099d60c00cbe038200a77f3cee1c56ffa78 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Mon, 7 Dec 2015 20:18:50 +0000 Subject: [PATCH] [TSan] Slightly improve check_analyze script. De-hardcode path to TSan-ified executable: pass it as an input to the scripts. Fix them so that they don't write to the current directory. Remove their invocation from Makefile.old: they are broken there anyway, as check_analyze.sh now matches trunk Clang. llvm-svn: 254936 --- compiler-rt/lib/tsan/Makefile.old | 1 - compiler-rt/lib/tsan/analyze_libtsan.sh | 23 +++++++++++++++++------ compiler-rt/lib/tsan/check_analyze.sh | 12 +++++++++++- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/compiler-rt/lib/tsan/Makefile.old b/compiler-rt/lib/tsan/Makefile.old index 72b472d49391..79f5d8a53101 100644 --- a/compiler-rt/lib/tsan/Makefile.old +++ b/compiler-rt/lib/tsan/Makefile.old @@ -79,7 +79,6 @@ presubmit: $(MAKE) -f Makefile.old clean $(MAKE) -f Makefile.old run DEBUG=0 -j 16 CC=gcc CXX=g++ ./check_memcpy.sh - ./check_analyze.sh # Sanity check for Go runtime (cd go && ./buildgo.sh) # Check cmake build diff --git a/compiler-rt/lib/tsan/analyze_libtsan.sh b/compiler-rt/lib/tsan/analyze_libtsan.sh index 705e4c5460f2..ae29f1b5b05a 100755 --- a/compiler-rt/lib/tsan/analyze_libtsan.sh +++ b/compiler-rt/lib/tsan/analyze_libtsan.sh @@ -1,10 +1,17 @@ #!/bin/bash +# +# Script that prints information about generated code in TSan runtime. set -e set -u +if [[ "$#" != 1 ]]; then + echo "Usage: $0 /path/to/binary/built/with/tsan" + exit 1 +fi + get_asm() { - grep __tsan_$1.: -A 10000 libtsan.objdump | \ + grep __tsan_$1.: -A 10000 ${OBJDUMP_CONTENTS} | \ awk "/[^:]$/ {print;} />:/ {c++; if (c == 2) {exit}}" } @@ -19,15 +26,19 @@ list="write1 \ func_entry \ func_exit" -BIN=`dirname $0`/tsan_test -objdump -d $BIN > libtsan.objdump -nm -S $BIN | grep "__tsan_" > libtsan.nm +BIN=$1 +OUTPUT_DIR=$(mktemp -t -d analyze_libtsan_out.XXXXXXXX) +OBJDUMP_CONTENTS=${OUTPUT_DIR}/libtsan_objdump +NM_CONTENTS=${OUTPUT_DIR}/libtsan_nm + +objdump -d $BIN > ${OBJDUMP_CONTENTS} +nm -S $BIN | grep "__tsan_" > ${NM_CONTENTS} for f in $list; do - file=asm_$f.s + file=${OUTPUT_DIR}/asm_$f.s get_asm $f > $file tot=$(wc -l < $file) - size=$(grep __tsan_$f$ libtsan.nm | awk --non-decimal-data '{print ("0x"$2)+0}') + size=$(grep __tsan_$f$ ${NM_CONTENTS} | awk --non-decimal-data '{print ("0x"$2)+0}') rsp=$(grep '(%rsp)' $file | wc -l) push=$(grep 'push' $file | wc -l) pop=$(grep 'pop' $file | wc -l) diff --git a/compiler-rt/lib/tsan/check_analyze.sh b/compiler-rt/lib/tsan/check_analyze.sh index 9d45cc00c972..0f6cc0698471 100755 --- a/compiler-rt/lib/tsan/check_analyze.sh +++ b/compiler-rt/lib/tsan/check_analyze.sh @@ -1,7 +1,17 @@ #!/bin/bash +# +# Script that checks that critical functions in TSan runtime have correct number +# of push/pop/rsp instructions to verify that runtime is efficient enough. + set -u -RES=$(./analyze_libtsan.sh) +if [[ "$#" != 1 ]]; then + echo "Usage: $0 /path/to/binary/built/with/tsan" + exit 1 +fi + +SCRIPTDIR=$(dirname $0) +RES=$(${SCRIPTDIR}/analyze_libtsan.sh $1) PrintRes() { printf "%s\n" "$RES" }