[PATCH 0/9] Update clang support for ARM

Hey all,
I decided to take a look again at what's needed to build and boot ARM platforms when building with clang. The good news is that this generally works now. Some size-constrained platforms don't build right now but I was able to test a reasonable part of my lab. This series also depends on: https://patchwork.ozlabs.org/project/uboot/patch/20200604203515.12971-1-trin... to fix the warning there.
At this point LTO + clang requires a bit more work, and to use llvm-ld. As the platform I was trying was still too large to link even with this, I've set that investigation aside for now.
I've boot tested clang-16 on Pi 3 (32bit, 64bit, arm64) and libretech-cc, and I'll be testing pine64_plus soon along with maybe mx6cuboxi and seeing what the failures are on am65x_evm / j721e_evm (these platforms require a bit more scripting on my part to make build and test clean).

Today, only gcc has __builtin_aarch64_crc32b (clang-16 does not, for example). Make this option depend on CC_IS_GCC.
Signed-off-by: Tom Rini trini@konsulko.com --- arch/arm/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index f0118e225419..d7e657806051 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -12,7 +12,7 @@ config ARM64
config ARM64_CRC32 bool "Enable support for CRC32 instruction" - depends on ARM64 + depends on ARM64 && CC_IS_GCC default y help ARMv8 implements dedicated crc32 instruction for crc32 calculation.

On Thu, 6 Apr 2023 at 11:49, Tom Rini trini@konsulko.com wrote:
Today, only gcc has __builtin_aarch64_crc32b (clang-16 does not, for example). Make this option depend on CC_IS_GCC.
Signed-off-by: Tom Rini trini@konsulko.com
arch/arm/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Apr 05, 2023 at 07:48:51PM -0400, Tom Rini wrote:
Today, only gcc has __builtin_aarch64_crc32b (clang-16 does not, for example). Make this option depend on CC_IS_GCC.
Signed-off-by: Tom Rini trini@konsulko.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

When we invoke $(CPP) to make u-boot.lds we have LDPPFLAGS available to set other required flags here. As this file is for the target and not the host, we must ensure that CPP knows what the target architecture is. For this, pass in $(CLANG_TARGET).
Signed-off-by: Tom Rini trini@konsulko.com --- Makefile | 1 + 1 file changed, 1 insertion(+)
diff --git a/Makefile b/Makefile index 5083beae359a..97a84ae3131e 100644 --- a/Makefile +++ b/Makefile @@ -437,6 +437,7 @@ KBUILD_LDFLAGS := ifeq ($(cc-name),clang) ifneq ($(CROSS_COMPILE),) CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=%)) +LDPPFLAGS += $(CLANG_TARGET) GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD))) CLANG_PREFIX := --prefix=$(GCC_TOOLCHAIN_DIR) GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)

On Thu, 6 Apr 2023 at 11:49, Tom Rini trini@konsulko.com wrote:
When we invoke $(CPP) to make u-boot.lds we have LDPPFLAGS available to set other required flags here. As this file is for the target and not the host, we must ensure that CPP knows what the target architecture is. For this, pass in $(CLANG_TARGET).
Signed-off-by: Tom Rini trini@konsulko.com
Makefile | 1 + 1 file changed, 1 insertion(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Apr 05, 2023 at 07:48:52PM -0400, Tom Rini wrote:
When we invoke $(CPP) to make u-boot.lds we have LDPPFLAGS available to set other required flags here. As this file is for the target and not the host, we must ensure that CPP knows what the target architecture is. For this, pass in $(CLANG_TARGET).
Signed-off-by: Tom Rini trini@konsulko.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

In the case of using clang to build, and having not already enabled the private libgcc, do not look for it, as it will not be found nor required.
Signed-off-by: Tom Rini trini@konsulko.com --- Makefile | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/Makefile b/Makefile index 97a84ae3131e..b5063446ff85 100644 --- a/Makefile +++ b/Makefile @@ -894,8 +894,10 @@ u-boot-main := $(libs-y) ifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y) PLATFORM_LIBGCC = arch/$(ARCH)/lib/lib.a else +ifndef CONFIG_CC_IS_CLANG PLATFORM_LIBGCC := -L $(shell dirname `$(CC) $(c_flags) -print-libgcc-file-name`) -lgcc endif +endif PLATFORM_LIBS += $(PLATFORM_LIBGCC)
ifdef CONFIG_CC_COVERAGE

On Thu, 6 Apr 2023 at 11:50, Tom Rini trini@konsulko.com wrote:
In the case of using clang to build, and having not already enabled the private libgcc, do not look for it, as it will not be found nor required.
Signed-off-by: Tom Rini trini@konsulko.com
Makefile | 2 ++ 1 file changed, 2 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Apr 05, 2023 at 07:48:53PM -0400, Tom Rini wrote:
In the case of using clang to build, and having not already enabled the private libgcc, do not look for it, as it will not be found nor required.
Signed-off-by: Tom Rini trini@konsulko.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

When building for ARM64, we need to pass -ffixed-x18 and otherwise pass -ffixed-r9. Rather than having this logic in two places, we can do this once in arch/arm/config.mk. Further, while gcc will ignore being passed both -ffixed-r9 and -ffixed-x18 and simply use -ffixed-x18, clang will note that -ffixed-r9 is not used. Remove this duplication to also remove the warning.
Signed-off-by: Tom Rini trini@konsulko.com --- arch/arm/config.mk | 10 ++++++++-- arch/arm/cpu/armv8/config.mk | 1 - 2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/arch/arm/config.mk b/arch/arm/config.mk index bf781f102620..5530d02b66c4 100644 --- a/arch/arm/config.mk +++ b/arch/arm/config.mk @@ -3,7 +3,13 @@ # (C) Copyright 2000-2002 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
-CFLAGS_NON_EFI := -fno-pic -ffixed-r9 -ffunction-sections -fdata-sections \ +ifeq ($(CONFIG_ARM64),y) +FIXED_REG := -ffixed-x18 +else +FIXED_REG := -ffixed-r9 +endif + +CFLAGS_NON_EFI := -fno-pic $(FIXED_REG) -ffunction-sections -fdata-sections \ -fstack-protector-strong CFLAGS_EFI := -fpic -fshort-wchar
@@ -15,7 +21,7 @@ ifneq ($(LTO_ENABLE),y) PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections endif
-PLATFORM_RELFLAGS += -fno-common -ffixed-r9 +PLATFORM_RELFLAGS += -fno-common $(FIXED_REG) PLATFORM_RELFLAGS += $(call cc-option, -msoft-float) \ $(call cc-option,-mgeneral-regs-only) \ $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) diff --git a/arch/arm/cpu/armv8/config.mk b/arch/arm/cpu/armv8/config.mk index ca06ed3d4f92..4d74b2a533e0 100644 --- a/arch/arm/cpu/armv8/config.mk +++ b/arch/arm/cpu/armv8/config.mk @@ -2,7 +2,6 @@ # # (C) Copyright 2002 # Gary Jennejohn, DENX Software Engineering, garyj@denx.de -PLATFORM_RELFLAGS += -fno-common -ffixed-x18 PLATFORM_RELFLAGS += $(call cc-option,-mbranch-protection=none)
PF_NO_UNALIGNED := $(call cc-option, -mstrict-align)

On Thu, 6 Apr 2023 at 11:50, Tom Rini trini@konsulko.com wrote:
When building for ARM64, we need to pass -ffixed-x18 and otherwise pass -ffixed-r9. Rather than having this logic in two places, we can do this once in arch/arm/config.mk. Further, while gcc will ignore being passed both -ffixed-r9 and -ffixed-x18 and simply use -ffixed-x18, clang will note that -ffixed-r9 is not used. Remove this duplication to also remove the warning.
Signed-off-by: Tom Rini trini@konsulko.com
arch/arm/config.mk | 10 ++++++++-- arch/arm/cpu/armv8/config.mk | 1 - 2 files changed, 8 insertions(+), 3 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Apr 05, 2023 at 07:48:54PM -0400, Tom Rini wrote:
When building for ARM64, we need to pass -ffixed-x18 and otherwise pass -ffixed-r9. Rather than having this logic in two places, we can do this once in arch/arm/config.mk. Further, while gcc will ignore being passed both -ffixed-r9 and -ffixed-x18 and simply use -ffixed-x18, clang will note that -ffixed-r9 is not used. Remove this duplication to also remove the warning.
Signed-off-by: Tom Rini trini@konsulko.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!
arch/arm/cpu/armv8/config.mk | 1 - 2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/arch/arm/config.mk b/arch/arm/config.mk index bf781f102620..5530d02b66c4 100644 --- a/arch/arm/config.mk +++ b/arch/arm/config.mk @@ -3,7 +3,13 @@ # (C) Copyright 2000-2002 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
-CFLAGS_NON_EFI := -fno-pic -ffixed-r9 -ffunction-sections -fdata-sections \ +ifeq ($(CONFIG_ARM64),y) +FIXED_REG := -ffixed-x18 +else +FIXED_REG := -ffixed-r9 +endif
+CFLAGS_NON_EFI := -fno-pic $(FIXED_REG) -ffunction-sections -fdata-sections \ -fstack-protector-strong CFLAGS_EFI := -fpic -fshort-wchar
@@ -15,7 +21,7 @@ ifneq ($(LTO_ENABLE),y) PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections endif
-PLATFORM_RELFLAGS += -fno-common -ffixed-r9 +PLATFORM_RELFLAGS += -fno-common $(FIXED_REG) PLATFORM_RELFLAGS += $(call cc-option, -msoft-float) \ $(call cc-option,-mgeneral-regs-only) \ $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) diff --git a/arch/arm/cpu/armv8/config.mk b/arch/arm/cpu/armv8/config.mk index ca06ed3d4f92..4d74b2a533e0 100644 --- a/arch/arm/cpu/armv8/config.mk +++ b/arch/arm/cpu/armv8/config.mk @@ -2,7 +2,6 @@ # # (C) Copyright 2002 # Gary Jennejohn, DENX Software Engineering, garyj@denx.de -PLATFORM_RELFLAGS += -fno-common -ffixed-x18 PLATFORM_RELFLAGS += $(call cc-option,-mbranch-protection=none)
PF_NO_UNALIGNED := $(call cc-option, -mstrict-align)

Toolchains which do not directly support using "isb" and "dsb" directly are no longer functionally supported in U-Boot. Furthermore, clang has for a long time warned about using the alternate form that we were. Update the code.
Signed-off-by: Tom Rini trini@konsulko.com --- arch/arm/cpu/armv7/start.S | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S index 7d7aac021e22..69e281b086af 100644 --- a/arch/arm/cpu/armv7/start.S +++ b/arch/arm/cpu/armv7/start.S @@ -134,8 +134,8 @@ ENTRY(c_runtime_cpu_setup) */ #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF) mcr p15, 0, r0, c7, c5, 0 @ invalidate icache - mcr p15, 0, r0, c7, c10, 4 @ DSB - mcr p15, 0, r0, c7, c5, 4 @ ISB + dsb + isb #endif
bx lr @@ -188,8 +188,8 @@ ENTRY(cpu_init_cp15) mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs mcr p15, 0, r0, c7, c5, 0 @ invalidate icache mcr p15, 0, r0, c7, c5, 6 @ invalidate BP array - mcr p15, 0, r0, c7, c10, 4 @ DSB - mcr p15, 0, r0, c7, c5, 4 @ ISB + dsb + isb
/* * disable MMU stuff and caches

On Thu, 6 Apr 2023 at 11:50, Tom Rini trini@konsulko.com wrote:
Toolchains which do not directly support using "isb" and "dsb" directly are no longer functionally supported in U-Boot. Furthermore, clang has for a long time warned about using the alternate form that we were. Update the code.
Signed-off-by: Tom Rini trini@konsulko.com
arch/arm/cpu/armv7/start.S | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Apr 05, 2023 at 07:48:55PM -0400, Tom Rini wrote:
Toolchains which do not directly support using "isb" and "dsb" directly are no longer functionally supported in U-Boot. Furthermore, clang has for a long time warned about using the alternate form that we were. Update the code.
Signed-off-by: Tom Rini trini@konsulko.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

When building with clang we get a warning that rdaddr could be uninitialized in one case. While this cannot functionally happen, we can easily silence the warning.
Signed-off-by: Tom Rini trini@konsulko.com --- boot/image-board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/boot/image-board.c b/boot/image-board.c index c602832249e3..d500da1b4b91 100644 --- a/boot/image-board.c +++ b/boot/image-board.c @@ -328,7 +328,7 @@ static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a bool done_select = !select; bool done = false; int rd_noffset; - ulong rd_addr; + ulong rd_addr = 0; char *buf;
if (CONFIG_IS_ENABLED(FIT)) {

On Thu, 6 Apr 2023 at 11:50, Tom Rini trini@konsulko.com wrote:
When building with clang we get a warning that rdaddr could be uninitialized in one case. While this cannot functionally happen, we can easily silence the warning.
Signed-off-by: Tom Rini trini@konsulko.com
boot/image-board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Apr 05, 2023 at 07:48:56PM -0400, Tom Rini wrote:
When building with clang we get a warning that rdaddr could be uninitialized in one case. While this cannot functionally happen, we can easily silence the warning.
Signed-off-by: Tom Rini trini@konsulko.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

When building with clang, it notes that sdinfo may be unused uninitialized in some cases. This appears to be true from reading the code, and we can simply set the variable to zero to start with and be as correct as before.
Signed-off-by: Tom Rini trini@konsulko.com --- I'm honestly not sure why gcc isn't complaining here as this seems to be a real issue.
Cc: Lukasz Majewski lukma@denx.de Cc: Marek Vasut marex@denx.de --- drivers/usb/gadget/f_mass_storage.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 45f0504b6e8a..f46829eb7adb 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -1117,7 +1117,7 @@ static int do_request_sense(struct fsg_common *common, struct fsg_buffhd *bh) { struct fsg_lun *curlun = &common->luns[common->lun]; u8 *buf = (u8 *) bh->buf; - u32 sd, sdinfo; + u32 sd, sdinfo = 0; int valid;
/* @@ -1145,7 +1145,6 @@ static int do_request_sense(struct fsg_common *common, struct fsg_buffhd *bh) if (!curlun) { /* Unsupported LUNs are okay */ common->bad_lun_okay = 1; sd = SS_LOGICAL_UNIT_NOT_SUPPORTED; - sdinfo = 0; valid = 0; } else { sd = curlun->sense_data;

On 4/6/23 01:48, Tom Rini wrote:
When building with clang, it notes that sdinfo may be unused uninitialized in some cases. This appears to be true from reading the code, and we can simply set the variable to zero to start with and be as correct as before.
Signed-off-by: Tom Rini trini@konsulko.com
I'm honestly not sure why gcc isn't complaining here as this seems to be a real issue.
It seems this also isn't the first issue where gcc isn't complaining and it should be complaining. IIRC there was one more case in spl_mmc.c too .
Reviewed-by: Marek Vasut marex@denx.de

On Wed, Apr 05, 2023 at 07:48:57PM -0400, Tom Rini wrote:
When building with clang, it notes that sdinfo may be unused uninitialized in some cases. This appears to be true from reading the code, and we can simply set the variable to zero to start with and be as correct as before.
Signed-off-by: Tom Rini trini@konsulko.com Reviewed-by: Marek Vasut marex@denx.de
Applied to u-boot/master, thanks!

When building with clang we see this warning: field guid within 'struct efi_hii_keyboard_layout' is less aligned than 'efi_guid_t' and is usually due to 'struct efi_hii_keyboard_layout' being packed, which can lead to unaligned accesses [-Wunaligned-access]
Which is correct and true as EFI payloads are by specification allowed to do unaligned access. And so to silence the warning here and only here, we make use of #pragma to push/pop turning off the warning.
Signed-off-by: Tom Rini trini@konsulko.com --- Cc: Heinrich Schuchardt xypron.glpk@gmx.de Cc: Ilias Apalodimas ilias.apalodimas@linaro.org --- include/efi_api.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/include/efi_api.h b/include/efi_api.h index dc6e5ce236c9..f3bcbf593bea 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -1168,9 +1168,21 @@ struct efi_key_descriptor { u16 affected_attribute; } __packed;
+/* The warniing: + * field guid within 'struct efi_hii_keyboard_layout' is less aligned than 'efi_guid_t' and is usually due to 'struct efi_hii_keyboard_layout' being packed, which can lead to unaligned accesses [-Wunaligned-access] + * is intentional due to EFI requiring unaligned access to be supported. + */ struct efi_hii_keyboard_layout { u16 layout_length; +#ifdef CONFIG_CC_IS_CLANG +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunaligned-access" +#endif efi_guid_t guid; +#ifdef CONFIG_CC_IS_CLANG +#pragma clang diagnostic pop +#endif + u32 layout_descriptor_string_offset; u8 descriptor_count; struct efi_key_descriptor descriptors[];

On 4/6/23 01:48, Tom Rini wrote:
When building with clang we see this warning: field guid within 'struct efi_hii_keyboard_layout' is less aligned than 'efi_guid_t' and is usually due to 'struct efi_hii_keyboard_layout' being packed, which can lead to unaligned accesses [-Wunaligned-access]
Which is correct and true as EFI payloads are by specification allowed to do unaligned access. And so to silence the warning here and only here, we make use of #pragma to push/pop turning off the warning.
Signed-off-by: Tom Rini trini@konsulko.com
Cc: Heinrich Schuchardt xypron.glpk@gmx.de Cc: Ilias Apalodimas ilias.apalodimas@linaro.org
include/efi_api.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/include/efi_api.h b/include/efi_api.h index dc6e5ce236c9..f3bcbf593bea 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -1168,9 +1168,21 @@ struct efi_key_descriptor { u16 affected_attribute; } __packed;
+/* The warniing:
- field guid within 'struct efi_hii_keyboard_layout' is less aligned than 'efi_guid_t' and is usually due to 'struct efi_hii_keyboard_layout' being packed, which can lead to unaligned accesses [-Wunaligned-access]
- is intentional due to EFI requiring unaligned access to be supported.
- */ struct efi_hii_keyboard_layout { u16 layout_length;
+#ifdef CONFIG_CC_IS_CLANG +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunaligned-access" +#endif efi_guid_t guid; +#ifdef CONFIG_CC_IS_CLANG +#pragma clang diagnostic pop +#endif
I don't think that the clang warning should be suppressed. We should replace efi_guid_t by u8[16] instead. This will force us to take the missing alignment into account when accessing the component in future.
- efi_guid_t guid; + u8 guid[16];
Best regards
Heinrich
- u32 layout_descriptor_string_offset; u8 descriptor_count; struct efi_key_descriptor descriptors[];

Hi
On Thu, 6 Apr 2023 at 09:16, Heinrich Schuchardt xypron.glpk@gmx.de wrote:
On 4/6/23 01:48, Tom Rini wrote:
When building with clang we see this warning: field guid within 'struct efi_hii_keyboard_layout' is less aligned than 'efi_guid_t' and is usually due to 'struct efi_hii_keyboard_layout' being packed, which can lead to unaligned accesses [-Wunaligned-access]
Which is correct and true as EFI payloads are by specification allowed to do unaligned access. And so to silence the warning here and only here, we make use of #pragma to push/pop turning off the warning.
Signed-off-by: Tom Rini trini@konsulko.com
Cc: Heinrich Schuchardt xypron.glpk@gmx.de Cc: Ilias Apalodimas ilias.apalodimas@linaro.org
include/efi_api.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/include/efi_api.h b/include/efi_api.h index dc6e5ce236c9..f3bcbf593bea 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -1168,9 +1168,21 @@ struct efi_key_descriptor { u16 affected_attribute; } __packed;
+/* The warniing:
- field guid within 'struct efi_hii_keyboard_layout' is less aligned than 'efi_guid_t' and is usually due to 'struct efi_hii_keyboard_layout' being packed, which can lead to unaligned accesses [-Wunaligned-access]
- is intentional due to EFI requiring unaligned access to be supported.
- */ struct efi_hii_keyboard_layout { u16 layout_length;
+#ifdef CONFIG_CC_IS_CLANG +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunaligned-access" +#endif efi_guid_t guid; +#ifdef CONFIG_CC_IS_CLANG +#pragma clang diagnostic pop +#endif
I don't think that the clang warning should be suppressed. We should replace efi_guid_t by u8[16] instead. This will force us to take the missing alignment into account when accessing the component in future.
efi_guid_t guid;
u8 guid[16];
I think what Heinrich suggests is fine, the EFI spec itself says that efi_guid must be 8-byte aligned unless otherwise specified. But we have another issue here. We aren't supposed to include structs that contain flexible length arrays into another array or struct. Quoting the C spec [0] Such a structure (and any union containing, possibly recursively, a member that is such a structure) shall not be a member of a structure or an element of an array. IOW efi_hii_keyboard_layout should not include struct efi_key_descriptor descriptors[]; since we include it at efi_hii_keyboard_package
Regards /Ilias
[0] https://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf chapter 6.7.2.1
Best regards
Heinrich
u32 layout_descriptor_string_offset; u8 descriptor_count; struct efi_key_descriptor descriptors[];

At this point, clang can be used on both 32bit and 64bit targets without issue.
Signed-off-by: Tom Rini trini@konsulko.com --- doc/build/clang.rst | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/doc/build/clang.rst b/doc/build/clang.rst index 1d35616eb5ef..222487032ce0 100644 --- a/doc/build/clang.rst +++ b/doc/build/clang.rst @@ -11,14 +11,6 @@ The ARM backend can be instructed not to use the r9 and x18 registers using supported inline assembly is needed to get and set the r9 or x18 value. This leads to larger code then strictly necessary, but at least works.
-**NOTE:** target compilation only work for _some_ ARM boards at the moment. -Also AArch64 is not supported currently due to a lack of private libgcc -support. Boards which reassign gd in c will also fail to compile, but there is -in no strict reason to do so in the ARM world, since crt0.S takes care of this. -These assignments can be avoided by changing the init calls but this is not in -mainline yet. - - Debian based ------------
@@ -28,14 +20,14 @@ Required packages can be installed via apt, e.g.
sudo apt-get install clang
-Note that we still use binutils for some tools so we must continue to set -CROSS_COMPILE. To compile U-Boot with Clang on Linux without IAS use e.g. +Note that we make use of the CROSS_COMPILE variable to determine what to tell +clang to use as the build target. +To compile U-Boot with Clang on Linux without IAS use e.g.
.. code-block:: bash
make HOSTCC=clang rpi_2_defconfig - make HOSTCC=clang CROSS_COMPILE=arm-linux-gnueabi- \ - CC="clang -target arm-linux-gnueabi" -j8 + make HOSTCC=clang CROSS_COMPILE=arm-linux-gnueabi- CC=clang -j8
It can also be used to compile sandbox:

On Thu, 6 Apr 2023 at 11:51, Tom Rini trini@konsulko.com wrote:
At this point, clang can be used on both 32bit and 64bit targets without issue.
Signed-off-by: Tom Rini trini@konsulko.com
doc/build/clang.rst | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On 4/6/23 01:48, Tom Rini wrote:
At this point, clang can be used on both 32bit and 64bit targets without issue.
Signed-off-by: Tom Rini trini@konsulko.com Reviewed-by: Simon Glass sjg@chromium.org
doc/build/clang.rst | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/doc/build/clang.rst b/doc/build/clang.rst index 1d35616eb5ef..222487032ce0 100644 --- a/doc/build/clang.rst +++ b/doc/build/clang.rst @@ -11,14 +11,6 @@ The ARM backend can be instructed not to use the r9 and x18 registers using supported inline assembly is needed to get and set the r9 or x18 value. This leads to larger code then strictly necessary, but at least works.
-**NOTE:** target compilation only work for _some_ ARM boards at the moment. -Also AArch64 is not supported currently due to a lack of private libgcc -support. Boards which reassign gd in c will also fail to compile, but there is -in no strict reason to do so in the ARM world, since crt0.S takes care of this. -These assignments can be avoided by changing the init calls but this is not in -mainline yet.
Debian based
@@ -28,14 +20,14 @@ Required packages can be installed via apt, e.g.
sudo apt-get install clang
-Note that we still use binutils for some tools so we must continue to set -CROSS_COMPILE. To compile U-Boot with Clang on Linux without IAS use e.g. +Note that we make use of the CROSS_COMPILE variable to determine what to tell +clang to use as the build target. +To compile U-Boot with Clang on Linux without IAS use e.g.
I had a hard time understanding this text block.
Do you mean:
"We use of the CROSS_COMPILE variable to derive the build target which is passed as -target parameter to clang.
The CROSS_COMPILE variable further determines the paths to other build tools. As assembler we use the binary pointed to by '$(CROSS_COMPILE)as' instead of the LLVM integrated assembler (IAS).
Here is an example demonstrating building U-Boot for the Raspberry Pi 2 using clang:"
Best regards
Heinrich
.. code-block:: bash
make HOSTCC=clang rpi_2_defconfig
- make HOSTCC=clang CROSS_COMPILE=arm-linux-gnueabi- \
CC="clang -target arm-linux-gnueabi" -j8
make HOSTCC=clang CROSS_COMPILE=arm-linux-gnueabi- CC=clang -j8
It can also be used to compile sandbox:

On Tue, Nov 21, 2023 at 02:26:14PM +0100, Heinrich Schuchardt wrote:
On 4/6/23 01:48, Tom Rini wrote:
At this point, clang can be used on both 32bit and 64bit targets without issue.
Signed-off-by: Tom Rini trini@konsulko.com Reviewed-by: Simon Glass sjg@chromium.org
doc/build/clang.rst | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/doc/build/clang.rst b/doc/build/clang.rst index 1d35616eb5ef..222487032ce0 100644 --- a/doc/build/clang.rst +++ b/doc/build/clang.rst @@ -11,14 +11,6 @@ The ARM backend can be instructed not to use the r9 and x18 registers using supported inline assembly is needed to get and set the r9 or x18 value. This leads to larger code then strictly necessary, but at least works.
-**NOTE:** target compilation only work for _some_ ARM boards at the moment. -Also AArch64 is not supported currently due to a lack of private libgcc -support. Boards which reassign gd in c will also fail to compile, but there is -in no strict reason to do so in the ARM world, since crt0.S takes care of this. -These assignments can be avoided by changing the init calls but this is not in -mainline yet.
Debian based
@@ -28,14 +20,14 @@ Required packages can be installed via apt, e.g.
sudo apt-get install clang
-Note that we still use binutils for some tools so we must continue to set -CROSS_COMPILE. To compile U-Boot with Clang on Linux without IAS use e.g. +Note that we make use of the CROSS_COMPILE variable to determine what to tell +clang to use as the build target. +To compile U-Boot with Clang on Linux without IAS use e.g.
I had a hard time understanding this text block.
Note that the logic in question (from the top-level Makefile) is: ifeq ($(cc-name),clang) ifneq ($(CROSS_COMPILE),) CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=%)) ...
So yes, "make CROSS_COMPILE=arm-linux-gnueabi- CC=clang" should in turn invoke "clang --target=arm-linux-gnueabi".
Do you mean:
"We use of the CROSS_COMPILE variable to derive the build target which is passed as -target parameter to clang.
The CROSS_COMPILE variable further determines the paths to other build tools. As assembler we use the binary pointed to by '$(CROSS_COMPILE)as' instead of the LLVM integrated assembler (IAS).
Here is an example demonstrating building U-Boot for the Raspberry Pi 2 using clang:"
That is clearer, yes, thanks. And then I see my example needs fixing again too. I'll v2 this patch at some point soon, thanks.

On 4/6/23 01:48, Tom Rini wrote:
Hey all,
I decided to take a look again at what's needed to build and boot ARM platforms when building with clang. The good news is that this generally works now. Some size-constrained platforms don't build right now but I was able to test a reasonable part of my lab. This series also depends on: https://patchwork.ozlabs.org/project/uboot/patch/20200604203515.12971-1-trin... to fix the warning there.
At this point LTO + clang requires a bit more work, and to use llvm-ld. As the platform I was trying was still too large to link even with this, I've set that investigation aside for now.
I've boot tested clang-16 on Pi 3 (32bit, 64bit, arm64) and libretech-cc, and I'll be testing pine64_plus soon along with maybe mx6cuboxi and seeing what the failures are on am65x_evm / j721e_evm (these platforms require a bit more scripting on my part to make build and test clean).
I tried to build qemu_arm64_defconfig with origin/WIP/update-clang-for-arm.
CROSS_COMPILE=aarch64-linux-gnu- HOSTCC=clang CC="clang make-target aarch64-linux-gnu" -j$(nproc)
I see a bunch of warnings and a build failure due to
examples/standalone/hello_world.c:15: undefined reference to `printf'
Best regards
Heinrich

On Thu, Apr 06, 2023 at 08:34:22AM +0200, Heinrich Schuchardt wrote:
On 4/6/23 01:48, Tom Rini wrote:
Hey all,
I decided to take a look again at what's needed to build and boot ARM platforms when building with clang. The good news is that this generally works now. Some size-constrained platforms don't build right now but I was able to test a reasonable part of my lab. This series also depends on: https://patchwork.ozlabs.org/project/uboot/patch/20200604203515.12971-1-trin... to fix the warning there.
At this point LTO + clang requires a bit more work, and to use llvm-ld. As the platform I was trying was still too large to link even with this, I've set that investigation aside for now.
I've boot tested clang-16 on Pi 3 (32bit, 64bit, arm64) and libretech-cc, and I'll be testing pine64_plus soon along with maybe mx6cuboxi and seeing what the failures are on am65x_evm / j721e_evm (these platforms require a bit more scripting on my part to make build and test clean).
I tried to build qemu_arm64_defconfig with origin/WIP/update-clang-for-arm.
CROSS_COMPILE=aarch64-linux-gnu- HOSTCC=clang CC="clang make-target aarch64-linux-gnu" -j$(nproc)
I see a bunch of warnings and a build failure due to
I see a few more warnings, OK, including an EFI one that suggests to me that you and Ilias will want to find some time to look at this deeper and address all of the cases of this issue.
I'm looking at the hello_world failure to see if that's something easy to fix or if perhaps another case of depends on CC_IS_GCC.
participants (5)
-
Heinrich Schuchardt
-
Ilias Apalodimas
-
Marek Vasut
-
Simon Glass
-
Tom Rini