erikj@459: #!/bin/bash erikj@459: # erikj@459: # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. erikj@459: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. erikj@459: # erikj@459: # This code is free software; you can redistribute it and/or modify it erikj@459: # under the terms of the GNU General Public License version 2 only, as erikj@459: # published by the Free Software Foundation. erikj@459: # erikj@459: # This code is distributed in the hope that it will be useful, but WITHOUT erikj@459: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or erikj@459: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License erikj@459: # version 2 for more details (a copy is included in the LICENSE file that erikj@459: # accompanied this code). erikj@459: # erikj@459: # You should have received a copy of the GNU General Public License version erikj@459: # 2 along with this work; if not, write to the Free Software Foundation, erikj@459: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. erikj@459: # erikj@459: # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA erikj@459: # or visit www.oracle.com if you need additional information or have any erikj@459: # questions. erikj@459: # erikj@459: erikj@459: # MANUAL erikj@459: # erikj@459: # ./common/bin/compare-objects.sh old_jdk_build_dir new_jdk_build_dir erikj@459: # erikj@459: # Compares object files erikj@459: # erikj@459: erikj@459: if [ "x$1" = "x-h" ] || [ "x$1" = "x--help" ] || [ "x$1" == "x" ]; then ohair@478: echo "bash ./common/bin/compare-objects.sh old_jdk_build_dir new_jdk_build_dir " erikj@459: echo "" erikj@459: echo "Compare object files" erikj@459: echo "" erikj@459: exit 10 erikj@459: fi erikj@459: erikj@459: ####### erikj@459: # erikj@459: # List of files (grep patterns) that are ignored erikj@459: # erikj@459: # 1) hotspot object files erikj@459: IGNORE="-e hotspot" erikj@459: erikj@459: # 2) various build artifacts: sizer.32.o sizer.64.o dummyodbc.o erikj@459: # these are produced during build and then e.g run to produce other data erikj@459: # i.e not directly put into build => safe to ignore erikj@459: IGNORE="${IGNORE} -e sizer.32.o -e sizer.64.o" erikj@459: IGNORE="${IGNORE} -e dummyodbc.o" erikj@459: IGNORE="${IGNORE} -e genSolarisConstants.o" erikj@459: IGNORE="${IGNORE} -e genUnixConstants.o" erikj@459: erikj@459: OLD="$1" erikj@459: NEW="$2" erikj@459: shift; shift erikj@459: PATTERN="$*" erikj@459: erikj@459: if [ -f $NEW/spec.sh ]; then erikj@459: . $NEW/spec.sh erikj@459: elif [ -f $NEW/../../spec.sh ]; then erikj@459: . $NEW/../../spec.sh erikj@459: elif [ -f $OLD/spec.sh ]; then erikj@459: . $OLD/spec.sh erikj@459: elif [ -f $OLD/../../spec.sh ]; then erikj@459: . $OLD/../../spec.sh erikj@459: else erikj@459: echo "Unable to find spec.sh" erikj@459: echo "Giving up" erikj@459: exit 1 erikj@459: fi erikj@459: erikj@459: export COMPARE_ROOT=/tmp/cimages.$USER/objects erikj@459: mkdir -p $COMPARE_ROOT erikj@459: erikj@459: (${CD} $OLD && ${FIND} . -name '*.o') > $COMPARE_ROOT/list.old erikj@459: (${CD} $NEW && ${FIND} . -name '*.o') > $COMPARE_ROOT/list.new erikj@459: erikj@459: # On macosx JobjC is build in both i386 and x86_64 variant (universial binary) erikj@459: # but new build only builds the x86_64 erikj@459: # Remove the 386 variants from comparison...to avoid "false" positives erikj@459: ${GREP} -v 'JObjC.dst/Objects-normal/i386' $COMPARE_ROOT/list.old > $COMPARE_ROOT/list.old.new erikj@459: ${CP} $COMPARE_ROOT/list.old $COMPARE_ROOT/list.old.full erikj@459: ${CP} $COMPARE_ROOT/list.old.new $COMPARE_ROOT/list.old erikj@459: erikj@459: findnew() { erikj@459: arg_1=$1 erikj@459: arg_2=$2 erikj@459: erikj@459: # special case 1 unpack-cmd => unpackexe erikj@459: arg_1=`${ECHO} $arg_1 | ${SED} 's!unpack-cmd!unpackexe!g'` erikj@459: arg_2=`${ECHO} $arg_2 | ${SED} 's!unpack-cmd!unpackexe!g'` erikj@459: erikj@459: # special case 2 /JObjC.dst/ => /libjobjc/ erikj@459: arg_1=`${ECHO} $arg_1 | ${SED} 's!/JObjC.dst/!/libjobjc/!g'` erikj@459: arg_2=`${ECHO} $arg_2 | ${SED} 's!/JObjC.dst/!/libjobjc/!g'` erikj@459: erikj@459: full=`${ECHO} $arg_1 | ${SED} 's!\.!\\\.!g'` erikj@459: medium=`${ECHO} $arg_1 | ${SED} 's!.*/\([^/]*/[^/]*\)!\1!'` erikj@459: short=`${ECHO} $arg_2 | ${SED} 's!\.!\\\.!g'` erikj@459: if [ "`${GREP} -c "/$full" $COMPARE_ROOT/list.new`" -eq 1 ] erikj@459: then erikj@459: ${ECHO} $NEW/$arg_1 erikj@459: return erikj@459: fi erikj@459: erikj@459: if [ "`${GREP} -c "$medium" $COMPARE_ROOT/list.new`" -eq 1 ] erikj@459: then erikj@459: ${GREP} "$medium" $COMPARE_ROOT/list.new erikj@459: return erikj@459: fi erikj@459: erikj@459: if [ "`${GREP} -c "/$short" $COMPARE_ROOT/list.new`" -eq 1 ] erikj@459: then erikj@459: ${GREP} "/$short" $COMPARE_ROOT/list.new erikj@459: return erikj@459: fi erikj@459: erikj@459: # old style has "dir" before obj{64} erikj@459: dir=`${ECHO} $arg_1 | ${SED} 's!.*/\([^/]*\)/obj[64]*.*!\1!g'` erikj@459: if [ -n "$dir" -a "$dir" != "$arg_1" ] erikj@459: then erikj@459: if [ "`${GREP} $dir $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ] erikj@459: then erikj@459: ${GREP} $dir $COMPARE_ROOT/list.new | ${GREP} "/$short" erikj@459: return erikj@459: fi erikj@459: erikj@459: # Try with lib$dir/ erikj@459: if [ "`${GREP} "lib$dir/" $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ] erikj@459: then erikj@459: ${GREP} "lib$dir/" $COMPARE_ROOT/list.new | ${GREP} "/$short" erikj@459: return erikj@459: fi erikj@459: erikj@459: # Try with $dir_objs erikj@459: if [ "`${GREP} "${dir}_objs" $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ] erikj@459: then erikj@459: ${GREP} "${dir}_objs" $COMPARE_ROOT/list.new | ${GREP} "/$short" erikj@459: return erikj@459: fi erikj@459: fi erikj@459: erikj@459: # check for some specifics... erikj@459: for i in demo hotspot jobjc erikj@459: do erikj@459: if [ "`${ECHO} $full | ${GREP} -c $i`" -gt 0 ] erikj@459: then erikj@459: if [ "`${GREP} $i $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ] erikj@459: then erikj@459: ${GREP} $i $COMPARE_ROOT/list.new | ${GREP} "/$short" erikj@459: return erikj@459: fi erikj@459: fi erikj@459: done erikj@459: erikj@459: # check for specific demo erikj@459: demo=`${ECHO} $arg_1 | ${SED} 's!.*/demo/jvmti/\([^/]*\)/.*!\1!g'` erikj@459: if [ -n "$demo" -a "$dir" != "$demo" ] erikj@459: then erikj@459: if [ "`${GREP} $demo $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ] erikj@459: then erikj@459: ${GREP} $demo $COMPARE_ROOT/list.new | ${GREP} "/$short" erikj@459: return erikj@459: fi erikj@459: fi erikj@459: erikj@459: return erikj@459: } erikj@459: erikj@459: compare() { erikj@459: old=$1 erikj@459: new=$2 erikj@459: ${DIFF} $old $new > /dev/null erikj@459: res=$? erikj@459: if [ $res -eq 0 ] erikj@459: then erikj@459: ${ECHO} 0 erikj@459: return erikj@459: fi erikj@459: erikj@459: # check if stripped objects gives equality erikj@459: ${CP} $old $COMPARE_ROOT/`basename $old`.old erikj@459: ${CP} $new $COMPARE_ROOT/`basename $old`.new erikj@459: ${POST_STRIP_CMD} $COMPARE_ROOT/`basename $old`.old $COMPARE_ROOT/`basename $old`.new > /dev/null 2>&1 erikj@459: ${DIFF} $COMPARE_ROOT/`basename $old`.old $COMPARE_ROOT/`basename $old`.new > /dev/null erikj@459: res=$? erikj@459: ${RM} $COMPARE_ROOT/`basename $old`.old $COMPARE_ROOT/`basename $old`.new erikj@459: if [ $res -eq 0 ] erikj@459: then erikj@459: ${ECHO} S erikj@459: return erikj@459: fi erikj@459: erikj@459: name=`basename $1 | ${SED} 's!\.o!!'` erikj@459: cntold=`strings $old | ${GREP} -c $name` erikj@459: cntnew=`strings $new | ${GREP} -c $name` erikj@459: erikj@459: if [ $cntold -gt 0 -a $cntnew -gt 0 ] erikj@459: then erikj@459: ${ECHO} F erikj@459: return erikj@459: fi erikj@459: erikj@459: ${ECHO} 1 erikj@459: } erikj@459: erikj@459: for F in `${CAT} $COMPARE_ROOT/list.old` erikj@459: do erikj@459: if [ "${IGNORE}" ] && [ "`${ECHO} $F | ${GREP} ${IGNORE}`" ] erikj@459: then erikj@459: # erikj@459: # skip ignored files erikj@459: # erikj@459: continue; erikj@459: fi erikj@459: erikj@459: if [ "$PATTERN" ] && [ `${ECHO} $F | ${GREP} -c $PATTERN` -eq 0 ] erikj@459: then erikj@459: continue; erikj@459: fi erikj@459: erikj@459: f=`basename $F` erikj@459: o=$OLD/$F erikj@459: n=`findnew $F $f` erikj@459: erikj@459: if [ "$n" ] erikj@459: then erikj@459: n="$NEW/$n" erikj@459: ${ECHO} `compare $o $n` : $f : $o : $n erikj@459: else erikj@459: ${ECHO} "- : $f : $o " erikj@459: fi erikj@459: done