5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License, Version 1.0 only
7 # (the "License"). You may not use this file except in compliance
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
27 #ident "%Z%%M% %I% %E% SMI"
29 # elfcmp - compare significant sections in two ELF files
31 # usage: elfcmp [-v] [-S] [-s section ...] <f1> <f2>
40 echo 'Usage: elfcmp [-v] [-S] [-s section ...] <f1> <f2>' 1>&2
74 trap "rm -f $TMP1 $TMP2" EXIT HUP INT QUIT PIPE TERM
77 dump
-h "$1" |
grep '\[[0-9]' |
awk '{print $7}'
80 list_alloc_sections
() {
81 dump
-hv "$1" |
grep '\[[0-9]' |
awk '$3 ~ /A/ {print $4, $5, $6, $7}'
85 /usr
/xpg
4/bin
/grep -v -e \\$SHSTRTAB -e \\.SUNW_signature
88 # get section lists for both files into temp files
90 if [[ "$SECTIONLIST" = "" ]]
92 if [[ $SIGNING_CHECK = 1 ]]
94 SHSTRNDX
=`dump -f "$1" | awk '{if (NR==11) print $5}'`
95 SHSTRTAB
=`dump -h "$1" | grep "^\\[$SHSTRNDX\\]" | \
102 list_sections
"$1" |
$FILTER |
sort >$TMP1
103 list_sections
"$2" |
$FILTER |
sort >$TMP2
105 echo "$SECTIONLIST" >$TMP1
106 echo "$SECTIONLIST" >$TMP2
109 # determine and print which ones aren't in both of the input files
111 NOT_IN_1
=$
(comm -13 $TMP1 $TMP2)
112 if [[ ! -z "$NOT_IN_1" ]]
114 echo "Section(s) $NOT_IN_1 not in $1"
117 NOT_IN_2
=$
(comm -23 $TMP1 $TMP2)
118 if [[ ! -z "$NOT_IN_2" ]]
120 echo "Section(s) $NOT_IN_2 not in $2"
124 # for all the sections which *are* common, do the following
126 for s
in $
(comm -12 $TMP1 $TMP2)
128 dump
-s -n $s "$1" |
sed '/:/d' >$TMP1
129 dump
-s -n $s "$2" |
sed '/:/d' >$TMP2
130 if cmp -s $TMP1 $TMP2
132 if [[ $VERBOSE = 1 ]]
134 echo "Section $s is the same"
137 echo "Section $s differs"
138 if [[ $VERBOSE = 1 ]]
140 dump
-sv -n $s "$1" |
sed '/:/d' >$TMP1
141 dump
-sv -n $s "$2" |
sed '/:/d' >$TMP2
148 # verify that allocated objects have not moved
149 # only applies to signed objects with a program header
151 if [[ $SIGNING_CHECK = 1 ]]
153 HDR
=$
(dump
-op $1 |
wc -l)
156 list_alloc_sections
"$1" |
sort >$TMP1
157 list_alloc_sections
"$2" |
sort >$TMP2
158 if cmp -s $TMP1 $TMP2
160 if [[ $VERBOSE = 1 ]]
162 echo "Allocated sections are the same"
165 echo "Allocated section(s) changed"
166 if [[ $VERBOSE = 1 ]]