Skip to contentSkip to conversation

OpenSBI LLVM related fixes

PATCH Superseded Anup Patel 4 participants 10 messages Dec 10, 2024 – Dec 11, 2024 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

cover OpenSBI LLVM related fixes

This series does few LLVM related fixes encountered using "Ubuntu clang version 18.1.3 (1ubuntu1)".

These patches can also be found in the riscv_llvm_compile_fixes_v1 branch at: https://github.com/avpatel/opensbi.git

Anup Patel (2):
lib: utils/fdt_cppc_rpmi: Fix compile error with LLVM
Makefile: Don't enable V-extension using -march option

 Makefile                       | 8 ++++----
 lib/sbi/sbi_trap_v_ldst.c      | 5 +++--
 lib/utils/cppc/fdt_cppc_rpmi.c | 7 +++++--
 3 files changed, 12 insertions(+), 8 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/2 lib: utils/fdt_cppc_rpmi: Fix compile error with LLVM

The following error is observed when compiling fdt_cppc_rpmi driver using LLVM:

lib/utils/cppc/fdt_cppc_rpmi.c:87:3: error: label followed by a declaration is a C23 extension [-Werror,-Wc23-extensions]
87 | u64 db_val_u64 = 0;

To fix the above issue, move the variable declaration at the start of function.

Fixes 591a98bdd549 ("lib: utils/cppc: Add RPMI CPPC driver")
---
 lib/utils/cppc/fdt_cppc_rpmi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
lib/utils/cppc/fdt_cppc_rpmi.c +5 -2
index 26e2d4f6..b6789901 100644
@@ -59,6 +59,11 @@ static void rpmi_cppc_fc_db_trigger(struct rpmi_cppc *cppc)
 	u8 db_val_u8 = 0;
 	u16 db_val_u16 = 0;
 	u32 db_val_u32 = 0;
+#if __riscv_xlen != 32
+	u64 db_val_u64 = 0;
+#else
+	u32 db_val_u32_hi = 0;
+#endif
 
 	switch (cppc->fc_db_width) {
 	case RPMI_CPPC_FAST_CHANNEL_DB_WIDTH_8:
@@ -84,14 +89,12 @@ static void rpmi_cppc_fc_db_trigger(struct rpmi_cppc *cppc)
 		break;
 	case RPMI_CPPC_FAST_CHANNEL_DB_WIDTH_64:
 #if __riscv_xlen != 32
-		u64 db_val_u64 = 0;
 		db_val_u64 = readq((void *)cppc->fc_db_addr);
 		db_val_u64 = cppc->fc_db_setmask |
 				(db_val_u64 & cppc->fc_db_preservemask);
 
 		writeq(db_val_u64, (void *)cppc->fc_db_addr);
 #else
-		u32 db_val_u32_hi = 0;
 		db_val_u32 = readl((void *)cppc->fc_db_addr);
 		db_val_u32_hi = readl((void *)(cppc->fc_db_addr + 4));
 
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH 2/2 Makefile: Don't enable V-extension using -march option

In reply to Anup Patel

Enabling V-extension using -march option causes OpenSBI boot-time hang with LLVM compiler.

As a work-around, don't enable V-extension using -march option and instead use a custom OpenSBI specific define inform availability of V-extension to lib/sbi/sbi_trap_v_ldst.c.

Fixes c2acc5e5b0d8 ("lib: sbi_misaligned_ldst: Add handling of vector load/store")
---
 Makefile                  | 8 ++++----
 lib/sbi/sbi_trap_v_ldst.c | 5 +++--
 2 files changed, 7 insertions(+), 6 deletions(-)
Makefile +4 -4
index 5ac95a0f..7e0a1399 100644
@@ -190,7 +190,7 @@ CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib
 CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep -e "zicsr" -e "zifencei" > /dev/null && echo n || echo y)
 
 # Check whether the assembler and the compiler support the Vector extension
-CC_SUPPORT_VECT := $(shell echo | $(CC) -dM -E -march=rv$(OPENSBI_CC_XLEN)gv - | grep -q riscv.*vector && echo y || echo n)
+CC_SUPPORT_VECT := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)gv -dM -E -x c /dev/null 2>&1 | grep -q riscv.*vector && echo y || echo n)
 
 ifneq ($(OPENSBI_LD_PIE),y)
 $(error Your linker does not support creating PIEs, opensbi requires this.)
