2011-01-08 14:33:04 +03:00
#!/bin/sh -efu
2011-01-30 04:20:31 +03:00
#
# brp-debuginfo - generate /usr/lib/debug and /usr/src/debug contents
# for debuginfo packages
#
# Written by Alexey Tourbin <at@altlinux.org>. Based on find-debuginfo.sh
# by Jeff Johnson <jbj@rpm5.org> and Roland McGrath <roland@redhat.com>.
2020-06-24 21:33:29 +03:00
# Copyright (c) 2020 Vitaly Chikunov <vt@altlinux.org>.
2011-01-30 04:20:31 +03:00
# License: GPLv2+.
2011-01-08 14:33:04 +03:00
. @RPMCONFIGDIR@/functions
ValidateBuildRoot
cd "$RPM_BUILD_ROOT"
2011-01-14 06:45:20 +03:00
rm -rf .tmp
mkdir .tmp
# Strip binaries, create .debug files under /usr/lib/debug and install sources into /usr/src/debug.
2013-10-29 04:36:46 +04:00
: ${RPM_DEBUGINFO_SKIPLIST:=}
2020-08-22 17:18:10 +03:00
: ${RPM_DEBUGINFO_STRIPPED_TERMINATE:=}
2013-10-29 04:36:46 +04:00
prune_paths="/lib/firmware /usr/lib/debug /usr/share /usr/src $RPM_DEBUGINFO_SKIPLIST"
prune_tests="$(printf %s "$prune_paths" |
tr '[:space:]' '\n' |
sort -u |
sed -n '/^\// s/.*/ -o -path .&/p')"
find . '(' -path './.*' $prune_tests ')' -prune -o -type f -print |sort |
2021-08-12 13:15:40 +03:00
file4 -NF$'\t' -f - >.tmp/file_full
2020-08-22 02:21:13 +03:00
sed -n -e 's/\t.* ELF .* \(executable\|shared object\), .*, stripped.*//p' <.tmp/file_full >.tmp/fstripped
if [ -s .tmp/fstripped ]; then
howmuch=$(wc -l <.tmp/fstripped)
Warning "You have $howmuch stripped ELF objects. Please compile with debugging information!"
Warning "An excerpt from the list of affected files follows:"
sed 's/^/ /; 10q' <.tmp/fstripped >&2
2020-08-22 17:18:10 +03:00
[ -z "$RPM_DEBUGINFO_STRIPPED_TERMINATE" ] \
|| Fatal "Stripped files found, terminating build"
2020-08-22 02:21:13 +03:00
fi
2017-04-18 19:42:41 +03:00
sed -n -e '/ ELF .* shared object, no machine, /d' \
2020-07-08 11:00:00 +03:00
-e 's/\t.* ELF .* \(executable\|shared object\), .*, not stripped.*//p' \
2020-07-09 11:00:00 +03:00
-e 's/^\(\.\/lib\/modules\/[^[:space:]]\+\.ko\)\t.* ELF .* relocatable, .*, not stripped.*/\1/p' \
2020-07-08 11:00:00 +03:00
-e 's/^\(\.\/lib\/modules\/[^[:space:]]\+\.ko\.[gx]z\)\t.* \(gzip\|xz\) compressed data.*/\1/p' \
2021-11-03 01:55:39 +03:00
-e 's/^\(\.\/lib\/modules\/[^[:space:]]\+\.ko\.zst\)\t.* Zstandard compressed data.*/\1/p' \
2020-08-22 02:21:13 +03:00
-e 's/^\(\.\/boot\/vmlinuz-[^[:space:]]\+\)\t.*/\1/p' <.tmp/file_full |
2011-02-05 00:33:25 +03:00
xargs -r --delimiter='\n' stat -c '%h %i %n' >.tmp/flist
2020-06-22 16:22:10 +03:00
2020-06-24 21:33:29 +03:00
# Filter out what will be hard-linked later and process the rest.
while read -r nlink ino f; do
2011-01-08 14:33:04 +03:00
if [ "$nlink" -gt 1 ]; then
eval f0="\${f0_$ino-}"
if [ -n "$f0" ]; then
2020-06-24 21:33:29 +03:00
printf '%u %s\n' "$ino" "$f" >&3
2011-01-08 14:33:04 +03:00
continue
else
eval f0_$ino="\$f"
fi
fi
2020-06-24 21:33:29 +03:00
printf '%s\n' "$f"
done <.tmp/flist \
2020-07-07 13:40:18 +03:00
>.tmp/xargs-list \
3>.tmp/link-list
xargs -r -P$(nproc) -n1 @RPMCONFIGDIR@/process-debuginfo <.tmp/xargs-list
2020-06-24 21:33:29 +03:00
# Hard-link debuginfo for hard-linked binaries
while read -r ino f; do
debugf=./usr/lib/debug${f#.}.debug
eval f0="\${f0_$ino-}"
debugf0=./usr/lib/debug${f0#.}.debug
if [ -f "$debugf0" ]; then
2011-02-05 00:33:25 +03:00
mkdir -p "${debugf%/*}"
2020-06-24 21:33:29 +03:00
ln -nf "$debugf0" "$debugf"
2011-02-03 10:29:08 +03:00
fi
mkdir -p .debuginfo/src/"${f%/*}"
2020-06-24 21:33:29 +03:00
ln -nf .debuginfo/src/"$f0" .debuginfo/src/"$f"
done <.tmp/link-list
2011-01-14 06:43:13 +03:00
# Make symbolic links that mimic the original tree.
2013-10-29 04:36:46 +04:00
find . '(' -path './.*' $prune_tests ')' -prune -o -type l -print |sort >.tmp/flist
2011-01-14 06:43:13 +03:00
while read -r l; do
f=$(readlink -vm "$l")
f=${f#$RPM_BUILD_ROOT}
debugf=./usr/lib/debug$f.debug
[ -f "$debugf" ] || continue
debugl=./usr/lib/debug${l#.}.debug
mkdir -p "${debugl%/*}"
ln -snf "$(relative "${debugf#.}" "${debugl#.}")" "$debugl"
mkdir -p .debuginfo/links/"${debugf%/*}"
printf '%s\n' "${debugl#.}" >>.debuginfo/links/"$debugf"
2011-02-05 00:33:25 +03:00
done <.tmp/flist
2020-08-21 18:37:48 +03:00
if [ -s .tmp/no_debug_info ]; then
howmuch=$(wc -l < .tmp/no_debug_info)
Warning "$howmuch non-stripped binaries don't contain .debug sections making -debuginfo"
Warning "package less relevant. An excerpt from the list of affected files follows:"
sed 's/^/ /; 10q' < .tmp/no_debug_info >&2
if egrep -q '/lib/modules/.*(/vmlinux|\.ko)$' .tmp/no_debug_info; then
Warning "Please enable CONFIG_DEBUG_INFO=y in the kernel package!"
fi
2020-08-22 17:18:10 +03:00
[ -z "$RPM_DEBUGINFO_STRIPPED_TERMINATE" ] \
|| Fatal "Files with stripped .debug_info found, terminating build"
2020-08-21 18:37:48 +03:00
fi
2020-12-17 01:20:08 +03:00
if [ -n "$(find usr/lib/debug -type f -print -quit 2>/dev/null)" ] &&
[ -z "$(find usr/src/debug -type f -print -quit 2>/dev/null)" ]; then
Warning 'debuginfo without debug sources.'
fi