Skip to contentSkip to conversation

sparc/build: Rework CFLAGS for clang compatibility

PATCH Superseded Koakuma 4 participants 20 messages Jul 17, 2024 – Oct 27, 2024

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Koakuma

author
#0 lore raw

v2 cover sparc/build: Rework CFLAGS for clang compatibility

Hello~

This changes the CFLAGS for building the SPARC kernel so that it can be built with clang, as a follow up from the discussion in this thread:

https://lore.kernel.org/lkml/JAYB7uS-EdLABTR4iWZdtFOVa5MvlKosIrD_cKTzgeozCOGRM7lhxeLigFB1g3exX445I_W5VKB-tAzl2_G1zCVJRQjp67ODfsSqiZWOZ9o=@protonmail.com/T/#u

The changes are removal of various -fcall-used-* flags, and adding clang target flags for SPARC:

- -fcall-used-* flags is removed as it is not supported in clang. Those should be safe to remove; the compiler will stop using the registers specified as temporaries, but it is a safe change wrt. the ABI. Assembly code can still use those registers as needed. A cursory look at the assembly generated by GCC 13.2 shows that the compiler was able to reallocate uses of those registers into other temporary registers without adding extra spills, so there should be no change in performance.

- More trivial is to add CLANG_TARGET_FLAGS for SPARC target.

Building with these changes still result in a working kernel, at least for Sun T5120, Oracle T4-1, and qemu virtual machines.

On the LLVM side, the effort for building Linux/SPARC is tracked here:
https://github.com/llvm/llvm-project/issues/40792

---
Changes in v2:
- Remove the -mv8plus change; it will be handled on clang side:
https://github.com/llvm/llvm-project/pull/98713
- Add CLANG_TARGET_FLAGS as suggested in v1 review.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Koakuma (2):
sparc/build: Remove all usage of -fcall-used* flags sparc/build: Add SPARC target flags for compiling with clang

 arch/sparc/Makefile      | 4 ++--
 arch/sparc/vdso/Makefile | 2 +-
 scripts/Makefile.clang   | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)

---
base-commit: 4d145e3f830ba2c2745b42bfba5c2f8fcb8d078a
change-id: 20240620-sparc-cflags-e7f2dbbd4b9d

Best regards,

Signature · 1 line
Koakuma <[email protected]>
author
#1 lore raw

PATCH v2 1/2 sparc/build: Remove all usage of -fcall-used* flags

Remove all usage of -fcall-used* flags so that all flags used are portable between GCC and clang.

The reasoning is as follows:

In the (normal) 32-bit ABI, %g5 and %g7 is normally reserved, and in the 64-bit ABI, %g7 is the reserved one.
Linux turns them into volatile registers by the way of -fcall-used-*, but on the other hand, omitting the flags shouldn't be harmful; compilers will now simply refuse to touch them, and any assembly code that happens to touch them would still work like usual (because Linux' conventions already treats them as volatile anyway).

---
 arch/sparc/Makefile      | 4 ++--
 arch/sparc/vdso/Makefile | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/sparc/Makefile +2 -2
index 757451c3ea1d..7318a8b452c3 100644
@@ -29,7 +29,7 @@ UTS_MACHINE    := sparc
 # versions of gcc.  Some gcc versions won't pass -Av8 to binutils when you
 # give -mcpu=v8.  This silently worked with older bintutils versions but
 # does not any more.
-KBUILD_CFLAGS  += -m32 -mcpu=v8 -pipe -mno-fpu -fcall-used-g5 -fcall-used-g7
+KBUILD_CFLAGS  += -m32 -mcpu=v8 -pipe -mno-fpu
 KBUILD_CFLAGS  += -Wa,-Av8
 
 KBUILD_AFLAGS  += -m32 -Wa,-Av8
@@ -45,7 +45,7 @@ export BITS   := 64
 UTS_MACHINE   := sparc64
 
 KBUILD_CFLAGS += -m64 -pipe -mno-fpu -mcpu=ultrasparc -mcmodel=medlow
-KBUILD_CFLAGS += -ffixed-g4 -ffixed-g5 -fcall-used-g7 -Wno-sign-compare
+KBUILD_CFLAGS += -ffixed-g4 -ffixed-g5 -Wno-sign-compare
 KBUILD_CFLAGS += -Wa,--undeclared-regs
 KBUILD_CFLAGS += $(call cc-option,-mtune=ultrasparc3)
 KBUILD_AFLAGS += -m64 -mcpu=ultrasparc -Wa,--undeclared-regs
arch/sparc/vdso/Makefile +1 -1
index 243dbfc4609d..e009443145af 100644
@@ -46,7 +46,7 @@ CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64
        -fno-omit-frame-pointer -foptimize-sibling-calls \
        -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
 
-SPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5 -fcall-used-g5 -fcall-used-g7
+SPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5
 
 $(vobjs): KBUILD_CFLAGS := $(filter-out $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
 
Signature · 1 line
2.45.2
maintainer Tested-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] sparc/build: Remove all usage of -fcall-used* flags

Quoted 13 lines · Koakuma

Remove all usage of -fcall-used* flags so that all flags used are portable between GCC and clang.

The reasoning is as follows:

In the (normal) 32-bit ABI, %g5 and %g7 is normally reserved, and in the 64-bit ABI, %g7 is the reserved one.
Linux turns them into volatile registers by the way of -fcall-used-*, but on the other hand, omitting the flags shouldn't be harmful; compilers will now simply refuse to touch them, and any assembly code that happens to touch them would still work like usual (because Linux' conventions already treats them as volatile anyway).

Quoted 1 line

As before, I tested this series with the vDSO patch mentioned before and a version of LLVM that supports the -m{,no-}v8plus flags and I was able to successfully boot a kernel in QEMU :)

Quoted 44 lines
---
 arch/sparc/Makefile      | 4 ++--
 arch/sparc/vdso/Makefile | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/sparc/Makefile +2 -2
index 757451c3ea1d..7318a8b452c3 100644
@@ -29,7 +29,7 @@ UTS_MACHINE    := sparc
 # versions of gcc.  Some gcc versions won't pass -Av8 to binutils when you
 # give -mcpu=v8.  This silently worked with older bintutils versions but
 # does not any more.
-KBUILD_CFLAGS  += -m32 -mcpu=v8 -pipe -mno-fpu -fcall-used-g5 -fcall-used-g7
+KBUILD_CFLAGS  += -m32 -mcpu=v8 -pipe -mno-fpu
 KBUILD_CFLAGS  += -Wa,-Av8
 
 KBUILD_AFLAGS  += -m32 -Wa,-Av8
@@ -45,7 +45,7 @@ export BITS   := 64
 UTS_MACHINE   := sparc64
 
 KBUILD_CFLAGS += -m64 -pipe -mno-fpu -mcpu=ultrasparc -mcmodel=medlow
-KBUILD_CFLAGS += -ffixed-g4 -ffixed-g5 -fcall-used-g7 -Wno-sign-compare
+KBUILD_CFLAGS += -ffixed-g4 -ffixed-g5 -Wno-sign-compare
 KBUILD_CFLAGS += -Wa,--undeclared-regs
 KBUILD_CFLAGS += $(call cc-option,-mtune=ultrasparc3)
 KBUILD_AFLAGS += -m64 -mcpu=ultrasparc -Wa,--undeclared-regs
arch/sparc/vdso/Makefile +1 -1
index 243dbfc4609d..e009443145af 100644
@@ -46,7 +46,7 @@ CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64
        -fno-omit-frame-pointer -foptimize-sibling-calls \
        -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
 
-SPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5 -fcall-used-g5 -fcall-used-g7
+SPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5
 
 $(vobjs): KBUILD_CFLAGS := $(filter-out $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
 
Signature · 2 lines
-- 
2.45.2
maintainer
#3 lore raw

Re: [PATCH v2 1/2] sparc/build: Remove all usage of -fcall-used* flags

In reply to Koakuma

Hi,

Sorry for being silent on your two patch sets. I did not have time to look into them for 6.12.

Quoted 26 lines · On 2024-07-17 18:10, Koakuma via B4 Relay wrote:

From: Koakuma <[email protected]>

Remove all usage of -fcall-used* flags so that all flags used are portable between GCC and clang.

The reasoning is as follows:

In the (normal) 32-bit ABI, %g5 and %g7 is normally reserved, and in the 64-bit ABI, %g7 is the reserved one.
Linux turns them into volatile registers by the way of -fcall-used-*, but on the other hand, omitting the flags shouldn't be harmful; compilers will now simply refuse to touch them, and any assembly code that happens to touch them would still work like usual (because Linux' conventions already treats them as volatile anyway).

---
 arch/sparc/Makefile      | 4 ++--
 arch/sparc/vdso/Makefile | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/sparc/Makefile +0 -0
index 757451c3ea1d..7318a8b452c3 100644

arch/sparc/Makefile UTS_MACHINE := sparc · line 32

Quoted 5 lines
arch/sparc/Makefile +1 -1
@@ -29,7 +29,7 @@ UTS_MACHINE    := sparc
 # versions of gcc.  Some gcc versions won't pass -Av8 to binutils when you
 # give -mcpu=v8.  This silently worked with older bintutils versions but
 # does not any more.
-KBUILD_CFLAGS  += -m32 -mcpu=v8 -pipe -mno-fpu -fcall-used-g5 -fcall-used-g7
+KBUILD_CFLAGS  += -m32 -mcpu=v8 -pipe -mno-fpu

Couldn't you use ifndef CONFIG_CC_IS_CLANG or perhaps better, use $(call cc-option,-fcall-used-g5) and $(call cc-option,-fcall-used-g7) to not remove the possibility for gcc to make use of these registers?