@@ -298,9 +298,6 @@ endif
 ifndef PLATFORM_RISCV_ISA
   ifneq ($(PLATFORM_RISCV_TOOLCHAIN_DEFAULT), 1)
     PLATFORM_RISCV_ISA := rv$(PLATFORM_RISCV_XLEN)imafdc
-    ifeq ($(CC_SUPPORT_VECT), y)
-      PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)v
-    endif
     ifeq ($(CC_SUPPORT_ZICSR_ZIFENCEI), y)
       PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)_zicsr_zifencei
     endif
@@ -363,6 +360,9 @@ GENFLAGS	+=	$(firmware-genflags-y)
 CFLAGS		=	-g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ffunction-sections -fdata-sections
 CFLAGS		+=	-fno-omit-frame-pointer -fno-optimize-sibling-calls
 # Optionally supported flags
+ifeq ($(CC_SUPPORT_VECT),y)
+CFLAGS		+=	-DOPENSBI_CC_SUPPORT_VECT -fno-tree-vectorize
+endif
 ifeq ($(CC_SUPPORT_SAVE_RESTORE),y)
 CFLAGS		+=	-mno-save-restore
 endif
lib/sbi/sbi_trap_v_ldst.c +3 -2
index 9929215c..75b79baa 100644
@@ -17,7 +17,8 @@
 #include <sbi/sbi_unpriv.h>
 #include <sbi/sbi_trap.h>
 
-#ifdef __riscv_vector
+#ifdef OPENSBI_CC_SUPPORT_VECT
+
 #define VLEN_MAX 65536
 
 static inline void set_vreg(ulong vlenb, ulong which,
@@ -340,4 +341,4 @@ int sbi_misaligned_v_st_emulator(int wlen, union sbi_ldst_data in_val,
 {
 	return 0;
 }
-#endif /* __riscv_vector  */
+#endif /* OPENSBI_CC_SUPPORT_VECT  */
Signature · 1 line
2.43.0
#3 lore raw

PATCH 2/2 Makefile: Don't enable V-extension using -march option

? 2024-12-10?? 09:46 +0530?Anup Patel???

Quoted 44 lines

Enabling V-extension using -march option causes OpenSBI boot-time hang with LLVM compiler.

As a work-around, don't enable V-extension using -march option and instead use a custom OpenSBI specific define inform availability of V-extension to lib/sbi/sbi_trap_v_ldst.c.

Fixes c2acc5e5b0d8 ("lib: sbi_misaligned_ldst: Add handling of vector load/store")

---
?Makefile????????????????? | 8 ++++----
?lib/sbi/sbi_trap_v_ldst.c | 5 +++--
?2 files changed, 7 insertions(+), 6 deletions(-)

Makefile +0 -0
index 5ac95a0f..7e0a1399 100644
@@ -190,7 +190,7 @@ CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib

?CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep -e "zicsr" -e "zifencei" > /dev/null && echo n || echo y)
?
?# Check whether the assembler and the compiler support the Vector extension

Makefile +1 -1
-CC_SUPPORT_VECT := $(shell echo | $(CC) -dM -E -march=rv$(OPENSBI_CC_XLEN)gv - | grep -q riscv.*vector && echo y || echo n)
+CC_SUPPORT_VECT := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)gv -dM -E -x c /dev/null 2>&1 | grep -q

riscv.*vector && echo y || echo n)
?
?ifneq ($(OPENSBI_LD_PIE),y)
?$(error Your linker does not support creating PIEs, opensbi requires this.)

Makefile +0 -0
@@ -298,9 +298,6 @@ endif

?ifndef PLATFORM_RISCV_ISA
?? ifneq ($(PLATFORM_RISCV_TOOLCHAIN_DEFAULT), 1)
???? PLATFORM_RISCV_ISA := rv$(PLATFORM_RISCV_XLEN)imafdc -??? ifeq ($(CC_SUPPORT_VECT), y)
-????? PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)v -??? endif
???? ifeq ($(CC_SUPPORT_ZICSR_ZIFENCEI), y)
?????? PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)_zicsr_zifencei ???? endif

Makefile +0 -0
@@ -363,6 +360,9 @@ GENFLAGS	+=	$(firmware-genflags-y)

?CFLAGS = -g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ffunction-sections -fdata-
sections
?CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
?# Optionally supported flags

