All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] toolchain/toolchain-external: introduce BR2_TOOLCHAIN_EXTERNAL_UPDATE_LINUX_HEADERS
@ 2025-11-12 17:43 Rustam Abdullaev
  0 siblings, 0 replies; 2+ messages in thread
From: Rustam Abdullaev @ 2025-11-12 17:43 UTC (permalink / raw)
  To: buildroot; +Cc: Giulio Benetti, Romain Naour, Thomas Petazzoni

This change makes it possible to update kernel headers in the external
toolchain with the headers from the current kernel.

It is important to have matching kernel headers when building packages
that make use of kernel features such as seccomp, as they depend on
system call definitions in linux/unistd.h. A typical example of this is
openssh - building it with the official ARM GNU toolchain and kernel 6.x
results in a non-working sshd.

Signed-off-by: Rustam Abdullaev <rustamabd@gmail.com>
---
 package/linux-headers/linux-headers.mk               |  3 ++-
 toolchain/Config.in                                  |  6 ++++++
 toolchain/helpers.mk                                 |  4 +---
 toolchain/toolchain-buildroot/Config.in              |  2 --
 toolchain/toolchain-external/Config.in               |  9 +++++++++
 .../toolchain-external/pkg-toolchain-external.mk     | 12 +++++++++++-
 6 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/package/linux-headers/linux-headers.mk b/package/linux-headers/linux-headers.mk
index e2a0b7a7c9..d738bd3e9b 100644
--- a/package/linux-headers/linux-headers.mk
+++ b/package/linux-headers/linux-headers.mk
@@ -5,7 +5,8 @@
 ################################################################################
 
 # This package is used to provide Linux kernel headers for the
-# internal toolchain backend.
+# internal toolchain backend and for external toolchains that need
+# updated kernel headers.
 
 # Set variables depending on whether we are using headers from a kernel
 # build or a standalone header package.
diff --git a/toolchain/Config.in b/toolchain/Config.in
index b3cbec8377..c02d77c08e 100644
--- a/toolchain/Config.in
+++ b/toolchain/Config.in
@@ -69,6 +69,12 @@ source "toolchain/toolchain-external/Config.in"
 # so put it here instead
 source "package/gdb/Config.in.host"
 
+# Linux headers can be used by both internal and external toolchains
+if BR2_TOOLCHAIN_BUILDROOT || BR2_TOOLCHAIN_EXTERNAL_UPDATE_LINUX_HEADERS
+source "package/linux-headers/Config.in.host"
+source "package/linux-headers/Config.in"
+endif
+
 comment "Toolchain Generic Options"
 
 # https://sourceware.org/bugzilla/show_bug.cgi?id=27597
diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk
index 08ee6060b0..b5cf2b7971 100644
--- a/toolchain/helpers.mk
+++ b/toolchain/helpers.mk
@@ -165,11 +165,9 @@ copy_toolchain_sysroot = \
 # $2: sysroot directory
 # $3: kernel version string, in the form: X.Y
 # $4: test to do for the latest kernel version, 'strict' or 'loose'
-#     always 'strict' if this is not the latest version.
 #
 check_kernel_headers_version = \
-	if ! support/scripts/check-kernel-headers.sh $(1) $(2) $(3) \
-		$(if $(BR2_TOOLCHAIN_HEADERS_LATEST),$(4),strict); \
+	if ! support/scripts/check-kernel-headers.sh $(1) $(2) $(3) $(4) ; \
 	then \
 		exit 1; \
 	fi
diff --git a/toolchain/toolchain-buildroot/Config.in b/toolchain/toolchain-buildroot/Config.in
index 64f7892f98..ebebe263db 100644
--- a/toolchain/toolchain-buildroot/Config.in
+++ b/toolchain/toolchain-buildroot/Config.in
@@ -104,8 +104,6 @@ config BR2_TOOLCHAIN_BUILDROOT_LIBC
 	default "glibc"  if BR2_TOOLCHAIN_BUILDROOT_GLIBC
 	default "musl"	 if BR2_TOOLCHAIN_BUILDROOT_MUSL
 
-source "package/linux-headers/Config.in.host"
-source "package/linux-headers/Config.in"
 source "package/musl/Config.in"
 source "package/uclibc/Config.in"
 source "package/glibc/Config.in"
diff --git a/toolchain/toolchain-external/Config.in b/toolchain/toolchain-external/Config.in
index c1c159cb8e..d364f92a95 100644
--- a/toolchain/toolchain-external/Config.in
+++ b/toolchain/toolchain-external/Config.in
@@ -157,4 +157,13 @@ config BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY
 	  Copy the gdbserver provided by the external toolchain to the
 	  target.
 
+config BR2_TOOLCHAIN_EXTERNAL_UPDATE_LINUX_HEADERS
+	bool "Update kernel headers"
+	select BR2_PACKAGE_LINUX_HEADERS
+	help
+	  Select this option to update the kernel headers in the
+	  external toolchain with headers from the kernel being built.
+	  This is useful when the external toolchain has older kernel
+	  headers than the kernel being built.
+
 endif # BR2_TOOLCHAIN_EXTERNAL
diff --git a/toolchain/toolchain-external/pkg-toolchain-external.mk b/toolchain/toolchain-external/pkg-toolchain-external.mk
index c37f3500d9..6527601773 100644
--- a/toolchain/toolchain-external/pkg-toolchain-external.mk
+++ b/toolchain/toolchain-external/pkg-toolchain-external.mk
@@ -557,19 +557,29 @@ $(2)_POST_EXTRACT_HOOKS += \
 	TOOLCHAIN_EXTERNAL_MOVE
 endif
 
+ifeq ($$(BR2_PACKAGE_LINUX_HEADERS),y)
+$(2)_DEPENDENCIES += linux-headers
+endif
+
 # Checks for an already installed toolchain: check the toolchain
 # location, check that it is usable, and then verify that it
 # matches the configuration provided in Buildroot: ABI, C++ support,
 # kernel headers version, type of C library and all C library features.
+# Also updates the kernel headers in the toolchain, if requested.
 define $(2)_CONFIGURE_CMDS
 	$$(Q)$$(call check_cross_compiler_exists,$$(TOOLCHAIN_EXTERNAL_CC))
 	$$(Q)$$(call check_unusable_toolchain,$$(TOOLCHAIN_EXTERNAL_CC),"$$(TOOLCHAIN_EXTERNAL_CFLAGS)")
 	$$(Q)SYSROOT_DIR="$$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC))" ; \
+	if test "$$(BR2_PACKAGE_LINUX_HEADERS)" = "y" ; then \
+		echo "Updating kernel headers in the external toolchain..." ; \
+		rsync -a $$(STAGING_DIR)/usr/include/ \
+			$$$${SYSROOT_DIR}/usr/include/ ; \
+	fi ; \
 	$$(call check_kernel_headers_version,\
 		$$(BUILD_DIR),\
 		$$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC)),\
 		$$(call qstrip,$$(BR2_TOOLCHAIN_HEADERS_AT_LEAST)),\
-		$$(if $$(BR2_TOOLCHAIN_EXTERNAL_CUSTOM),loose,strict)); \
+		$$(if $$(or $$(BR2_TOOLCHAIN_EXTERNAL_CUSTOM),$$(BR2_PACKAGE_LINUX_HEADERS)),loose,strict)); \
 	$$(call check_gcc_version,$$(TOOLCHAIN_EXTERNAL_CC),\
 		$$(call qstrip,$$(BR2_TOOLCHAIN_GCC_AT_LEAST))); \
 	if test "$$(BR2_arm)" = "y" ; then \
-- 
2.39.5

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH 1/1] toolchain/toolchain-external: introduce BR2_TOOLCHAIN_EXTERNAL_UPDATE_LINUX_HEADERS
       [not found] <mailman.15362.1763026615.1650107.buildroot@buildroot.org>
@ 2025-11-26  7:07 ` Andreas Ziegler
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Ziegler @ 2025-11-26  7:07 UTC (permalink / raw)
  To: Rustam Abdullaev
  Cc: buildroot, Giulio Benetti, Romain Naour, Thomas Petazzoni

Hi Rustam,

you should add your remark about glibc upward compatibility to the patch 
description. It helps to understand the context ...

Further remarks below:

On 2025-11-12 17:43, Rustam Abdullaev wrote:
> 
> This change makes it possible to update kernel headers in the external
> toolchain with the headers from the current kernel.
> 
> It is important to have matching kernel headers when building packages
> that make use of kernel features such as seccomp, as they depend on
> system call definitions in linux/unistd.h. A typical example of this is
> openssh - building it with the official ARM GNU toolchain and kernel 
> 6.x
> results in a non-working sshd.
> 
> Signed-off-by: Rustam Abdullaev <rustamabd@gmail.com>
> ---
>  package/linux-headers/linux-headers.mk               |  3 ++-
>  toolchain/Config.in                                  |  6 ++++++
>  toolchain/helpers.mk                                 |  4 +---
>  toolchain/toolchain-buildroot/Config.in              |  2 --
>  toolchain/toolchain-external/Config.in               |  9 +++++++++
>  .../toolchain-external/pkg-toolchain-external.mk     | 12 +++++++++++-
>  6 files changed, 29 insertions(+), 7 deletions(-)
> 
> diff --git a/package/linux-headers/linux-headers.mk 
> b/package/linux-headers/linux-headers.mk
> index e2a0b7a7c9..d738bd3e9b 100644
> --- a/package/linux-headers/linux-headers.mk
> +++ b/package/linux-headers/linux-headers.mk
> @@ -5,7 +5,8 @@
>  
> ################################################################################
> 
>  # This package is used to provide Linux kernel headers for the
> -# internal toolchain backend.
> +# internal toolchain backend and for external toolchains that need
> +# updated kernel headers.
> 
>  # Set variables depending on whether we are using headers from a 
> kernel
>  # build or a standalone header package.
> diff --git a/toolchain/Config.in b/toolchain/Config.in
> index b3cbec8377..c02d77c08e 100644
> --- a/toolchain/Config.in
> +++ b/toolchain/Config.in
> @@ -69,6 +69,12 @@ source "toolchain/toolchain-external/Config.in"
>  # so put it here instead
>  source "package/gdb/Config.in.host"
> 
> +# Linux headers can be used by both internal and external toolchains
> +if BR2_TOOLCHAIN_BUILDROOT || 
> BR2_TOOLCHAIN_EXTERNAL_UPDATE_LINUX_HEADERS
> +source "package/linux-headers/Config.in.host"
> +source "package/linux-headers/Config.in"
> +endif
> +
>  comment "Toolchain Generic Options"
> 
>  # https://sourceware.org/bugzilla/show_bug.cgi?id=27597
> diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk
> index 08ee6060b0..b5cf2b7971 100644
> --- a/toolchain/helpers.mk
> +++ b/toolchain/helpers.mk
> @@ -165,11 +165,9 @@ copy_toolchain_sysroot = \
>  # $2: sysroot directory
>  # $3: kernel version string, in the form: X.Y
>  # $4: test to do for the latest kernel version, 'strict' or 'loose'
> -#     always 'strict' if this is not the latest version.
>  #
>  check_kernel_headers_version = \
> -	if ! support/scripts/check-kernel-headers.sh $(1) $(2) $(3) \
> -		$(if $(BR2_TOOLCHAIN_HEADERS_LATEST),$(4),strict); \
> +	if ! support/scripts/check-kernel-headers.sh $(1) $(2) $(3) $(4) ; \

Do not remove the check completely, but test for 
BR2_PACKAGE_LINUX_HEADERS additionally, similar to 
toolchain/toolchain-external/pkg-toolchain-external.mk

>  	then \
>  		exit 1; \
>  	fi
> diff --git a/toolchain/toolchain-buildroot/Config.in 
> b/toolchain/toolchain-buildroot/Config.in
> index 64f7892f98..ebebe263db 100644
> --- a/toolchain/toolchain-buildroot/Config.in
> +++ b/toolchain/toolchain-buildroot/Config.in
> @@ -104,8 +104,6 @@ config BR2_TOOLCHAIN_BUILDROOT_LIBC
>  	default "glibc"  if BR2_TOOLCHAIN_BUILDROOT_GLIBC
>  	default "musl"	 if BR2_TOOLCHAIN_BUILDROOT_MUSL
> 
> -source "package/linux-headers/Config.in.host"
> -source "package/linux-headers/Config.in"
>  source "package/musl/Config.in"
>  source "package/uclibc/Config.in"
>  source "package/glibc/Config.in"
> diff --git a/toolchain/toolchain-external/Config.in 
> b/toolchain/toolchain-external/Config.in
> index c1c159cb8e..d364f92a95 100644
> --- a/toolchain/toolchain-external/Config.in
> +++ b/toolchain/toolchain-external/Config.in
> @@ -157,4 +157,13 @@ config BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY
>  	  Copy the gdbserver provided by the external toolchain to the
>  	  target.
> 
> +config BR2_TOOLCHAIN_EXTERNAL_UPDATE_LINUX_HEADERS
> +	bool "Update kernel headers"
> +	select BR2_PACKAGE_LINUX_HEADERS
> +	help
> +	  Select this option to update the kernel headers in the
> +	  external toolchain with headers from the kernel being built.
> +	  This is useful when the external toolchain has older kernel
> +	  headers than the kernel being built.
> +

This approach probably works only for glibc toolchains, so the option 
should depend on BR2_TOOLCHAIN_EXTERNAL_GLIBC (or 
BR2_TOOLCHAIN_USES_GLIBC).

With (internal) uClibc and musl I had occasional problems updating 
kernel versions while not rebuilding the toolchain ...

>  endif # BR2_TOOLCHAIN_EXTERNAL
> diff --git a/toolchain/toolchain-external/pkg-toolchain-external.mk 
> b/toolchain/toolchain-external/pkg-toolchain-external.mk
> index c37f3500d9..6527601773 100644
> --- a/toolchain/toolchain-external/pkg-toolchain-external.mk
> +++ b/toolchain/toolchain-external/pkg-toolchain-external.mk
> @@ -557,19 +557,29 @@ $(2)_POST_EXTRACT_HOOKS += \
>  	TOOLCHAIN_EXTERNAL_MOVE
>  endif
> 
> +ifeq ($$(BR2_PACKAGE_LINUX_HEADERS),y)
> +$(2)_DEPENDENCIES += linux-headers
> +endif
> +
>  # Checks for an already installed toolchain: check the toolchain
>  # location, check that it is usable, and then verify that it
>  # matches the configuration provided in Buildroot: ABI, C++ support,
>  # kernel headers version, type of C library and all C library 
> features.
> +# Also updates the kernel headers in the toolchain, if requested.
>  define $(2)_CONFIGURE_CMDS
>  	$$(Q)$$(call check_cross_compiler_exists,$$(TOOLCHAIN_EXTERNAL_CC))
>  	$$(Q)$$(call 
> check_unusable_toolchain,$$(TOOLCHAIN_EXTERNAL_CC),"$$(TOOLCHAIN_EXTERNAL_CFLAGS)")
>  	$$(Q)SYSROOT_DIR="$$(call 
> toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC))" ; \
> +	if test "$$(BR2_PACKAGE_LINUX_HEADERS)" = "y" ; then \
> +		echo "Updating kernel headers in the external toolchain..." ; \
> +		rsync -a $$(STAGING_DIR)/usr/include/ \
> +			$$$${SYSROOT_DIR}/usr/include/ ; \
> +	fi ; \

Not a good idea. This might work when the kernel headers are processed 
initially, but once you upgrade the kernel patch level, you will copy a 
lot of unrelated headers into your toolchain include directory.

The kernel uses INSTALL_HDR_PATH to determine the install location for 
the headers. This variable is set in linux-headers.mk and you should 
adapt the INSTALL_STAGING_CMDS there.

>  	$$(call check_kernel_headers_version,\
>  		$$(BUILD_DIR),\
>  		$$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC)),\
>  		$$(call qstrip,$$(BR2_TOOLCHAIN_HEADERS_AT_LEAST)),\
> -		$$(if $$(BR2_TOOLCHAIN_EXTERNAL_CUSTOM),loose,strict)); \
> +		$$(if $$(or 
> $$(BR2_TOOLCHAIN_EXTERNAL_CUSTOM),$$(BR2_PACKAGE_LINUX_HEADERS)),loose,strict)); 
> \
>  	$$(call check_gcc_version,$$(TOOLCHAIN_EXTERNAL_CC),\
>  		$$(call qstrip,$$(BR2_TOOLCHAIN_GCC_AT_LEAST))); \
>  	if test "$$(BR2_arm)" = "y" ; then \
> --
> 2.39.5

Kind regards,
Andreas
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

end of thread, other threads:[~2025-11-26  7:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-12 17:43 [Buildroot] [PATCH 1/1] toolchain/toolchain-external: introduce BR2_TOOLCHAIN_EXTERNAL_UPDATE_LINUX_HEADERS Rustam Abdullaev
     [not found] <mailman.15362.1763026615.1650107.buildroot@buildroot.org>
2025-11-26  7:07 ` Andreas Ziegler

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.