@@ -563,11 +563,13 @@ endif
563563# # RISCV (32-bit)
564564ifeq ($(ARCH ) ,RISCV)
565565 CROSS_COMPILE? =riscv32-unknown-elf-
566- # GCC 12+ requires explicit zicsr/zifencei extensions
567- # Note: use $(CROSS_COMPILE)gcc directly because CC is not yet defined
568- # at this point in the Makefile (it's set later in the USE_GCC block).
569- RISCV32_ZICSR := $(shell echo "" | $(CROSS_COMPILE ) gcc -march=rv32imac_zicsr -x c -c - -o /dev/null 2>/dev/null && echo _zicsr)
570- RISCV32_ZIFENCEI := $(shell echo "" | $(CROSS_COMPILE ) gcc -march=rv32imac_zifencei -x c -c - -o /dev/null 2>/dev/null && echo _zifencei)
566+ # GCC 12-14 split CSR/fence.i into separate extensions (zicsr, zifencei)
567+ # and require them explicitly. GCC 15+ re-implies them, and adding them
568+ # explicitly can cause multilib lookup failures. Detect by testing if a
569+ # CSR/fence.i instruction assembles WITHOUT the extension flag. If it
570+ # fails, add the extension.
571+ RISCV32_ZICSR := $(shell echo "void f(void) {__asm__ volatile(\"csrr a0,mhartid\");}" | $(CROSS_COMPILE ) gcc -march=rv32imac -mabi=ilp32 -x c -c - -o /dev/null 2>/dev/null || echo _zicsr)
572+ RISCV32_ZIFENCEI := $(shell echo "void f(void) {__asm__ volatile(\"fence.i\");}" | $(CROSS_COMPILE ) gcc -march=rv32imac -mabi=ilp32 -x c -c - -o /dev/null 2>/dev/null || echo _zifencei)
571573 ARCH_FLAGS=-march =rv32imac$(RISCV32_ZICSR )$(RISCV32_ZIFENCEI ) -mabi=ilp32 -mcmodel=medany
572574 CFLAGS+ =-fno-builtin-printf -DUSE_M_TIME -g -nostartfiles -DARCH_RISCV
573575 CFLAGS+ =$(ARCH_FLAGS )
@@ -610,12 +612,13 @@ ifeq ($(ARCH),RISCV64)
610612 UPDATE_OBJS? =src/update_ram.o
611613 endif
612614
613- # GCC 12+ / binutils 2.38+ split CSR and fence.i instructions into
614- # separate extensions (zicsr, zifencei). Detect and add if supported.
615- # Note: use $(CROSS_COMPILE)gcc directly because CC is not yet defined
616- # at this point in the Makefile (it's set later in the USE_GCC block).
617- RISCV64_ZICSR := $(shell echo "" | $(CROSS_COMPILE ) gcc -march=rv64imac_zicsr -x c -c - -o /dev/null 2>/dev/null && echo _zicsr)
618- RISCV64_ZIFENCEI := $(shell echo "" | $(CROSS_COMPILE ) gcc -march=rv64imac_zifencei -x c -c - -o /dev/null 2>/dev/null && echo _zifencei)
615+ # GCC 12-14 split CSR/fence.i into separate extensions (zicsr, zifencei)
616+ # and require them explicitly. GCC 15+ re-implies them, and adding them
617+ # explicitly can cause multilib lookup failures. Detect by testing if a
618+ # CSR/fence.i instruction assembles WITHOUT the extension flag. If it
619+ # fails, add the extension.
620+ RISCV64_ZICSR := $(shell echo "void f(void) {__asm__ volatile(\"csrr a0,mhartid\");}" | $(CROSS_COMPILE ) gcc -march=rv64imac -mabi=lp64 -x c -c - -o /dev/null 2>/dev/null || echo _zicsr)
621+ RISCV64_ZIFENCEI := $(shell echo "void f(void) {__asm__ volatile(\"fence.i\");}" | $(CROSS_COMPILE ) gcc -march=rv64imac -mabi=lp64 -x c -c - -o /dev/null 2>/dev/null || echo _zifencei)
619622
620623 ifeq ($(RISCV_MMODE),1)
621624 # E51 core: rv64imac (no FPU, no crypto extensions)
0 commit comments