Generate debuginfo for kernel packages

- Support uncompressed (std-def) and compressed (un-def) modules. Also,
  support xz(1) compression if we'd switch to it.
- If module is uncompressed it stays in the kernel-image rpm, if it's
  compressed then uncompressed module goes into /usr/lib/debug tree and
  will be in debuginfo rpm. Compressed modules will be re-compressed after
  stripping.
- vmlinuz binary triggers extraction of vmlinux from the kernel-source
  tree, and it's then placed into /usr/lib/debug tree, then processed and
  stripped as usual.
- Logic of processing of vmlinux binary for domU packages is not changed.
  Some flavours do not even pack it. Thus, do not remove your
  `%brp_strip_none'.
- Output of file(1) for vmlinuz is only parsed for filename, because, on
  different architectures it detects completely different things.
- Debug files are compressed with `eu-elfcompress'.
- You still need to enable `CONFIG_DEBUG_INFO=y' in for `.config'.
  No other changes to spec should be needed.

Thanks to Nikita Ermakov for starting this work.
This commit is contained in:
Виталий Чикунов 2020-06-22 16:22:10 +03:00
parent 019977a4d4
commit 7aa048df38
2 changed files with 56 additions and 3 deletions

View File

@ -26,9 +26,36 @@ prune_tests="$(printf %s "$prune_paths" |
find . '(' -path './.*' $prune_tests ')' -prune -o -type f -print |sort |
file -NF$'\t' -f - |
sed -n -e '/ ELF .* shared object, no machine, /d' \
-e 's/\t.* ELF .* \(executable\|shared object\), .*, not stripped.*//p' |
-e 's/\t.* ELF .* \(executable\|shared object\|relocatable\), .*, not stripped.*//p' \
-e 's/^\(\.\/lib\/modules\/.*\.ko\.[gx]z\)\t.* \(gzip\|xz\) compressed data.*/\1/p' \
-e 's/^\(\.\/boot\/vmlinuz-.*\)\t.*/\1/p' |
xargs -r --delimiter='\n' stat -c '%h %i %n' >.tmp/flist
while read -r nlink ino f; do
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-}
vmlinuxs=$(set +f; ls "$RPM_BUILD_DIR"/kernel-image-*/kernel-source-*/vmlinux)
vmlinuxd=./usr/lib/debug/lib/modules/$kver/vmlinux
if [ -f "$vmlinuxs" ]; then
install -pD -m644 "$vmlinuxs" "$vmlinuxd"
f=$vmlinuxd
elfcompress=yes
else
echo "Warning: vmlinux not found for -debuginfo" >&2
fi
fi
debugf=./usr/lib/debug${f#.}.debug
if [ "$nlink" -gt 1 ]; then
eval f0="\${f0_$ino-}"
@ -63,6 +90,9 @@ while read -r nlink ino f; do
if [ -n "$strip" ]; then
mkdir -p "${debugf%/*}"
LD_ORIGIN_PATH=/usr/bin eu-strip $strip --remove-comment -f "$debugf" "$f"
if [ -n "$elfcompress" ]; then
LD_ORIGIN_PATH=/usr/bin eu-elfcompress "$debugf"
fi
touch -r .tmp/stamp "$debugf" "$f"
chmod 644 "$debugf"
else
@ -77,6 +107,11 @@ while read -r nlink ino f; do
printf '%s\n' /usr/src/debug/"$src"
done >.debuginfo/src/"$f"
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
done <.tmp/flist
# Make symbolic links that mimic the original tree.

View File

@ -21,6 +21,24 @@ mkdir .tmp
while read -r f; do
f=${f#$RPM_BUILD_ROOT}
if [ -z "${f##/boot/vmlinuz-*}" ]; then
# Redirect to vmlinux saved by debuginfo.brp into debug tree's
# %modules_dir.
kver=${f#/boot/vmlinuz-}
f=/usr/lib/debug/lib/modules/$kver/vmlinux
printf '%s\n' "$f" >> .tmp/files
fi
fbin=$f # Actual binary for linking
if [ -z "${f#/lib/modules/*.ko.[gx]z}" ]; then
# For gzipped modules actual binary is kept in debug tree
# (placed by debuginfo.brp) and goes into -debuginfo package.
f=${f%.[gx]z}
fbin=/usr/lib/debug$f
printf '%s\n' "$fbin" >> .tmp/files
fi
if [ -f .debuginfo/src/"$f" ]; then
LC_ALL=C sort -m -u -o .tmp/src .tmp/src .debuginfo/src/"$f"
fi
@ -43,11 +61,11 @@ while read -r f; do
link=./usr/lib/debug/.build-id/${id:0:2}/${id:2}
if [ ! -L "$link" ]; then
mkdir -p "${link%/*}"
ln -snf "$(relative "$f" "${link#.}")" "$link"
ln -snf "$(relative "$fbin" "${link#.}")" "$link"
ln -snf "$(relative "${debugf#.}" "${link#.}".debug)" "$link".debug
fi
to=$(readlink -vm "$link")
if [ "$to" = "$RPM_BUILD_ROOT$f" ]; then
if [ "$to" = "$RPM_BUILD_ROOT$fbin" ]; then
printf '%s\n' "${link#.}" >> .tmp/links
printf '%s\n' "${link#.}".debug >> .tmp/links
fi