xref: /aosp_15_r20/external/compiler-rt/lib/tsan/analyze_libtsan.sh (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot#!/bin/bash
2*7c3d14c8STreehugger Robot#
3*7c3d14c8STreehugger Robot# Script that prints information about generated code in TSan runtime.
4*7c3d14c8STreehugger Robot
5*7c3d14c8STreehugger Robotset -e
6*7c3d14c8STreehugger Robotset -u
7*7c3d14c8STreehugger Robot
8*7c3d14c8STreehugger Robotif [[ "$#" != 1 ]]; then
9*7c3d14c8STreehugger Robot  echo "Usage: $0 /path/to/binary/built/with/tsan"
10*7c3d14c8STreehugger Robot  exit 1
11*7c3d14c8STreehugger Robotfi
12*7c3d14c8STreehugger Robot
13*7c3d14c8STreehugger Robotget_asm() {
14*7c3d14c8STreehugger Robot  grep __tsan_$1.: -A 10000 ${OBJDUMP_CONTENTS} | \
15*7c3d14c8STreehugger Robot    awk "/[^:]$/ {print;} />:/ {c++; if (c == 2) {exit}}"
16*7c3d14c8STreehugger Robot}
17*7c3d14c8STreehugger Robot
18*7c3d14c8STreehugger Robotlist="write1 \
19*7c3d14c8STreehugger Robot      write2 \
20*7c3d14c8STreehugger Robot      write4 \
21*7c3d14c8STreehugger Robot      write8 \
22*7c3d14c8STreehugger Robot      read1 \
23*7c3d14c8STreehugger Robot      read2 \
24*7c3d14c8STreehugger Robot      read4 \
25*7c3d14c8STreehugger Robot      read8 \
26*7c3d14c8STreehugger Robot      func_entry \
27*7c3d14c8STreehugger Robot      func_exit"
28*7c3d14c8STreehugger Robot
29*7c3d14c8STreehugger RobotBIN=$1
30*7c3d14c8STreehugger RobotOUTPUT_DIR=$(mktemp -t -d analyze_libtsan_out.XXXXXXXX)
31*7c3d14c8STreehugger RobotOBJDUMP_CONTENTS=${OUTPUT_DIR}/libtsan_objdump
32*7c3d14c8STreehugger RobotNM_CONTENTS=${OUTPUT_DIR}/libtsan_nm
33*7c3d14c8STreehugger Robot
34*7c3d14c8STreehugger Robotobjdump -d $BIN  > ${OBJDUMP_CONTENTS}
35*7c3d14c8STreehugger Robotnm -S $BIN | grep "__tsan_" > ${NM_CONTENTS}
36*7c3d14c8STreehugger Robot
37*7c3d14c8STreehugger Robotfor f in $list; do
38*7c3d14c8STreehugger Robot  file=${OUTPUT_DIR}/asm_$f.s
39*7c3d14c8STreehugger Robot  get_asm $f > $file
40*7c3d14c8STreehugger Robot  tot=$(wc -l < $file)
41*7c3d14c8STreehugger Robot  size=$(grep __tsan_$f$ ${NM_CONTENTS} | awk --non-decimal-data '{print ("0x"$2)+0}')
42*7c3d14c8STreehugger Robot  rsp=$(grep '(%rsp)' $file | wc -l)
43*7c3d14c8STreehugger Robot  push=$(grep 'push' $file | wc -l)
44*7c3d14c8STreehugger Robot  pop=$(grep 'pop' $file | wc -l)
45*7c3d14c8STreehugger Robot  call=$(grep 'call' $file | wc -l)
46*7c3d14c8STreehugger Robot  load=$(egrep 'mov .*\,.*\(.*\)|cmp .*\,.*\(.*\)' $file | wc -l)
47*7c3d14c8STreehugger Robot  store=$(egrep 'mov .*\(.*\),' $file | wc -l)
48*7c3d14c8STreehugger Robot  mov=$(grep 'mov' $file | wc -l)
49*7c3d14c8STreehugger Robot  lea=$(grep 'lea' $file | wc -l)
50*7c3d14c8STreehugger Robot  sh=$(grep 'shr\|shl' $file | wc -l)
51*7c3d14c8STreehugger Robot  cmp=$(grep 'cmp\|test' $file | wc -l)
52*7c3d14c8STreehugger Robot  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*7c3d14c8STreehugger Robot    $f $tot $size $rsp $push $pop $call $load $store $sh $mov $lea $cmp;
54*7c3d14c8STreehugger Robotdone
55