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