libmakepkg: Do not "strip" files when the format is not recognised

We use a multi step process during stripping to ensure permissions do
not get changed.  However, if the initial objcopy fails, the subsequent cat
results in a blank file.  Abandon early if objcopy fails.

Fixes FS#74486

Signed-off-by: Allan McRae <allan@archlinux.org>
(cherry picked from commit 18152a211a)
This commit is contained in:
Allan McRae 2022-05-12 09:45:12 +10:00
parent a1837fa585
commit ce40629b7d

View file

@ -80,7 +80,12 @@ strip_file() {
# copy debug symbols to debug directory # copy debug symbols to debug directory
mkdir -p "$dbgdir/${binary%/*}" mkdir -p "$dbgdir/${binary%/*}"
objcopy --only-keep-debug "$binary" "$dbgdir/$binary.debug"
# abandon processing files that are not a recognised format
if ! objcopy --only-keep-debug "$binary" "$dbgdir/$binary.debug" 2>/dev/null; then
return
fi
local tempfile=$(mktemp "$binary.XXXXXX") local tempfile=$(mktemp "$binary.XXXXXX")
objcopy --add-gnu-debuglink="$dbgdir/${binary#/}.debug" "$binary" "$tempfile" objcopy --add-gnu-debuglink="$dbgdir/${binary#/}.debug" "$binary" "$tempfile"
cat "$tempfile" > "$binary" cat "$tempfile" > "$binary"