diff options
author | 2017-08-12 16:33:11 +0000 | |
---|---|---|
committer | 2017-08-12 16:33:11 +0000 | |
commit | d7477b103106e34e026e137089d96d326107e74e (patch) | |
tree | 123ff0a489ffbd9677620a6864130ceac7635862 /usr.bin/ctfconv | |
parent | Make not yet implemented pledges more visible in grep output. (diff) | |
download | wireguard-openbsd-d7477b103106e34e026e137089d96d326107e74e.tar.xz wireguard-openbsd-d7477b103106e34e026e137089d96d326107e74e.zip |
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@
Diffstat (limited to 'usr.bin/ctfconv')
-rwxr-xr-x | usr.bin/ctfconv/ctfstrip | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/usr.bin/ctfconv/ctfstrip b/usr.bin/ctfconv/ctfstrip index cca1117e579..ebb7cbbbdd4 100755 --- a/usr.bin/ctfconv/ctfstrip +++ b/usr.bin/ctfconv/ctfstrip @@ -1,8 +1,8 @@ #!/bin/sh # -# $OpenBSD: ctfstrip,v 1.3 2017/08/11 15:08:16 jasper Exp $ +# $OpenBSD: ctfstrip,v 1.4 2017/08/12 16:33:11 jasper Exp $ # -# Copyright (c) 2017 Martin Pieuchot +# 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 @@ -27,14 +27,20 @@ trap "cleanup" 1 2 3 13 15 USAGE="usage: ${0##*/} [-S] [-o outfile] file" -while getopts "o:S" opt; do - case $opt in - S) STRIPFLAG=-g;; - o) OUTFILE="${OPTARG}";; - *) print -u2 "${USAGE}"; exit 1;; +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 -shift $((OPTIND-1)) if [[ $# == 0 ]]; then print -u2 "${USAGE}"; @@ -43,14 +49,21 @@ fi LABEL="unknown" TMPFILE=$(mktemp /tmp/.ctf.XXXXXXXXXX) +INFILE=$(eval "echo \${$#}") # Extract kernel version -if [[ "$1" == bsd* ]]; then - LABEL=`what $1 |tr -d '\n'|awk -F"$1 " '{ print $2 '\n' }'` +if [[ "$INFILE" == bsd* ]]; then + LABEL=`what $INFILE |tr -d '\n'|awk -F"${INFILE} " '{ print $2 '\n' }'` fi -ctfconv -o ${TMPFILE} -l "${LABEL}" $1 || cleanup +# 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 -objcopy --add-section .SUNW_ctf=${TMPFILE} ${STRIPFLAG} $1 ${OUTFILE} +if [[ $? == 0 ]]; then + objcopy --add-section .SUNW_ctf=${TMPFILE} ${STRIPFLAG} ${INFILE} ${OUTFILE} +else + strip ${STRIPFLAG} $@ -o ${OUTFILE} ${INFILE} +fi rm -f ${TMPFILE} |