kernel-srpm-macros/macros.kmp
Eugene Syromiatnikov 2571351ab3 Enable extraction of debug information for kmods
This hack temporary adds executable permission for the *.ko files
during post-install stage so they are picked up by find-debuginfo.sh.
Since the intention is to avoid changing of behaviour in non-kmod
workloads, it's done by adding two additional brp-* scripts to the
__spec_install_post macro when kernel_module_package is instantiated.

* brp-kmod-restore-perms: New file.
* brp-kmod-set-exec-bit: Likewise.
* macros.kmp (%__brp_kmod_set_exec_bit, %__brp_kmod_restore_perms,
%__kmod_brps_added): New macros.
(%kernel_module_package): Rewrite __spec_install_post macro.
* redhat-rpm-config.spec (Source701, Source702): Add
brp-kmod-restore-perms and brp-kmod-set-exec-bit.
(Requires): Add find requirement for brp-kmod-set-exec-bit.
(%files): Explicitly list brp-* scripts for redhat-rpm-config and
kernel-rpm-macros packages.

Resolves: #2002887
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
2021-11-18 16:38:10 +01:00

91 lines
4.2 KiB
Plaintext

# Use these macros to differentiate between RH and other KMP implementation(s).
redhat_kernel_module_package 1
kernel_module_package_release 1
%__brp_kmod_set_exec_bit /usr/lib/rpm/redhat/brp-kmod-set-exec-bit
%__brp_kmod_restore_perms /usr/lib/rpm/redhat/brp-kmod-restore-perms
%__kmod_brps_added 0
%__find_provides /usr/lib/rpm/redhat/find-provides
%__find_requires /usr/lib/rpm/redhat/find-requires
#kernel_module_package [ -n name ] [ -v version ] [ -r release ] [ -s script ]
# [ -f filelist] [ -x ] [ -p preamble ] flavor flavor ...
%kernel_module_package_buildreqs %global kmodtool_generate_buildreqs 1 \
kernel-devel kernel-abi-stablelists redhat-rpm-config kernel-rpm-macros elfutils-libelf-devel kmod
%kernel_module_package(n:v:r:s:f:xp:) %{expand:%( \
## An ugly hack: we want kmods to be processed by find-debuginfo,
## but it processes only files with executable permission set.
## It is important now since, as of now, if debuginfo package
## is enabled (and it is enabled), there's an RPM build error
## as a result of lack of ether absence or emptiness of
## debugsourcefiles.list (which is likely a bug in RPM, but it looks
## like that there's no obvious fix and apparently no one have
## any issues with this).
## In order to minimise intrusiveness, usually (in Red Hat-built kmod
## RPMs) *.ko files just have executable permission being set as a part
## of %build section. There are two caveats with kmp, however:
## * We have no control over %build section itself (and it wasn't
## required previously)
## * Changing the criteria used in find-debuginfo.sh/brp-strip
## for selecting files that have to undergo debug section separation
## may introduce regression.
## As a result, we insert additional hooks in __spec_install_post
## (__brp_kmod_set_exec_bit in the beginning and
## __brp_kmod_restore_perms in the end) that (temporarily) set
## executable permission for *.ko files so find-debuginfo.sh will pick
## them up.
## Unfortunately, __spec_install_post's body is copied here since
## we want that __debug_package macro expansion has been performed
## lazily and it looks like RPM has no ability to provide a body
## of a macro verbatim.
if [ 0 = "%{__kmod_brps_added}" ]; then \
echo "%%global __spec_install_post \\\\" \
echo " %%{?__brp_kmod_set_exec_bit} \\\\" \
echo " %%%%{?__debug_package:%%%%{__debug_install_post}} \\\\" \
echo " %%{__arch_install_post} \\\\" \
echo " %%{__os_install_post} \\\\" \
echo " %%{?__brp_kmod_restore_perms} \\\\" \
echo "%%{nil}" \
fi \
%global __kmod_brps_added 1 \
%global kmodtool %{-s*}%{!-s:/usr/lib/rpm/redhat/kmodtool} \
%global kmod_version %{-v*}%{!-v:%{version}} \
%global kmod_release %{-r*}%{!-r:%{release}} \
%global latest_kernel %({ rpm -q --qf '%%{VERSION}-%%{RELEASE}.%%{ARCH}\\\\n' `rpm -qa | egrep "^kernel(-rt|-aarch64)?-devel" | /usr/lib/rpm/redhat/rpmsort -r | head -n 1`; echo '%%%%{nil}'; } | head -n 1) \
%{!?kernel_version:%{expand:%%global kernel_version %{latest_kernel}}} \
%global kverrel %(%{kmodtool} verrel %{?kernel_version} 2>/dev/null) \
flavors="default" \
if [ -z "%*" ]; then \
flavors_to_build=$flavors \
elif [ -z "%{-x}" ]; then \
flavors_to_build="%*" \
else \
flavors_to_build=" $flavors "\
for i in %* \
do \
flavors_to_build=${flavors_to_build//$i /}
done \
fi \
echo "%%global flavors_to_build ${flavors_to_build:-%%nil}" \
echo "%%global kernel_source() \\\$([ default = \"%%%%{1}\" ] && echo \"/usr/src/kernels//%%%%kverrel\" || %{kmodtool} kernel_source \"%%%%{kverrel}\" \"%%%%{1}\" 2>/dev/null || { ls -Ud \"/usr/src/kernels///%%%%{kverrel}\"[.+]\"%%%%{1}\" | sort -V | tail -n 1; } || echo \"/usr/src/kernels////%%%%kverrel.%%%%1\")" \
echo "%%global kernel_module_package_moddir() extra" \
if [ ! -z "%{-f*}" ] \
then \
filelist="%{-f*}" \
fi \
if [ ! -z "%{-p*}" ] \
then \
preamble="%{-p*}" \
fi \
nobuildreqs="yes" \
if [ "x%{kmodtool_generate_buildreqs}" != "x1" ] \
then \
nobuildreqs="no" \
fi \
override_filelist="$filelist" override_preamble="$preamble" nobuildreqs="$nobuildreqs" kmod_version=%kmod_version kmod_release=%kmod_release %{kmodtool} rpmtemplate %{-n*}%{!-n:%name} %{kverrel} $flavors_to_build 2>/dev/null \
)}