Print this page
8858 /usr/bin/grep doesn't support -E option
4580 /usr/bin/grep can't handle multibyte characters
8929 8868 tests are not delivered with system/test/utiltest
8860 Example in grep(1) is incorrect
Reviewed by: Peter Tribble <peter.tribble@gmail.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Yuri Pankov <yuripv@gmx.com>


   7 # (the "License").  You may not use this file except in compliance
   8 # with the License.
   9 #
  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.
  14 #
  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]
  20 #
  21 # CDDL HEADER END
  22 #
  23 #
  24 # Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 # 
  27 #ident  "%Z%%M% %I%     %E% SMI"
  28 #
  29 # elfcmp - compare significant sections in two ELF files
  30 #
  31 # usage: elfcmp [-v] [-S] [-s section ...] <f1> <f2>
  32 #
  33 
  34 VERBOSE=0
  35 SECTIONLIST=""
  36 SIGNING_CHECK=0
  37 ERRORS=0
  38 
  39 usage() {
  40         echo 'Usage: elfcmp [-v] [-S] [-s section ...] <f1> <f2>' 1>&2
  41         exit 1
  42 }
  43 
  44 while [[ $# > 0 ]]
  45 do
  46         case "$1" in
  47         -v)
  48                 VERBOSE=1


  65 done
  66 
  67 if [[ $# != 2 ]]
  68 then
  69         usage
  70 fi
  71 
  72 TMP1=/tmp/elfcmp.1.$$
  73 TMP2=/tmp/elfcmp.2.$$
  74 trap "rm -f $TMP1 $TMP2" EXIT HUP INT QUIT PIPE TERM
  75 
  76 list_sections() {
  77         dump -h "$1" | grep '\[[0-9]' | awk '{print $7}'
  78 }
  79 
  80 list_alloc_sections() {
  81         dump -hv "$1" | grep '\[[0-9]' | awk '$3 ~ /A/ {print $4, $5, $6, $7}'
  82 }
  83 
  84 signing_filter() {
  85         /usr/xpg4/bin/grep -v -e \\$SHSTRTAB -e \\.SUNW_signature
  86 }
  87         
  88 # get section lists for both files into temp files
  89 
  90 if [[ "$SECTIONLIST" = "" ]]
  91 then
  92         if [[ $SIGNING_CHECK = 1 ]]
  93         then
  94                 SHSTRNDX=`dump -f "$1" | awk '{if (NR==11) print $5}'`
  95                 SHSTRTAB=`dump -h "$1" | grep "^\\[$SHSTRNDX\\]" | \
  96                         awk '{print $7}'`
  97                 FILTER=signing_filter
  98         else
  99                 FILTER=cat
 100         fi
 101 
 102         list_sections "$1" | $FILTER | sort >$TMP1
 103         list_sections "$2" | $FILTER | sort >$TMP2
 104 else
 105         echo "$SECTIONLIST" >$TMP1




   7 # (the "License").  You may not use this file except in compliance
   8 # with the License.
   9 #
  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.
  14 #
  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]
  20 #
  21 # CDDL HEADER END
  22 #
  23 #
  24 # Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 # 


  27 # elfcmp - compare significant sections in two ELF files
  28 #
  29 # usage: elfcmp [-v] [-S] [-s section ...] <f1> <f2>
  30 #
  31 
  32 VERBOSE=0
  33 SECTIONLIST=""
  34 SIGNING_CHECK=0
  35 ERRORS=0
  36 
  37 usage() {
  38         echo 'Usage: elfcmp [-v] [-S] [-s section ...] <f1> <f2>' 1>&2
  39         exit 1
  40 }
  41 
  42 while [[ $# > 0 ]]
  43 do
  44         case "$1" in
  45         -v)
  46                 VERBOSE=1


  63 done
  64 
  65 if [[ $# != 2 ]]
  66 then
  67         usage
  68 fi
  69 
  70 TMP1=/tmp/elfcmp.1.$$
  71 TMP2=/tmp/elfcmp.2.$$
  72 trap "rm -f $TMP1 $TMP2" EXIT HUP INT QUIT PIPE TERM
  73 
  74 list_sections() {
  75         dump -h "$1" | grep '\[[0-9]' | awk '{print $7}'
  76 }
  77 
  78 list_alloc_sections() {
  79         dump -hv "$1" | grep '\[[0-9]' | awk '$3 ~ /A/ {print $4, $5, $6, $7}'
  80 }
  81 
  82 signing_filter() {
  83         /usr/bin/grep -v -e \\$SHSTRTAB -e \\.SUNW_signature
  84 }
  85         
  86 # get section lists for both files into temp files
  87 
  88 if [[ "$SECTIONLIST" = "" ]]
  89 then
  90         if [[ $SIGNING_CHECK = 1 ]]
  91         then
  92                 SHSTRNDX=`dump -f "$1" | awk '{if (NR==11) print $5}'`
  93                 SHSTRTAB=`dump -h "$1" | grep "^\\[$SHSTRNDX\\]" | \
  94                         awk '{print $7}'`
  95                 FILTER=signing_filter
  96         else
  97                 FILTER=cat
  98         fi
  99 
 100         list_sections "$1" | $FILTER | sort >$TMP1
 101         list_sections "$2" | $FILTER | sort >$TMP2
 102 else
 103         echo "$SECTIONLIST" >$TMP1