Home | History | Annotate | Download | only in tsan
      1 #!/bin/bash
      2 # This scripts builds a self-contained executable file for ThreadSanitizer.
      3 # Usage:
      4 #   ./mk-self-contained-tsan.sh            \
      5 #      /pin/root                           \
      6 #      /dir/where/tsan-pin-files/reside    \
      7 #      resulting_binary
      8 
      9 # take Pin from here:
     10 PIN_ROOT="$1"
     11 # Our .so files are here:
     12 IN_DIR="$2"
     13 # Put the result here:
     14 OUT="$3"
     15 # The files/dirs to take:
     16 IN_FILES="tsan_pin.sh bin/*ts_pin.so"
     17 
     18 rm -rf $OUT           # remove the old one
     19 touch  $OUT           # create the new one
     20 chmod +x $OUT
     21 
     22 # Create the header.
     23 cat << 'EOF' >> $OUT
     24 #!/bin/bash
     25 # This is a self-extracting executable of ThreadSanitizerPin.
     26 # This file is autogenerated by mk-self-contained-tsan-pin.sh.
     27 
     28 # We extract the temporary files to $TSAN_EXTRACT_DIR/tsan_pin.XXXXXX
     29 TSAN_EXTRACT_DIR=${TSAN_EXTRACT_DIR:-/tmp}
     30 EXTRACT_DIR="$(mktemp -d $TSAN_EXTRACT_DIR/tsan_pin.XXXXXX)"
     31 
     32 cleanup() {
     33   rm -rf $EXTRACT_DIR
     34 }
     35 # We will cleanup on exit.
     36 trap cleanup EXIT
     37 
     38 mkdir -p $EXTRACT_DIR
     39 chmod +rwx $EXTRACT_DIR
     40 EOF
     41 # end of header
     42 
     43 # Create the self-extractor
     44 
     45 # Exclude unneeded binaries.
     46 TAR_EXCLUDE="$TAR_EXCLUDE --exclude=*/doc/*       \
     47                           --exclude=*/include/*   \
     48                           --exclude=*/examples/*   \
     49                           "
     50 # Create the running part.
     51 
     52 cat << 'EOF' >> $OUT
     53 # Extract:
     54 echo Extracting ThreadSanitizerPin to $EXTRACT_DIR
     55 sed '1,/^__COMPRESSED_DATA_BELOW__$/d' $0 | tar xz -C $EXTRACT_DIR
     56 
     57 export PIN_ROOT=$EXTRACT_DIR
     58 export TS_ROOT=$EXTRACT_DIR
     59 $EXTRACT_DIR/tsan_pin.sh "$@"
     60 EXIT_STATUS=$?
     61 cleanup # the trap above will handle the cleanup only if we are in bash 3.x
     62 exit $EXIT_STATUS # make sure to return the exit code from the tool.
     63 
     64 __COMPRESSED_DATA_BELOW__
     65 EOF
     66 
     67 # Dump the compressed binary at the very end of the file.
     68 echo tar zcvh -C $IN_DIR $TAR_EXCLUDE $IN_FILES
     69 tar zcvh -C $IN_DIR $TAR_EXCLUDE $IN_FILES -C $PIN_ROOT ./{extras,ia32,intel64,pin}  >> $OUT
     70 
     71 echo "File $OUT successfully created"
     72 
     73