2020-06-24 21:33:29 +03:00
#!/bin/sh -efu
#
# Process single file for debuginfo business.
# (Will be run multiple instances in parallel.)
#
# Copyright (c) 2020 Vitaly Chikunov <vt@altlinux.org>. Based on brp-debuginfo
# written by Alexey Tourbin <at@altlinux.org>. Based on find-debuginfo.sh
# by Jeff Johnson <jbj@rpm5.org> and Roland McGrath <roland@redhat.com>.
# License: GPLv2+.
. @RPMCONFIGDIR@/functions
ValidateBuildRoot
cd "$RPM_BUILD_ROOT"
mkdir -p .tmp
f=$1
rezip=
elfcompress=
if [ -z "${f#./lib/modules/*.ko}" ]; then
elfcompress=yes
elif [ -z "${f#./lib/modules/*.ko.[gx]z}" ]; then
rezip=${f##*.}
rezip=${rezip/gz/gzip}
# Compressed module: uncompress it, and work with uncompressed one.
$rezip --decompress --force "$f"
f=${f%.[gx]z}
elfcompress=yes
elif [ -z "${f##./boot/vmlinuz-*}" ]; then
# Compressed kernel: trigger extraction of vmlinux from the source.
kver=${f#./boot/vmlinuz-}
2020-07-06 23:50:42 +03:00
vmlinuxs=$(find "$RPM_BUILD_DIR" -depth -maxdepth 3 -type f -name vmlinux -print -quit)
2020-06-24 21:33:29 +03:00
vmlinuxd=./usr/lib/debug/lib/modules/$kver/vmlinux
if [ -f "$vmlinuxs" ]; then
install -pD -m644 "$vmlinuxs" "$vmlinuxd"
f=$vmlinuxd
else
echo "Warning: vmlinux not found for -debuginfo" >&2
2020-07-06 23:50:42 +03:00
exit
2020-06-24 21:33:29 +03:00
fi
fi
debugf=./usr/lib/debug${f#.}.debug
strip='--strip-all'
for pat in ${RPM_BRP_STRIP_DEBUG-}; do
if [ -z "${f##.$pat}" ]; then
strip='--strip-debug'
break
fi
done
for pat in ${RPM_BRP_STRIP_NONE-}; do
if [ -z "${f##.$pat}" ]; then
strip=
break
fi
done
timestamp=$(date --iso-8601=ns --reference="$f")
@RPMCONFIGDIR@/debugedit -b "$RPM_BUILD_DIR" -d /usr/src/debug -l .tmp/src.$$ "$f"
if [ -n "$strip" ]; then
mkdir -p "${debugf%/*}"
LD_ORIGIN_PATH=/usr/bin eu-strip $strip --remove-comment -f "$debugf" "$f"
2020-07-09 18:20:51 +03:00
if [ -n "$elfcompress" ] && [ -x /usr/bin/eu-elfcompress ]; then
2020-06-24 21:33:29 +03:00
LD_ORIGIN_PATH=/usr/bin eu-elfcompress --quiet "$debugf"
fi
touch --date=$timestamp "$debugf" "$f"
chmod 644 "$debugf"
else
touch --date=$timestamp "$f"
fi
mkdir -p .debuginfo/src/"${f%/*}"
awk 'BEGIN{RS="\0";ORS="\n"}{print}' .tmp/src.$$ |LC_ALL=C sort -u |
while read -r src; do
[ -f "$RPM_BUILD_DIR"/"$src" ] || continue
if [ ! -f ./usr/src/debug/"$src" ]; then
install -pD -m644 "$RPM_BUILD_DIR"/"$src" ./usr/src/debug/"$src".$$
mv -f ./usr/src/debug/"$src".$$ ./usr/src/debug/"$src"
fi
printf '%s\n' /usr/src/debug/"$src"
done >.debuginfo/src/"$f"
2020-08-21 18:37:48 +03:00
[ -s .tmp/src.$$ ] || printf '%s\n' "$f" >> .tmp/no_debug_info
2020-06-24 21:33:29 +03:00
rm .tmp/src.$$
if [ -n "$rezip" ]; then
# Compress module, move uncompressed into debug tree.
$rezip --keep --force "$f"
mv "$f" ./usr/lib/debug"${f#.}"
fi