1 #!/bin/ksh 2 # 3 # CDDL HEADER START 4 # 5 # The contents of this file are subject to the terms of the 6 # Common Development and Distribution License (the "License"). 7 # You may not use this file except in compliance with the License. 8 # 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 # or http://www.opensolaris.org/os/licensing. 11 # See the License for the specific language governing permissions 12 # and limitations under the License. 13 # 14 # When distributing Covered Code, include this CDDL HEADER in each 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 # If applicable, add the following below this CDDL HEADER, with the 17 # fields enclosed by brackets "[]" replaced with your own identifying 18 # information: Portions Copyright [yyyy] [name of copyright owner] 19 # 20 # CDDL HEADER END 21 # 22 # 23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 #ident "@(#)post_process_so.ksh 1.4 08/08/04 SMI" 27 28 progname=`basename $0` 29 30 if [ ! -f "$1" ]; then 31 echo "$0: error: $1 not found." 32 exit 1 33 fi 34 35 if [ -z "${SFWRELEASE}" ]; then 36 SFWRELEASE=`grep ^SFWRELEASE= $SRC/Makefile.master | \ 37 sed -e 's,^SFWRELEASE=[ ]*,,'` 38 fi 39 40 if [ -z "${SFWVERSION}" ]; then 41 SFWVERSION=`grep ^SFWVERSION= $SRC/Makefile.master | \ 42 sed -e 's,^SFWVERSION=[ ]*,,'` 43 fi 44 45 if [ -z "${RELEASE_DATE}" ]; then 46 RELEASE_DATE=`grep ^RELEASE_DATE= $SRC/Makefile.master | \ 47 sed -e 's,^RELEASE_DATE=[ ]*,,'` 48 fi 49 PATCHID=${SFWVERSION} 50 PATCH_DATE=${RELEASE_DATE} 51 RELEASE_CM="@(#)SunOS ${SFWRELEASE} ${PATCHID} ${PATCH_DATE}" 52 53 strip -x $* 54 /usr/ccs/bin/mcs -d -a "${RELEASE_CM}" $* 55 56 # 57 # Sadly, the runpaths in many binaries end up with the 58 # references to the proto area and other such oddities 59 # in them. Sometimes this is fixable and sometimes it 60 # is not, so lets just give in and fix them up a bit 61 # here. There are a couple of easy things we can do: 62 # 63 # - If we see $(ROOT) in the runpath, we can remove it. 64 # - We can remove duplicate entries (but not change the 65 # order). This is both useful because some things end 66 # up repeated, and because we may have just caused that 67 # if the runpath had $(ROOT)/usr/blah/lib:/usr/blah/lib 68 # in it. 69 # 70 # Things we could do in the future: 71 # 72 # - remove 32-bit directories from 64-bit runpaths and 73 # vice-versa. Harder, but may be useful as it's hard 74 # to tell some software that doesn't know it could 75 # be compiled 64-bit to stop putting the 32-bit 76 # directories in. 77 # - remove /ws/ and /opt/ references. Possibly useful 78 # but usually the result of forgetting -norunpath when 79 # using CC. But as it may be hard to get -norunpath in 80 # all the right places it might be needed. 81 # 82 # Note that currently we cannot end up with an empty 83 # runpath, but if we start deleting things we may, 84 # and then we'd have to delete it completely (we 85 # don't want to set the runpath to the current directory). 86 # 87 for file in $* 88 do 89 rpath=`dump -Lv ${file} | grep RUN | nawk '{print $3}'` 90 if [ -z ${rpath} ]; then 91 # skip files with no runpath 92 continue 93 fi 94 newrpath=`echo ${rpath} | sed -e s,${ROOT},,` 95 newrpath=`echo ${newrpath} | nawk -F: ' 96 BEGIN {first=1;} \ 97 { \ 98 for (i = 1; i <= NF; i++) { \ 99 if (found[$i] == "1") \ 100 continue; \ 101 found[$i] = "1"; \ 102 if (!first) \ 103 printf(":"); \ 104 first=0; \ 105 printf("%s", $i); \ 106 } \ 107 } ' \ 108 ` 109 if [ "${rpath}" = "${newrpath}" ]; then 110 # skip files where the runpath didn't change. 111 continue 112 fi 113 elfedit -e "dyn:runpath ${newrpath}" ${file} 114 echo "${progname} - runpath of ${file} - ${rpath} => ${newrpath}." 115 done 116