Makefile GENFLAGS += $(firmware-genflags-y) · line 365

Quoted 3 lines
Makefile +3 -0
+ifeq ($(CC_SUPPORT_VECT),y)
+CFLAGS		+=	-DOPENSBI_CC_SUPPORT_VECT -fno-tree-vectorize
+endif

Suggest adding an else branch to add $(warning) to indicate that the toolchain needs to be updated.

Regards,
Xiang W

Quoted 27 lines

?ifeq ($(CC_SUPPORT_SAVE_RESTORE),y)
?CFLAGS += -mno-save-restore
?endif

lib/sbi/sbi_trap_v_ldst.c +0 -0
index 9929215c..75b79baa 100644
@@ -17,7 +17,8 @@

?#include <sbi/sbi_unpriv.h>
?#include <sbi/sbi_trap.h>
?

lib/sbi/sbi_trap_v_ldst.c +2 -1
-#ifdef __riscv_vector
+#ifdef OPENSBI_CC_SUPPORT_VECT
+

?#define VLEN_MAX 65536
?
?static inline void set_vreg(ulong vlenb, ulong which,

lib/sbi/sbi_trap_v_ldst.c +1 -1
@@ -340,4 +341,4 @@ int sbi_misaligned_v_st_emulator(int wlen, union sbi_ldst_data in_val,
 ?{
 ?	return 0;
 ?}
-#endif /* __riscv_vector? */
+#endif /* OPENSBI_CC_SUPPORT_VECT? */
Signature · 1 line
2.43.0
#8 lore raw

PATCH 2/2 Makefile: Don't enable V-extension using -march option

In reply to Anup Patel
Quoted 42 lines · Anup Patel

Enabling V-extension using -march option causes OpenSBI boot-time hang with LLVM compiler.

As a work-around, don't enable V-extension using -march option and instead use a custom OpenSBI specific define inform availability of V-extension to lib/sbi/sbi_trap_v_ldst.c.

Fixes c2acc5e5b0d8 ("lib: sbi_misaligned_ldst: Add handling of vector load/store")

---
Makefile | 8 ++++----
lib/sbi/sbi_trap_v_ldst.c | 5 +++--

2 files changed, 7 insertions(+), 6 deletions(-)
Makefile +1 -1
index 5ac95a0f..7e0a1399 100644
@@ -190,7 +190,7 @@ CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib
 CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep -e "zicsr" -e "zifencei" > /dev/null && echo n || echo y)
 
 # Check whether the assembler and the compiler support the Vector extension
-CC_SUPPORT_VECT := $(shell echo | $(CC) -dM -E -march=rv$(OPENSBI_CC_XLEN)gv - | grep -q riscv.*vector && echo y || echo n)
+CC_SUPPORT_VECT := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)gv -dM -E -x c /dev/null 2>&1 | grep -q riscv.*vector && echo y || echo n)
 
 ifneq ($(OPENSBI_LD_PIE),y)
 $(error Your linker does not support creating PIEs, opensbi requires this.)
@@ -298,9 +298,6 @@ endif

ifndef PLATFORM_RISCV_ISA
ifneq ($(PLATFORM_RISCV_TOOLCHAIN_DEFAULT), 1)

    PLATFORM_RISCV_ISA := rv$(PLATFORM_RISCV_XLEN)imafdc
Makefile +0 -3
-    ifeq ($(CC_SUPPORT_VECT), y)
-      PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)v
-    endif
    ifeq ($(CC_SUPPORT_ZICSR_ZIFENCEI), y)
      PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)_zicsr_zifencei
    endif
@@ -363,6 +360,9 @@ GENFLAGS += $(firmware-genflags-y)

CFLAGS = -g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ffunction-sections -fdata-sections CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
# Optionally supported flags

Makefile GENFLAGS += $(firmware-genflags-y) · line 364

Quoted 2 lines
Makefile +2 -0
+ifeq ($(CC_SUPPORT_VECT),y)
+CFLAGS += -DOPENSBI_CC_SUPPORT_VECT -fno-tree-vectorize

The latter isn?t needed now you don?t enable V. Clang ignores it, even, it?s a flag that?s tied to GCC?s internals.

Jess

#4 lore raw

PATCH 2/2 Makefile: Don't enable V-extension using -march option

In reply to Xiang W
Quoted 42 lines · On Tue, Dec 10, 2024 at 10:35?AM Xiang W <[email protected]> wrote:

? 2024-12-10?? 09:46 +0530?Anup Patel???

Quoted 40 lines

Enabling V-extension using -march option causes OpenSBI boot-time hang with LLVM compiler.

As a work-around, don't enable V-extension using -march option and instead use a custom OpenSBI specific define inform availability of V-extension to lib/sbi/sbi_trap_v_ldst.c.

Fixes c2acc5e5b0d8 ("lib: sbi_misaligned_ldst: Add handling of vector load/store")
---
 Makefile                  | 8 ++++----
 lib/sbi/sbi_trap_v_ldst.c | 5 +++--
 2 files changed, 7 insertions(+), 6 deletions(-)
Makefile +1 -1
index 5ac95a0f..7e0a1399 100644
@@ -190,7 +190,7 @@ CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib
 CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c
 /dev/null -o /dev/null 2>&1 | grep -e "zicsr" -e "zifencei" > /dev/null && echo n || echo y)
 
 # Check whether the assembler and the compiler support the Vector extension
-CC_SUPPORT_VECT := $(shell echo | $(CC) -dM -E -march=rv$(OPENSBI_CC_XLEN)gv - | grep -q riscv.*vector && echo y || echo n)
+CC_SUPPORT_VECT := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)gv -dM -E -x c /dev/null 2>&1 | grep -q
 riscv.*vector && echo y || echo n)
 

ifneq ($(OPENSBI_LD_PIE),y)
$(error Your linker does not support creating PIEs, opensbi requires this.)

Makefile +0 -3
@@ -298,9 +298,6 @@ endif
 ifndef PLATFORM_RISCV_ISA
   ifneq ($(PLATFORM_RISCV_TOOLCHAIN_DEFAULT), 1)
     PLATFORM_RISCV_ISA := rv$(PLATFORM_RISCV_XLEN)imafdc
-    ifeq ($(CC_SUPPORT_VECT), y)
-      PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)v
-    endif
     ifeq ($(CC_SUPPORT_ZICSR_ZIFENCEI), y)
       PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)_zicsr_zifencei
     endif
@@ -363,6 +360,9 @@ GENFLAGS  +=      $(firmware-genflags-y)
Quoted 8 lines

Makefile GENFLAGS += $(firmware-genflags-y) · line 365

Quoted 7 lines
Makefile +0 -0
 CFLAGS               =       -g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ffunction-sections -fdata-

sections
CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
# Optionally supported flags

Makefile +3 -0
+ifeq ($(CC_SUPPORT_VECT),y)
+CFLAGS               +=      -DOPENSBI_CC_SUPPORT_VECT -fno-tree-vectorize
+endif

Suggest adding an else branch to add $(warning) to indicate that the toolchain needs to be updated.

I don't think such a warning is needed. The Linux kernel also does not warn about it.

Regards,
Anup

Quoted 31 lines

Regards,
Xiang W

Quoted 27 lines

ifeq ($(CC_SUPPORT_SAVE_RESTORE),y)
CFLAGS += -mno-save-restore
endif

lib/sbi/sbi_trap_v_ldst.c +3 -3
index 9929215c..75b79baa 100644
@@ -17,7 +17,8 @@
 #include <sbi/sbi_unpriv.h>
 #include <sbi/sbi_trap.h>
 
