scsi: scsi_debug: Fix memory leak if LBP enabled and module is unloaded
[linux/fpc-iii.git] / scripts / objdiff
blob62e51dae2138db450555f3d15dbd14cc53c53652
1 #!/bin/bash
3 # objdiff - a small script for validating that a commit or series of commits
4 # didn't change object code.
6 # Copyright 2014, Jason Cooper <jason@lakedaemon.net>
8 # Licensed under the terms of the GNU GPL version 2
10 # usage example:
12 # $ git checkout COMMIT_A
13 # $ <your fancy build command here>
14 # $ ./scripts/objdiff record path/to/*.o
16 # $ git checkout COMMIT_B
17 # $ <your fancy build command here>
18 # $ ./scripts/objdiff record path/to/*.o
20 # $ ./scripts/objdiff diff COMMIT_A COMMIT_B
21 # $
23 # And to clean up (everything is in .tmp_objdiff/*)
24 # $ ./scripts/objdiff clean all
26 # Note: 'make mrproper' will also remove .tmp_objdiff
28 SRCTREE=$(cd $(git rev-parse --show-toplevel 2>/dev/null); pwd)
30 if [ -z "$SRCTREE" ]; then
31 echo >&2 "ERROR: Not a git repository."
32 exit 1
35 TMPD=$SRCTREE/.tmp_objdiff
37 usage() {
38 echo >&2 "Usage: $0 <command> <args>"
39 echo >&2 " record <list of object files or directories>"
40 echo >&2 " diff <commitA> <commitB>"
41 echo >&2 " clean all | <commit>"
42 exit 1
45 get_output_dir() {
46 dir=${1%/*}
48 if [ "$dir" = "$1" ]; then
49 dir=.
52 dir=$(cd $dir; pwd)
54 echo $TMPD/$CMT${dir#$SRCTREE}
57 do_objdump() {
58 dir=$(get_output_dir $1)
59 base=${1##*/}
60 dis=$dir/${base%.o}.dis
62 [ ! -d "$dir" ] && mkdir -p $dir
64 # remove addresses for a cleaner diff
65 # http://dummdida.tumblr.com/post/60924060451/binary-diff-between-libc-from-scientificlinux-and
66 $OBJDUMP -D $1 | sed "s/^[[:space:]]\+[0-9a-f]\+//" > $dis
69 dorecord() {
70 [ $# -eq 0 ] && usage
72 FILES="$*"
74 CMT="`git rev-parse --short HEAD`"
76 OBJDUMP="${CROSS_COMPILE}objdump"
78 for d in $FILES; do
79 if [ -d "$d" ]; then
80 for f in $(find $d -name '*.o')
82 do_objdump $f
83 done
84 else
85 do_objdump $d
87 done
90 dodiff() {
91 [ $# -ne 2 ] && [ $# -ne 0 ] && usage
93 if [ $# -eq 0 ]; then
94 SRC="`git rev-parse --short HEAD^`"
95 DST="`git rev-parse --short HEAD`"
96 else
97 SRC="`git rev-parse --short $1`"
98 DST="`git rev-parse --short $2`"
101 DIFF="`which colordiff`"
103 if [ ${#DIFF} -eq 0 ] || [ ! -x "$DIFF" ]; then
104 DIFF="`which diff`"
107 SRCD="$TMPD/$SRC"
108 DSTD="$TMPD/$DST"
110 if [ ! -d "$SRCD" ]; then
111 echo >&2 "ERROR: $SRCD doesn't exist"
112 exit 1
115 if [ ! -d "$DSTD" ]; then
116 echo >&2 "ERROR: $DSTD doesn't exist"
117 exit 1
120 $DIFF -Nurd $SRCD $DSTD
123 doclean() {
124 [ $# -eq 0 ] && usage
125 [ $# -gt 1 ] && usage
127 if [ "x$1" = "xall" ]; then
128 rm -rf $TMPD/*
129 else
130 CMT="`git rev-parse --short $1`"
132 if [ -d "$TMPD/$CMT" ]; then
133 rm -rf $TMPD/$CMT
134 else
135 echo >&2 "$CMT not found"
140 [ $# -eq 0 ] && usage
142 case "$1" in
143 record)
144 shift
145 dorecord $*
147 diff)
148 shift
149 dodiff $*
151 clean)
152 shift
153 doclean $*
156 echo >&2 "Unrecognized command '$1'"
157 exit 1
159 esac