diff mbox series

kernel.bbclass: Set pkg-config variables for building modules

Message ID 20240222202827.3675576-1-kamatam@amazon.com
State Accepted, archived
Commit cd2072e5d953af981339427028e19083257e6a92
Headers show
Series kernel.bbclass: Set pkg-config variables for building modules | expand

Commit Message

Munehisa Kamata Feb. 22, 2024, 8:28 p.m. UTC
The pkg-config workaround has been applied for kernel image building, but
not for module building. On x86, this can trigger rebuilding of objtool
unnecessary at do_compile_kernelmodules task. If the kernel is built with
CONFIG_DEBUG_INFO_BTF=y, the task even rebuilds vmlinux and leads to
inconsistent build-id between bzImage and vmlinux, and also BTF mismatches
between the bzImage and modules.

To avoid the inconsistency, apply the same workaround when building
modules. For kernels 5.19+, simply set HOSTPKG_CONFIG in the make command
line.

Signed-off-by: Munehisa Kamata <kamatam@amazon.com>
---
 meta/classes-recipe/kernel.bbclass | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Bruce Ashfield Feb. 22, 2024, 9:38 p.m. UTC | #1
On Thu, Feb 22, 2024 at 3:28 PM Munehisa Kamata via
lists.openembedded.org <kamatam=amazon.com@lists.openembedded.org>
wrote:
>
> The pkg-config workaround has been applied for kernel image building, but
> not for module building. On x86, this can trigger rebuilding of objtool
> unnecessary at do_compile_kernelmodules task. If the kernel is built with
> CONFIG_DEBUG_INFO_BTF=y, the task even rebuilds vmlinux and leads to
> inconsistent build-id between bzImage and vmlinux, and also BTF mismatches
> between the bzImage and modules.

I don't question the change, as it is what I had to do for the mail
kernel build.

What I would like to see logged is a set of steps that managed to trigger the
issue.

Since the module builds are dependent on the main kernel, everything that they
need should be available and already timestamped to not be required, so the
missing pkconfig shouldn't trigger much.

That way we'll know if there's a gap somewhere in the dependencies, or another
race condition and we can test for it.

Bruce

>
> To avoid the inconsistency, apply the same workaround when building
> modules. For kernels 5.19+, simply set HOSTPKG_CONFIG in the make command
> line.
>
> Signed-off-by: Munehisa Kamata <kamatam@amazon.com>
> ---
>  meta/classes-recipe/kernel.bbclass | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/meta/classes-recipe/kernel.bbclass b/meta/classes-recipe/kernel.bbclass
> index a76aaee5ba..db4461e551 100644
> --- a/meta/classes-recipe/kernel.bbclass
> +++ b/meta/classes-recipe/kernel.bbclass
> @@ -239,6 +239,8 @@ KERNEL_EXTRA_ARGS ?= ""
>  EXTRA_OEMAKE += ' CC="${KERNEL_CC}" LD="${KERNEL_LD}" OBJCOPY="${KERNEL_OBJCOPY}" STRIP="${KERNEL_STRIP}"'
>  EXTRA_OEMAKE += ' HOSTCC="${BUILD_CC}" HOSTCFLAGS="${BUILD_CFLAGS}" HOSTLDFLAGS="${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}"'
>  EXTRA_OEMAKE += ' HOSTCXX="${BUILD_CXX}" HOSTCXXFLAGS="${BUILD_CXXFLAGS}"'
> +# Only for newer kernels (5.19+), native pkg-config variables are set for older kernels when building kernel and modules
> +EXTRA_OEMAKE += ' HOSTPKG_CONFIG="pkg-config-native"'
>
>  KERNEL_ALT_IMAGETYPE ??= ""
>
> @@ -356,9 +358,6 @@ kernel_do_compile() {
>         export PKG_CONFIG_LIBDIR="$PKG_CONFIG_DIR"
>         export PKG_CONFIG_SYSROOT_DIR=""
>
> -       # for newer kernels (5.19+) there's a dedicated variable
> -       export HOSTPKG_CONFIG="pkg-config-native"
> -
>         if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then
>                 # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
>                 # be set....
> @@ -408,6 +407,13 @@ addtask transform_kernel after do_compile before do_install
>
>  do_compile_kernelmodules() {
>         unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
> +
> +       # setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
> +       export PKG_CONFIG_DIR="${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig"
> +       export PKG_CONFIG_PATH="$PKG_CONFIG_DIR:${STAGING_DATADIR_NATIVE}/pkgconfig"
> +       export PKG_CONFIG_LIBDIR="$PKG_CONFIG_DIR"
> +       export PKG_CONFIG_SYSROOT_DIR=""
> +
>         if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then
>                 # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
>                 # be set....
> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#196041): https://lists.openembedded.org/g/openembedded-core/message/196041
> Mute This Topic: https://lists.openembedded.org/mt/104516377/1050810
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [bruce.ashfield@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
diff mbox series

Patch

diff --git a/meta/classes-recipe/kernel.bbclass b/meta/classes-recipe/kernel.bbclass
index a76aaee5ba..db4461e551 100644
--- a/meta/classes-recipe/kernel.bbclass
+++ b/meta/classes-recipe/kernel.bbclass
@@ -239,6 +239,8 @@  KERNEL_EXTRA_ARGS ?= ""
 EXTRA_OEMAKE += ' CC="${KERNEL_CC}" LD="${KERNEL_LD}" OBJCOPY="${KERNEL_OBJCOPY}" STRIP="${KERNEL_STRIP}"'
 EXTRA_OEMAKE += ' HOSTCC="${BUILD_CC}" HOSTCFLAGS="${BUILD_CFLAGS}" HOSTLDFLAGS="${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}"'
 EXTRA_OEMAKE += ' HOSTCXX="${BUILD_CXX}" HOSTCXXFLAGS="${BUILD_CXXFLAGS}"'
+# Only for newer kernels (5.19+), native pkg-config variables are set for older kernels when building kernel and modules
+EXTRA_OEMAKE += ' HOSTPKG_CONFIG="pkg-config-native"'
 
 KERNEL_ALT_IMAGETYPE ??= ""
 
@@ -356,9 +358,6 @@  kernel_do_compile() {
 	export PKG_CONFIG_LIBDIR="$PKG_CONFIG_DIR"
 	export PKG_CONFIG_SYSROOT_DIR=""
 
-	# for newer kernels (5.19+) there's a dedicated variable
-	export HOSTPKG_CONFIG="pkg-config-native"
-
 	if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then
 		# kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
 		# be set....
@@ -408,6 +407,13 @@  addtask transform_kernel after do_compile before do_install
 
 do_compile_kernelmodules() {
 	unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
+
+	# setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
+	export PKG_CONFIG_DIR="${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig"
+	export PKG_CONFIG_PATH="$PKG_CONFIG_DIR:${STAGING_DATADIR_NATIVE}/pkgconfig"
+	export PKG_CONFIG_LIBDIR="$PKG_CONFIG_DIR"
+	export PKG_CONFIG_SYSROOT_DIR=""
+
 	if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then
 		# kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
 		# be set....