arch/sparc/Makefile export BITS := 64 · line 48

Quoted 9 lines
arch/sparc/Makefile +1 -1
 KBUILD_CFLAGS  += -Wa,-Av8
 
 KBUILD_AFLAGS  += -m32 -Wa,-Av8
@@ -45,7 +45,7 @@ export BITS   := 64
 UTS_MACHINE   := sparc64
 
 KBUILD_CFLAGS += -m64 -pipe -mno-fpu -mcpu=ultrasparc -mcmodel=medlow
-KBUILD_CFLAGS += -ffixed-g4 -ffixed-g5 -fcall-used-g7 -Wno-sign-compare
+KBUILD_CFLAGS += -ffixed-g4 -ffixed-g5 -Wno-sign-compare

Similarly here

arch/sparc/vdso/Makefile CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64 · line 49

Quoted 13 lines
arch/sparc/Makefile +0 -0
 KBUILD_CFLAGS += -Wa,--undeclared-regs
 KBUILD_CFLAGS += $(call cc-option,-mtune=ultrasparc3)
 KBUILD_AFLAGS += -m64 -mcpu=ultrasparc -Wa,--undeclared-regs
arch/sparc/vdso/Makefile +1 -1
index 243dbfc4609d..e009443145af 100644
@@ -46,7 +46,7 @@ CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64
        -fno-omit-frame-pointer -foptimize-sibling-calls \
        -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
 
-SPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5 -fcall-used-g5 -fcall-used-g7
+SPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5

and here.

arch/sparc/vdso/Makefile CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64

Quoted 4 lines
arch/sparc/vdso/Makefile +0 -0
 $(vobjs): KBUILD_CFLAGS := $(filter-out $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
 
 

Thanks,
Andreas

author
#4 lore raw

Re: [PATCH v2 1/2] sparc/build: Remove all usage of -fcall-used* flags

Quoted 3 lines · Andreas Larsson

Couldn't you use ifndef CONFIG_CC_IS_CLANG or perhaps better, use $(call cc-option,-fcall-used-g5) and $(call cc-option,-fcall-used-g7) to not remove the possibility for gcc to make use of these registers?

Sure sure! It works okay that way too.
But before I send a v3, let me wait for clarification for the docs issue for the other patch.

author
#5 lore raw

PATCH v2 2/2 sparc/build: Add SPARC target flags for compiling with clang

In reply to Koakuma

clang only supports building 64-bit kernel, so we use the sparc64-linux-gnu target.

See also: https://lore.kernel.org/lkml/e26PTXUXEz8OYXmaeKn4Mpuejr4IOlFfFwdB5vpsluXlYiqDdlyQTYcDtdAny_o4gO4SfPeQCCN2qpyT6e0nog5EaP3xk2SeUPTrF54p1gM=@protonmail.com/T/#m068e010dcf8b99d3510a90d7532bcdb70e2e2c6b

---
 scripts/Makefile.clang | 1 +
 1 file changed, 1 insertion(+)
scripts/Makefile.clang +1 -0
index 6c23c6af797f..2435efae67f5 100644
@@ -10,6 +10,7 @@ CLANG_TARGET_FLAGS_mips		:= mipsel-linux-gnu
 CLANG_TARGET_FLAGS_powerpc	:= powerpc64le-linux-gnu
 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
 CLANG_TARGET_FLAGS_um		:= $(CLANG_TARGET_FLAGS_$(SUBARCH))
 CLANG_TARGET_FLAGS		:= $(CLANG_TARGET_FLAGS_$(SRCARCH))
Signature · 1 line
2.45.2
maintainer Reviewed-by on v2 2/2
#6 lore raw

Re: [PATCH v2 2/2] sparc/build: Add SPARC target flags for compiling with clang

Hi Koakuma,

Quoted 2 lines · Koakuma

clang only supports building 64-bit kernel, so we use the sparc64-linux-gnu target.

It should not really matter which sparc target you pick (32-bit or 64-bit), as the comment at the top of the file mentions that architectures should use the command line options to control word size and endianness, which arch/sparc does. Not that I really think it is worth correcting, just thought I would mention :)

Quoted 3 lines

See also: https://lore.kernel.org/lkml/e26PTXUXEz8OYXmaeKn4Mpuejr4IOlFfFwdB5vpsluXlYiqDdlyQTYcDtdAny_o4gO4SfPeQCCN2qpyT6e0nog5EaP3xk2SeUPTrF54p1gM=@protonmail.com/T/#m068e010dcf8b99d3510a90d7532bcdb70e2e2c6b

Thanks for all the work you have done driving this, it is pretty cool to see :)

Quoted 20 lines
---
 scripts/Makefile.clang | 1 +
 1 file changed, 1 insertion(+)
