kbuild: clang: Support building UM with SUBARCH=i386
Subsystems (2)
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 ...
---
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
@@ -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
Quoted 6 lines · Kees Cook
The UM builds distinguish i386 from
x86_64via 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")Signed-off-by Kees Cook <[email protected]>
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@@ -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
Kees Cook
AppliedQuoted 4 lines · Kees Cook
The UM builds distinguish i386 from
x86_64via 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
Quoted 7 lines · Kees Cook
The UM builds distinguish i386 from
x86_64via 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")Signed-off-by Kees Cook <[email protected]>---
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@@ -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
Quoted 13 lines · David Gow
Quoted 12 lines · Kees Cook
The UM builds distinguish i386 from
x86_64via 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")Signed-off-by Kees Cook <[email protected]>---
Thanks for this -- I'd been using
--kconfig_add CONFIG_64BIT=nas 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_SOURCEis 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 breaksFORTIFY_SOURCEhere.)
Also fixed! :)
https://lore.kernel.org/lkml/[email protected]/
Quoted 1 line
Tested-by David Gow <[email protected]>
Thanks for testing; I've updated the trailers in my tree.
-Kees
Signature · 1 line
Kees Cook