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