scripts/Makefile.clang +1 -0
index 6c23c6af797f..2435efae67f5 100644
@@ -10,6 +10,7 @@ CLANG_TARGET_FLAGS_mips		:= mipsel-linux-gnu
 CLANG_TARGET_FLAGS_powerpc	:= powerpc64le-linux-gnu
 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
 CLANG_TARGET_FLAGS_um		:= $(CLANG_TARGET_FLAGS_$(SUBARCH))
 CLANG_TARGET_FLAGS		:= $(CLANG_TARGET_FLAGS_$(SRCARCH))
Signature · 2 lines
-- 
2.45.2
Acked-by on v2 2/2
#7 lore raw

Re: [PATCH v2 2/2] sparc/build: Add SPARC target flags for compiling with clang

In reply to Koakuma
Quoted 9 lines · On Thu, Jul 18, 2024 at 1:12 AM Koakuma via B4 Relay…

From: Koakuma <[email protected]>

clang only supports building 64-bit kernel, so we use the sparc64-linux-gnu target.

See also: https://lore.kernel.org/lkml/e26PTXUXEz8OYXmaeKn4Mpuejr4IOlFfFwdB5vpsluXlYiqDdlyQTYcDtdAny_o4gO4SfPeQCCN2qpyT6e0nog5EaP3xk2SeUPTrF54p1gM=@protonmail.com/T/#m068e010dcf8b99d3510a90d7532bcdb70e2e2c6b

(I assume this will go through the sparc subsystem)

Signature · 2 lines
Best Regards
Masahiro Yamada
#8 lore raw
In reply to Koakuma

Hi Andreas,

Quoted 4 lines · Koakuma

This changes the CFLAGS for building the SPARC kernel so that it can be built with clang, as a follow up from the discussion in this thread:

https://lore.kernel.org/lkml/JAYB7uS-EdLABTR4iWZdtFOVa5MvlKosIrD_cKTzgeozCOGRM7lhxeLigFB1g3exX445I_W5VKB-tAzl2_G1zCVJRQjp67ODfsSqiZWOZ9o=@protonmail.com/T/#u

...

Quoted 19 lines

Building with these changes still result in a working kernel, at least for Sun T5120, Oracle T4-1, and qemu virtual machines.

On the LLVM side, the effort for building Linux/SPARC is tracked here:
https://github.com/llvm/llvm-project/issues/40792

---
Changes in v2:
- Remove the -mv8plus change; it will be handled on clang side:
https://github.com/llvm/llvm-project/pull/98713
- Add CLANG_TARGET_FLAGS as suggested in v1 review.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Koakuma (2):
sparc/build: Remove all usage of -fcall-used* flags sparc/build: Add SPARC target flags for compiling with clang

Quoted 4 lines
 arch/sparc/Makefile      | 4 ++--
 arch/sparc/vdso/Makefile | 2 +-
 scripts/Makefile.clang   | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)

Would you be able to help move this series [1] and its companion patch for the vDSO [2] along to Linus for 6.13? If you are not able to for whatever reason but the changes look reasonable to you, would you be able to provide an Ack so it can be chauffeured by someone else, such as Masahiro/Kbuild or Andrew/-mm?

For the record, I retested these three changes on top of 6.12-rc4, where they still apply cleanly. Now that the LLVM PR linked above (98713) has been merged into LLVM main, a clang built straight from llvm-project.git can build the kernel with this series (I tested at dca43a1c82f1).

[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/

Cheers,
Nathan

#9 lore raw
Quoted 44 lines · Nathan Chancellor

Hi Andreas,

Quoted 4 lines · Koakuma

This changes the CFLAGS for building the SPARC kernel so that it can be built with clang, as a follow up from the discussion in this thread:

https://lore.kernel.org/lkml/JAYB7uS-EdLABTR4iWZdtFOVa5MvlKosIrD_cKTzgeozCOGRM7lhxeLigFB1g3exX445I_W5VKB-tAzl2_G1zCVJRQjp67ODfsSqiZWOZ9o=@protonmail.com/T/#u

...

Quoted 19 lines

Building with these changes still result in a working kernel, at least for Sun T5120, Oracle T4-1, and qemu virtual machines.

On the LLVM side, the effort for building Linux/SPARC is tracked here:
https://github.com/llvm/llvm-project/issues/40792

---
Changes in v2:
- Remove the -mv8plus change; it will be handled on clang side:
https://github.com/llvm/llvm-project/pull/98713
- Add CLANG_TARGET_FLAGS as suggested in v1 review.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Koakuma (2):
sparc/build: Remove all usage of -fcall-used* flags sparc/build: Add SPARC target flags for compiling with clang

Quoted 4 lines
 arch/sparc/Makefile      | 4 ++--
 arch/sparc/vdso/Makefile | 2 +-
 scripts/Makefile.clang   | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)

Would you be able to help move this series [1] and its companion patch for the vDSO [2] along to Linus for 6.13? If you are not able to for whatever reason but the changes look reasonable to you, would you be able to provide an Ack so it can be chauffeured by someone else, such as Masahiro/Kbuild or Andrew/-mm?

