Path: blob/aarch64-shenandoah-jdk8u272-b10/common/bin/compare-objects.sh
32278 views
#!/bin/bash1#2# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4#5# This code is free software; you can redistribute it and/or modify it6# under the terms of the GNU General Public License version 2 only, as7# published by the Free Software Foundation.8#9# This code is distributed in the hope that it will be useful, but WITHOUT10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12# version 2 for more details (a copy is included in the LICENSE file that13# accompanied this code).14#15# You should have received a copy of the GNU General Public License version16# 2 along with this work; if not, write to the Free Software Foundation,17# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18#19# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20# or visit www.oracle.com if you need additional information or have any21# questions.22#2324# MANUAL25#26# ./common/bin/compare-objects.sh old_jdk_build_dir new_jdk_build_dir27#28# Compares object files29#3031if [ "x$1" = "x-h" ] || [ "x$1" = "x--help" ] || [ "x$1" == "x" ]; then32echo "bash ./common/bin/compare-objects.sh old_jdk_build_dir new_jdk_build_dir <pattern>"33echo ""34echo "Compare object files"35echo ""36exit 1037fi3839#######40#41# List of files (grep patterns) that are ignored42#43# 1) hotspot object files44IGNORE="-e hotspot"4546# 2) various build artifacts: sizer.32.o sizer.64.o dummyodbc.o47# these are produced during build and then e.g run to produce other data48# i.e not directly put into build => safe to ignore49IGNORE="${IGNORE} -e sizer.32.o -e sizer.64.o"50IGNORE="${IGNORE} -e dummyodbc.o"51IGNORE="${IGNORE} -e genSolarisConstants.o"52IGNORE="${IGNORE} -e genUnixConstants.o"5354OLD="$1"55NEW="$2"56shift; shift57PATTERN="$*"5859if [ -f $NEW/spec.sh ]; then60. $NEW/spec.sh61elif [ -f $NEW/../../spec.sh ]; then62. $NEW/../../spec.sh63elif [ -f $OLD/spec.sh ]; then64. $OLD/spec.sh65elif [ -f $OLD/../../spec.sh ]; then66. $OLD/../../spec.sh67else68echo "Unable to find spec.sh"69echo "Giving up"70exit 171fi7273export COMPARE_ROOT=/tmp/cimages.$USER/objects74mkdir -p $COMPARE_ROOT7576(${CD} $OLD && ${FIND} . -name '*.o') > $COMPARE_ROOT/list.old77(${CD} $NEW && ${FIND} . -name '*.o') > $COMPARE_ROOT/list.new7879# On macosx JobjC is build in both i386 and x86_64 variant (universial binary)80# but new build only builds the x86_6481# Remove the 386 variants from comparison...to avoid "false" positives82${GREP} -v 'JObjC.dst/Objects-normal/i386' $COMPARE_ROOT/list.old > $COMPARE_ROOT/list.old.new83${CP} $COMPARE_ROOT/list.old $COMPARE_ROOT/list.old.full84${CP} $COMPARE_ROOT/list.old.new $COMPARE_ROOT/list.old8586findnew() {87arg_1=$188arg_2=$28990# special case 1 unpack-cmd => unpackexe91arg_1=`${ECHO} $arg_1 | ${SED} 's!unpack-cmd!unpackexe!g'`92arg_2=`${ECHO} $arg_2 | ${SED} 's!unpack-cmd!unpackexe!g'`9394# special case 2 /JObjC.dst/ => /libjobjc/95arg_1=`${ECHO} $arg_1 | ${SED} 's!/JObjC.dst/!/libjobjc/!g'`96arg_2=`${ECHO} $arg_2 | ${SED} 's!/JObjC.dst/!/libjobjc/!g'`9798full=`${ECHO} $arg_1 | ${SED} 's!\.!\\\.!g'`99medium=`${ECHO} $arg_1 | ${SED} 's!.*/\([^/]*/[^/]*\)!\1!'`100short=`${ECHO} $arg_2 | ${SED} 's!\.!\\\.!g'`101if [ "`${GREP} -c "/$full" $COMPARE_ROOT/list.new`" -eq 1 ]102then103${ECHO} $NEW/$arg_1104return105fi106107if [ "`${GREP} -c "$medium" $COMPARE_ROOT/list.new`" -eq 1 ]108then109${GREP} "$medium" $COMPARE_ROOT/list.new110return111fi112113if [ "`${GREP} -c "/$short" $COMPARE_ROOT/list.new`" -eq 1 ]114then115${GREP} "/$short" $COMPARE_ROOT/list.new116return117fi118119# old style has "dir" before obj{64}120dir=`${ECHO} $arg_1 | ${SED} 's!.*/\([^/]*\)/obj[64]*.*!\1!g'`121if [ -n "$dir" -a "$dir" != "$arg_1" ]122then123if [ "`${GREP} $dir $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ]124then125${GREP} $dir $COMPARE_ROOT/list.new | ${GREP} "/$short"126return127fi128129# Try with lib$dir/130if [ "`${GREP} "lib$dir/" $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ]131then132${GREP} "lib$dir/" $COMPARE_ROOT/list.new | ${GREP} "/$short"133return134fi135136# Try with $dir_objs137if [ "`${GREP} "${dir}_objs" $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ]138then139${GREP} "${dir}_objs" $COMPARE_ROOT/list.new | ${GREP} "/$short"140return141fi142fi143144# check for some specifics...145for i in demo hotspot jobjc146do147if [ "`${ECHO} $full | ${GREP} -c $i`" -gt 0 ]148then149if [ "`${GREP} $i $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ]150then151${GREP} $i $COMPARE_ROOT/list.new | ${GREP} "/$short"152return153fi154fi155done156157# check for specific demo158demo=`${ECHO} $arg_1 | ${SED} 's!.*/demo/jvmti/\([^/]*\)/.*!\1!g'`159if [ -n "$demo" -a "$dir" != "$demo" ]160then161if [ "`${GREP} $demo $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ]162then163${GREP} $demo $COMPARE_ROOT/list.new | ${GREP} "/$short"164return165fi166fi167168return169}170171compare() {172old=$1173new=$2174${DIFF} $old $new > /dev/null175res=$?176if [ $res -eq 0 ]177then178${ECHO} 0179return180fi181182# check if stripped objects gives equality183${CP} $old $COMPARE_ROOT/`basename $old`.old184${CP} $new $COMPARE_ROOT/`basename $old`.new185${POST_STRIP_CMD} $COMPARE_ROOT/`basename $old`.old $COMPARE_ROOT/`basename $old`.new > /dev/null 2>&1186${DIFF} $COMPARE_ROOT/`basename $old`.old $COMPARE_ROOT/`basename $old`.new > /dev/null187res=$?188${RM} $COMPARE_ROOT/`basename $old`.old $COMPARE_ROOT/`basename $old`.new189if [ $res -eq 0 ]190then191${ECHO} S192return193fi194195name=`basename $1 | ${SED} 's!\.o!!'`196cntold=`strings $old | ${GREP} -c $name`197cntnew=`strings $new | ${GREP} -c $name`198199if [ $cntold -gt 0 -a $cntnew -gt 0 ]200then201${ECHO} F202return203fi204205${ECHO} 1206}207208for F in `${CAT} $COMPARE_ROOT/list.old`209do210if [ "${IGNORE}" ] && [ "`${ECHO} $F | ${GREP} ${IGNORE}`" ]211then212#213# skip ignored files214#215continue;216fi217218if [ "$PATTERN" ] && [ `${ECHO} $F | ${GREP} -c $PATTERN` -eq 0 ]219then220continue;221fi222223f=`basename $F`224o=$OLD/$F225n=`findnew $F $f`226227if [ "$n" ]228then229n="$NEW/$n"230${ECHO} `compare $o $n` : $f : $o : $n231else232${ECHO} "- : $f : $o "233fi234done235236237