Re: [PATCH v2] kbuild: clang: Support building UM with SUBARCH=i386

From: David Gow
Date: Thu Mar 06 2025 - 04:00:20 EST


On Wed, 5 Mar 2025 at 00:21, Kees Cook <kees@xxxxxxxxxx> 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@xxxxxxxxxx>
> ---

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@xxxxxxxxxx>

Cheers,
-- David


> Cc: Nathan Chancellor <nathan@xxxxxxxxxx>
> Cc: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
> Cc: Bill Wendling <morbo@xxxxxxxxxx>
> Cc: Justin Stitt <justinstitt@xxxxxxxxxx>
> Cc: Masahiro Yamada <masahiroy@xxxxxxxxxx>
> Cc: Nicolas Schier <nicolas@xxxxxxxxx>
> Cc: llvm@xxxxxxxxxxxxxxx
> Cc: linux-kbuild@xxxxxxxxxxxxxxx
> ---
> 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: smime.p7s
Description: S/MIME Cryptographic Signature