Skip to contentSkip to conversation

riscv: fix build with binutils 2.38

PATCH In review Aurelien Jarno 6 participants 13 messages Jan 26, 2022 – Apr 1, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 arch/riscv/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
arch/riscv/Makefile +6 -0
index 8a107ed18b0d..7d81102cffd4 100644
@@ -50,6 +50,12 @@ riscv-march-$(CONFIG_ARCH_RV32I)	:= rv32ima
 riscv-march-$(CONFIG_ARCH_RV64I)	:= rv64ima
 riscv-march-$(CONFIG_FPU)		:= $(riscv-march-y)fd
 riscv-march-$(CONFIG_RISCV_ISA_C)	:= $(riscv-march-y)c
+
+# Newer binutils versions default to ISA spec version 20191213 which moves some
+# instructions from the I extension to the Zicsr and Zifencei extensions.
+toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
+riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
+
 KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
 KBUILD_AFLAGS += -march=$(riscv-march-y)
 
Signature · 1 line
2.34.1
Tested-by on v1 1/1
#1 lore raw

Hi Aurelien,

Quoted 43 lines · Aurelien Jarno

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.

---
 arch/riscv/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
arch/riscv/Makefile +6 -1
index 8a107ed18b0d..7d81102cffd4 100644
@@ -50,6 +50,12 @@ riscv-march-$(CONFIG_ARCH_RV32I)     := rv32ima
 riscv-march-$(CONFIG_ARCH_RV64I)       := rv64ima
 riscv-march-$(CONFIG_FPU)              := $(riscv-march-y)fd
 riscv-march-$(CONFIG_RISCV_ISA_C)      := $(riscv-march-y)c
+
+# Newer binutils versions default to ISA spec version 20191213 which moves some
+# instructions from the I extension to the Zicsr and Zifencei extensions.
+toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
+riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
+
 KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
 KBUILD_AFLAGS += -march=$(riscv-march-y)
 
--
Quoted 3 lines

2.34.1

That fixes our kernel build with the new binutils, so you can add:

Thanks for working on this!

Alex

Quoted 4 lines

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

maintainer
#2 lore raw
In reply to Aurelien Jarno
Quoted 30 lines · On Wed, 26 Jan 2022 09:14:42 PST (-0800), [email protected] wrote:

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.

---
 arch/riscv/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
arch/riscv/Makefile +0 -0
index 8a107ed18b0d..7d81102cffd4 100644
@@ -50,6 +50,12 @@ riscv-march-$(CONFIG_ARCH_RV32I)	:= rv32ima
 riscv-march-$(CONFIG_ARCH_RV64I)	:= rv64ima

arch/riscv/Makefile riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima · line 60

Quoted 10 lines
arch/riscv/Makefile +6 -0
 riscv-march-$(CONFIG_FPU)		:= $(riscv-march-y)fd
 riscv-march-$(CONFIG_RISCV_ISA_C)	:= $(riscv-march-y)c
+
+# Newer binutils versions default to ISA spec version 20191213 which moves some
+# instructions from the I extension to the Zicsr and Zifencei extensions.
+toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
+riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
+
 KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
 KBUILD_AFLAGS += -march=$(riscv-march-y)

Thanks, this is on fixes. It's CC stable, but doesn't have a "Fixes" tag -- I did that on purpose as this isn't really fixing a bug in Linux so I'm not sure it's right to point at a particular patch, but I'm not sure how that will play with the stable tree.

maintainer
#3 lore raw
Quoted 38 lines · Palmer Dabbelt
Quoted 37 lines · On Wed, 26 Jan 2022 09:14:42 PST (-0800), [email protected] wrote:

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.

---
 arch/riscv/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
arch/riscv/Makefile +5 -0
index 8a107ed18b0d..7d81102cffd4 100644
@@ -50,6 +50,12 @@ riscv-march-$(CONFIG_ARCH_RV32I)	:= rv32ima
 riscv-march-$(CONFIG_ARCH_RV64I)	:= rv64ima
 riscv-march-$(CONFIG_FPU)		:= $(riscv-march-y)fd
 riscv-march-$(CONFIG_RISCV_ISA_C)	:= $(riscv-march-y)c
+
+# Newer binutils versions default to ISA spec version 20191213 which moves some
+# instructions from the I extension to the Zicsr and Zifencei extensions.
+toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
+riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
Quoted 8 lines

arch/riscv/Makefile riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima · line 60

Quoted 3 lines
arch/riscv/Makefile +1 -0
+
 KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
 KBUILD_AFLAGS += -march=$(riscv-march-y)

Thanks, this is on fixes. It's CC stable, but doesn't have a "Fixes" tag -- I did that on purpose as this isn't really fixing a bug in Linux so I'm not sure it's right to point at a particular patch, but I'm not sure how that will play with the stable tree.

I will backport it as far back as it easily goes to, and then forget about it :)

If you have a Fixes: tag, and it doesn't properly backport that far, then you will get a "FAILED:" email notifying you about it.

hope that helps explain things,

greg k-h

#4 lore raw
In reply to Aurelien Jarno
Quoted 30 lines · Aurelien Jarno

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.

---
 arch/riscv/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
arch/riscv/Makefile +0 -0
index 8a107ed18b0d..7d81102cffd4 100644
@@ -50,6 +50,12 @@ riscv-march-$(CONFIG_ARCH_RV32I)	:= rv32ima
 riscv-march-$(CONFIG_ARCH_RV64I)	:= rv64ima

arch/riscv/Makefile riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima · line 60

Quoted 10 lines
arch/riscv/Makefile +6 -0
 riscv-march-$(CONFIG_FPU)		:= $(riscv-march-y)fd
 riscv-march-$(CONFIG_RISCV_ISA_C)	:= $(riscv-march-y)c
+
+# Newer binutils versions default to ISA spec version 20191213 which moves some
+# instructions from the I extension to the Zicsr and Zifencei extensions.
+toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
+riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
+
 KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
 KBUILD_AFLAGS += -march=$(riscv-march-y)

I'm on current linus/master, this change breaks on current Debian testing with:

| make: Leaving directory 'linux'
|   SYNC    include/config/auto.conf.cmd
|   GEN     Makefile
|   GEN     Makefile
|   CC      scripts/mod/empty.o
|   CHECK   linux/scripts/mod/empty.c
| invalid argument to '-march': '_zicsr_zifencei'

Used components:

| $ riscv64-linux-gnu-gcc -v
| Using built-in specs.
| COLLECT_GCC=/usr/bin/riscv64-linux-gnu-gcc
| COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/riscv64-linux-gnu/11/lto-wrapper
| Target: riscv64-linux-gnu
| Configured with: ../src/configure -v --with-pkgversion='Debian 11.2.0-9' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --without-target-system-zlib --enable-multiarch --disable-werror --disable-multilib --with-arch=rv64imafdc --with-abi=lp64d --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=riscv64-linux-gnu --program-prefix=riscv64-linux-gnu- --includedir=/usr/riscv64-linux-gnu/include --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
| Thread model: posix
| Supported LTO compression algorithms: zlib zstd
| gcc version 11.2.0 (Debian 11.2.0-9) 
| $ riscv64-linux-gnu-ld -v
| GNU ld (GNU Binutils for Debian) 2.38

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |
#5 lore raw
Quoted 45 lines · Marc Kleine-Budde
Quoted 30 lines · Aurelien Jarno

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.

---
 arch/riscv/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
arch/riscv/Makefile +0 -0
index 8a107ed18b0d..7d81102cffd4 100644
@@ -50,6 +50,12 @@ riscv-march-$(CONFIG_ARCH_RV32I)	:= rv32ima
 riscv-march-$(CONFIG_ARCH_RV64I)	:= rv64ima

arch/riscv/Makefile riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima · line 60

Quoted 10 lines
arch/riscv/Makefile +6 -0
 riscv-march-$(CONFIG_FPU)		:= $(riscv-march-y)fd
 riscv-march-$(CONFIG_RISCV_ISA_C)	:= $(riscv-march-y)c
+
+# Newer binutils versions default to ISA spec version 20191213 which moves some
+# instructions from the I extension to the Zicsr and Zifencei extensions.
+toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
+riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
+
 KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
 KBUILD_AFLAGS += -march=$(riscv-march-y)

I'm on current linus/master, this change breaks on current Debian testing with:

Quoted 6 lines
| make: Leaving directory 'linux'
|   SYNC    include/config/auto.conf.cmd
|   GEN     Makefile
|   GEN     Makefile
|   CC      scripts/mod/empty.o
|   CHECK   linux/scripts/mod/empty.c
      ^^^^^

It's actually "sparse" that breaks

Quoted 1 line

| invalid argument to '-march': '_zicsr_zifencei'

| $ sparse --version
| 0.6.4 (Debian: 0.6.4-2)

Compiling without "C=1" for now.

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |
#6 lore raw

Cc += linux-sparse, Uwe, Luc Van Oostenryck

tl;dr:

A recent change in the kernel regarding the riscv -march handling breaks current sparse.

Quoted 52 lines · Marc Kleine-Budde
Quoted 45 lines · Marc Kleine-Budde
Quoted 30 lines · Aurelien Jarno

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.

---
 arch/riscv/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
arch/riscv/Makefile +0 -0
index 8a107ed18b0d..7d81102cffd4 100644
@@ -50,6 +50,12 @@ riscv-march-$(CONFIG_ARCH_RV32I)	:= rv32ima
 riscv-march-$(CONFIG_ARCH_RV64I)	:= rv64ima

arch/riscv/Makefile riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima · line 60

Quoted 10 lines
arch/riscv/Makefile +6 -0
 riscv-march-$(CONFIG_FPU)		:= $(riscv-march-y)fd
 riscv-march-$(CONFIG_RISCV_ISA_C)	:= $(riscv-march-y)c
+
+# Newer binutils versions default to ISA spec version 20191213 which moves some
+# instructions from the I extension to the Zicsr and Zifencei extensions.
+toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
+riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
+
 KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
 KBUILD_AFLAGS += -march=$(riscv-march-y)

I'm on current linus/master, this change breaks on current Debian testing with:

Quoted 6 lines
| make: Leaving directory 'linux'
|   SYNC    include/config/auto.conf.cmd
|   GEN     Makefile
|   GEN     Makefile
|   CC      scripts/mod/empty.o
|   CHECK   linux/scripts/mod/empty.c
Quoted 7 lines
      ^^^^^

It's actually "sparse" that breaks

Quoted 1 line

| invalid argument to '-march': '_zicsr_zifencei'

| $ sparse --version
| 0.6.4 (Debian: 0.6.4-2)

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |
#7 lore raw

Hi,

Quoted 67 lines · Marc Kleine-Budde

Cc += linux-sparse, Uwe, Luc Van Oostenryck

tl;dr:

A recent change in the kernel regarding the riscv -march handling breaks current sparse.

Quoted 59 lines · Marc Kleine-Budde
Quoted 45 lines · Marc Kleine-Budde
Quoted 30 lines · Aurelien Jarno

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.

---
 arch/riscv/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
arch/riscv/Makefile +0 -0
index 8a107ed18b0d..7d81102cffd4 100644
@@ -50,6 +50,12 @@ riscv-march-$(CONFIG_ARCH_RV32I)	:= rv32ima
 riscv-march-$(CONFIG_ARCH_RV64I)	:= rv64ima

arch/riscv/Makefile riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima · line 60

Quoted 10 lines
arch/riscv/Makefile +6 -0
 riscv-march-$(CONFIG_FPU)		:= $(riscv-march-y)fd
 riscv-march-$(CONFIG_RISCV_ISA_C)	:= $(riscv-march-y)c
+
+# Newer binutils versions default to ISA spec version 20191213 which moves some
+# instructions from the I extension to the Zicsr and Zifencei extensions.
+toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
+riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
+
 KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
 KBUILD_AFLAGS += -march=$(riscv-march-y)

I'm on current linus/master, this change breaks on current Debian testing with:

Quoted 6 lines
| make: Leaving directory 'linux'
|   SYNC    include/config/auto.conf.cmd
|   GEN     Makefile
|   GEN     Makefile
|   CC      scripts/mod/empty.o
|   CHECK   linux/scripts/mod/empty.c
      ^^^^^

It's actually "sparse" that breaks

Quoted 1 line

| invalid argument to '-march': '_zicsr_zifencei'

| $ sparse --version
| 0.6.4 (Debian: 0.6.4-2)

I confirm the issue. To make things clear, it's not a Makefile issue, sparse get passed the correct -march=rv64ima_zicsr_zifencei value, and only display the part it can't parse.

On the medium/long term, sparse should get fixed to support those extensions. On the short term, we need to find a way to get different flags for sparse than for as/gcc.

Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                 http://www.aurel32.net
#8 lore raw
In reply to Marc Kleine-Budde
Quoted 7 lines · Marc Kleine-Budde

Cc += linux-sparse, Uwe, Luc Van Oostenryck

tl;dr:

A recent change in the kernel regarding the riscv -march handling breaks current sparse.

Gaah. Normally sparse doesn't even look at the -march flag, but for riscv it does, because it's meaningful for the predefined macros.

Maybe that 'die()' shouldn't be so fatal. And maybe add a few more extensions (but ignore them) to the parsing.

Something ENTIRELY UNTESTED like the attached.

Linus

 target-riscv.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
target-riscv.c +12 -2
index 6d9113c1..201ac375 100644
@@ -3,6 +3,7 @@
 #include "target.h"
 #include "machine.h"
 #include <string.h>
+#include <stdio.h>
 
 #define RISCV_32BIT	(1 << 0)
 #define RISCV_64BIT	(1 << 1)
@@ -47,6 +48,12 @@ static void parse_march_riscv(const char *arg)
 		{ "n",		0 },
 		{ "h",		0 },
 		{ "s",		0 },
+		{ "i",		0 },
+		{ "e",		0 },
+		{ "_",		0 },
+		{ "Counters",	0 },
+		{ "Zicsr",	0 },
+		{ "Zifencei",	0 },
 	};
 	int i;
 
@@ -60,7 +67,10 @@ static void parse_march_riscv(const char *arg)
 			goto ext;
 		}
 	}
-	die("invalid argument to '-march': '%s'\n", arg);
+
+unknown:
+	fprintf(stderr, "WARNING: invalid argument to '-march': '%s'\n", arg);
+	return;
 
 ext:
 	for (i = 0; i < ARRAY_SIZE(extensions); i++) {
@@ -73,7 +83,7 @@ ext:
 		}
 	}
 	if (arg[0])
-		die("invalid argument to '-march': '%s'\n", arg);
+		goto unknown;
 }
 
 static void init_riscv(const struct target *self)
maintainer
#9 lore raw
Quoted 8 lines · Linus Torvalds
Quoted 7 lines · Marc Kleine-Budde

Cc += linux-sparse, Uwe, Luc Van Oostenryck

tl;dr:

A recent change in the kernel regarding the riscv -march handling breaks current sparse.

Sorry about that, looks like I'm not running sparse as part of my testing. I'll add it, but it might take a bit as I'm assuming there will be a bunch of issues it points out.

Quoted 7 lines

Gaah. Normally sparse doesn't even look at the -march flag, but for riscv it does, because it's meaningful for the predefined macros.

Maybe that 'die()' shouldn't be so fatal. And maybe add a few more extensions (but ignore them) to the parsing.

Something ENTIRELY UNTESTED like the attached.

Converting this to a warning seems reasonable to me, as then we're not as coupled to the sparse version. The current crop of extensions don't set anything exciting for Linux, but there are some on the horizon that likely will -- hopefully having sparse in my test setup should be sufficient to dig those up, though.

As far as the new extension go: "Counters" isn't an ISA extension, and "e" defines "__riscv_32e". It'd also be slightly saner to match on "_Zifencei", but that probably doesn't matter (GCC is sufficiently strict here). Looks like there's also some oddities in the sparse ISA string parsing, I'll go clean them up as I get it running locally.

We could also stop relying on the compiler's defines, which would avoid this problem entirely, but IIRC that was discussed when decided to modify sparse in the first place and we went this way (though I don't remember why). That would keep everything inside the kernel.

#10 lore raw
In reply to Linus Torvalds
Quoted 9 lines · Linus Torvalds
Quoted 7 lines · Marc Kleine-Budde

Cc += linux-sparse, Uwe, Luc Van Oostenryck

tl;dr:

A recent change in the kernel regarding the riscv -march handling breaks current sparse.

Quoted 7 lines

Gaah. Normally sparse doesn't even look at the -march flag, but for riscv it does, because it's meaningful for the predefined macros.

Maybe that 'die()' shouldn't be so fatal. And maybe add a few more extensions (but ignore them) to the parsing.

Something ENTIRELY UNTESTED like the attached.

Works-for-me:

| CHECK /srv/work/frogger/socketcan/linux/drivers/net/can/usb/etas_es58x/es58x_core.c
| WARNING: invalid argument to '-march': 'zicsr_zifencei'

Regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |
#11 lore raw
Quoted 2 lines · Marc Kleine-Budde

| WARNING: invalid argument to '-march': 'zicsr_zifencei'

Gaah, it works but still warns because I cut-and-pasted those zicsr/zifencei options from some random source that had them capitalized and I didn't look closely enough at the reports.

Anyway, hopefully somebody can bother to fix up that. Possibly by changing the strncmp to a strnicmp - but I don't know what the rules for lower-case vs capitals are for the other options. I'm still busy with the kernel merge window, so this gets archived on my side..

Linus

maintainer
#12 lore raw
Quoted 4 lines · Linus Torvalds
Quoted 2 lines · Marc Kleine-Budde

| WARNING: invalid argument to '-march': 'zicsr_zifencei'

Quoted 8 lines

Gaah, it works but still warns because I cut-and-pasted those zicsr/zifencei options from some random source that had them capitalized and I didn't look closely enough at the reports.

Anyway, hopefully somebody can bother to fix up that. Possibly by changing the strncmp to a strnicmp - but I don't know what the rules for lower-case vs capitals are for the other options. I'm still busy with the kernel merge window, so this gets archived on my side..

I'm gluing sparse to my build tests now, so I'll sort it out (that'll also make sure a failure doesn't leak again). Might not be today, but shouldn't take too long.