Skip to contentSkip to conversation

kbuild: clang: Support building UM with SUBARCH=i386

PATCH Applied Kees Cook 3 participants 5 messages Mar 4, 2025 – Mar 7, 2025

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH v2 1/1 kbuild: clang: Support building UM with SUBARCH=i386

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")

---
Cc: Nathan Chancellor <[email protected]>
Cc: Thomas Weißschuh <[email protected]>
Cc: Bill Wendling <[email protected]>
Cc: Justin Stitt <[email protected]>
Cc: Masahiro Yamada <[email protected]>
Cc: Nicolas Schier <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 scripts/Makefile.clang | 2 ++
 1 file changed, 2 insertions(+)
scripts/Makefile.clang +2 -0
index 2435efae67f5..b67636b28c35 100644
@@ -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))
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Kees Cook

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:

Quoted 7 lines
$ ./tools/testing/kunit/kunit.py run \
	--make_options LLVM=1 \
	--make_options SUBARCH=i386
...
Fixes c7500c1b53bf ("um: Allow builds with Clang")
Quoted 29 lines

---
Cc: Nathan Chancellor <[email protected]>
Cc: Thomas Weißschuh <[email protected]>
Cc: Bill Wendling <[email protected]>
Cc: Justin Stitt <[email protected]>
Cc: Masahiro Yamada <[email protected]>
Cc: Nicolas Schier <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 scripts/Makefile.clang | 2 ++
 1 file changed, 2 insertions(+)
scripts/Makefile.clang +2 -0
index 2435efae67f5..b67636b28c35 100644
@@ -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))
 
Signature · 1 line
2.34.1
author Applied
#2 lore raw
In reply to Kees Cook
Quoted 4 lines · Kees Cook

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.

Quoted 8 lines

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,

Signature · 1 line
Kees Cook
Tested-by on v2 1/1
#3 lore raw
In reply to Kees Cook
Quoted 7 lines · Kees Cook

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:

Quoted 8 lines
$ ./tools/testing/kunit/kunit.py run \
        --make_options LLVM=1 \
        --make_options SUBARCH=i386
...
Fixes c7500c1b53bf ("um: Allow builds with Clang")

---

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,

Cheers,
-- David

Quoted 28 lines
Cc Nathan Chancellor <[email protected]>
Cc Thomas Weißschuh <[email protected]>
Cc Bill Wendling <[email protected]>
Cc Justin Stitt <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Nicolas Schier <[email protected]>
---
 scripts/Makefile.clang | 2 ++
 1 file changed, 2 insertions(+)
scripts/Makefile.clang +2 -1
index 2435efae67f5..b67636b28c35 100644
@@ -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

author
#4 lore raw
Quoted 13 lines · David Gow
Quoted 12 lines · Kees Cook

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
...
Quoted 7 lines
Quoted 3 lines
Fixes c7500c1b53bf ("um: Allow builds with Clang")

---

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.

Quoted 5 lines

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/[email protected]/

Quoted 1 line

Thanks for testing; I've updated the trailers in my tree.

-Kees

Signature · 1 line
Kees Cook