* Re: [PATCH v2] kbuild: clang: Support building UM with SUBARCH=i386
2025-03-04 16:21 [PATCH v2] kbuild: clang: Support building UM with SUBARCH=i386 Kees Cook
@ 2025-03-04 16:28 ` Nathan Chancellor
2025-03-04 17:50 ` Kees Cook
2025-03-06 8:59 ` David Gow
2 siblings, 0 replies; 5+ messages in thread
From: Nathan Chancellor @ 2025-03-04 16:28 UTC (permalink / raw)
To: Kees Cook
Cc: Thomas Weißschuh, Bill Wendling, Justin Stitt,
Masahiro Yamada, Nicolas Schier, llvm, linux-kbuild, David Gow,
linux-kernel, linux-hardening
On Tue, Mar 04, 2025 at 08:21:29AM -0800, Kees Cook wrote:
> The UM builds distinguish i386 from x86_64 via SUBARCH, but we don't
> support building i386 directly with Clang. To make SUBARCH work for
> i386 UM, we need to explicitly test for it.
>
> This lets me run i386 KUnit tests with Clang:
>
> $ ./tools/testing/kunit/kunit.py run \
> --make_options LLVM=1 \
> --make_options SUBARCH=i386
> ...
>
> Fixes: c7500c1b53bf ("um: Allow builds with Clang")
> Signed-off-by: Kees Cook <kees@kernel.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
> ---
> Cc: Nathan Chancellor <nathan@kernel.org>
> Cc: Thomas Weißschuh <linux@weissschuh.net>
> Cc: Bill Wendling <morbo@google.com>
> Cc: Justin Stitt <justinstitt@google.com>
> Cc: Masahiro Yamada <masahiroy@kernel.org>
> Cc: Nicolas Schier <nicolas@fjasle.eu>
> Cc: llvm@lists.linux.dev
> Cc: linux-kbuild@vger.kernel.org
> ---
> scripts/Makefile.clang | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
> index 2435efae67f5..b67636b28c35 100644
> --- a/scripts/Makefile.clang
> +++ b/scripts/Makefile.clang
> @@ -12,6 +12,8 @@ CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu
> CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu
> CLANG_TARGET_FLAGS_sparc := sparc64-linux-gnu
> CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu
> +# This is only for i386 UM builds, which need the 32-bit target not -m32
> +CLANG_TARGET_FLAGS_i386 := i386-linux-gnu
> CLANG_TARGET_FLAGS_um := $(CLANG_TARGET_FLAGS_$(SUBARCH))
> CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(SRCARCH))
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] kbuild: clang: Support building UM with SUBARCH=i386
2025-03-04 16:21 [PATCH v2] kbuild: clang: Support building UM with SUBARCH=i386 Kees Cook
2025-03-04 16:28 ` Nathan Chancellor
@ 2025-03-04 17:50 ` Kees Cook
2025-03-06 8:59 ` David Gow
2 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2025-03-04 17:50 UTC (permalink / raw)
To: Nathan Chancellor, Kees Cook
Cc: Thomas Weißschuh, Bill Wendling, Justin Stitt,
Masahiro Yamada, Nicolas Schier, llvm, linux-kbuild, David Gow,
linux-kernel, linux-hardening
On Tue, 04 Mar 2025 08:21:29 -0800, Kees Cook wrote:
> The UM builds distinguish i386 from x86_64 via SUBARCH, but we don't
> support building i386 directly with Clang. To make SUBARCH work for
> i386 UM, we need to explicitly test for it.
>
> This lets me run i386 KUnit tests with Clang:
>
> $ ./tools/testing/kunit/kunit.py run \
> --make_options LLVM=1 \
> --make_options SUBARCH=i386
> ...
>
> [...]
Applied to for-next/hardening, thanks!
[1/1] kbuild: clang: Support building UM with SUBARCH=i386
https://git.kernel.org/kees/c/a48d9ebdbb5a
Take care,
--
Kees Cook
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] kbuild: clang: Support building UM with SUBARCH=i386
2025-03-04 16:21 [PATCH v2] kbuild: clang: Support building UM with SUBARCH=i386 Kees Cook
2025-03-04 16:28 ` Nathan Chancellor
2025-03-04 17:50 ` Kees Cook
@ 2025-03-06 8:59 ` David Gow
2025-03-07 3:41 ` Kees Cook
2 siblings, 1 reply; 5+ messages in thread
From: David Gow @ 2025-03-06 8:59 UTC (permalink / raw)
To: Kees Cook
Cc: Nathan Chancellor, Thomas Weißschuh, Bill Wendling,
Justin Stitt, Masahiro Yamada, Nicolas Schier, llvm, linux-kbuild,
linux-kernel, linux-hardening
[-- Attachment #1: Type: text/plain, Size: 2253 bytes --]
On Wed, 5 Mar 2025 at 00:21, Kees Cook <kees@kernel.org> wrote:
>
> The UM builds distinguish i386 from x86_64 via SUBARCH, but we don't
> support building i386 directly with Clang. To make SUBARCH work for
> i386 UM, we need to explicitly test for it.
>
> This lets me run i386 KUnit tests with Clang:
>
> $ ./tools/testing/kunit/kunit.py run \
> --make_options LLVM=1 \
> --make_options SUBARCH=i386
> ...
>
> Fixes: c7500c1b53bf ("um: Allow builds with Clang")
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
Thanks for this -- I'd been using `--kconfig_add CONFIG_64BIT=n` as a
way to build i386 UML kernels, which seems to work even without this
patch -- but this is definitely an improvement.
It may be worth noting that CONFIG_FORTIFY_SOURCE is incompatible with
clang + i386, which seems to affect UML as well. (That might actually
not be required, as I think UML doesn't use any of the strange
-mregparm calling convention stuff which appears to be what breaks
FORTIFY_SOURCE here.)
Regardless,
Tested-by: David Gow <davidgow@google.com>
Cheers,
-- David
> Cc: Nathan Chancellor <nathan@kernel.org>
> Cc: Thomas Weißschuh <linux@weissschuh.net>
> Cc: Bill Wendling <morbo@google.com>
> Cc: Justin Stitt <justinstitt@google.com>
> Cc: Masahiro Yamada <masahiroy@kernel.org>
> Cc: Nicolas Schier <nicolas@fjasle.eu>
> Cc: llvm@lists.linux.dev
> Cc: linux-kbuild@vger.kernel.org
> ---
> scripts/Makefile.clang | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
> index 2435efae67f5..b67636b28c35 100644
> --- a/scripts/Makefile.clang
> +++ b/scripts/Makefile.clang
> @@ -12,6 +12,8 @@ CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu
> CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu
> CLANG_TARGET_FLAGS_sparc := sparc64-linux-gnu
> CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu
> +# This is only for i386 UM builds, which need the 32-bit target not -m32
> +CLANG_TARGET_FLAGS_i386 := i386-linux-gnu
> CLANG_TARGET_FLAGS_um := $(CLANG_TARGET_FLAGS_$(SUBARCH))
> CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(SRCARCH))
>
> --
> 2.34.1
>
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5281 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] kbuild: clang: Support building UM with SUBARCH=i386
2025-03-06 8:59 ` David Gow
@ 2025-03-07 3:41 ` Kees Cook
0 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2025-03-07 3:41 UTC (permalink / raw)
To: David Gow
Cc: Nathan Chancellor, Thomas Weißschuh, Bill Wendling,
Justin Stitt, Masahiro Yamada, Nicolas Schier, llvm, linux-kbuild,
linux-kernel, linux-hardening
On Thu, Mar 06, 2025 at 04:59:53PM +0800, David Gow wrote:
> On Wed, 5 Mar 2025 at 00:21, Kees Cook <kees@kernel.org> wrote:
> >
> > The UM builds distinguish i386 from x86_64 via SUBARCH, but we don't
> > support building i386 directly with Clang. To make SUBARCH work for
> > i386 UM, we need to explicitly test for it.
> >
> > This lets me run i386 KUnit tests with Clang:
> >
> > $ ./tools/testing/kunit/kunit.py run \
> > --make_options LLVM=1 \
> > --make_options SUBARCH=i386
> > ...
> >
> > Fixes: c7500c1b53bf ("um: Allow builds with Clang")
> > Signed-off-by: Kees Cook <kees@kernel.org>
> > ---
>
> Thanks for this -- I'd been using `--kconfig_add CONFIG_64BIT=n` as a
> way to build i386 UML kernels, which seems to work even without this
> patch -- but this is definitely an improvement.
Thanks! Yeah, I figured there must have been a way to get at it. I
wanted to make it work the "normal" way.
> It may be worth noting that CONFIG_FORTIFY_SOURCE is incompatible with
> clang + i386, which seems to affect UML as well. (That might actually
> not be required, as I think UML doesn't use any of the strange
> -mregparm calling convention stuff which appears to be what breaks
> FORTIFY_SOURCE here.)
Also fixed! :)
https://lore.kernel.org/lkml/20250303214929.work.499-kees@kernel.org/
> Tested-by: David Gow <davidgow@google.com>
Thanks for testing; I've updated the trailers in my tree.
-Kees
--
Kees Cook
^ permalink raw reply [flat|nested] 5+ messages in thread