55 lines · bash
1#!/usr/bin/env bash2#3# Script that prints information about generated code in TSan runtime.4 5set -e6set -u7 8if [[ "$#" != 1 ]]; then9 echo "Usage: $0 /path/to/binary/built/with/tsan"10 exit 111fi12 13get_asm() {14 grep __tsan_$1.: -A 10000 ${OBJDUMP_CONTENTS} | \15 awk "/[^:]$/ {print;} />:/ {c++; if (c == 2) {exit}}"16}17 18list="write1 \19 write2 \20 write4 \21 write8 \22 read1 \23 read2 \24 read4 \25 read8 \26 func_entry \27 func_exit"28 29BIN=$130OUTPUT_DIR=$(mktemp -t -d analyze_libtsan_out.XXXXXXXX)31OBJDUMP_CONTENTS=${OUTPUT_DIR}/libtsan_objdump32NM_CONTENTS=${OUTPUT_DIR}/libtsan_nm33 34objdump -d $BIN > ${OBJDUMP_CONTENTS}35nm -S $BIN | grep "__tsan_" > ${NM_CONTENTS}36 37for f in $list; do38 file=${OUTPUT_DIR}/asm_$f.s39 get_asm $f > $file40 tot=$(wc -l < $file)41 size=$(grep __tsan_$f$ ${NM_CONTENTS} | awk --non-decimal-data '{print ("0x"$2)+0}')42 rsp=$(grep '(%rsp)' $file | wc -l)43 push=$(grep 'push' $file | wc -l)44 pop=$(grep 'pop' $file | wc -l)45 call=$(grep 'call' $file | wc -l)46 load=$(egrep 'mov .*\,.*\(.*\)|cmp .*\,.*\(.*\)' $file | wc -l)47 store=$(egrep 'mov .*\(.*\),' $file | wc -l)48 mov=$(grep 'mov' $file | wc -l)49 lea=$(grep 'lea' $file | wc -l)50 sh=$(grep 'shr\|shl' $file | wc -l)51 cmp=$(grep 'cmp\|test' $file | wc -l)52 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" \53 $f $tot $size $rsp $push $pop $call $load $store $sh $mov $lea $cmp;54done55