xref: /llvm-project/compiler-rt/lib/tsan/analyze_libtsan.sh (revision 626e2a6c6236d2fd7582928a0363d381c55eb43d)
1*626e2a6cSFrederic Cambus#!/usr/bin/env bash
2a8bf5099SAlexey Samsonov#
3a8bf5099SAlexey Samsonov# Script that prints information about generated code in TSan runtime.
45b7cb1dbSKostya Serebryany
55b7cb1dbSKostya Serebryanyset -e
65b7cb1dbSKostya Serebryanyset -u
75b7cb1dbSKostya Serebryany
8a8bf5099SAlexey Samsonovif [[ "$#" != 1 ]]; then
9a8bf5099SAlexey Samsonov  echo "Usage: $0 /path/to/binary/built/with/tsan"
10a8bf5099SAlexey Samsonov  exit 1
11a8bf5099SAlexey Samsonovfi
12a8bf5099SAlexey Samsonov
135b7cb1dbSKostya Serebryanyget_asm() {
14a8bf5099SAlexey Samsonov  grep __tsan_$1.: -A 10000 ${OBJDUMP_CONTENTS} | \
155b7cb1dbSKostya Serebryany    awk "/[^:]$/ {print;} />:/ {c++; if (c == 2) {exit}}"
165b7cb1dbSKostya Serebryany}
175b7cb1dbSKostya Serebryany
185b7cb1dbSKostya Serebryanylist="write1 \
195b7cb1dbSKostya Serebryany      write2 \
205b7cb1dbSKostya Serebryany      write4 \
215b7cb1dbSKostya Serebryany      write8 \
225b7cb1dbSKostya Serebryany      read1 \
235b7cb1dbSKostya Serebryany      read2 \
245b7cb1dbSKostya Serebryany      read4 \
255b7cb1dbSKostya Serebryany      read8 \
265b7cb1dbSKostya Serebryany      func_entry \
275b7cb1dbSKostya Serebryany      func_exit"
285b7cb1dbSKostya Serebryany
29a8bf5099SAlexey SamsonovBIN=$1
30a8bf5099SAlexey SamsonovOUTPUT_DIR=$(mktemp -t -d analyze_libtsan_out.XXXXXXXX)
31a8bf5099SAlexey SamsonovOBJDUMP_CONTENTS=${OUTPUT_DIR}/libtsan_objdump
32a8bf5099SAlexey SamsonovNM_CONTENTS=${OUTPUT_DIR}/libtsan_nm
33a8bf5099SAlexey Samsonov
34a8bf5099SAlexey Samsonovobjdump -d $BIN  > ${OBJDUMP_CONTENTS}
35a8bf5099SAlexey Samsonovnm -S $BIN | grep "__tsan_" > ${NM_CONTENTS}
365b7cb1dbSKostya Serebryany
375b7cb1dbSKostya Serebryanyfor f in $list; do
38a8bf5099SAlexey Samsonov  file=${OUTPUT_DIR}/asm_$f.s
395b7cb1dbSKostya Serebryany  get_asm $f > $file
405b7cb1dbSKostya Serebryany  tot=$(wc -l < $file)
41a8bf5099SAlexey Samsonov  size=$(grep __tsan_$f$ ${NM_CONTENTS} | awk --non-decimal-data '{print ("0x"$2)+0}')
425b7cb1dbSKostya Serebryany  rsp=$(grep '(%rsp)' $file | wc -l)
435b7cb1dbSKostya Serebryany  push=$(grep 'push' $file | wc -l)
445b7cb1dbSKostya Serebryany  pop=$(grep 'pop' $file | wc -l)
455b7cb1dbSKostya Serebryany  call=$(grep 'call' $file | wc -l)
465b7cb1dbSKostya Serebryany  load=$(egrep 'mov .*\,.*\(.*\)|cmp .*\,.*\(.*\)' $file | wc -l)
475b7cb1dbSKostya Serebryany  store=$(egrep 'mov .*\(.*\),' $file | wc -l)
485b7cb1dbSKostya Serebryany  mov=$(grep 'mov' $file | wc -l)
495b7cb1dbSKostya Serebryany  lea=$(grep 'lea' $file | wc -l)
505b7cb1dbSKostya Serebryany  sh=$(grep 'shr\|shl' $file | wc -l)
515b7cb1dbSKostya Serebryany  cmp=$(grep 'cmp\|test' $file | wc -l)
525b7cb1dbSKostya Serebryany  printf "%10s tot %3d; size %4d; rsp %d; push %d; pop %d; call %d; load %2d; store %2d; sh %3d; mov %3d; lea %3d; cmp %3d\n" \
535b7cb1dbSKostya Serebryany    $f $tot $size $rsp $push $pop $call $load $store $sh $mov $lea $cmp;
545b7cb1dbSKostya Serebryanydone
55