File: [local] / src / usr.bin / ctfconv / ctfstrip (download)
Revision 1.4, Sat Aug 12 16:33:11 2017 UTC (6 years, 9 months ago) by jasper
Branch: MAIN
Changes since 1.3: +26 -13 lines
fallback to strip(1) in case ctfconv(1) couldn't handle the file (i.e. when
the input file lacks useful debug sections).
adjust option handling accordingly to pass any flags not handled by
ctfstrip(1) down to strip(1).
help and ok mpi@ tb@
|
#!/bin/sh
#
# $OpenBSD: ctfstrip,v 1.4 2017/08/12 16:33:11 jasper Exp $
#
# Copyright (c) 2017 Martin Pieuchot
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
set -o posix
cleanup() {
rm -f ${TMPFILE}
exit 1
}
trap "cleanup" 1 2 3 13 15
USAGE="usage: ${0##*/} [-S] [-o outfile] file"
for arg in "$@"; do
if [ -n "$OSET" ]; then
OUTFILE="$arg"
unset OSET
shift
continue
fi
case "$arg" in
-o) OSET=1; shift; continue;;
-S) STRIPFLAG=-g; shift; continue;;
esac
shift
set -- "$@" "$arg"
done
if [[ $# == 0 ]]; then
print -u2 "${USAGE}";
exit 1
fi
LABEL="unknown"
TMPFILE=$(mktemp /tmp/.ctf.XXXXXXXXXX)
INFILE=$(eval "echo \${$#}")
# Extract kernel version
if [[ "$INFILE" == bsd* ]]; then
LABEL=`what $INFILE |tr -d '\n'|awk -F"${INFILE} " '{ print $2 '\n' }'`
fi
# If ctfstrip was passed a file that lacks useful debug sections, ctfconv will fail.
# So try to run ctfconv and silently fallback to plain strip(1) if that failed.
ctfconv -o ${TMPFILE} -l "${LABEL}" ${INFILE} 2> /dev/null
if [[ $? == 0 ]]; then
objcopy --add-section .SUNW_ctf=${TMPFILE} ${STRIPFLAG} ${INFILE} ${OUTFILE}
else
strip ${STRIPFLAG} $@ -o ${OUTFILE} ${INFILE}
fi
rm -f ${TMPFILE}