-#ifdef __riscv_vector
+#ifdef OPENSBI_CC_SUPPORT_VECT
+
 #define VLEN_MAX 65536
 
 static inline void set_vreg(ulong vlenb, ulong which,
@@ -340,4 +341,4 @@ int sbi_misaligned_v_st_emulator(int wlen, union sbi_ldst_data in_val,
 {
      return 0;
 }
-#endif /* __riscv_vector  */
+#endif /* OPENSBI_CC_SUPPORT_VECT  */
--

2.43.0

#9 lore raw

PATCH 2/2 Makefile: Don't enable V-extension using -march option

In reply to Jessica Clarke
Quoted 41 lines · On Tue, Dec 10, 2024 at 10:38?AM Jessica Clarke <[email protected]> wrote:
Quoted 39 lines · Anup Patel

Enabling V-extension using -march option causes OpenSBI boot-time hang with LLVM compiler.

As a work-around, don't enable V-extension using -march option and instead use a custom OpenSBI specific define inform availability of V-extension to lib/sbi/sbi_trap_v_ldst.c.

Fixes c2acc5e5b0d8 ("lib: sbi_misaligned_ldst: Add handling of vector load/store")

---
Makefile | 8 ++++----
lib/sbi/sbi_trap_v_ldst.c | 5 +++--

2 files changed, 7 insertions(+), 6 deletions(-)
Makefile +1 -1
index 5ac95a0f..7e0a1399 100644
@@ -190,7 +190,7 @@ CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib
 CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep -e "zicsr" -e "zifencei" > /dev/null && echo n || echo y)
 
 # Check whether the assembler and the compiler support the Vector extension
-CC_SUPPORT_VECT := $(shell echo | $(CC) -dM -E -march=rv$(OPENSBI_CC_XLEN)gv - | grep -q riscv.*vector && echo y || echo n)
+CC_SUPPORT_VECT := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)gv -dM -E -x c /dev/null 2>&1 | grep -q riscv.*vector && echo y || echo n)
 
 ifneq ($(OPENSBI_LD_PIE),y)
 $(error Your linker does not support creating PIEs, opensbi requires this.)
@@ -298,9 +298,6 @@ endif

ifndef PLATFORM_RISCV_ISA
ifneq ($(PLATFORM_RISCV_TOOLCHAIN_DEFAULT), 1)

    PLATFORM_RISCV_ISA := rv$(PLATFORM_RISCV_XLEN)imafdc
Makefile +0 -3
-    ifeq ($(CC_SUPPORT_VECT), y)
-      PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)v
-    endif
    ifeq ($(CC_SUPPORT_ZICSR_ZIFENCEI), y)
      PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)_zicsr_zifencei
    endif
@@ -363,6 +360,9 @@ GENFLAGS += $(firmware-genflags-y)
Quoted 9 lines

Makefile GENFLAGS += $(firmware-genflags-y) · line 364

Quoted 5 lines

CFLAGS = -g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ffunction-sections -fdata-sections CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
# Optionally supported flags

Makefile +2 -0
+ifeq ($(CC_SUPPORT_VECT),y)
+CFLAGS += -DOPENSBI_CC_SUPPORT_VECT -fno-tree-vectorize

The latter isn?t needed now you don?t enable V. Clang ignores it, even, it?s a flag that?s tied to GCC?s internals.

It's a left-over from an alternate patch which I was working on. I will drop this option in the next revision.

Regards,
Anup

#5 lore raw

PATCH 2/2 Makefile: Don't enable V-extension using -march option

In reply to Anup Patel

? 2024-12-10?? 10:46 +0530?Anup Patel???

Quoted 54 lines · On Tue, Dec 10, 2024 at 10:35?AM Xiang W <[email protected]> wrote:
Quoted 44 lines

? 2024-12-10?? 09:46 +0530?Anup Patel???

Quoted 42 lines

Enabling V-extension using -march option causes OpenSBI boot-time hang with LLVM compiler.

As a work-around, don't enable V-extension using -march option and instead use a custom OpenSBI specific define inform availability of V-extension to lib/sbi/sbi_trap_v_ldst.c.

Fixes c2acc5e5b0d8 ("lib: sbi_misaligned_ldst: Add handling of vector load/store")

---
?Makefile????????????????? | 8 ++++----
?lib/sbi/sbi_trap_v_ldst.c | 5 +++--
?2 files changed, 7 insertions(+), 6 deletions(-)

Makefile +0 -0
index 5ac95a0f..7e0a1399 100644
@@ -190,7 +190,7 @@ CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib

?CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep -e "zicsr" -e "zifencei" > /dev/null && echo n || echo y)

?# Check whether the assembler and the compiler support the Vector extension

Makefile +1 -2
-CC_SUPPORT_VECT := $(shell echo | $(CC) -dM -E -march=rv$(OPENSBI_CC_XLEN)gv - | grep -q riscv.*vector && echo y || echo n)
+CC_SUPPORT_VECT := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)gv -dM -E -x c /dev/null 2>&1 | grep
-q

riscv.*vector && echo y || echo n)

?ifneq ($(OPENSBI_LD_PIE),y)
?$(error Your linker does not support creating PIEs, opensbi requires this.)

Makefile +0 -0
@@ -298,9 +298,6 @@ endif

