Skip to content

build system: Fix compilation for RISC-V with newer GCC#17951

Merged
fabian18 merged 3 commits intoRIOT-OS:masterfrom
maribu:makefiles/arch/riscv.inc.mk
May 2, 2022
Merged

build system: Fix compilation for RISC-V with newer GCC#17951
fabian18 merged 3 commits intoRIOT-OS:masterfrom
maribu:makefiles/arch/riscv.inc.mk

Conversation

@maribu
Copy link
Copy Markdown
Member

@maribu maribu commented Apr 14, 2022

Contribution description

A backward incompatible change in the RISC-V resulting in instructions previously included by rv32imac to only be available with rv32imac_zicsr. All RISC-V CPUs supported by RIOT are hence either considered as rv32imac (from the old ISA spec point of view) or as rv32imac_zicsr (from the new ISA spec point of view). This adds a simple test if GCC understands rv32imac_zicsr and uses it then as march, but uses rv32imac as march if not.

Testing procedure

When running make BOARD=hifive1b -C examples/default with newer GCC versions, one will see an error message similar to:

/home/foobar/RIOT/cpu/riscv_common/start.S: Assembler messages:
/home/foobar/RIOT/cpu/riscv_common/start.S:20: Error: unrecognized opcode `csrc 0x300,0x00000008'

With this PR, the compilation should work again, but also remain working with older GCC versions.

Issues/PRs references

None

A backward incompatible change in the RISC-V resulting in instructions
previously included by rv32imac to only be available with
rv32imac_zicsr. All RISC-V CPUs supported by RIOT are hence either
considered as rv32imac (from the old ISA spec point of view) or as
rv32imac_zicsr (from the new ISA spec point of view). This adds a
simple test if GCC understands rv32imac_zicsr and uses it then as march,
but uses rv32imac as march if not.
@maribu maribu added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: build system Area: Build system Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms labels Apr 14, 2022
@maribu
Copy link
Copy Markdown
Member Author

maribu commented Apr 14, 2022

@fabian18, @miri64, or @kaspar030 : You are using Arch, right? That one is also recent enough to no longer work.

Note: It uses the riscv64-elf target triple, which previously was not in the list of targets to detect. I biggybacked a second commit to also test for riscv32-elf, riscv-elf and riscv64-elf. Note that riscv64-elf will only work when multilib support (that includes 32 bit versions) is enabled, but let's just assume that Arch Linux does this.

@miri64
Copy link
Copy Markdown
Member

miri64 commented Apr 14, 2022

@fabian18, @miri64, or @kaspar030 : You are using Arch, right? That one is also recent enough to no longer work.

If you tell me, which package I need to install on Arch to build this, I can test it.

@maribu
Copy link
Copy Markdown
Member Author

maribu commented Apr 14, 2022

I think when you install riscv32-elf-newlib it will pull in riscv64-linux-gnu-gcc and riscv64-elf-binutils as dependencies automatically. So just installing newlib for RISC-V should be fine.

Copy link
Copy Markdown
Contributor

@fabian18 fabian18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I installed all three packages, you have metioned.
But there is something not right.

$ BOARD=hifive1b make
/bin/sh: -g: Ungültige Option
Aufruf: /bin/sh [Lange GNU-Option] [Option] ...
        /bin/sh [Lange GNU-Option] [Option] Script-Datei ...
Lange GNU-Optionen:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --pretty-print
        --rcfile
        --restricted
        --verbose
        --version
Shell-Optionen:
        -ilrsD oder -c Kommando oder -O shopt_option            (Nur Aufruf)
        -abefhkmnptuvxBCHP oder Option -o
Building application "default" for "hifive1b" with MCU "fe310".

gcc: Fehler: nicht erkanntes Kommandozeilenargument in Option »-mabi=ilp32«
gcc: Anmerkung: gültige Argumente für »-mabi=« sind: ms sysv
gcc: Fehler: nicht erkanntes Kommandozeilenargument in Option »-mcmodel=medlow«
gcc: Anmerkung: gültige Argumente für »-mcmodel=« sind: 32 kernel large medium small
gcc: Fehler: unbekannte Kommandozeilenoption »-msmall-data-limit=8«
make[1]: *** [/home/fabian/forks/RIOT/Makefile.base:146: /home/fabian/forks/RIOT/examples/default/bin/hifive1b/application_default/main.o] Fehler 1
make: *** [/home/fabian/forks/RIOT/examples/default/../../Makefile.include:737: application_default.module] Fehler 2

Omitting the middle part of `riscv32-none-elf` is apparently legal and
done by Arch Linux.
@maribu maribu force-pushed the makefiles/arch/riscv.inc.mk branch from 9b62fa1 to c89331f Compare April 14, 2022 17:25
@kaspar030
Copy link
Copy Markdown
Contributor

But there is something not right.

I'm getting the same.

When no toolchain could be detected, provide a friendly message
instead.
@maribu
Copy link
Copy Markdown
Member Author

maribu commented Apr 19, 2022

OK, the issue is that it you need riscv64-elf-newlib, not riscv32-elf-newlib. And riscv64-elf-gcc has to be manually installed.

The build system spilled out the garbage when no toolchain was detected (the issue is present in master already). I added an additional commit to provide a proper error message if the toolchain is not detected.

Note: make BOARD=hifive1b DISABLE_MODULE=newlib_nano -C examples/default worked for my in an Arch Linux Docker container. With newlib nano it failed to link due to missing libs - but that looks suspiciously like a bug on the Arch Linux side to me.

@fabian18
Copy link
Copy Markdown
Contributor

make BOARD=hifive1b DISABLE_MODULE=newlib_nano -C examples/default compiles.
Without disabling newlib_nano, I get this.

/usr/lib/gcc/riscv64-elf/11.1.0/../../../../riscv64-elf/bin/ld: cannot find -lm_nano
/usr/lib/gcc/riscv64-elf/11.1.0/../../../../riscv64-elf/bin/ld: cannot find -lgloss_nano
collect2: error: ld returned 1 exit status
make: *** [/home/fabian/forks/RIOT/examples/default/../../Makefile.include:728: /home/fabian/forks/RIOT/examples/default/bin/hifive1b/default.elf] Fehler 1

@kaspar030
Copy link
Copy Markdown
Contributor

Not using nanospecs but selecting -lc_nano manually compiles and links at least hello-world correctly here.

https://gist.github.com/f1c3eb91b759e924782691cd9e75ba56

(digging out the qemu command line for testing)

@maribu
Copy link
Copy Markdown
Member Author

maribu commented Apr 19, 2022

Not using nanospecs but selecting -lc_nano manually compiles and links at least hello-world correctly here.

https://gist.github.com/f1c3eb91b759e924782691cd9e75ba56

(digging out the qemu command line for testing)

So, I'd blame Arch :) (But I could try to upstream a fix, though. After all, I have been a happy Archer myself for years.)

@maribu
Copy link
Copy Markdown
Member Author

maribu commented Apr 25, 2022

The issue with nano has just been fixed upstream. I guess by tomorrow you can test again on Arch with the updated package and it should just work fingers crossed.

@fabian18
Copy link
Copy Markdown
Contributor

I just did a system upgrade and make BOARD=hifive1b -C examples/default compiles fine.

@fabian18 fabian18 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 29, 2022
Copy link
Copy Markdown
Contributor

@fabian18 fabian18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Murdock is green and the compilation works again. ACK.

@fabian18 fabian18 merged commit 5db3ddd into RIOT-OS:master May 2, 2022
@maribu maribu deleted the makefiles/arch/riscv.inc.mk branch May 2, 2022 17:42
@maribu
Copy link
Copy Markdown
Member Author

maribu commented May 2, 2022

Thanks!

@nmeum
Copy link
Copy Markdown
Member

nmeum commented May 4, 2022

For me, with a riscv-gnu-toolchain this breaks linking:

make: Entering directory '/home/soeren/src/RIOT/examples/hello-world'
Building application "hello-world" for "hifive1" with MCU "fe310".

"make" -C /home/soeren/src/RIOT/boards/common/init
"make" -C /home/soeren/src/RIOT/boards/hifive1
"make" -C /home/soeren/src/RIOT/core
"make" -C /home/soeren/src/RIOT/core/lib
"make" -C /home/soeren/src/RIOT/cpu/fe310
"make" -C /home/soeren/src/RIOT/drivers
"make" -C /home/soeren/src/RIOT/sys
"make" -C /home/soeren/src/RIOT/drivers/periph_common
"make" -C /home/soeren/src/RIOT/cpu/fe310/periph
"make" -C /home/soeren/src/RIOT/cpu/fe310/vendor
"make" -C /home/soeren/src/RIOT/sys/auto_init
"make" -C /home/soeren/src/RIOT/cpu/riscv_common
"make" -C /home/soeren/src/RIOT/sys/div
"make" -C /home/soeren/src/RIOT/sys/malloc_thread_safe
"make" -C /home/soeren/src/RIOT/sys/newlib_syscalls_default
"make" -C /home/soeren/src/RIOT/sys/stdio_uart
"make" -C /home/soeren/src/RIOT/cpu/riscv_common/periph
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /home/soeren/src/RIOT/examples/hello-world/bin/hifive1/riscv_common/start.o: mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/libgcc.a(_udivdi3.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/libgcc.a(_clz.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-errno.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-impure.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-init.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-malloc.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-memcmp.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-memcpy-asm.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-memset.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-mstats.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-nano-freer.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-nano-mallinfor.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-nano-mallocr.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-nano-malloptr.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-nano-mallstatsr.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-printf.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-puts.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-realloc.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-wbuf.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-wsetup.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-fflush.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-findfp.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-fprintf.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-fwalk.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-makebuf.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-mlock.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-nano-reallocr.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-nano-vfprintf.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-nano-vfprintf_i.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-stdio.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-fvwrite.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-memchr.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-memmove.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
/opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/bin/ld: warning: /opt/rv32imc/lib/gcc/riscv32-unknown-elf/10.2.0/../../../../riscv32-unknown-elf/lib/libc_nano.a(lib_a-nano-msizer.o): mis-matched ISA version -1.-1 for 'zicsr' extension, the output version is 2.0
   text	   data	    bss	    dec	    hex	filename
   7322	    768	   2248	  10338	   2862	/home/soeren/src/RIOT/examples/hello-world/bin/hifive1/hello-world.elf
make: Leaving directory '/home/soeren/src/RIOT/examples/hello-world'

I don't think just checking the assembler (as(1) as provided by binutils) is sufficient here as both gcc as well as newlib may not support _zicsr. I don't have a better solution though. For example, you might also end up with a scenario where binutils supports -march=rv32imac_zicsr but gcc doesn't. Also: GCC versions prior two GCC 12.X will accept -march=rv32imac_zicsr but won't do anything (the error message you posted above is also from the binutils assembler, not from GCC).

If I bypass the check it works again for me but the autodetection is broken:

--- a/makefiles/arch/riscv.inc.mk
+++ b/makefiles/arch/riscv.inc.mk
@@ -41,7 +41,7 @@ ifeq ($(TOOLCHAIN),gnu)
   NEW_RISCV_ISA := $(shell echo "" | $(TARGET_ARCH)-as -march=rv32imac_zicsr -mabi=ilp32 - > /dev/null 2>&1 && echo 1 || echo 0)
 endif

-NEW_RISCV_ISA ?= 0
+NEW_RISCV_ISA = 0

 # Since RISC-V ISA specifications 20191213 instructions previously included in
 # rv32imac have been moved to the ZICSR extension. See

@maribu
Copy link
Copy Markdown
Member Author

maribu commented May 11, 2022

@nmeum Sorry for the late reply. I can reproduce the issue with the current Arch Linux toolchain (apparently now there are ISA versions -1.-1, 2.0 and 2.1 into play).

However, forcing NEW_RISCV_ISA=0 fails to build. (Note that you have to run a make clean to actually rebuild the assembly file that requires th _zicsr extension.) With the current master it does yield a lot of mismatching ISA version warning, but links successfully (as is seemingly the case for you).

I currently have no better solution that just waiting until the hole toolchain gets into a state of consistency again regarding the RISC-V ISA version.

@nmeum
Copy link
Copy Markdown
Member

nmeum commented May 12, 2022

One alternative solution might be explicitly specifying the ISA version used by RIOT. See the GCC documentation on RISC-V options. In that case, the following would need to be added to CFLAGS_CPU in makefiles/arch/riscv.inc.mk:

CFLAGS_CPU += -misa-spec=2.2

Version 2.2 is last specification standard where CSR support is still part of the base ISA (i.e. i and thus there is no need to add _zicsr to -march). Does that fix the problem you are seeing? Note though that -misa-spec is only supported by recent GCC versions, however, older GCC version should default to that RISC-V specification version anyhow.

See also: https://groups.google.com/a/groups.riscv.org/g/sw-dev/c/aE1ZeHHCYf4/m/v88QeovDAAAJ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: build system Area: Build system CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants