2 # SPDX-License-Identifier: GPL-2.0-only
4 # objdiff - a small script for validating that a commit or series of commits
5 # didn't change object code.
7 # Copyright 2014, Jason Cooper <jason@lakedaemon.net>
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
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."
35 TMPD
=$SRCTREE/.tmp_objdiff
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>"
48 if [ "$dir" = "$1" ]; then
54 echo $TMPD/$CMT${dir#$SRCTREE}
58 dir
=$
(get_output_dir
$1)
60 stripped
=$dir/${base%.o}.stripped
61 dis
=$dir/${base%.o}.dis
63 [ ! -d "$dir" ] && mkdir
-p $dir
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 |
sed -e "s/^[[:space:]]\+[0-9a-f]\+//" -e "s:^$stripped:$1:" > $dis
76 CMT
="`git rev-parse --short HEAD`"
78 STRIP
="${CROSS_COMPILE}strip"
79 OBJDUMP
="${CROSS_COMPILE}objdump"
83 for f
in $
(find $d -name '*.o')
94 [ $# -ne 2 ] && [ $# -ne 0 ] && usage
97 SRC
="`git rev-parse --short HEAD^`"
98 DST
="`git rev-parse --short HEAD`"
100 SRC
="`git rev-parse --short $1`"
101 DST
="`git rev-parse --short $2`"
104 DIFF
="`which colordiff`"
106 if [ ${#DIFF} -eq 0 ] ||
[ ! -x "$DIFF" ]; then
113 if [ ! -d "$SRCD" ]; then
114 echo >&2 "ERROR: $SRCD doesn't exist"
118 if [ ! -d "$DSTD" ]; then
119 echo >&2 "ERROR: $DSTD doesn't exist"
123 $DIFF -Nurd $SRCD $DSTD
127 [ $# -eq 0 ] && usage
128 [ $# -gt 1 ] && usage
130 if [ "x$1" = "xall" ]; then
133 CMT
="`git rev-parse --short $1`"
135 if [ -d "$TMPD/$CMT" ]; then
138 echo >&2 "$CMT not found"
143 [ $# -eq 0 ] && usage
159 echo >&2 "Unrecognized command '$1'"