[PATCH 0/1] riscv: Support building with Clang

Hello everyone!
This is a minimal patchset for making U-Boot build with Clang on RISC-V, something I stumbled upon while writing U-Boot build scripts for SerenityOS's RISC-V port. The only change is a (for unclear reasons...) differently-named flag for fixing the global pointer.
Notably, this patch does not make U-Boot actually functional under Clang. Booting this on QEMU (`-M virt -kernel path/to/u-boot -serial stdio`) hangs after the image is loaded. I do not have the motivation to debug this, but it may be helpful for further work on getting a working build out of Clang on this architecture.
Greetings, kleines Filmröllchen
PS: I am new to a mail patch contribution workflow and may have messed this up despite reading through plenty relevant documentation. Please kindly point out any improvements I could make on my side.
kleines Filmröllchen (1): riscv: Support building with Clang
arch/riscv/config.mk | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)

The -ffixed-gp option of GCC has an exact equivalent of -ffixed-x3 in Clang.
Signed-off-by: kleines Filmröllchen filmroellchen@serenityos.org ---
arch/riscv/config.mk | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/config.mk b/arch/riscv/config.mk index 9cf2aef0a4..dc4f30d673 100644 --- a/arch/riscv/config.mk +++ b/arch/riscv/config.mk @@ -9,6 +9,9 @@ # Copyright (C) 2017 Andes Technology Corporation # Rick Chen, Andes Technology Corporation rick@andestech.com # +# Copyright (C) 2024 the SerenityOS project +# kleines Filmröllchen filmroellchen@serenityos.org +#
32bit-emul := elf32lriscv 64bit-emul := elf64lriscv @@ -25,7 +28,12 @@ EFI_LDS := elf_riscv64_efi.lds PLATFORM_ELFFLAGS += -B riscv -O elf64-littleriscv endif
-PLATFORM_CPPFLAGS += -ffixed-gp -fpic +PLATFORM_CPPFLAGS += -fpic +ifeq ($(cc-name),clang) +PLATFORM_CPPFLAGS += -ffixed-x3 +else +PLATFORM_CPPFLAGS += -ffixed-gp +endif PLATFORM_RELFLAGS += -fno-common -ffunction-sections -fdata-sections LDFLAGS_u-boot += --gc-sections -static -pie

On Sat, Jan 20, 2024 at 01:14:04AM +0100, kleines Filmröllchen wrote:
The -ffixed-gp option of GCC has an exact equivalent of -ffixed-x3 in Clang.
Signed-off-by: kleines Filmröllchen filmroellchen@serenityos.org
arch/riscv/config.mk | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/config.mk b/arch/riscv/config.mk index 9cf2aef0a4..dc4f30d673 100644 --- a/arch/riscv/config.mk +++ b/arch/riscv/config.mk @@ -9,6 +9,9 @@ # Copyright (C) 2017 Andes Technology Corporation # Rick Chen, Andes Technology Corporation rick@andestech.com # +# Copyright (C) 2024 the SerenityOS project +# kleines Filmröllchen filmroellchen@serenityos.org +#
32bit-emul := elf32lriscv 64bit-emul := elf64lriscv
We don't have hard and fast rules about adding copyright lines, but this seems a bit excessive.
@@ -25,7 +28,12 @@ EFI_LDS := elf_riscv64_efi.lds PLATFORM_ELFFLAGS += -B riscv -O elf64-littleriscv endif
-PLATFORM_CPPFLAGS += -ffixed-gp -fpic +PLATFORM_CPPFLAGS += -fpic +ifeq ($(cc-name),clang) +PLATFORM_CPPFLAGS += -ffixed-x3 +else +PLATFORM_CPPFLAGS += -ffixed-gp +endif PLATFORM_RELFLAGS += -fno-common -ffunction-sections -fdata-sections LDFLAGS_u-boot += --gc-sections -static -pie
A quick check shows that GCC support -ffixed-x3 as well, so we should just use that in all cases.

Hello everyone!
This is a minimal patchset for making U-Boot build with Clang on RISC-V, something I stumbled upon while writing U-Boot build scripts for SerenityOS's RISC-V port. The only change is a (for unclear reasons...) differently-named flag for fixing the global pointer.
Notably, this patch does not make U-Boot actually functional under Clang. Booting this on QEMU (`-M virt -kernel path/to/u-boot -serial stdio`) hangs after the image is loaded. I do not have the motivation to debug this, but it may be helpful for further work on getting a working build out of Clang on this architecture.
Greetings, kleines Filmröllchen
Changes in v2: - Removed copyright attribution - Use -ffixed-x3 unconditionally as it is also supported by GCC
kleines Filmröllchen (1): riscv: Support building with Clang
arch/riscv/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)

The -ffixed-gp option of GCC has an exact equivalent of -ffixed-x3 in Clang.
Signed-off-by: kleines Filmröllchen filmroellchen@serenityos.org ---
Changes in v2: - Removed copyright attribution - Use -ffixed-x3 unconditionally as it is also supported by GCC
arch/riscv/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/riscv/config.mk b/arch/riscv/config.mk index 9cf2aef0a4..9f16dda92a 100644 --- a/arch/riscv/config.mk +++ b/arch/riscv/config.mk @@ -25,7 +25,7 @@ EFI_LDS := elf_riscv64_efi.lds PLATFORM_ELFFLAGS += -B riscv -O elf64-littleriscv endif
-PLATFORM_CPPFLAGS += -ffixed-gp -fpic +PLATFORM_CPPFLAGS += -ffixed-x3 -fpic PLATFORM_RELFLAGS += -fno-common -ffunction-sections -fdata-sections LDFLAGS_u-boot += --gc-sections -static -pie

On Thu, Jan 25, 2024 at 03:06:59PM +0100, kleines Filmröllchen wrote:
The -ffixed-gp option of GCC has an exact equivalent of -ffixed-x3 in Clang.
Signed-off-by: kleines Filmröllchen filmroellchen@serenityos.org
Reviewed-by: Tom Rini trini@konsulko.com
participants (2)
-
kleines Filmröllchen
-
Tom Rini