Debian Codegraph @

scripts/objdiff

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # SPDX-License-Identifier: GPL-2.0-only
3
4 # objdiff - a small script for validating that a commit or series of commits
5 # didn't change object code.
6 #
7 # Copyright 2014, Jason Cooper <[email protected]>
8 #
9
10 # usage example:
11 #
12 # $ git checkout COMMIT_A
13 # $ <your fancy build command here>
14 # $ ./scripts/objdiff record path/to/*.o
15 #
16 # $ git checkout COMMIT_B
17 # $ <your fancy build command here>
18 # $ ./scripts/objdiff record path/to/*.o
19 #
20 # $ ./scripts/objdiff diff COMMIT_A COMMIT_B
21 # $
22
23 # And to clean up (everything is in .objdiff/*)
24 # $ ./scripts/objdiff clean all
25 #
26 # Note: 'make mrproper' will also remove .objdiff
27
28 SRCTREE=$(cd $(gitscip-shell system . . git. rev-parse --show-toplevel 2>/dev/nullscip-shell filesystem . . `/dev/null`.); pwdscip-shell system . . pwd.)
29
30 if [scip-shell system . . `[`. -z "$SRCTREE" ]; then
31 echoscip-shell system . . echo. >&2 "ERROR: Not a git repository."
32 exit 1
33 fi
34
35 TMPD=$SRCTREE/.objdiff
36
37 usagescip-shell shell linux 7.0.12-2 usage().() {
38 echoscip-shell system . . echo. >&2 "Usage: $0 <command> <args>"
39 echoscip-shell system . . echo. >&2 " record <list of object files or directories>"
40 echoscip-shell system . . echo. >&2 " diff <commitA> <commitB>"
41 echoscip-shell system . . echo. >&2 " clean all | <commit>"
42 exit 1
43 }
44
45 get_output_dirscip-shell shell linux 7.0.12-2 get_output_dir().() {
46 dir=${1%/*}
47
48 if [scip-shell system . . `[`. "$dir" = "$1" ]; then
49 dir=.
50 fi
51
52 dir=$(cd $dir; pwdscip-shell system . . pwd.)
53
54 echoscip-shell system . . echo. $TMPD/$CMT${dir#$SRCTREE}
55 }
56
57 do_objdumpscip-shell shell linux 7.0.12-2 do_objdump().() {
58 dir=$(get_output_dirscip-shell shell linux 7.0.12-2 get_output_dir(). $1)
59 base=${1##*/}
60 stripped=$dir/${base%.o}.stripped
61 dis=$dir/${base%.o}.dis
62
63 [scip-shell system . . `[`. ! -d "$dir" ] && mkdirscip-shell system . . mkdir. -p $dir
64
65 # remove addresses for a cleaner diff
66 # http://dummdida.tumblr.com/post/60924060451/binary-diff-between-libc-from-scientificlinux-and
67 $STRIP -g $1 -R __bug_table -R .note -R .comment -o $stripped
68 $OBJDUMP -D $stripped | sedscip-shell system . . sed. -e "s/^[[:space:]]\+[0-9a-f]\+//" -e "s:^$stripped:$1:" > $dis
69 }
70
71 dorecordscip-shell shell linux 7.0.12-2 dorecord().() {
72 [scip-shell system . . `[`. $# -eq 0 ] && usagescip-shell shell linux 7.0.12-2 usage().
73
74 FILES="$*"
75
76 CMT="`gitscip-shell system . . git. rev-parse --short HEAD`"
77
78 STRIP="${CROSS_COMPILE}strip"
79 OBJDUMP="${CROSS_COMPILE}objdump"
80
81 for d in $FILES; do
82 if [scip-shell system . . `[`. -d "$d" ]; then
83 for f in $(findscip-shell system . . find. $d -name '*.o')
84 do
85 do_objdumpscip-shell shell linux 7.0.12-2 do_objdump(). $f
86 done
87 else
88 do_objdumpscip-shell shell linux 7.0.12-2 do_objdump(). $d
89 fi
90 done
91 }
92
93 dodiffscip-shell shell linux 7.0.12-2 dodiff().() {
94 [scip-shell system . . `[`. $# -ne 2 ] && [scip-shell system . . `[`. $# -ne 0 ] && usagescip-shell shell linux 7.0.12-2 usage().
95
96 if [scip-shell system . . `[`. $# -eq 0 ]; then
97 SRC="`gitscip-shell system . . git. rev-parse --short HEAD^`"
98 DST="`gitscip-shell system . . git. rev-parse --short HEAD`"
99 else
100 SRC="`gitscip-shell system . . git. rev-parse --short $1`"
101 DST="`gitscip-shell system . . git. rev-parse --short $2`"
102 fi
103
104 DIFF="`whichscip-shell system . . which. colordiff`"
105
106 if [scip-shell system . . `[`. ${#DIFF} -eq 0 ] || [scip-shell system . . `[`. ! -x "$DIFF" ]; then
107 DIFF="`whichscip-shell system . . which. diff`"
108 fi
109
110 SRCD="$TMPD/$SRC"
111 DSTD="$TMPD/$DST"
112
113 if [scip-shell system . . `[`. ! -d "$SRCD" ]; then
114 echoscip-shell system . . echo. >&2 "ERROR: $SRCD doesn't exist"
115 exit 1
116 fi
117
118 if [scip-shell system . . `[`. ! -d "$DSTD" ]; then
119 echoscip-shell system . . echo. >&2 "ERROR: $DSTD doesn't exist"
120 exit 1
121 fi
122
123 $DIFF -Nurd $SRCD $DSTD
124 }
125
126 docleanscip-shell shell linux 7.0.12-2 doclean().() {
127 [scip-shell system . . `[`. $# -eq 0 ] && usagescip-shell shell linux 7.0.12-2 usage().
128 [scip-shell system . . `[`. $# -gt 1 ] && usagescip-shell shell linux 7.0.12-2 usage().
129
130 if [scip-shell system . . `[`. "x$1" = "xall" ]; then
131 rmscip-shell system . . rm. -rf $TMPD/*
132 else
133 CMT="`gitscip-shell system . . git. rev-parse --short $1`"
134
135 if [scip-shell system . . `[`. -d "$TMPD/$CMT" ]; then
136 rmscip-shell system . . rm. -rf $TMPD/$CMT
137 else
138 echoscip-shell system . . echo. >&2 "$CMT not found"
139 fi
140 fi
141 }
142
143 [scip-shell system . . `[`. $# -eq 0 ] && usagescip-shell shell linux 7.0.12-2 usage().
144
145 case "$1" in
146 record)
147 shift
148 dorecordscip-shell shell linux 7.0.12-2 dorecord(). $*
149 ;;
150 diff)
151 shift
152 dodiffscip-shell shell linux 7.0.12-2 dodiff(). $*
153 ;;
154 clean)
155 shift
156 docleanscip-shell shell linux 7.0.12-2 doclean(). $*
157 ;;
158 *)
159 echoscip-shell system . . echo. >&2 "Unrecognized command '$1'"
160 exit 1
161 ;;
162 esac