Skip to content

Commit 6df2a01

Browse files
aurel32palmer-dabbelt
authored andcommitted
riscv: fix build with binutils 2.38
From version 2.38, binutils default to ISA spec version 20191213. This means that the csr read/write (csrr*/csrw*) instructions and fence.i instruction has separated from the `I` extension, become two standalone extensions: Zicsr and Zifencei. As the kernel uses those instruction, this causes the following build failure: CC arch/riscv/kernel/vdso/vgettimeofday.o <<BUILDDIR>>/arch/riscv/include/asm/vdso/gettimeofday.h: Assembler messages: <<BUILDDIR>>/arch/riscv/include/asm/vdso/gettimeofday.h:71: Error: unrecognized opcode `csrr a5,0xc01' <<BUILDDIR>>/arch/riscv/include/asm/vdso/gettimeofday.h:71: Error: unrecognized opcode `csrr a5,0xc01' <<BUILDDIR>>/arch/riscv/include/asm/vdso/gettimeofday.h:71: Error: unrecognized opcode `csrr a5,0xc01' <<BUILDDIR>>/arch/riscv/include/asm/vdso/gettimeofday.h:71: Error: unrecognized opcode `csrr a5,0xc01' The fix is to specify those extensions explicitely in -march. However as older binutils version do not support this, we first need to detect that. Signed-off-by: Aurelien Jarno <[email protected]> Tested-by: Alexandre Ghiti <[email protected]> Cc: [email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent f40fe31 commit 6df2a01

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

arch/riscv/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima
5050
riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima
5151
riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd
5252
riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c
53+
54+
# Newer binutils versions default to ISA spec version 20191213 which moves some
55+
# instructions from the I extension to the Zicsr and Zifencei extensions.
56+
toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
57+
riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
58+
5359
KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
5460
KBUILD_AFLAGS += -march=$(riscv-march-y)
5561

0 commit comments

Comments
 (0)