?ifndef PLATFORM_RISCV_ISA
?? ifneq ($(PLATFORM_RISCV_TOOLCHAIN_DEFAULT), 1)
???? PLATFORM_RISCV_ISA := rv$(PLATFORM_RISCV_XLEN)imafdc -??? ifeq ($(CC_SUPPORT_VECT), y)
-????? PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)v -??? endif
???? ifeq ($(CC_SUPPORT_ZICSR_ZIFENCEI), y)
?????? PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)_zicsr_zifencei ???? endif

Makefile +0 -0
@@ -363,6 +360,9 @@ GENFLAGS? +=????? $(firmware-genflags-y)

?CFLAGS?????????????? =?????? -g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ffunction-sections -

Quoted 8 lines

Makefile GENFLAGS += $(firmware-genflags-y) · line 365

Quoted 7 lines

fdata-
sections
?CFLAGS?????????????? +=????? -fno-omit-frame-pointer -fno-optimize-sibling-calls ?# Optionally supported flags

Makefile +3 -0
+ifeq ($(CC_SUPPORT_VECT),y)
+CFLAGS?????????????? +=????? -DOPENSBI_CC_SUPPORT_VECT -fno-tree-vectorize
+endif

Suggest adding an else branch to add $(warning) to indicate that the toolchain needs to be updated.

Quoted 2 lines

I don't think such a warning is needed. The Linux kernel also does not warn about it.

If the warning is not added to the makefile, it can only be used to generateOPENSBI_CC_SUPPORT_VECT macros in place of the __riscv_vector macros, which only adds to the complexity. It is recommended to remove the detection of the
v extension from the makefile and revert to using __riscv_vector in?
sbi_trap_v_ldst.c.

Regards,
Xiang W

Quoted 35 lines

Regards,
Anup

Quoted 31 lines

Regards,
Xiang W

Quoted 27 lines

?ifeq ($(CC_SUPPORT_SAVE_RESTORE),y)
?CFLAGS?????????????? +=????? -mno-save-restore
?endif

lib/sbi/sbi_trap_v_ldst.c +0 -0
index 9929215c..75b79baa 100644
@@ -17,7 +17,8 @@

?#include <sbi/sbi_unpriv.h>
?#include <sbi/sbi_trap.h>

lib/sbi/sbi_trap_v_ldst.c +2 -1
-#ifdef __riscv_vector
+#ifdef OPENSBI_CC_SUPPORT_VECT
+

?#define VLEN_MAX 65536

?static inline void set_vreg(ulong vlenb, ulong which,

lib/sbi/sbi_trap_v_ldst.c +1 -2
@@ -340,4 +341,4 @@ int sbi_misaligned_v_st_emulator(int wlen, union sbi_ldst_data in_val,
 ?{
 ????? return 0;
 ?}
-#endif /* __riscv_vector? */
+#endif /* OPENSBI_CC_SUPPORT_VECT? */
--

2.43.0

#6 lore raw

PATCH 2/2 Makefile: Don't enable V-extension using -march option

Quoted 56 lines · Xiang W

? 2024-12-10?? 10:46 +0530?Anup Patel???

Quoted 54 lines · On Tue, Dec 10, 2024 at 10:35?AM Xiang W <[email protected]> wrote:
Quoted 52 lines

? 2024-12-10?? 09:46 +0530?Anup Patel???

Quoted 46 lines

Enabling V-extension using -march option causes OpenSBI boot-time hang with LLVM compiler.

As a work-around, don't enable V-extension using -march option and instead use a custom OpenSBI specific define inform availability of V-extension to lib/sbi/sbi_trap_v_ldst.c.

Fixes c2acc5e5b0d8 ("lib: sbi_misaligned_ldst: Add handling of vector load/store")
---
 Makefile                  | 8 ++++----
 lib/sbi/sbi_trap_v_ldst.c | 5 +++--
 2 files changed, 7 insertions(+), 6 deletions(-)
Makefile +1 -5
index 5ac95a0f..7e0a1399 100644
@@ -190,7 +190,7 @@ CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib
 CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c
 /dev/null -o /dev/null 2>&1 | grep -e "zicsr" -e "zifencei" > /dev/null && echo n || echo y)
 
 # Check whether the assembler and the compiler support the Vector extension
-CC_SUPPORT_VECT := $(shell echo | $(CC) -dM -E -march=rv$(OPENSBI_CC_XLEN)gv - | grep -q riscv.*vector && echo y || echo n)
+CC_SUPPORT_VECT := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)gv -dM -E -x c /dev/null 2>&1 | grep
-q
 riscv.*vector && echo y || echo n)
 
 ifneq ($(OPENSBI_LD_PIE),y)
 $(error Your linker does not support creating PIEs, opensbi requires this.)
@@ -298,9 +298,6 @@ endif
 ifndef PLATFORM_RISCV_ISA
   ifneq ($(PLATFORM_RISCV_TOOLCHAIN_DEFAULT), 1)
     PLATFORM_RISCV_ISA := rv$(PLATFORM_RISCV_XLEN)imafdc
-    ifeq ($(CC_SUPPORT_VECT), y)
-      PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)v
-    endif
     ifeq ($(CC_SUPPORT_ZICSR_ZIFENCEI), y)
       PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)_zicsr_zifencei
     endif
@@ -363,6 +360,9 @@ GENFLAGS  +=      $(firmware-genflags-y)
 CFLAGS               =       -g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ffunction-sections -

fdata-
sections
CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
# Optionally supported flags

Makefile GENFLAGS += $(firmware-genflags-y) · line 365

Quoted 3 lines
Makefile +3 -0
+ifeq ($(CC_SUPPORT_VECT),y)
+CFLAGS               +=      -DOPENSBI_CC_SUPPORT_VECT -fno-tree-vectorize
+endif

Suggest adding an else branch to add $(warning) to indicate that the toolchain needs to be updated.

Quoted 6 lines
Quoted 2 lines

I don't think such a warning is needed. The Linux kernel also does not warn about it.

If the warning is not added to the makefile, it can only be used to generateOPENSBI_CC_SUPPORT_VECT macros in place of the __riscv_vector macros, which only adds to the complexity. It is recommended to remove the detection of the
v extension from the makefile and revert to using __riscv_vector in
sbi_trap_v_ldst.c.

Without V enabled you won?t get __riscv_vector defined. Enabling V outside of code that?s explicitly expecting to use vectors is wrong, as discussed before. Defining __riscv_vector manually would also be wrong, and could break compiler headers. The only correct approach is to have a different macro defined, with V not in the default -march.

Jess

Quoted 44 lines

Regards,
Xiang W

Quoted 35 lines

Regards,
Anup

Quoted 31 lines

Regards,
Xiang W

Quoted 27 lines

ifeq ($(CC_SUPPORT_SAVE_RESTORE),y)
CFLAGS += -mno-save-restore
endif

lib/sbi/sbi_trap_v_ldst.c +3 -3
index 9929215c..75b79baa 100644
@@ -17,7 +17,8 @@
 #include <sbi/sbi_unpriv.h>
 #include <sbi/sbi_trap.h>
 
-#ifdef __riscv_vector
+#ifdef OPENSBI_CC_SUPPORT_VECT
+
 #define VLEN_MAX 65536
 
 static inline void set_vreg(ulong vlenb, ulong which,
@@ -340,4 +341,4 @@ int sbi_misaligned_v_st_emulator(int wlen, union sbi_ldst_data in_val,
 {
      return 0;
 }
-#endif /* __riscv_vector  */
+#endif /* OPENSBI_CC_SUPPORT_VECT  */
--

2.43.0

Signature · 3 lines
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
#7 lore raw

PATCH 2/2 Makefile: Don't enable V-extension using -march option

? 2024-12-11?? 02:58 +0000?Jessica Clarke???

Quoted 68 lines · Xiang W
Quoted 59 lines

? 2024-12-10?? 10:46 +0530?Anup Patel???

Quoted 57 lines · On Tue, Dec 10, 2024 at 10:35?AM Xiang W <[email protected]> wrote:
Quoted 55 lines

? 2024-12-10?? 09:46 +0530?Anup Patel???

Quoted 49 lines

Enabling V-extension using -march option causes OpenSBI boot-time hang with LLVM compiler.

As a work-around, don't enable V-extension using -march option and instead use a custom OpenSBI specific define inform availability of V-extension to lib/sbi/sbi_trap_v_ldst.c.

Fixes c2acc5e5b0d8 ("lib: sbi_misaligned_ldst: Add handling of vector load/store")

---
?Makefile????????????????? | 8 ++++----
?lib/sbi/sbi_trap_v_ldst.c | 5 +++--
?2 files changed, 7 insertions(+), 6 deletions(-)

Makefile +0 -0
index 5ac95a0f..7e0a1399 100644
@@ -190,7 +190,7 @@ CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib

?CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c
/dev/null -o /dev/null 2>&1 | grep -e "zicsr" -e "zifencei" > /dev/null && echo n || echo y)

?# Check whether the assembler and the compiler support the Vector extension

Makefile +1 -1
-CC_SUPPORT_VECT := $(shell echo | $(CC) -dM -E -march=rv$(OPENSBI_CC_XLEN)gv - | grep -q riscv.*vector && echo y || echo n)
+CC_SUPPORT_VECT := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)gv -dM -E -x c /dev/null 2>&1 |

