riscv.patch 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. From 6df2a016c0c8a3d0933ef33dd192ea6606b115e3 Mon Sep 17 00:00:00 2001
  2. From: Aurelien Jarno <aurelien@aurel32.net>
  3. Date: Wed, 26 Jan 2022 18:14:42 +0100
  4. Subject: riscv: fix build with binutils 2.38
  5. From version 2.38, binutils default to ISA spec version 20191213. This
  6. means that the csr read/write (csrr*/csrw*) instructions and fence.i
  7. instruction has separated from the `I` extension, become two standalone
  8. extensions: Zicsr and Zifencei. As the kernel uses those instruction,
  9. this causes the following build failure:
  10. CC arch/riscv/kernel/vdso/vgettimeofday.o
  11. <<BUILDDIR>>/arch/riscv/include/asm/vdso/gettimeofday.h: Assembler messages:
  12. <<BUILDDIR>>/arch/riscv/include/asm/vdso/gettimeofday.h:71: Error: unrecognized opcode `csrr a5,0xc01'
  13. <<BUILDDIR>>/arch/riscv/include/asm/vdso/gettimeofday.h:71: Error: unrecognized opcode `csrr a5,0xc01'
  14. <<BUILDDIR>>/arch/riscv/include/asm/vdso/gettimeofday.h:71: Error: unrecognized opcode `csrr a5,0xc01'
  15. <<BUILDDIR>>/arch/riscv/include/asm/vdso/gettimeofday.h:71: Error: unrecognized opcode `csrr a5,0xc01'
  16. The fix is to specify those extensions explicitely in -march. However as
  17. older binutils version do not support this, we first need to detect
  18. that.
  19. Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
  20. Tested-by: Alexandre Ghiti <alexandre.ghiti@canonical.com>
  21. Cc: stable@vger.kernel.org
  22. Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
  23. ---
  24. arch/riscv/Makefile | 6 ++++++
  25. 1 file changed, 6 insertions(+)
  26. (limited to 'arch/riscv')
  27. diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
  28. index 8a107ed18b0dc..7d81102cffd48 100644
  29. --- a/arch/riscv/Makefile
  30. +++ b/arch/riscv/Makefile
  31. @@ -50,6 +50,12 @@ riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima
  32. riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima
  33. riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd
  34. riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c
  35. +
  36. +# Newer binutils versions default to ISA spec version 20191213 which moves some
  37. +# instructions from the I extension to the Zicsr and Zifencei extensions.
  38. +toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
  39. +riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
  40. +
  41. KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
  42. KBUILD_AFLAGS += -march=$(riscv-march-y)
  43. --
  44. cgit