common/bin/compare-objects.sh

changeset 0
75a576e87639
child 1133
50aaf272884f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/common/bin/compare-objects.sh	Wed Apr 27 01:39:08 2016 +0800
     1.3 @@ -0,0 +1,235 @@
     1.4 +#!/bin/bash
     1.5 +#
     1.6 +# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     1.7 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8 +#
     1.9 +# This code is free software; you can redistribute it and/or modify it
    1.10 +# under the terms of the GNU General Public License version 2 only, as
    1.11 +# published by the Free Software Foundation.
    1.12 +#
    1.13 +# This code is distributed in the hope that it will be useful, but WITHOUT
    1.14 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.15 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.16 +# version 2 for more details (a copy is included in the LICENSE file that
    1.17 +# accompanied this code).
    1.18 +#
    1.19 +# You should have received a copy of the GNU General Public License version
    1.20 +# 2 along with this work; if not, write to the Free Software Foundation,
    1.21 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.22 +#
    1.23 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.24 +# or visit www.oracle.com if you need additional information or have any
    1.25 +# questions.
    1.26 +#
    1.27 +
    1.28 +# MANUAL
    1.29 +#
    1.30 +# ./common/bin/compare-objects.sh old_jdk_build_dir new_jdk_build_dir
    1.31 +#
    1.32 +# Compares object files
    1.33 +#
    1.34 +
    1.35 +if [ "x$1" = "x-h" ] || [ "x$1" = "x--help" ] || [ "x$1" == "x" ]; then
    1.36 +    echo "bash ./common/bin/compare-objects.sh old_jdk_build_dir new_jdk_build_dir <pattern>"
    1.37 +    echo ""
    1.38 +    echo "Compare object files"
    1.39 +    echo ""
    1.40 +    exit 10
    1.41 +fi
    1.42 +
    1.43 +#######
    1.44 +#
    1.45 +# List of files (grep patterns) that are ignored
    1.46 +# 
    1.47 +# 1) hotspot object files
    1.48 +IGNORE="-e hotspot"
    1.49 +
    1.50 +# 2) various build artifacts: sizer.32.o sizer.64.o dummyodbc.o
    1.51 +#    these are produced during build and then e.g run to produce other data
    1.52 +#    i.e not directly put into build => safe to ignore
    1.53 +IGNORE="${IGNORE} -e sizer.32.o -e sizer.64.o"
    1.54 +IGNORE="${IGNORE} -e dummyodbc.o"
    1.55 +IGNORE="${IGNORE} -e genSolarisConstants.o"
    1.56 +IGNORE="${IGNORE} -e genUnixConstants.o"
    1.57 +
    1.58 +OLD="$1"
    1.59 +NEW="$2"
    1.60 +shift; shift
    1.61 +PATTERN="$*"
    1.62 +
    1.63 +if [ -f $NEW/spec.sh ]; then
    1.64 +    . $NEW/spec.sh
    1.65 +elif [ -f $NEW/../../spec.sh ]; then
    1.66 +    . $NEW/../../spec.sh
    1.67 +elif [ -f $OLD/spec.sh ]; then
    1.68 +    . $OLD/spec.sh
    1.69 +elif [ -f $OLD/../../spec.sh ]; then
    1.70 +    . $OLD/../../spec.sh
    1.71 +else
    1.72 +    echo "Unable to find spec.sh"
    1.73 +    echo "Giving up"
    1.74 +    exit 1
    1.75 +fi
    1.76 +
    1.77 +export COMPARE_ROOT=/tmp/cimages.$USER/objects
    1.78 +mkdir -p $COMPARE_ROOT
    1.79 +
    1.80 +(${CD} $OLD && ${FIND} . -name '*.o') > $COMPARE_ROOT/list.old
    1.81 +(${CD} $NEW && ${FIND} . -name '*.o') > $COMPARE_ROOT/list.new
    1.82 +
    1.83 +# On macosx JobjC is build in both i386 and x86_64 variant (universial binary)
    1.84 +#   but new build only builds the x86_64
    1.85 +# Remove the 386 variants from comparison...to avoid "false" positives
    1.86 +${GREP} -v 'JObjC.dst/Objects-normal/i386' $COMPARE_ROOT/list.old > $COMPARE_ROOT/list.old.new
    1.87 +${CP} $COMPARE_ROOT/list.old $COMPARE_ROOT/list.old.full
    1.88 +${CP} $COMPARE_ROOT/list.old.new $COMPARE_ROOT/list.old
    1.89 +
    1.90 +findnew() {
    1.91 +    arg_1=$1
    1.92 +    arg_2=$2
    1.93 +
    1.94 +    # special case 1 unpack-cmd => unpackexe
    1.95 +    arg_1=`${ECHO} $arg_1 | ${SED} 's!unpack-cmd!unpackexe!g'`
    1.96 +    arg_2=`${ECHO} $arg_2 | ${SED} 's!unpack-cmd!unpackexe!g'`
    1.97 +
    1.98 +    # special case 2 /JObjC.dst/ => /libjobjc/
    1.99 +    arg_1=`${ECHO} $arg_1 | ${SED} 's!/JObjC.dst/!/libjobjc/!g'`
   1.100 +    arg_2=`${ECHO} $arg_2 | ${SED} 's!/JObjC.dst/!/libjobjc/!g'`
   1.101 +
   1.102 +    full=`${ECHO} $arg_1 | ${SED} 's!\.!\\\.!g'`
   1.103 +    medium=`${ECHO} $arg_1 | ${SED} 's!.*/\([^/]*/[^/]*\)!\1!'`
   1.104 +    short=`${ECHO} $arg_2 | ${SED} 's!\.!\\\.!g'`
   1.105 +    if [ "`${GREP} -c "/$full" $COMPARE_ROOT/list.new`" -eq 1 ]
   1.106 +    then
   1.107 +	${ECHO} $NEW/$arg_1
   1.108 +	return
   1.109 +    fi
   1.110 +
   1.111 +    if [ "`${GREP} -c "$medium" $COMPARE_ROOT/list.new`" -eq 1 ]
   1.112 +    then
   1.113 +	${GREP} "$medium" $COMPARE_ROOT/list.new
   1.114 +	return
   1.115 +    fi
   1.116 +
   1.117 +    if [ "`${GREP} -c "/$short" $COMPARE_ROOT/list.new`" -eq 1 ]
   1.118 +    then
   1.119 +	${GREP} "/$short" $COMPARE_ROOT/list.new
   1.120 +	return
   1.121 +    fi
   1.122 +
   1.123 +    # old style has "dir" before obj{64}
   1.124 +    dir=`${ECHO} $arg_1 | ${SED} 's!.*/\([^/]*\)/obj[64]*.*!\1!g'`
   1.125 +    if [ -n "$dir" -a "$dir" != "$arg_1" ]
   1.126 +    then
   1.127 +	if [ "`${GREP} $dir $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ]
   1.128 +	then
   1.129 +	    ${GREP} $dir $COMPARE_ROOT/list.new | ${GREP} "/$short"
   1.130 +	    return
   1.131 +	fi
   1.132 +
   1.133 +	# Try with lib$dir/
   1.134 +	if [ "`${GREP} "lib$dir/" $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ]
   1.135 +	then
   1.136 +	    ${GREP} "lib$dir/" $COMPARE_ROOT/list.new | ${GREP} "/$short"
   1.137 +	    return
   1.138 +	fi
   1.139 +
   1.140 +	# Try with $dir_objs
   1.141 +	if [ "`${GREP} "${dir}_objs" $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ]
   1.142 +	then
   1.143 +	    ${GREP} "${dir}_objs" $COMPARE_ROOT/list.new | ${GREP} "/$short"
   1.144 +	    return
   1.145 +	fi
   1.146 +    fi
   1.147 +
   1.148 +    # check for some specifics...
   1.149 +    for i in demo hotspot jobjc
   1.150 +    do
   1.151 +	if [ "`${ECHO} $full | ${GREP} -c $i`" -gt 0 ]
   1.152 +	then
   1.153 +	    if [ "`${GREP} $i $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ]
   1.154 +	    then
   1.155 +		${GREP} $i $COMPARE_ROOT/list.new | ${GREP} "/$short"
   1.156 +		return
   1.157 +	    fi
   1.158 +	fi
   1.159 +    done
   1.160 +
   1.161 +    # check for specific demo
   1.162 +    demo=`${ECHO} $arg_1 | ${SED} 's!.*/demo/jvmti/\([^/]*\)/.*!\1!g'`
   1.163 +    if [ -n "$demo" -a "$dir" != "$demo" ]
   1.164 +    then
   1.165 +	if [ "`${GREP} $demo $COMPARE_ROOT/list.new | ${GREP} -c "/$short"`" -eq 1 ]
   1.166 +	then
   1.167 +	    ${GREP} $demo $COMPARE_ROOT/list.new | ${GREP} "/$short"
   1.168 +	    return
   1.169 +	fi
   1.170 +    fi
   1.171 +
   1.172 +    return
   1.173 +}
   1.174 +
   1.175 +compare() {
   1.176 +    old=$1
   1.177 +    new=$2
   1.178 +    ${DIFF} $old $new > /dev/null
   1.179 +    res=$?
   1.180 +    if [ $res -eq 0 ]
   1.181 +    then
   1.182 +	${ECHO} 0
   1.183 +	return
   1.184 +    fi
   1.185 +
   1.186 +    # check if stripped objects gives equality
   1.187 +    ${CP} $old $COMPARE_ROOT/`basename $old`.old
   1.188 +    ${CP} $new $COMPARE_ROOT/`basename $old`.new
   1.189 +    ${POST_STRIP_CMD} $COMPARE_ROOT/`basename $old`.old $COMPARE_ROOT/`basename $old`.new > /dev/null 2>&1
   1.190 +    ${DIFF} $COMPARE_ROOT/`basename $old`.old $COMPARE_ROOT/`basename $old`.new > /dev/null
   1.191 +    res=$?
   1.192 +    ${RM} $COMPARE_ROOT/`basename $old`.old $COMPARE_ROOT/`basename $old`.new
   1.193 +    if [ $res -eq 0 ]
   1.194 +    then
   1.195 +	${ECHO} S
   1.196 +	return
   1.197 +    fi
   1.198 +
   1.199 +    name=`basename $1 | ${SED} 's!\.o!!'`
   1.200 +    cntold=`strings $old | ${GREP} -c $name`
   1.201 +    cntnew=`strings $new | ${GREP} -c $name`
   1.202 +    
   1.203 +    if [ $cntold -gt 0 -a $cntnew -gt 0 ]
   1.204 +    then
   1.205 +	${ECHO} F
   1.206 +	return
   1.207 +    fi
   1.208 +
   1.209 +    ${ECHO} 1
   1.210 +}
   1.211 +
   1.212 +for F in `${CAT} $COMPARE_ROOT/list.old`
   1.213 +do
   1.214 +    if [ "${IGNORE}" ] && [ "`${ECHO} $F | ${GREP} ${IGNORE}`" ]
   1.215 +    then
   1.216 +	#
   1.217 +	# skip ignored files
   1.218 +        #
   1.219 +	continue;
   1.220 +    fi
   1.221 +
   1.222 +    if [ "$PATTERN" ] && [ `${ECHO} $F | ${GREP} -c $PATTERN` -eq 0 ]
   1.223 +    then
   1.224 +	continue;
   1.225 +    fi
   1.226 +
   1.227 +    f=`basename $F`
   1.228 +    o=$OLD/$F
   1.229 +    n=`findnew $F $f`
   1.230 +
   1.231 +    if [ "$n" ]
   1.232 +    then	
   1.233 +	n="$NEW/$n"
   1.234 +	${ECHO} `compare $o $n` : $f : $o : $n
   1.235 +    else
   1.236 +	${ECHO} "- : $f : $o "
   1.237 +    fi
   1.238 +done

mercurial