grep
-q
riscv.*vector && echo y || echo n)

?ifneq ($(OPENSBI_LD_PIE),y)
?$(error Your linker does not support creating PIEs, opensbi requires this.)

Makefile +0 -0
@@ -298,9 +298,6 @@ endif

?ifndef PLATFORM_RISCV_ISA
?? ifneq ($(PLATFORM_RISCV_TOOLCHAIN_DEFAULT), 1)
???? PLATFORM_RISCV_ISA := rv$(PLATFORM_RISCV_XLEN)imafdc -??? ifeq ($(CC_SUPPORT_VECT), y)
-????? PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)v -??? endif
???? ifeq ($(CC_SUPPORT_ZICSR_ZIFENCEI), y)
?????? PLATFORM_RISCV_ISA := $(PLATFORM_RISCV_ISA)_zicsr_zifencei ???? endif

Makefile +0 -0
@@ -363,6 +360,9 @@ GENFLAGS? +=????? $(firmware-genflags-y)

?CFLAGS?????????????? =?????? -g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ffunction-sections -
fdata-
sections
?CFLAGS?????????????? +=????? -fno-omit-frame-pointer -fno-optimize-sibling-calls
?# Optionally supported flags

Makefile GENFLAGS += $(firmware-genflags-y) · line 365

Quoted 3 lines
Makefile +3 -0
+ifeq ($(CC_SUPPORT_VECT),y)
+CFLAGS?????????????? +=????? -DOPENSBI_CC_SUPPORT_VECT -fno-tree-vectorize
+endif

Suggest adding an else branch to add $(warning) to indicate that the toolchain needs to be updated.

Quoted 7 lines
Quoted 2 lines

I don't think such a warning is needed. The Linux kernel also does not warn about it.

If the warning is not added to the makefile, it can only be used to generateOPENSBI_CC_SUPPORT_VECT macros in place of the __riscv_vector macros, which
only adds to the complexity. It is recommended to remove the detection of the
v extension from the makefile and revert to using __riscv_vector in
sbi_trap_v_ldst.c.

Quoted 6 lines

Without V enabled you won?t get __riscv_vector defined. Enabling V outside of code that?s explicitly expecting to use vectors is wrong, as discussed before. Defining __riscv_vector manually would also be wrong, and could break compiler headers. The only correct approach is to have a different macro defined, with V not in the default -march.

Thank for the reply

Regards,
Xiang W

Quoted 46 lines

Jess

Quoted 43 lines

Xiang W

Quoted 35 lines

Regards,
Anup

Quoted 31 lines

Regards,
Xiang W

Quoted 27 lines

?ifeq ($(CC_SUPPORT_SAVE_RESTORE),y)
?CFLAGS?????????????? +=????? -mno-save-restore
?endif

lib/sbi/sbi_trap_v_ldst.c +0 -0
index 9929215c..75b79baa 100644
@@ -17,7 +17,8 @@

?#include <sbi/sbi_unpriv.h>
?#include <sbi/sbi_trap.h>

lib/sbi/sbi_trap_v_ldst.c +2 -1
-#ifdef __riscv_vector
+#ifdef OPENSBI_CC_SUPPORT_VECT
+

?#define VLEN_MAX 65536

?static inline void set_vreg(ulong vlenb, ulong which,

lib/sbi/sbi_trap_v_ldst.c +1 -2
@@ -340,4 +341,4 @@ int sbi_misaligned_v_st_emulator(int wlen, union sbi_ldst_data in_val,
 ?{
 ????? return 0;
 ?}
-#endif /* __riscv_vector? */
+#endif /* OPENSBI_CC_SUPPORT_VECT? */
--

2.43.0

Signature · 3 lines
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi