public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 1/3] eclass/kernel-{build,install}.eclass: link to config,Sys.map in moddir
@ 2024-07-24  9:52 Andrew Ammerlaan
  2024-07-24  9:52 ` [gentoo-dev] [PATCH 2/3] kernel-build.eclass: fix determining kernel release with MODULES=n Andrew Ammerlaan
  2024-07-24  9:52 ` [gentoo-dev] [PATCH 3/3] kernel-build.eclass: set toolchain variables more comprehensibly Andrew Ammerlaan
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Ammerlaan @ 2024-07-24  9:52 UTC (permalink / raw
  To: gentoo-dev; +Cc: Andrew Ammerlaan

The kernels 'make rpm-pkg' and 'make deb-pkg' install the config
and System.map into the modules directory for easy access. Let's
do the same here so our gpkg's are more symetric to rpm's and
deb's and tools that look for these files there can find it.

This also provides an easy location for the user to access the
config. Considering that /boot/config-x.y.z does not always
exist (the config instalation via /sbin/installkernel depends
on layout and +/-systemd configuration).

Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
Closes: https://github.com/gentoo/gentoo/pull/37684
Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
---
 eclass/kernel-build.eclass   | 2 ++
 eclass/kernel-install.eclass | 7 +++++++
 2 files changed, 9 insertions(+)

diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index be0256c21102..29719609b912 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -448,6 +448,8 @@ kernel-build_src_install() {
 	# fix source tree and build dir symlinks
 	dosym "../../../${kernel_dir}" "/lib/modules/${KV_FULL}/build"
 	dosym "../../../${kernel_dir}" "/lib/modules/${KV_FULL}/source"
+	dosym "../../../${kernel_dir}/.config" "/lib/modules/${KV_FULL}/config"
+	dosym "../../../${kernel_dir}/System.map" "/lib/modules/${KV_FULL}/System.map"
 	if [[ "${image_path}" == *vmlinux* ]]; then
 		dosym "../../../${kernel_dir}/${image_path}" "/lib/modules/${KV_FULL}/vmlinux"
 	else
diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass
index e6f0b404dcaa..0a85bfb8629d 100644
--- a/eclass/kernel-install.eclass
+++ b/eclass/kernel-install.eclass
@@ -623,6 +623,13 @@ kernel-install_pkg_preinst() {
 		rm "${ED}/lib/modules/${KV_FULL}"/{build,source} || die
 		dosym "../../../src/linux-${KV_FULL}" "/usr/lib/modules/${KV_FULL}/build"
 		dosym "../../../src/linux-${KV_FULL}" "/usr/lib/modules/${KV_FULL}/source"
+		local file
+		for file in .config System.map; do
+			if [[ -L "${ED}/lib/modules/${KV_FULL}/${file#.}" ]]; then
+				rm "${ED}/lib/modules/${KV_FULL}/${file#.}" || die
+				dosym "../../../src/linux-${KV_FULL}/${file}" "/usr/lib/modules/${KV_FULL}/${file#.}"
+			fi
+		done
 		for file in vmlinux vmlinuz; do
 			if [[ -L "${ED}/lib/modules/${KV_FULL}/${file}" ]]; then
 				rm "${ED}/lib/modules/${KV_FULL}/${file}" || die
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-dev] [PATCH 2/3] kernel-build.eclass: fix determining kernel release with MODULES=n
  2024-07-24  9:52 [gentoo-dev] [PATCH 1/3] eclass/kernel-{build,install}.eclass: link to config,Sys.map in moddir Andrew Ammerlaan
@ 2024-07-24  9:52 ` Andrew Ammerlaan
  2024-07-24  9:52 ` [gentoo-dev] [PATCH 3/3] kernel-build.eclass: set toolchain variables more comprehensibly Andrew Ammerlaan
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Ammerlaan @ 2024-07-24  9:52 UTC (permalink / raw
  To: gentoo-dev; +Cc: Andrew Ammerlaan

For module-less kernels 'make modules_prepare' does nothing, we only get
kernel.release after running src_compile. Luckily the kernel has the
"kernelrelease" target which we can use for this purpose.

Note, in kernel-install.eclass we still read the kernel release directly from
the file since a) kernel.release will always exist and b) calling make there
again would require duplicating (some subset off) ${MAKEARGS[@]}.

The "make help" page specifies that this target should be called with "-s".

The version check is moved up, before 'make modules_prepare' so we quit earlier
if the KV_FULL is wrong. Note it should be run after we have completed the
config in 'make olddefconfig'.

Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
Closes: https://github.com/gentoo/gentoo/pull/37694
Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
---
 eclass/kernel-build.eclass | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index 29719609b912..f478cf636a27 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -253,25 +253,21 @@ kernel-build_src_configure() {
 	mkdir -p "${WORKDIR}"/modprep || die
 	mv .config "${WORKDIR}"/modprep/ || die
 	emake O="${WORKDIR}"/modprep "${MAKEARGS[@]}" olddefconfig
-	emake O="${WORKDIR}"/modprep "${MAKEARGS[@]}" modules_prepare
-	cp -pR "${WORKDIR}"/modprep "${WORKDIR}"/build || die
 
-	# Now that we have a release file, set KV_FULL
-	local relfile=${WORKDIR}/build/include/config/kernel.release
+	local k_release=$(emake -s O="${WORKDIR}"/modprep "${MAKEARGS[@]}" kernelrelease)
 	if [[ -z ${KV_FULL} ]]; then
-		KV_FULL=$(<"${relfile}") || die
+		KV_FULL=${k_release}
 	fi
 
 	# Make sure we are about to build the correct kernel
 	if [[ ${PV} != *9999 ]]; then
 		local expected_ver=$(dist-kernel_PV_to_KV "${PV}")
-		local expected_rel=$(<"${relfile}")
 
-		if [[ ${KV_FULL} != ${expected_rel} ]]; then
+		if [[ ${KV_FULL} != ${k_release} ]]; then
 			eerror "KV_FULL mismatch!"
 			eerror "KV_FULL:  ${KV_FULL}"
-			eerror "Expected: ${expected_rel}"
-			die "KV_FULL mismatch: got ${KV_FULL}, expected ${expected_rel}"
+			eerror "Expected: ${k_release}"
+			die "KV_FULL mismatch: got ${KV_FULL}, expected ${k_release}"
 		fi
 
 		if [[ ${KV_FULL} != ${expected_ver}* ]]; then
@@ -282,6 +278,9 @@ kernel-build_src_configure() {
 			die "Kernel version mismatch: got ${KV_FULL}, expected ${expected_ver}*"
 		fi
 	fi
+
+	emake O="${WORKDIR}"/modprep "${MAKEARGS[@]}" modules_prepare
+	cp -pR "${WORKDIR}"/modprep "${WORKDIR}"/build || die
 }
 
 # @FUNCTION: kernel-build_src_compile
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-dev] [PATCH 3/3] kernel-build.eclass: set toolchain variables more comprehensibly
  2024-07-24  9:52 [gentoo-dev] [PATCH 1/3] eclass/kernel-{build,install}.eclass: link to config,Sys.map in moddir Andrew Ammerlaan
  2024-07-24  9:52 ` [gentoo-dev] [PATCH 2/3] kernel-build.eclass: fix determining kernel release with MODULES=n Andrew Ammerlaan
@ 2024-07-24  9:52 ` Andrew Ammerlaan
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Ammerlaan @ 2024-07-24  9:52 UTC (permalink / raw
  To: gentoo-dev; +Cc: Alfred Wingate, Andrew Ammerlaan

From: Alfred Wingate <parona@protonmail.com>

Building on llvm profiles is problematic if toolchain variables are not properly
set. So set HOSTLD and HOSTAR to match at least the kernels own LLVM=1 variable
to ensure a smoother build for end users.

For example an unset HOSTLD causes issues as it defaults to GNU ld
otherwise.

https://docs.kernel.org/kbuild/llvm.html#the-llvm-argument

Signed-off-by: Alfred Wingate <parona@protonmail.com>
Closes: https://github.com/gentoo/gentoo/pull/37690
Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
---
 eclass/kernel-build.eclass | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index f478cf636a27..893a1bdb449c 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -187,6 +187,10 @@ kernel-build_src_configure() {
 	fi
 
 	# force ld.bfd if we can find it easily
+	local HOSTLD="$(tc-getBUILD_LD)"
+	if type -P "${HOSTLD}.bfd" &>/dev/null; then
+		HOSTLD+=.bfd
+	fi
 	local LD="$(tc-getLD)"
 	if type -P "${LD}.bfd" &>/dev/null; then
 		LD+=.bfd
@@ -198,6 +202,8 @@ kernel-build_src_configure() {
 
 		HOSTCC="$(tc-getBUILD_CC)"
 		HOSTCXX="$(tc-getBUILD_CXX)"
+		HOSTLD="${HOSTLD}"
+		HOSTAR="$(tc-getBUILD_AR)"
 		HOSTCFLAGS="${BUILD_CFLAGS}"
 		HOSTLDFLAGS="${BUILD_LDFLAGS}"
 
@@ -210,6 +216,7 @@ kernel-build_src_configure() {
 		STRIP="$(tc-getSTRIP)"
 		OBJCOPY="$(tc-getOBJCOPY)"
 		OBJDUMP="$(tc-getOBJDUMP)"
+		READELF="$(tc-getREADELF)"
 
 		# we need to pass it to override colliding Gentoo envvar
 		ARCH=$(tc-arch-kernel)
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-07-24  9:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-24  9:52 [gentoo-dev] [PATCH 1/3] eclass/kernel-{build,install}.eclass: link to config,Sys.map in moddir Andrew Ammerlaan
2024-07-24  9:52 ` [gentoo-dev] [PATCH 2/3] kernel-build.eclass: fix determining kernel release with MODULES=n Andrew Ammerlaan
2024-07-24  9:52 ` [gentoo-dev] [PATCH 3/3] kernel-build.eclass: set toolchain variables more comprehensibly Andrew Ammerlaan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox