public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kbuild: builddeb - avoid recompiles for non-cross-compiles
@ 2026-04-02 14:51 Mathias Krause
  2026-04-07 20:20 ` Nicolas Schier
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mathias Krause @ 2026-04-02 14:51 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, linux-kbuild
  Cc: Mathias Krause, Masahiro Yamada

Commit e2c318225ac1 ("kbuild: deb-pkg: add
pkg.linux-upstream.nokernelheaders build profile") changed how
install-extmod-build gets called, making it always rebuild the host
programs below scripts/ if HOSTCC wasn't specified with its full triplet
on the make command line. That is, apparently, needed to fix up commit
f1d87664b82a ("kbuild: cross-compile linux-headers package when
possible") for cross-compiles. However, in the much more common case of
non-cross-compile builds this will lead to unnecessary rebuilding of
host tools including gcc plugins. This, in turn, will lead to a full
kernel rebuild on the next 'make bindeb-pkg' which is unfortunate.

Avoid that by only triggering the rebuild of host tools for actual
cross-compile builds.

Signed-off-by: Mathias Krause <minipli@grsecurity.net>
Fixes: e2c318225ac1 ("kbuild: deb-pkg: add pkg.linux-upstream.nokernelheaders build profile")
Cc: Masahiro Yamada <masahiroy@kernel.org>
---
 scripts/package/builddeb | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/scripts/package/builddeb b/scripts/package/builddeb
index 3627ca227e5a..ba1defc61652 100755
--- a/scripts/package/builddeb
+++ b/scripts/package/builddeb
@@ -139,7 +139,13 @@ install_kernel_headers () {
 	pdir=debian/$1
 	version=${1#linux-headers-}
 
-	CC="${DEB_HOST_GNU_TYPE}-gcc" "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"
+	# Override $CC only for cross-compiles, to not unnecessarily rebuild
+	# scripts/ including plugins, which may lead to a full kernel rebuild.
+	if [ -n "${CROSS_COMPILE}" ]; then
+		CC="${DEB_HOST_GNU_TYPE}-gcc" "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"
+	else
+		"${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"
+	fi
 
 	mkdir -p $pdir/lib/modules/$version/
 	ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build
-- 
2.47.3


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

* Re: [PATCH] kbuild: builddeb - avoid recompiles for non-cross-compiles
  2026-04-02 14:51 [PATCH] kbuild: builddeb - avoid recompiles for non-cross-compiles Mathias Krause
@ 2026-04-07 20:20 ` Nicolas Schier
  2026-04-08 22:13 ` Nathan Chancellor
  2026-04-13 20:14 ` Nicolas Schier
  2 siblings, 0 replies; 5+ messages in thread
From: Nicolas Schier @ 2026-04-07 20:20 UTC (permalink / raw)
  To: Mathias Krause; +Cc: Nathan Chancellor, linux-kbuild, Masahiro Yamada

On Thu, Apr 02, 2026 at 04:51:16PM +0200, Mathias Krause wrote:
> Commit e2c318225ac1 ("kbuild: deb-pkg: add
> pkg.linux-upstream.nokernelheaders build profile") changed how
> install-extmod-build gets called, making it always rebuild the host
> programs below scripts/ if HOSTCC wasn't specified with its full triplet
> on the make command line. That is, apparently, needed to fix up commit
> f1d87664b82a ("kbuild: cross-compile linux-headers package when
> possible") for cross-compiles. However, in the much more common case of
> non-cross-compile builds this will lead to unnecessary rebuilding of
> host tools including gcc plugins. This, in turn, will lead to a full
> kernel rebuild on the next 'make bindeb-pkg' which is unfortunate.
> 
> Avoid that by only triggering the rebuild of host tools for actual
> cross-compile builds.
> 
> Signed-off-by: Mathias Krause <minipli@grsecurity.net>
> Fixes: e2c318225ac1 ("kbuild: deb-pkg: add pkg.linux-upstream.nokernelheaders build profile")
> Cc: Masahiro Yamada <masahiroy@kernel.org>
> ---
>  scripts/package/builddeb | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/package/builddeb b/scripts/package/builddeb
> index 3627ca227e5a..ba1defc61652 100755
> --- a/scripts/package/builddeb
> +++ b/scripts/package/builddeb
> @@ -139,7 +139,13 @@ install_kernel_headers () {
>  	pdir=debian/$1
>  	version=${1#linux-headers-}
>  
> -	CC="${DEB_HOST_GNU_TYPE}-gcc" "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"
> +	# Override $CC only for cross-compiles, to not unnecessarily rebuild
> +	# scripts/ including plugins, which may lead to a full kernel rebuild.
> +	if [ -n "${CROSS_COMPILE}" ]; then
> +		CC="${DEB_HOST_GNU_TYPE}-gcc" "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"
> +	else
> +		"${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"
> +	fi
>  
>  	mkdir -p $pdir/lib/modules/$version/
>  	ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build
> -- 
> 2.47.3
> 

Thanks!

Reviewed-by: Nicolas Schier <nsc@kernel.org>

-- 
Nicolas

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

* Re: [PATCH] kbuild: builddeb - avoid recompiles for non-cross-compiles
  2026-04-02 14:51 [PATCH] kbuild: builddeb - avoid recompiles for non-cross-compiles Mathias Krause
  2026-04-07 20:20 ` Nicolas Schier
@ 2026-04-08 22:13 ` Nathan Chancellor
  2026-04-13  9:12   ` Mathias Krause
  2026-04-13 20:14 ` Nicolas Schier
  2 siblings, 1 reply; 5+ messages in thread
From: Nathan Chancellor @ 2026-04-08 22:13 UTC (permalink / raw)
  To: Mathias Krause; +Cc: Nicolas Schier, linux-kbuild, Masahiro Yamada

On Thu, Apr 02, 2026 at 04:51:16PM +0200, Mathias Krause wrote:
> Commit e2c318225ac1 ("kbuild: deb-pkg: add
> pkg.linux-upstream.nokernelheaders build profile") changed how
> install-extmod-build gets called, making it always rebuild the host
> programs below scripts/ if HOSTCC wasn't specified with its full triplet
> on the make command line. That is, apparently, needed to fix up commit
> f1d87664b82a ("kbuild: cross-compile linux-headers package when
> possible") for cross-compiles. However, in the much more common case of
> non-cross-compile builds this will lead to unnecessary rebuilding of
> host tools including gcc plugins. This, in turn, will lead to a full
> kernel rebuild on the next 'make bindeb-pkg' which is unfortunate.
> 
> Avoid that by only triggering the rebuild of host tools for actual
> cross-compile builds.
> 
> Signed-off-by: Mathias Krause <minipli@grsecurity.net>
> Fixes: e2c318225ac1 ("kbuild: deb-pkg: add pkg.linux-upstream.nokernelheaders build profile")
> Cc: Masahiro Yamada <masahiroy@kernel.org>

Yeah, this seems like a reasonable workaround. I think this also helps
avoid some weirdness I have noticed when building Debian packages with
LLVM (as CC becomes gcc, always triggering the same logic since HOSTCC
will be clang).

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  scripts/package/builddeb | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/package/builddeb b/scripts/package/builddeb
> index 3627ca227e5a..ba1defc61652 100755
> --- a/scripts/package/builddeb
> +++ b/scripts/package/builddeb
> @@ -139,7 +139,13 @@ install_kernel_headers () {
>  	pdir=debian/$1
>  	version=${1#linux-headers-}
>  
> -	CC="${DEB_HOST_GNU_TYPE}-gcc" "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"
> +	# Override $CC only for cross-compiles, to not unnecessarily rebuild
> +	# scripts/ including plugins, which may lead to a full kernel rebuild.
> +	if [ -n "${CROSS_COMPILE}" ]; then
> +		CC="${DEB_HOST_GNU_TYPE}-gcc" "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"
> +	else
> +		"${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"
> +	fi
>  
>  	mkdir -p $pdir/lib/modules/$version/
>  	ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build
> -- 
> 2.47.3
> 

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

* Re: [PATCH] kbuild: builddeb - avoid recompiles for non-cross-compiles
  2026-04-08 22:13 ` Nathan Chancellor
@ 2026-04-13  9:12   ` Mathias Krause
  0 siblings, 0 replies; 5+ messages in thread
From: Mathias Krause @ 2026-04-13  9:12 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier; +Cc: linux-kbuild, Masahiro Yamada

On 09.04.26 00:13, Nathan Chancellor wrote:
> On Thu, Apr 02, 2026 at 04:51:16PM +0200, Mathias Krause wrote:
>> Commit e2c318225ac1 ("kbuild: deb-pkg: add
>> pkg.linux-upstream.nokernelheaders build profile") changed how
>> install-extmod-build gets called, making it always rebuild the host
>> programs below scripts/ if HOSTCC wasn't specified with its full triplet
>> on the make command line. That is, apparently, needed to fix up commit
>> f1d87664b82a ("kbuild: cross-compile linux-headers package when
>> possible") for cross-compiles. However, in the much more common case of
>> non-cross-compile builds this will lead to unnecessary rebuilding of
>> host tools including gcc plugins. This, in turn, will lead to a full
>> kernel rebuild on the next 'make bindeb-pkg' which is unfortunate.
>>
>> Avoid that by only triggering the rebuild of host tools for actual
>> cross-compile builds.
>>
>> Signed-off-by: Mathias Krause <minipli@grsecurity.net>
>> Fixes: e2c318225ac1 ("kbuild: deb-pkg: add pkg.linux-upstream.nokernelheaders build profile")
>> Cc: Masahiro Yamada <masahiroy@kernel.org>
> 
> Yeah, this seems like a reasonable workaround. I think this also helps
> avoid some weirdness I have noticed when building Debian packages with
> LLVM (as CC becomes gcc, always triggering the same logic since HOSTCC
> will be clang).
> 
> Reviewed-by: Nathan Chancellor <nathan@kernel.org>

Can you carry this via the kbuild tree, which seems to be the most
fitting one, according to MAINTAINERS?

Thanks,
Mathias

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

* Re: [PATCH] kbuild: builddeb - avoid recompiles for non-cross-compiles
  2026-04-02 14:51 [PATCH] kbuild: builddeb - avoid recompiles for non-cross-compiles Mathias Krause
  2026-04-07 20:20 ` Nicolas Schier
  2026-04-08 22:13 ` Nathan Chancellor
@ 2026-04-13 20:14 ` Nicolas Schier
  2 siblings, 0 replies; 5+ messages in thread
From: Nicolas Schier @ 2026-04-13 20:14 UTC (permalink / raw)
  To: Nathan Chancellor, linux-kbuild, Mathias Krause
  Cc: Nicolas Schier, Masahiro Yamada

On Thu, 02 Apr 2026 16:51:16 +0200, Mathias Krause wrote:
> Commit e2c318225ac1 ("kbuild: deb-pkg: add
> pkg.linux-upstream.nokernelheaders build profile") changed how
> install-extmod-build gets called, making it always rebuild the host
> programs below scripts/ if HOSTCC wasn't specified with its full triplet
> on the make command line. That is, apparently, needed to fix up commit
> f1d87664b82a ("kbuild: cross-compile linux-headers package when
> possible") for cross-compiles. However, in the much more common case of
> non-cross-compile builds this will lead to unnecessary rebuilding of
> host tools including gcc plugins. This, in turn, will lead to a full
> kernel rebuild on the next 'make bindeb-pkg' which is unfortunate.
> 
> [...]

Applied to kbuild/linux.git (kbuild-fixes-unstable), thanks!

[1/1] kbuild: builddeb - avoid recompiles for non-cross-compiles
      https://git.kernel.org/kbuild/c/2452dcf4

Please look out for regression or issue reports or other follow up
comments, as they may result in the patch/series getting dropped,
reverted or modified (e.g. trailers). Patches applied to the
kbuild-fixes-unstable branch are accepted pending wider testing in
linux-next and any post-commit review; they will generally be moved
to the kbuild-fixes branch in a week if no issues are found.

Best regards,
-- 
Nicolas


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

end of thread, other threads:[~2026-04-13 20:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-02 14:51 [PATCH] kbuild: builddeb - avoid recompiles for non-cross-compiles Mathias Krause
2026-04-07 20:20 ` Nicolas Schier
2026-04-08 22:13 ` Nathan Chancellor
2026-04-13  9:12   ` Mathias Krause
2026-04-13 20:14 ` Nicolas Schier

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