For the record, I retested these three changes on top of 6.12-rc4, where they still apply cleanly. Now that the LLVM PR linked above (98713) has been merged into LLVM main, a clang built straight from llvm-project.git can build the kernel with this series (I tested at dca43a1c82f1).

Quoted 5 lines

[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/

Cheers,
Nathan

I applied this patch set, but I still observe a build error.

masahiro@zoe:~/workspace/linux-kbuild(kbuild)$ ~/tools/llvm-latest/bin/clang --version ClangBuiltLinux clang version 20.0.0git
(https://github.com/llvm/llvm-project.git
d1401822e2d2753bed3ac597a42cc0b261de40a4)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /home/masahiro/tools/llvm-latest/bin

masahiro@zoe:~/workspace/linux-kbuild(kbuild)$ make
LLVM=~/tools/llvm-latest/bin/  ARCH=sparc sparc64_defconfig all
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/confdata.o
  HOSTCC  scripts/kconfig/expr.o
  HOSTCC  scripts/kconfig/lexer.lex.o
  HOSTCC  scripts/kconfig/menu.o
  HOSTCC  scripts/kconfig/parser.tab.o
  HOSTCC  scripts/kconfig/preprocess.o
  HOSTCC  scripts/kconfig/symbol.o
  HOSTCC  scripts/kconfig/util.o
  HOSTLD  scripts/kconfig/conf
#
# configuration written to .config
#
  SYNC    include/config/auto.conf.cmd
  HOSTCC  scripts/genksyms/genksyms.o
  HOSTCC  scripts/genksyms/parse.tab.o
  HOSTCC  scripts/genksyms/lex.lex.o
  HOSTLD  scripts/genksyms/genksyms
  HOSTCC  scripts/kallsyms
  UPD     include/generated/compile.h
  CC      scripts/mod/empty.o
clang: error: unsupported argument '--undeclared-regs' to option '-Wa,'
make[3]: *** [scripts/Makefile.build:229: scripts/mod/empty.o] Error 1
make[2]: *** [Makefile:1208: prepare0] Error 2
make[1]: *** [/home/masahiro/workspace/linux-kbuild/Makefile:347:
__build_one_by_one] Error 2
make: *** [Makefile:224: __sub-make] Error 2
Signature · 2 lines
Best Regards
Masahiro Yamada
#10 lore raw
Quoted 1 line · Masahiro Yamada

I applied this patch set, but I still observe a build error.

...

Quoted 2 lines
masahiro@zoe:~/workspace/linux-kbuild(kbuild)$ make
LLVM=~/tools/llvm-latest/bin/  ARCH=sparc sparc64_defconfig all

...

Quoted 1 line

clang: error: unsupported argument '--undeclared-regs' to option '-Wa,'

Koakuma might know more than I do but I did not test either the integrated assembler or the rest of the LLVM tools; I only tested clang for CC. As far as I am aware, that has been where most of the effort in llvm-project has been going and I think there are probably other fixes that will be needed for the other tools. The command I tested was:

  $ make -skj"$(nproc)" \
         ARCH=sparc64 \
         CC=clang \
         CROSS_COMPILE=sparc64-linux-gnu- \
         LLVM_IAS=0 \
         mrproper defconfig all

I see this as more of a stepping stone series to make testing those other components easier as time goes on, hence why I did not really consider user facing documentation either like you brought up in the other thread.

Cheers,
Nathan

author
#11 lore raw
Quoted 13 lines · Nathan Chancellor

Koakuma might know more than I do but I did not test either the integrated assembler or the rest of the LLVM tools; I only tested clang for CC. As far as I am aware, that has been where most of the effort in llvm-project has been going and I think there are probably other fixes that will be needed for the other tools. The command I tested was:

$ make -skj"$(nproc)" \
ARCH=sparc64 \
CC=clang \
CROSS_COMPILE=sparc64-linux-gnu- \
LLVM_IAS=0 \
mrproper defconfig all
Quoted 7 lines

I see this as more of a stepping stone series to make testing those other components easier as time goes on, hence why I did not really consider user facing documentation either like you brought up in the other thread.

Cheers,
Nathan

Ah, pardon me for forgetting to say it in the cover letter.
But yeah. At the moment only clang as CC works, all other LLVM tools are still incomplete and need some work to be able to build the kernel, so these patches indeed are intended as stepping stones to make it easier to work on the rest of the tools.

I'm not sure if I should update the documentation now given that LLVM support is nowhere near as complete as other architectures, but I'll do it if needed...

#12 lore raw
Quoted 23 lines · Koakuma
Quoted 13 lines · Nathan Chancellor

Koakuma might know more than I do but I did not test either the integrated assembler or the rest of the LLVM tools; I only tested clang for CC. As far as I am aware, that has been where most of the effort in llvm-project has been going and I think there are probably other fixes that will be needed for the other tools. The command I tested was:

$ make -skj"$(nproc)" \
ARCH=sparc64 \
CC=clang \
CROSS_COMPILE=sparc64-linux-gnu- \
LLVM_IAS=0 \
mrproper defconfig all
Quoted 7 lines

I see this as more of a stepping stone series to make testing those other components easier as time goes on, hence why I did not really consider user facing documentation either like you brought up in the other thread.

Cheers,
Nathan

Quoted 8 lines

Ah, pardon me for forgetting to say it in the cover letter.
But yeah. At the moment only clang as CC works, all other LLVM tools are still incomplete and need some work to be able to build the kernel, so these patches indeed are intended as stepping stones to make it easier to work on the rest of the tools.

I'm not sure if I should update the documentation now given that LLVM support is nowhere near as complete as other architectures, but I'll do it if needed...

Nathan said he was able to build the kernel.

If so, I think this should be documented (required LLVM version and the supported build command),
otherwise people cannot test this patch.

Anyway, the sparc subsystem is maintained.
I hope Andreas can take a look.

commit eb5b0f9812fff72f82e6ecc9ad4dafaf4971a16a
Merge: 4ffc45808373 d21dffe51baa
Author: Linus Torvalds <[email protected]>
Date: Wed Sep 25 11:21:06 2024 -0700

    Merge tag 'sparc-for-6.12-tag1' of

git://git.kernel.org/pub/scm/linux/kernel/git/alarsson/linux-sparc

Pull sparc32 update from Andreas Larsson:

- Remove an unused variable for sparc32

* tag 'sparc-for-6.12-tag1' of
git://git.kernel.org/pub/scm/linux/kernel/git/alarsson/linux-sparc:
arch/sparc: remove unused varible paddrbase in function leon_swprobe()

commit 7dd894c1bf65a9591ba27f6175cf3238748deb47
Merge: 1c7d0c3af5cc a3da15389112
Author: Linus Torvalds <[email protected]>
Date: Thu Jul 18 15:48:41 2024 -0700

    Merge tag 'sparc-for-6.11-tag1' of

git://git.kernel.org/pub/scm/linux/kernel/git/alarsson/linux-sparc

Pull sparc updates from Andreas Larsson:

- Add MODULE_DESCRIPTION for a number of sbus drivers

- Fix linking error for large sparc32 kernels

- Fix incorrect functions signature and prototype warnings for sparc64

* tag 'sparc-for-6.11-tag1' of
git://git.kernel.org/pub/scm/linux/kernel/git/alarsson/linux-sparc:
sparc64: Fix prototype warnings in hibernate.c
sparc64: Fix prototype warning for prom_get_mmu_ihandle
sparc64: Fix incorrect function signature and add prototype for
prom_cif_init
sparc64: Fix prototype warnings for floppy_64.h
sparc32: Fix truncated relocation errors when linking large kernels
sbus: add missing MODULE_DESCRIPTION() macros

Signature · 2 lines
Best Regards
Masahiro Yamada
#13 lore raw
Quoted 9 lines · Masahiro Yamada
Quoted 2 lines · Koakuma

I'm not sure if I should update the documentation now given that LLVM support is nowhere near as complete as other architectures, but I'll do it if needed...

Nathan said he was able to build the kernel.

If so, I think this should be documented (required LLVM version and the supported build command),
otherwise people cannot test this patch.

I am not sure that there is a super concise way to describe for Documentation/kbuild/llvm.rst that sparc currently requires 'CC=clang LLVM_IAS=0' along with a build of clang from the main branch of llvm-project to work properly. I worry that adding any sort of mention of sparc in there will have people flooding to try older versions of clang like you did or LLVM=1 when there are obviously known issues that the upstream LLVM folks have not had a chance to tackle (but maybe it will be good to get issues on file for those).

If it would be useful, I could send a separate email documenting exactly what was tested and how it was tested as a reference in the face of future changes, until better support for the LLVM tools is enacted.

Cheers,
Nathan

author
#14 lore raw
Quoted 3 lines · Masahiro Yamada

I think this should be documented (required LLVM version and the supported build command),
otherwise people cannot test this patch.

Quoted 4 lines · Nathan Chancellor

I am not sure that there is a super concise way to describe for Documentation/kbuild/llvm.rst that sparc currently requires 'CC=clang LLVM_IAS=0' along with a build of clang from the main branch of llvm-project to work properly.

So about this, as a middle ground, would it be okay if I put

``CC=clang LLVM_IAS=0`` (LLVM >= 20)

In the documentation, in a similar manner to the s390x entry? I know that LLVM 20 is still a couple months away but those commits will likely be released with that version, and since it also tells people to not use a version that is too old, I think it should be okay (?)

#15 lore raw
Quoted 7 lines · Koakuma
Quoted 3 lines · Masahiro Yamada

I think this should be documented (required LLVM version and the supported build command),
otherwise people cannot test this patch.

Nathan Chancellor <[email protected]> wrote:

Quoted 8 lines
Quoted 4 lines

I am not sure that there is a super concise way to describe for Documentation/kbuild/llvm.rst that sparc currently requires 'CC=clang LLVM_IAS=0' along with a build of clang from the main branch of llvm-project to work properly.

So about this, as a middle ground, would it be okay if I put

``CC=clang LLVM_IAS=0`` (LLVM >= 20)

I am OK with this.

Having this info is more helpful than nothing.

Quoted 5 lines

In the documentation, in a similar manner to the s390x entry? I know that LLVM 20 is still a couple months away but those commits will likely be released with that version, and since it also tells people to not use a version that is too old, I think it should be okay (?)

Signature · 2 lines
Best Regards
Masahiro Yamada
#16 lore raw
In reply to Koakuma
Quoted 11 lines · Koakuma
Quoted 3 lines · Masahiro Yamada

I think this should be documented (required LLVM version and the supported build command),
otherwise people cannot test this patch.

Quoted 4 lines · Nathan Chancellor

I am not sure that there is a super concise way to describe for Documentation/kbuild/llvm.rst that sparc currently requires 'CC=clang LLVM_IAS=0' along with a build of clang from the main branch of llvm-project to work properly.

Quoted 8 lines

So about this, as a middle ground, would it be okay if I put

``CC=clang LLVM_IAS=0`` (LLVM >= 20)

In the documentation, in a similar manner to the s390x entry? I know that LLVM 20 is still a couple months away but those commits will likely be released with that version, and since it also tells people to not use a version that is too old, I think it should be okay (?)

Yes, I think that would be reasonable.

Cheers,
Nathan

#17 lore raw
In reply to Nathan Chancellor
Quoted 15 lines · Nathan Chancellor
Quoted 1 line · Masahiro Yamada

I applied this patch set, but I still observe a build error.

...

Quoted 2 lines
masahiro@zoe:~/workspace/linux-kbuild(kbuild)$ make
LLVM=~/tools/llvm-latest/bin/  ARCH=sparc sparc64_defconfig all

...

Quoted 1 line

clang: error: unsupported argument '--undeclared-regs' to option '-Wa,'

Koakuma might know more than I do but I did not test either the integrated assembler or the rest of the LLVM tools; I only tested clang for CC. As far as I am aware, that has been where most of the effort in llvm-project has been going and I think there are probably other fixes that will be needed for the other tools. The command I tested was:

Quoted 6 lines
  $ make -skj"$(nproc)" \
         ARCH=sparc64 \
         CC=clang \
         CROSS_COMPILE=sparc64-linux-gnu- \
         LLVM_IAS=0 \
         mrproper defconfig all

With running this command in Ubuntu 24.10, I got improvements, but I still got another build error. (unknown argument: '-mv8plus')

masahiro@3606c94ac88c:~/workspace/linux-kbuild$ make -skj"$(nproc)"
ARCH=sparc64 CC=clang CROSS_COMPILE=sparc64-linux-gnu- LLVM_IAS=0
mrproper defconfig all
<stdin>:1519:2: warning: syscall clone3 not implemented [-W#warnings]
 1519 | #warning syscall clone3 not implemented
      |  ^
1 warning generated.
arch/sparc/vdso/vclock_gettime.c:274:1: warning: no previous prototype
for function '__vdso_clock_gettime' [-Wmissing-prototypes]
  274 | __vdso_clock_gettime(clockid_t clock, struct __kernel_old_timespec *ts)
      | ^
arch/sparc/vdso/vclock_gettime.c:273:9: note: declare 'static' if the
function is not intended to be used outside of this translation unit
  273 | notrace int
      |         ^
      |         static
arch/sparc/vdso/vclock_gettime.c:302:1: warning: no previous prototype
for function '__vdso_clock_gettime_stick' [-Wmissing-prototypes]
  302 | __vdso_clock_gettime_stick(clockid_t clock, struct
__kernel_old_timespec *ts)
      | ^
arch/sparc/vdso/vclock_gettime.c:301:9: note: declare 'static' if the
function is not intended to be used outside of this translation unit
  301 | notrace int
      |         ^
      |         static
arch/sparc/vdso/vclock_gettime.c:327:1: warning: no previous prototype
for function '__vdso_gettimeofday' [-Wmissing-prototypes]
  327 | __vdso_gettimeofday(struct __kernel_old_timeval *tv, struct
timezone *tz)
      | ^
arch/sparc/vdso/vclock_gettime.c:326:9: note: declare 'static' if the
function is not intended to be used outside of this translation unit
  326 | notrace int
      |         ^
      |         static
arch/sparc/vdso/vclock_gettime.c:363:1: warning: no previous prototype
for function '__vdso_gettimeofday_stick' [-Wmissing-prototypes]
  363 | __vdso_gettimeofday_stick(struct __kernel_old_timeval *tv,
struct timezone *tz)
      | ^
arch/sparc/vdso/vclock_gettime.c:362:9: note: declare 'static' if the
function is not intended to be used outside of this translation unit
  362 | notrace int
      |         ^
      |         static
4 warnings generated.
clang: error: unknown argument: '-mv8plus'
make[5]: *** [scripts/Makefile.build:229:
arch/sparc/vdso/vdso32/vclock_gettime.o] Error 1
sparc64-linux-gnu-ld: warning: arch/sparc/vdso/vdso-note.o: missing
.note.GNU-stack section implies executable stack
sparc64-linux-gnu-ld: NOTE: This behaviour is deprecated and will be
removed in a future version of the linker
make[5]: Target 'arch/sparc/vdso/' not remade because of errors.
make[4]: *** [scripts/Makefile.build:478: arch/sparc/vdso] Error 2
masahiro@3606c94ac88c:~/workspace/linux-kbuild$ clang --version
Ubuntu clang version 19.1.1 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin

Is this version too old, or am I missing something?

Quoted 7 lines

I see this as more of a stepping stone series to make testing those other components easier as time goes on, hence why I did not really consider user facing documentation either like you brought up in the other thread.

Cheers,
Nathan

Signature · 2 lines
Best Regards
Masahiro Yamada
#18 lore raw
Quoted 10 lines · Masahiro Yamada

With running this command in Ubuntu 24.10, I got improvements, but I still got another build error. (unknown argument: '-mv8plus')

clang: error: unknown argument: '-mv8plus'
make[5]: *** [scripts/Makefile.build:229:

masahiro@3606c94ac88c:~/workspace/linux-kbuild$ clang --version
Ubuntu clang version 19.1.1 (1ubuntu1)

Is this version too old, or am I missing something?

Yes, that is the issue resolved by the pull request that Koakuma mentioned in the changelog:

https://github.com/llvm/llvm-project/pull/98713
https://github.com/llvm/llvm-project/commit/6c270a8b9f1e1b80a6016aafb438db7dd89bcb99

which depends on some codegen changes too:

https://github.com/llvm/llvm-project/commit/aca971d336d9c7650120fc0fd6dfe58866408216

Those patches missed the LLVM 19 branch point by a couple of weeks:

https://github.com/llvm/llvm-project/commit/8f701b5df0adb3a2960d78ca2ad9cf53f39ba2fe

They are relatively simple, so maybe we would have a chance of convincing the stable maintainer of LLVM to take them for a later 19.1 release but given how little usage this is likely to see until the full LLVM stack is further developed, I am not sure that petition would be worth it.

Cheers,
Nathan

#19 lore raw
In reply to Nathan Chancellor
Quoted 44 lines · Nathan Chancellor

Hi Andreas,

Quoted 4 lines · Koakuma

This changes the CFLAGS for building the SPARC kernel so that it can be built with clang, as a follow up from the discussion in this thread:

https://lore.kernel.org/lkml/JAYB7uS-EdLABTR4iWZdtFOVa5MvlKosIrD_cKTzgeozCOGRM7lhxeLigFB1g3exX445I_W5VKB-tAzl2_G1zCVJRQjp67ODfsSqiZWOZ9o=@protonmail.com/T/#u

...

Quoted 19 lines

Building with these changes still result in a working kernel, at least for Sun T5120, Oracle T4-1, and qemu virtual machines.

On the LLVM side, the effort for building Linux/SPARC is tracked here:
https://github.com/llvm/llvm-project/issues/40792

---
Changes in v2:
- Remove the -mv8plus change; it will be handled on clang side:
https://github.com/llvm/llvm-project/pull/98713
- Add CLANG_TARGET_FLAGS as suggested in v1 review.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Koakuma (2):
sparc/build: Remove all usage of -fcall-used* flags sparc/build: Add SPARC target flags for compiling with clang

Quoted 4 lines
 arch/sparc/Makefile      | 4 ++--
 arch/sparc/vdso/Makefile | 2 +-
 scripts/Makefile.clang   | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)

Would you be able to help move this series [1] and its companion patch for the vDSO [2] along to Linus for 6.13? If you are not able to for whatever reason but the changes look reasonable to you, would you be able to provide an Ack so it can be chauffeured by someone else, such as Masahiro/Kbuild or Andrew/-mm?

For the record, I retested these three changes on top of 6.12-rc4, where they still apply cleanly. Now that the LLVM PR linked above (98713) has been merged into LLVM main, a clang built straight from llvm-project.git can build the kernel with this series (I tested at dca43a1c82f1).

Quoted 5 lines

[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/

Cheers,
Nathan

2/2 should update the "Supported Architectures"
of Documentation/kbuild/llvm.rst if this is adding a new architecture support.

--
Best Regards
Masahiro Yamada