2014-04-07 22:30:29 +04:00
|
|
|
#!/bin/bash
|
2019-05-28 19:57:26 +03:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
2014-04-07 22:30:29 +04:00
|
|
|
|
|
|
|
# objdiff - a small script for validating that a commit or series of commits
|
|
|
|
# didn't change object code.
|
|
|
|
#
|
|
|
|
# Copyright 2014, Jason Cooper <jason@lakedaemon.net>
|
|
|
|
#
|
|
|
|
|
|
|
|
# usage example:
|
|
|
|
#
|
|
|
|
# $ git checkout COMMIT_A
|
|
|
|
# $ <your fancy build command here>
|
|
|
|
# $ ./scripts/objdiff record path/to/*.o
|
|
|
|
#
|
|
|
|
# $ git checkout COMMIT_B
|
|
|
|
# $ <your fancy build command here>
|
|
|
|
# $ ./scripts/objdiff record path/to/*.o
|
|
|
|
#
|
|
|
|
# $ ./scripts/objdiff diff COMMIT_A COMMIT_B
|
|
|
|
# $
|
|
|
|
|
|
|
|
# And to clean up (everything is in .tmp_objdiff/*)
|
|
|
|
# $ ./scripts/objdiff clean all
|
|
|
|
#
|
|
|
|
# Note: 'make mrproper' will also remove .tmp_objdiff
|
|
|
|
|
2014-06-09 06:16:37 +04:00
|
|
|
SRCTREE=$(cd $(git rev-parse --show-toplevel 2>/dev/null); pwd)
|
2014-04-07 22:30:29 +04:00
|
|
|
|
2014-06-09 06:16:34 +04:00
|
|
|
if [ -z "$SRCTREE" ]; then
|
2014-06-09 06:16:35 +04:00
|
|
|
echo >&2 "ERROR: Not a git repository."
|
2014-04-07 22:30:29 +04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-06-09 06:16:34 +04:00
|
|
|
TMPD=$SRCTREE/.tmp_objdiff
|
|
|
|
|
2014-04-07 22:30:29 +04:00
|
|
|
usage() {
|
2014-06-09 06:16:35 +04:00
|
|
|
echo >&2 "Usage: $0 <command> <args>"
|
2014-06-09 06:16:40 +04:00
|
|
|
echo >&2 " record <list of object files or directories>"
|
2014-06-09 06:16:35 +04:00
|
|
|
echo >&2 " diff <commitA> <commitB>"
|
|
|
|
echo >&2 " clean all | <commit>"
|
2014-04-07 22:30:29 +04:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2014-06-09 06:16:37 +04:00
|
|
|
get_output_dir() {
|
|
|
|
dir=${1%/*}
|
|
|
|
|
|
|
|
if [ "$dir" = "$1" ]; then
|
|
|
|
dir=.
|
|
|
|
fi
|
|
|
|
|
|
|
|
dir=$(cd $dir; pwd)
|
|
|
|
|
|
|
|
echo $TMPD/$CMT${dir#$SRCTREE}
|
|
|
|
}
|
|
|
|
|
2014-06-09 06:16:40 +04:00
|
|
|
do_objdump() {
|
|
|
|
dir=$(get_output_dir $1)
|
|
|
|
base=${1##*/}
|
2017-02-17 00:18:20 +03:00
|
|
|
stripped=$dir/${base%.o}.stripped
|
2014-06-09 06:16:40 +04:00
|
|
|
dis=$dir/${base%.o}.dis
|
|
|
|
|
|
|
|
[ ! -d "$dir" ] && mkdir -p $dir
|
|
|
|
|
|
|
|
# remove addresses for a cleaner diff
|
|
|
|
# http://dummdida.tumblr.com/post/60924060451/binary-diff-between-libc-from-scientificlinux-and
|
2017-02-17 00:18:20 +03:00
|
|
|
$STRIP -g $1 -R __bug_table -R .note -R .comment -o $stripped
|
|
|
|
$OBJDUMP -D $stripped | sed -e "s/^[[:space:]]\+[0-9a-f]\+//" -e "s:^$stripped:$1:" > $dis
|
2014-06-09 06:16:40 +04:00
|
|
|
}
|
|
|
|
|
2014-04-07 22:30:29 +04:00
|
|
|
dorecord() {
|
|
|
|
[ $# -eq 0 ] && usage
|
|
|
|
|
|
|
|
FILES="$*"
|
|
|
|
|
|
|
|
CMT="`git rev-parse --short HEAD`"
|
|
|
|
|
2017-02-17 00:18:20 +03:00
|
|
|
STRIP="${CROSS_COMPILE}strip"
|
2014-04-07 22:30:29 +04:00
|
|
|
OBJDUMP="${CROSS_COMPILE}objdump"
|
|
|
|
|
2014-06-09 06:16:40 +04:00
|
|
|
for d in $FILES; do
|
|
|
|
if [ -d "$d" ]; then
|
|
|
|
for f in $(find $d -name '*.o')
|
|
|
|
do
|
|
|
|
do_objdump $f
|
|
|
|
done
|
|
|
|
else
|
|
|
|
do_objdump $d
|
|
|
|
fi
|
2014-04-07 22:30:29 +04:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
dodiff() {
|
|
|
|
[ $# -ne 2 ] && [ $# -ne 0 ] && usage
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
SRC="`git rev-parse --short HEAD^`"
|
|
|
|
DST="`git rev-parse --short HEAD`"
|
|
|
|
else
|
|
|
|
SRC="`git rev-parse --short $1`"
|
|
|
|
DST="`git rev-parse --short $2`"
|
|
|
|
fi
|
|
|
|
|
|
|
|
DIFF="`which colordiff`"
|
|
|
|
|
|
|
|
if [ ${#DIFF} -eq 0 ] || [ ! -x "$DIFF" ]; then
|
|
|
|
DIFF="`which diff`"
|
|
|
|
fi
|
|
|
|
|
|
|
|
SRCD="$TMPD/$SRC"
|
|
|
|
DSTD="$TMPD/$DST"
|
|
|
|
|
|
|
|
if [ ! -d "$SRCD" ]; then
|
2014-06-09 06:16:35 +04:00
|
|
|
echo >&2 "ERROR: $SRCD doesn't exist"
|
2014-04-07 22:30:29 +04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d "$DSTD" ]; then
|
2014-06-09 06:16:35 +04:00
|
|
|
echo >&2 "ERROR: $DSTD doesn't exist"
|
2014-04-07 22:30:29 +04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
$DIFF -Nurd $SRCD $DSTD
|
|
|
|
}
|
|
|
|
|
|
|
|
doclean() {
|
|
|
|
[ $# -eq 0 ] && usage
|
|
|
|
[ $# -gt 1 ] && usage
|
|
|
|
|
|
|
|
if [ "x$1" = "xall" ]; then
|
|
|
|
rm -rf $TMPD/*
|
|
|
|
else
|
|
|
|
CMT="`git rev-parse --short $1`"
|
|
|
|
|
|
|
|
if [ -d "$TMPD/$CMT" ]; then
|
|
|
|
rm -rf $TMPD/$CMT
|
|
|
|
else
|
2014-06-09 06:16:35 +04:00
|
|
|
echo >&2 "$CMT not found"
|
2014-04-07 22:30:29 +04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
[ $# -eq 0 ] && usage
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
record)
|
|
|
|
shift
|
|
|
|
dorecord $*
|
|
|
|
;;
|
|
|
|
diff)
|
|
|
|
shift
|
|
|
|
dodiff $*
|
|
|
|
;;
|
|
|
|
clean)
|
|
|
|
shift
|
|
|
|
doclean $*
|
|
|
|
;;
|
|
|
|
*)
|
2014-06-09 06:16:35 +04:00
|
|
|
echo >&2 "Unrecognized command '$1'"
|
2014-04-07 22:30:29 +04:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|