scripts: objdiff: sync with Linux 3.16

Import scripts/objdiff improvements from Linux v3.16, which
consists of 7 commits written by me.

  commit 7fa0e6db3cedc9b70d68a4170f1352e2b1aa0f90
  scripts: objdiff: support directories for the augument of record command

  commit 8ac28bee76eec006aac5ba5c418878a607d53a9b
  scripts: objdiff: fix a comment

  commit 8b5d0f20d64f00ffd5685879f8eb3659379f5aaa
  scripts: objdiff: change the extension of disassembly from .o to .dis

  commit 18165efa8203a34d82f60a1831ea290e7304c654
  scripts: objdiff: improve path flexibility for record command

  commit 1ecc8e489abfdaa6d8d1689f7ff62fdf1adda30c
  scripts: objdiff: remove unnecessary code

  commit 5ab370e91af70d5f1b1dbaec78798a2ff236a2d5
  scripts: objdiff: direct error messages to stderr

  commit fd6e12423311697860f30d10398a0f9eb91977d2
  scripts: objdiff: get the path to .tmp_objdiff more simply

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
This commit is contained in:
Masahiro Yamada 2014-08-05 15:56:45 +09:00 committed by Tom Rini
parent e773440425
commit 9b586031db

View file

@ -25,25 +25,47 @@
# #
# Note: 'make mrproper' will also remove .tmp_objdiff # Note: 'make mrproper' will also remove .tmp_objdiff
GIT_DIR="`git rev-parse --git-dir`" SRCTREE=$(cd $(git rev-parse --show-toplevel 2>/dev/null); pwd)
if [ -d "$GIT_DIR" ]; then if [ -z "$SRCTREE" ]; then
TMPD="${GIT_DIR%git}tmp_objdiff" echo >&2 "ERROR: Not a git repository."
[ -d "$TMPD" ] || mkdir "$TMPD"
else
echo "ERROR: git directory not found."
exit 1 exit 1
fi fi
TMPD=$SRCTREE/.tmp_objdiff
usage() { usage() {
echo "Usage: $0 <command> <args>" echo >&2 "Usage: $0 <command> <args>"
echo " record <list of object files>" echo >&2 " record <list of object files or directories>"
echo " diff <commitA> <commitB>" echo >&2 " diff <commitA> <commitB>"
echo " clean all | <commit>" echo >&2 " clean all | <commit>"
exit 1 exit 1
} }
get_output_dir() {
dir=${1%/*}
if [ "$dir" = "$1" ]; then
dir=.
fi
dir=$(cd $dir; pwd)
echo $TMPD/$CMT${dir#$SRCTREE}
}
do_objdump() {
dir=$(get_output_dir $1)
base=${1##*/}
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
$OBJDUMP -D $1 | sed "s/^[[:space:]]\+[0-9a-f]\+//" > $dis
}
dorecord() { dorecord() {
[ $# -eq 0 ] && usage [ $# -eq 0 ] && usage
@ -52,20 +74,16 @@ dorecord() {
CMT="`git rev-parse --short HEAD`" CMT="`git rev-parse --short HEAD`"
OBJDUMP="${CROSS_COMPILE}objdump" OBJDUMP="${CROSS_COMPILE}objdump"
OBJDIFFD="$TMPD/$CMT"
[ ! -d "$OBJDIFFD" ] && mkdir -p "$OBJDIFFD" for d in $FILES; do
if [ -d "$d" ]; then
for f in $FILES; do for f in $(find $d -name '*.o')
dn="${f%/*}" do
bn="${f##*/}" do_objdump $f
done
[ ! -d "$OBJDIFFD/$dn" ] && mkdir -p "$OBJDIFFD/$dn" else
do_objdump $d
# remove addresses for a more clear diff fi
# http://dummdida.tumblr.com/post/60924060451/binary-diff-between-libc-from-scientificlinux-and
$OBJDUMP -D "$f" | sed "s/^[[:space:]]\+[0-9a-f]\+//" \
>"$OBJDIFFD/$dn/$bn"
done done
} }
@ -90,12 +108,12 @@ dodiff() {
DSTD="$TMPD/$DST" DSTD="$TMPD/$DST"
if [ ! -d "$SRCD" ]; then if [ ! -d "$SRCD" ]; then
echo "ERROR: $SRCD doesn't exist" echo >&2 "ERROR: $SRCD doesn't exist"
exit 1 exit 1
fi fi
if [ ! -d "$DSTD" ]; then if [ ! -d "$DSTD" ]; then
echo "ERROR: $DSTD doesn't exist" echo >&2 "ERROR: $DSTD doesn't exist"
exit 1 exit 1
fi fi
@ -114,7 +132,7 @@ doclean() {
if [ -d "$TMPD/$CMT" ]; then if [ -d "$TMPD/$CMT" ]; then
rm -rf $TMPD/$CMT rm -rf $TMPD/$CMT
else else
echo "$CMT not found" echo >&2 "$CMT not found"
fi fi
fi fi
} }
@ -135,7 +153,7 @@ case "$1" in
doclean $* doclean $*
;; ;;
*) *)
echo "Unrecognized command '$1'" echo >&2 "Unrecognized command '$1'"
exit 1 exit 1
;; ;;
esac esac