diff options
author | Jason Cooper <jason@lakedaemon.net> | 2014-04-07 14:30:29 -0400 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2014-04-08 10:41:44 -0400 |
commit | 79192ca8ebd9a25c583aa46024a250fef1e7766f (patch) | |
tree | e84e8eb7e9fe7b8566671952850570461729d08f | |
parent | 0a830dad5e3ceffc1f12f3e674322182d809e3a9 (diff) |
scripts: objdiff: detect object code changes between two commits
objdiff is useful when doing large code cleanups. For example, when
removing checkpatch warnings and errors from new drivers in the staging
tree.
objdiff can be used in conjunction with a git rebase to confirm that
each commit made no changes to the resulting object code. It has the
same return values as diff(1).
This was written specifically to support adding the skein and threefish
cryto drivers to the staging tree. I needed a programmatic way to
confirm that commits changing >90% of the lines didn't inadvertently
change the code.
Temporary files (objdump output) are stored in
/path/to/linux/.tmp_objdiff
'make mrproper' will remove this directory.
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
Signed-off-by: Michal Marek <mmarek@suse.cz>
-rw-r--r-- | Makefile | 2 | ||||
-rwxr-xr-x | scripts/objdiff | 141 |
2 files changed, 142 insertions, 1 deletions
@@ -1066,7 +1066,7 @@ CLEAN_DIRS += $(MODVERDIR) | |||
1066 | 1066 | ||
1067 | # Directories & files removed with 'make mrproper' | 1067 | # Directories & files removed with 'make mrproper' |
1068 | MRPROPER_DIRS += include/config usr/include include/generated \ | 1068 | MRPROPER_DIRS += include/config usr/include include/generated \ |
1069 | arch/*/include/generated | 1069 | arch/*/include/generated .tmp_objdiff |
1070 | MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \ | 1070 | MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \ |
1071 | Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \ | 1071 | Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \ |
1072 | signing_key.priv signing_key.x509 x509.genkey \ | 1072 | signing_key.priv signing_key.x509 x509.genkey \ |
diff --git a/scripts/objdiff b/scripts/objdiff new file mode 100755 index 000000000000..b3e4f10bfc3e --- /dev/null +++ b/scripts/objdiff | |||
@@ -0,0 +1,141 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | # objdiff - a small script for validating that a commit or series of commits | ||
4 | # didn't change object code. | ||
5 | # | ||
6 | # Copyright 2014, Jason Cooper <jason@lakedaemon.net> | ||
7 | # | ||
8 | # Licensed under the terms of the GNU GPL version 2 | ||
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 .tmp_objdiff/*) | ||
24 | # $ ./scripts/objdiff clean all | ||
25 | # | ||
26 | # Note: 'make mrproper' will also remove .tmp_objdiff | ||
27 | |||
28 | GIT_DIR="`git rev-parse --git-dir`" | ||
29 | |||
30 | if [ -d "$GIT_DIR" ]; then | ||
31 | TMPD="${GIT_DIR%git}tmp_objdiff" | ||
32 | |||
33 | [ -d "$TMPD" ] || mkdir "$TMPD" | ||
34 | else | ||
35 | echo "ERROR: git directory not found." | ||
36 | exit 1 | ||
37 | fi | ||
38 | |||
39 | usage() { | ||
40 | echo "Usage: $0 <command> <args>" | ||
41 | echo " record <list of object files>" | ||
42 | echo " diff <commitA> <commitB>" | ||
43 | echo " clean all | <commit>" | ||
44 | exit 1 | ||
45 | } | ||
46 | |||
47 | dorecord() { | ||
48 | [ $# -eq 0 ] && usage | ||
49 | |||
50 | FILES="$*" | ||
51 | |||
52 | CMT="`git rev-parse --short HEAD`" | ||
53 | |||
54 | OBJDUMP="${CROSS_COMPILE}objdump" | ||
55 | OBJDIFFD="$TMPD/$CMT" | ||
56 | |||
57 | [ ! -d "$OBJDIFFD" ] && mkdir -p "$OBJDIFFD" | ||
58 | |||
59 | for f in $FILES; do | ||
60 | dn="${f%/*}" | ||
61 | bn="${f##*/}" | ||
62 | |||
63 | [ ! -d "$OBJDIFFD/$dn" ] && mkdir -p "$OBJDIFFD/$dn" | ||
64 | |||
65 | # remove addresses for a more clear diff | ||
66 | # http://dummdida.tumblr.com/post/60924060451/binary-diff-between-libc-from-scientificlinux-and | ||
67 | $OBJDUMP -D "$f" | sed "s/^[[:space:]]\+[0-9a-f]\+//" \ | ||
68 | >"$OBJDIFFD/$dn/$bn" | ||
69 | done | ||
70 | } | ||
71 | |||
72 | dodiff() { | ||
73 | [ $# -ne 2 ] && [ $# -ne 0 ] && usage | ||
74 | |||
75 | if [ $# -eq 0 ]; then | ||
76 | SRC="`git rev-parse --short HEAD^`" | ||
77 | DST="`git rev-parse --short HEAD`" | ||
78 | else | ||
79 | SRC="`git rev-parse --short $1`" | ||
80 | DST="`git rev-parse --short $2`" | ||
81 | fi | ||
82 | |||
83 | DIFF="`which colordiff`" | ||
84 | |||
85 | if [ ${#DIFF} -eq 0 ] || [ ! -x "$DIFF" ]; then | ||
86 | DIFF="`which diff`" | ||
87 | fi | ||
88 | |||
89 | SRCD="$TMPD/$SRC" | ||
90 | DSTD="$TMPD/$DST" | ||
91 | |||
92 | if [ ! -d "$SRCD" ]; then | ||
93 | echo "ERROR: $SRCD doesn't exist" | ||
94 | exit 1 | ||
95 | fi | ||
96 | |||
97 | if [ ! -d "$DSTD" ]; then | ||
98 | echo "ERROR: $DSTD doesn't exist" | ||
99 | exit 1 | ||
100 | fi | ||
101 | |||
102 | $DIFF -Nurd $SRCD $DSTD | ||
103 | } | ||
104 | |||
105 | doclean() { | ||
106 | [ $# -eq 0 ] && usage | ||
107 | [ $# -gt 1 ] && usage | ||
108 | |||
109 | if [ "x$1" = "xall" ]; then | ||
110 | rm -rf $TMPD/* | ||
111 | else | ||
112 | CMT="`git rev-parse --short $1`" | ||
113 | |||
114 | if [ -d "$TMPD/$CMT" ]; then | ||
115 | rm -rf $TMPD/$CMT | ||
116 | else | ||
117 | echo "$CMT not found" | ||
118 | fi | ||
119 | fi | ||
120 | } | ||
121 | |||
122 | [ $# -eq 0 ] && usage | ||
123 | |||
124 | case "$1" in | ||
125 | record) | ||
126 | shift | ||
127 | dorecord $* | ||
128 | ;; | ||
129 | diff) | ||
130 | shift | ||
131 | dodiff $* | ||
132 | ;; | ||
133 | clean) | ||
134 | shift | ||
135 | doclean $* | ||
136 | ;; | ||
137 | *) | ||
138 | echo "Unrecognized command '$1'" | ||
139 | exit 1 | ||
140 | ;; | ||
141 | esac | ||