common/bin/compare-objects.sh

Thu, 31 Aug 2017 15:40:18 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:40:18 +0800
changeset 1133
50aaf272884f
parent 478
2ba6f4da4bf3
parent 0
75a576e87639
permissions
-rw-r--r--

merge

aoqi@0 1 #!/bin/bash
aoqi@0 2 #
aoqi@0 3 # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 5 #
aoqi@0 6 # This code is free software; you can redistribute it and/or modify it
aoqi@0 7 # under the terms of the GNU General Public License version 2 only, as
aoqi@0 8 # published by the Free Software Foundation.
aoqi@0 9 #
aoqi@0 10 # This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 13 # version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 14 # accompanied this code).
aoqi@0 15 #
aoqi@0 16 # You should have received a copy of the GNU General Public License version
aoqi@0 17 # 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 19 #
aoqi@0 20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 21 # or visit www.oracle.com if you need additional information or have any
aoqi@0 22 # questions.
aoqi@0 23 #
aoqi@0 24
aoqi@0 25 # MANUAL
aoqi@0 26 #
aoqi@0 27 # ./common/bin/compare-objects.sh old_jdk_build_dir new_jdk_build_dir
aoqi@0 28 #
aoqi@0 29 # Compares object files
aoqi@0 30 #
aoqi@0 31
aoqi@0 32 if [ "x$1" = "x-h" ] || [ "x$1" = "x--help" ] || [ "x$1" == "x" ]; then
aoqi@0 33 echo "bash ./common/bin/compare-objects.sh old_jdk_build_dir new_jdk_build_dir <pattern>"
aoqi@0 34 echo ""
aoqi@0 35 echo "Compare object files"
aoqi@0 36 echo ""
aoqi@0 37 exit 10
aoqi@0 38 fi
aoqi@0 39
aoqi@0 40 #######
aoqi@0 41 #
aoqi@0 42 # List of files (grep patterns) that are ignored
aoqi@0 43 #
aoqi@0 44 # 1) hotspot object files
aoqi@0 45 IGNORE="-e hotspot"
aoqi@0 46
aoqi@0 47 # 2) various build artifacts: sizer.32.o sizer.64.o dummyodbc.o
aoqi@0 48 # these are produced during build and then e.g run to produce other data
aoqi@0 49 # i.e not directly put into build => safe to ignore
aoqi@0 50 IGNORE="${IGNORE} -e sizer.32.o -e sizer.64.o"
aoqi@0 51 IGNORE="${IGNORE} -e dummyodbc.o"
aoqi@0 52 IGNORE="${IGNORE} -e genSolarisConstants.o"
aoqi@0 53 IGNORE="${IGNORE} -e genUnixConstants.o"
aoqi@0 54
aoqi@0 55 OLD="$1"
aoqi@0 56 NEW="$2"
aoqi@0 57 shift; shift
aoqi@0 58 PATTERN="$*"
aoqi@0 59
aoqi@0 60 if [ -f $NEW/spec.sh ]; then
aoqi@0 61 . $NEW/spec.sh
aoqi@0 62 elif [ -f $NEW/../../spec.sh ]; then
aoqi@0 63 . $NEW/../../spec.sh
aoqi@0 64 elif [ -f $OLD/spec.sh ]; then
aoqi@0 65 . $OLD/spec.sh
aoqi@0 66 elif [ -f $OLD/../../spec.sh ]; then
aoqi@0 67 . $OLD/../../spec.sh
aoqi@0 68 else
aoqi@0 69 echo "Unable to find spec.sh"
aoqi@0 70 echo "Giving up"
aoqi@0 71 exit 1
aoqi@0 72 fi
aoqi@0 73
aoqi@0 74 export COMPARE_ROOT=/tmp/cimages.$USER/objects
aoqi@0 75 mkdir -p $COMPARE_ROOT
aoqi@0 76
aoqi@0 77 (${CD} $OLD && ${FIND} . -name '*.o') > $COMPARE_ROOT/list.old
aoqi@0 78 (${CD} $NEW && ${FIND} . -name '*.o') > $COMPARE_ROOT/list.new
aoqi@0 79
aoqi@0 80 # On macosx JobjC is build in both i386 and x86_64 variant (universial binary)
aoqi@0 81 # but new build only builds the x86_64
aoqi@0 82 # Remove the 386 variants from comparison...to avoid "false" positives
aoqi@0 83 ${GREP} -v 'JObjC.dst/Objects-normal/i386' $COMPARE_ROOT/list.old > $COMPARE_ROOT/list.old.new
aoqi@0 84 ${CP} $COMPARE_ROOT/list.old $COMPARE_ROOT/list.old.full
aoqi@0 85 ${CP} $COMPARE_ROOT/list.old.new $COMPARE_ROOT/list.old
aoqi@0 86
aoqi@0 87 findnew() {
aoqi@0 88 arg_1=$1
aoqi@0 89 arg_2=$2
aoqi@0 90
aoqi@0 91 # special case 1 unpack-cmd => unpackexe
aoqi@0 92 arg_1=`${ECHO} $arg_1 | ${SED} 's!unpack-cmd!unpackexe!g'`
aoqi@0 93 arg_2=`${ECHO} $arg_2 | ${SED} 's!unpack-cmd!unpackexe!g'`
aoqi@0 94
aoqi@0 95 # special case 2 /JObjC.dst/ => /libjobjc/
aoqi@0 96 arg_1=`${ECHO} $arg_1 | ${SED} 's!/JObjC.dst/!/libjobjc/!g'`
aoqi@0 97 arg_2=`${ECHO} $arg_2 | ${SED} 's!/JObjC.dst/!/libjobjc/!g'`
aoqi@0 98
aoqi@0 99 full=`${ECHO} $arg_1 | ${SED} 's!\.!\\\.!g'`
aoqi@0 100 medium=`${ECHO} $arg_1 | ${SED} 's!.*/\([^/]*/[^/]*\)!\1!'`
aoqi@0 101 short=`${ECHO} $arg_2 | ${SED} 's!\.!\\\.!g'`
aoqi@0 102 if [ "`${GREP} -c "/$full" $COMPARE_ROOT/list.new`" -eq 1 ]
aoqi@0 103 then
aoqi@0 104 ${ECHO} $NEW/$arg_1
aoqi@0 105 return
aoqi@0 106 fi
aoqi@0 107
aoqi@0 108 if [ "`${GREP} -c "$medium" $COMPARE_ROOT/list.new`" -eq 1 ]
aoqi@0 109 then
aoqi@0 110 ${GREP} "$medium" $COMPARE_ROOT/list.new
aoqi@0 111 return
aoqi@0 112 fi
aoqi@0 113
aoqi@0 114 if [ "`${GREP} -c "/$short" $COMPARE_ROOT/list.new`" -eq 1 ]
aoqi@0 115 then
aoqi@0 116 ${GREP} "/$short" $COMPARE_ROOT/list.new
aoqi@0 117 return
aoqi@0 118 fi
aoqi@0 119
aoqi@0 120 # old style has "dir" before obj{64}
aoqi@0 121 dir=`${ECHO} $arg_1 | ${SED} 's!.*/\([^/]*\)/obj[64]*.*!\1!g'`
aoqi@0 122 if [ -n "$dir" -a "$dir" != "$arg_1" ]
aoqi@0 123 then
aoqi@0 124 if [ "`${GREP} $dir $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ]
aoqi@0 125 then
aoqi@0 126 ${GREP} $dir $COMPARE_ROOT/list.new | ${GREP} "/$short"
aoqi@0 127 return
aoqi@0 128 fi
aoqi@0 129
aoqi@0 130 # Try with lib$dir/
aoqi@0 131 if [ "`${GREP} "lib$dir/" $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ]
aoqi@0 132 then
aoqi@0 133 ${GREP} "lib$dir/" $COMPARE_ROOT/list.new | ${GREP} "/$short"
aoqi@0 134 return
aoqi@0 135 fi
aoqi@0 136
aoqi@0 137 # Try with $dir_objs
aoqi@0 138 if [ "`${GREP} "${dir}_objs" $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ]
aoqi@0 139 then
aoqi@0 140 ${GREP} "${dir}_objs" $COMPARE_ROOT/list.new | ${GREP} "/$short"
aoqi@0 141 return
aoqi@0 142 fi
aoqi@0 143 fi
aoqi@0 144
aoqi@0 145 # check for some specifics...
aoqi@0 146 for i in demo hotspot jobjc
aoqi@0 147 do
aoqi@0 148 if [ "`${ECHO} $full | ${GREP} -c $i`" -gt 0 ]
aoqi@0 149 then
aoqi@0 150 if [ "`${GREP} $i $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ]
aoqi@0 151 then
aoqi@0 152 ${GREP} $i $COMPARE_ROOT/list.new | ${GREP} "/$short"
aoqi@0 153 return
aoqi@0 154 fi
aoqi@0 155 fi
aoqi@0 156 done
aoqi@0 157
aoqi@0 158 # check for specific demo
aoqi@0 159 demo=`${ECHO} $arg_1 | ${SED} 's!.*/demo/jvmti/\([^/]*\)/.*!\1!g'`
aoqi@0 160 if [ -n "$demo" -a "$dir" != "$demo" ]
aoqi@0 161 then
aoqi@0 162 if [ "`${GREP} $demo $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ]
aoqi@0 163 then
aoqi@0 164 ${GREP} $demo $COMPARE_ROOT/list.new | ${GREP} "/$short"
aoqi@0 165 return
aoqi@0 166 fi
aoqi@0 167 fi
aoqi@0 168
aoqi@0 169 return
aoqi@0 170 }
aoqi@0 171
aoqi@0 172 compare() {
aoqi@0 173 old=$1
aoqi@0 174 new=$2
aoqi@0 175 ${DIFF} $old $new > /dev/null
aoqi@0 176 res=$?
aoqi@0 177 if [ $res -eq 0 ]
aoqi@0 178 then
aoqi@0 179 ${ECHO} 0
aoqi@0 180 return
aoqi@0 181 fi
aoqi@0 182
aoqi@0 183 # check if stripped objects gives equality
aoqi@0 184 ${CP} $old $COMPARE_ROOT/`basename $old`.old
aoqi@0 185 ${CP} $new $COMPARE_ROOT/`basename $old`.new
aoqi@0 186 ${POST_STRIP_CMD} $COMPARE_ROOT/`basename $old`.old $COMPARE_ROOT/`basename $old`.new > /dev/null 2>&1
aoqi@0 187 ${DIFF} $COMPARE_ROOT/`basename $old`.old $COMPARE_ROOT/`basename $old`.new > /dev/null
aoqi@0 188 res=$?
aoqi@0 189 ${RM} $COMPARE_ROOT/`basename $old`.old $COMPARE_ROOT/`basename $old`.new
aoqi@0 190 if [ $res -eq 0 ]
aoqi@0 191 then
aoqi@0 192 ${ECHO} S
aoqi@0 193 return
aoqi@0 194 fi
aoqi@0 195
aoqi@0 196 name=`basename $1 | ${SED} 's!\.o!!'`
aoqi@0 197 cntold=`strings $old | ${GREP} -c $name`
aoqi@0 198 cntnew=`strings $new | ${GREP} -c $name`
aoqi@0 199
aoqi@0 200 if [ $cntold -gt 0 -a $cntnew -gt 0 ]
aoqi@0 201 then
aoqi@0 202 ${ECHO} F
aoqi@0 203 return
aoqi@0 204 fi
aoqi@0 205
aoqi@0 206 ${ECHO} 1
aoqi@0 207 }
aoqi@0 208
aoqi@0 209 for F in `${CAT} $COMPARE_ROOT/list.old`
aoqi@0 210 do
aoqi@0 211 if [ "${IGNORE}" ] && [ "`${ECHO} $F | ${GREP} ${IGNORE}`" ]
aoqi@0 212 then
aoqi@0 213 #
aoqi@0 214 # skip ignored files
aoqi@0 215 #
aoqi@0 216 continue;
aoqi@0 217 fi
aoqi@0 218
aoqi@0 219 if [ "$PATTERN" ] && [ `${ECHO} $F | ${GREP} -c $PATTERN` -eq 0 ]
aoqi@0 220 then
aoqi@0 221 continue;
aoqi@0 222 fi
aoqi@0 223
aoqi@0 224 f=`basename $F`
aoqi@0 225 o=$OLD/$F
aoqi@0 226 n=`findnew $F $f`
aoqi@0 227
aoqi@0 228 if [ "$n" ]
aoqi@0 229 then
aoqi@0 230 n="$NEW/$n"
aoqi@0 231 ${ECHO} `compare $o $n` : $f : $o : $n
aoqi@0 232 else
aoqi@0 233 ${ECHO} "- : $f : $o "
aoqi@0 234 fi
aoqi@0 235 done

mercurial