commit: 8dd431f54fa807b44b23777066a2284c685a51f2
Author: James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Thu May 22 13:40:53 2025 +0000
Commit: James Le Cuirot <chewi <AT> gentoo <DOT> org>
CommitDate: Thu Jun 5 10:55:03 2025 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8dd431f5
linux-mod-r1.eclass: Fix building with different arch than KV_OUT_DIR
The kernel we're building against may have had its tools (e.g. modpost)
built for the target arch or even some other arch than the we're
building with now. To work around this, rebuild those tools with make
modules_prepare when necessary.
Doing this in pkg_setup is not ideal, but some ebuilds have their own
src_configure and src_compile functions. It will not trigger in the vast
majority of cases, and it is not done when installing binary packages.
Signed-off-by: James Le Cuirot <chewi <AT> gentoo.org>
eclass/linux-mod-r1.eclass | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/eclass/linux-mod-r1.eclass b/eclass/linux-mod-r1.eclass
index 786e0fb79619..91dca82c8f35 100644
--- a/eclass/linux-mod-r1.eclass
+++ b/eclass/linux-mod-r1.eclass
@@ -351,6 +351,8 @@ linux-mod-r1_pkg_setup() {
_modules_set_makeargs
+ _modules_prepare_cross
+
_modules_sanity_gccplugins
}
@@ -668,6 +670,36 @@ _modules_check_migration() {
# - ECONF_PARAMS: documented but was a no-op in linux-mod too
}
+# @FUNCTION: _modules_prepare_cross
+# @INTERNAL
+# @DESCRIPTION:
+# Checks whether modpost works locally as it might have been built for a
+# different architecture. If it doesn't work, it is built in a new
+# environment and KV_OUT_DIR is repointed there.
+_modules_prepare_cross() {
+ # modpost should do nothing successfully when called without args.
+ if ! "${KV_OUT_DIR}"/scripts/mod/modpost &>/dev/null; then
+ # Try to run make modules_prepare in a new separate output
directory.
+ # This cannot be done if the source directory is not clean. In
that
+ # case, copy the whole source directory.
+ if [[ -e ${KV_DIR}/.config ]]; then
+ cp -rLT --reflink=auto -- "${KV_DIR}"
"${WORKDIR}"/extmod-build || die
+ emake -C "${WORKDIR}"/extmod-build
"${MODULES_MAKEARGS[@]}" modules_prepare \
+ KBUILD_OUTPUT=
+ else
+ mkdir -- "${WORKDIR}"/extmod-build || die
+ cp -- "${KV_OUT_DIR}"/{.config,Module.symvers}
"${WORKDIR}"/extmod-build || die
+ # KV_OUT_DIR may have been prepared with
install-extmod-build, which
+ # doesn't include all the files needed to call make
modules_prepare,
+ # so use the Makefile from the full kernel sources.
+ emake -C "${WORKDIR}"/extmod-build
"${MODULES_MAKEARGS[@]}" modules_prepare \
+ KBUILD_OUTPUT="${WORKDIR}"/extmod-build -f
"${KERNEL_MAKEFILE}"
+ fi
+ KV_OUT_DIR=${WORKDIR}/extmod-build
+ KBUILD_OUTPUT=${KBUILD_OUTPUT+${KV_OUT_DIR}}
+ fi
+}
+
# @FUNCTION: _modules_prepare_kernel
# @INTERNAL
# @DESCRIPTION: