Skip to contentSkip to conversation

Update clang support for ARM

PATCH In review Tom Rini 5 participants 31 messages Apr 5, 2023 – Nov 21, 2023

Subsystems (3)
lore
Share & tools
lore

Tom Rini

author
#0 lore raw

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

Signature · 1 line
Tom
author
#1 lore raw

PATCH 1/9 arm: Only support ARM64_CRC32 when using GCC

Today, only gcc has __builtin_aarch64_crc32b (clang-16 does not, for example). Make this option depend on CC_IS_GCC.

---
 arch/arm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/Kconfig +1 -1
index f0118e225419..d7e657806051 100644
@@ -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.
Signature · 1 line
2.34.1
Reviewed-by on v1 1/9
#2 lore raw

Re: [PATCH 1/9] arm: Only support ARM64_CRC32 when using GCC

Quoted 8 lines · Tom Rini

Today, only gcc has __builtin_aarch64_crc32b (clang-16 does not, for example). Make this option depend on CC_IS_GCC.

---
 arch/arm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
author
#4 lore raw

PATCH 2/9 clang: Add $(CLANG_TARGET) to LDPPFLAGS

In reply to Tom Rini

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

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index 5083beae359a..97a84ae3131e 100644
@@ -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)/..)
Signature · 1 line
2.34.1
Reviewed-by on v1 2/9
#5 lore raw

Re: [PATCH 2/9] clang: Add $(CLANG_TARGET) to LDPPFLAGS

Quoted 10 lines · Tom Rini

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

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
author
#6 lore raw

Re: [PATCH 2/9] clang: Add $(CLANG_TARGET) to LDPPFLAGS

In reply to Tom Rini
Quoted 7 lines · Tom Rini

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

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
author
#7 lore raw

PATCH 3/9 clang: Don't look for libgcc

In reply to Tom Rini

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.

---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +2 -0
index 97a84ae3131e..b5063446ff85 100644
@@ -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
Signature · 1 line
2.34.1
Reviewed-by on v1 3/9
#8 lore raw

Re: [PATCH 3/9] clang: Don't look for libgcc

Quoted 10 lines · Tom Rini

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.

---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
author
#10 lore raw

PATCH 4/9 arm: Centralize fixed register logic

In reply to Tom Rini

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.

---
 arch/arm/config.mk           | 10 ++++++++--
 arch/arm/cpu/armv8/config.mk |  1 -
 2 files changed, 8 insertions(+), 3 deletions(-)
arch/arm/config.mk +8 -2
index bf781f102620..5530d02b66c4 100644
@@ -3,7 +3,13 @@
 # (C) Copyright 2000-2002
 # Wolfgang Denk, DENX Software Engineering, [email protected].
 
-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,))
arch/arm/cpu/armv8/config.mk +0 -1
index ca06ed3d4f92..4d74b2a533e0 100644
@@ -2,7 +2,6 @@
 #
 # (C) Copyright 2002
 # Gary Jennejohn, DENX Software Engineering, <[email protected]>
-PLATFORM_RELFLAGS += -fno-common -ffixed-x18
 PLATFORM_RELFLAGS += $(call cc-option,-mbranch-protection=none)
 
 PF_NO_UNALIGNED := $(call cc-option, -mstrict-align)
Signature · 1 line
2.34.1
Reviewed-by on v1 4/9
#11 lore raw

Re: [PATCH 4/9] arm: Centralize fixed register logic

Quoted 8 lines · Tom Rini

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.

Quoted 5 lines
---
 arch/arm/config.mk           | 10 ++++++++--
 arch/arm/cpu/armv8/config.mk |  1 -
 2 files changed, 8 insertions(+), 3 deletions(-)
author
#12 lore raw

Re: [PATCH 4/9] arm: Centralize fixed register logic

In reply to Tom Rini
Quoted 9 lines · Tom Rini

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.

Applied to u-boot/master, thanks!

Quoted 43 lines
 arch/arm/cpu/armv8/config.mk |  1 -
 2 files changed, 8 insertions(+), 3 deletions(-)
arch/arm/config.mk +8 -2
index bf781f102620..5530d02b66c4 100644
@@ -3,7 +3,13 @@
 # (C) Copyright 2000-2002
 # Wolfgang Denk, DENX Software Engineering, [email protected].
 
-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,))
arch/arm/cpu/armv8/config.mk +0 -1
index ca06ed3d4f92..4d74b2a533e0 100644
@@ -2,7 +2,6 @@
 #
 # (C) Copyright 2002
 # Gary Jennejohn, DENX Software Engineering, <[email protected]>
-PLATFORM_RELFLAGS += -fno-common -ffixed-x18
 PLATFORM_RELFLAGS += $(call cc-option,-mbranch-protection=none)
 
 PF_NO_UNALIGNED := $(call cc-option, -mstrict-align)
Signature · 1 line
Tom
author
#13 lore raw

PATCH 5/9 armv7: Use isb/dsb directly in start.S

In reply to Tom Rini

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.

---
 arch/arm/cpu/armv7/start.S | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm/cpu/armv7/start.S +4 -4
index 7d7aac021e22..69e281b086af 100644
@@ -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
Signature · 1 line
2.34.1
Reviewed-by on v1 5/9
#14 lore raw

Re: [PATCH 5/9] armv7: Use isb/dsb directly in start.S

Quoted 10 lines · Tom Rini

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.

---
 arch/arm/cpu/armv7/start.S | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
author
#15 lore raw

Re: [PATCH 5/9] armv7: Use isb/dsb directly in start.S

In reply to Tom Rini
Quoted 7 lines · Tom Rini

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.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
author
#16 lore raw

PATCH 6/9 boot/image-board.c: Silence warning in select_ramdisk

In reply to Tom Rini

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.

---
 boot/image-board.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
boot/image-board.c +1 -1
index c602832249e3..d500da1b4b91 100644
@@ -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)) {
Signature · 1 line
2.34.1
Reviewed-by on v1 6/9
#17 lore raw

Re: [PATCH 6/9] boot/image-board.c: Silence warning in select_ramdisk

Quoted 9 lines · Tom Rini

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.

---
 boot/image-board.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
author
#19 lore raw

PATCH 7/9 usb: gadget: f_mass_storage: Rework do_request_sense slightly

In reply to Tom Rini

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.

---
I'm honestly not sure why gcc isn't complaining here as this seems to be a real issue.

Cc Lukasz Majewski <[email protected]>
Cc Marek Vasut <[email protected]>
---
 drivers/usb/gadget/f_mass_storage.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/gadget/f_mass_storage.c +1 -2
index 45f0504b6e8a..f46829eb7adb 100644
@@ -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;
Signature · 1 line
2.34.1
Reviewed-by on v1 7/9
#20 lore raw

Re: [PATCH 7/9] usb: gadget: f_mass_storage: Rework do_request_sense slightly

Quoted 9 lines · Tom Rini

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.

---
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 .

author
#21 lore raw

Re: [PATCH 7/9] usb: gadget: f_mass_storage: Rework do_request_sense slightly

In reply to Tom Rini
Quoted 7 lines · Tom Rini

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.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
author
#22 lore raw

PATCH 8/9 clang: efi payload: Silence unaligned access warning

In reply to Tom Rini

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.

---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>

---
 include/efi_api.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/efi_api.h +12 -0
index dc6e5ce236c9..f3bcbf593bea 100644
@@ -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[];
Signature · 1 line
2.34.1
#23 lore raw

Re: [PATCH 8/9] clang: efi payload: Silence unaligned access warning

Quoted 27 lines · Tom Rini

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.

---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>

---
  include/efi_api.h | 12 ++++++++++++
  1 file changed, 12 insertions(+)
include/efi_api.h +4 -0
index dc6e5ce236c9..f3bcbf593bea 100644
@@ -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.
+ */

include/efi_api.h struct efi_key_descriptor { · line 1184

Quoted 10 lines
include/efi_api.h +7 -0
  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

Quoted 4 lines
include/efi_api.h +1 -0
+
  	u32 layout_descriptor_string_offset;
  	u8 descriptor_count;
  	struct efi_key_descriptor descriptors[];
#24 lore raw

Re: [PATCH 8/9] clang: efi payload: Silence unaligned access warning

Hi

Quoted 44 lines · Heinrich Schuchardt
Quoted 27 lines · Tom Rini

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.

---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>

---
  include/efi_api.h | 12 ++++++++++++
  1 file changed, 12 insertions(+)
include/efi_api.h +4 -0
index dc6e5ce236c9..f3bcbf593bea 100644
@@ -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.
+ */

include/efi_api.h struct efi_key_descriptor { · line 1184

Quoted 10 lines
include/efi_api.h +7 -0
  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.

Review

Quoted 2 lines
(quoted diff) +1 -1
-       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

Quoted 10 lines

Best regards

Heinrich

Quoted 4 lines
include/efi_api.h +1 -0
+
      u32 layout_descriptor_string_offset;
      u8 descriptor_count;
      struct efi_key_descriptor descriptors[];
author
#25 lore raw

PATCH 9/9 doc: clang: Update and correct support notes

In reply to Tom Rini

At this point, clang can be used on both 32bit and 64bit targets without issue.

---
 doc/build/clang.rst | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
doc/build/clang.rst +4 -12
index 1d35616eb5ef..222487032ce0 100644
@@ -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:
 
Signature · 1 line
2.34.1
Reviewed-by on v1 9/9
#26 lore raw

Re: [PATCH 9/9] doc: clang: Update and correct support notes

Quoted 8 lines · Tom Rini

At this point, clang can be used on both 32bit and 64bit targets without issue.

---
 doc/build/clang.rst | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
#27 lore raw

Re: [PATCH 9/9] doc: clang: Update and correct support notes

In reply to Tom Rini
Quoted 29 lines · Tom Rini

At this point, clang can be used on both 32bit and 64bit targets without issue.

---
  doc/build/clang.rst | 16 ++++------------
  1 file changed, 4 insertions(+), 12 deletions(-)
doc/build/clang.rst +0 -8
index 1d35616eb5ef..222487032ce0 100644
@@ -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
  ------------
 

doc/build/clang.rst Required packages can be installed via apt, e.g. · line 25

Quoted 8 lines
doc/build/clang.rst +3 -2
@@ -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

Quoted 10 lines
doc/build/clang.rst +1 -2
  .. 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:
 
author
#28 lore raw

Re: [PATCH 9/9] doc: clang: Update and correct support notes

Quoted 33 lines · Heinrich Schuchardt
Quoted 32 lines · Tom Rini

At this point, clang can be used on both 32bit and 64bit targets without issue.

---
  doc/build/clang.rst | 16 ++++------------
  1 file changed, 4 insertions(+), 12 deletions(-)
doc/build/clang.rst +0 -8
index 1d35616eb5ef..222487032ce0 100644
@@ -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
 
Quoted 7 lines

doc/build/clang.rst Required packages can be installed via apt, e.g. · line 25

Quoted 5 lines
doc/build/clang.rst +3 -2
-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".

Quoted 11 lines

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.

Signature · 1 line
Tom
#29 lore raw
In reply to Tom Rini
Quoted 14 lines · Tom Rini

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

Quoted 6 lines

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

author
#30 lore raw
Quoted 22 lines · Heinrich Schuchardt
Quoted 14 lines · Tom Rini

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

Quoted 6 lines

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

Quoted 6 lines

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.

Signature · 1 line
Tom