gcc-embedded: CSRs and gcc-riscv-none-elf / picolibc-riscv-none-elf
There seems to have been a GCC upstream change which now requires passing zicsr
in -march
for RISC-V when compiling code that uses CSRs (e.g. via the csrr
instruction). With the recent gcc-embedded upgrade this change is now also in Alpine Edge. The problem is that this is not yet supported by the riscv-gnu-toolchain. For this reason, many OSS projects (like RIOT) don't pass -march=rv32imac_zicsr
therefore resulting in compilation errors with the gcc-embedded RISC-V toolchain (as packaged in Alpine Edge), such as:
Error: unrecognized opcode `csrc 0x300,0x00000008'
Furthermore, it also seems that the newlib
and picolib
package don't properly support the _zicsr
combination yet. For example, if I attempt to compile the RIOT code with -march=rv32imac_zicsr
I get the following error instead:
/usr/lib/gcc/riscv-none-elf/11.2.0/../../../../riscv-none-elf/bin/ld: /usr/picolibc/riscv-none-elf/lib/./libc.a(libc_ctype_ctype_.c.o): can't link double-float modules with soft-float modules
It looks like riscv-none-elf-gcc uses /usr/picolibc/riscv-none-elf/lib/libc.a
instead of /usr/picolibc/riscv-none-elf/lib/rv32imac/ilp32/libc.a
with -march=rv32imac_zicsr
. As such, this seems to be an issue with the picolibc / newlibc package?
@maribu IIRC you also use RIOT and maintain the involved gcc / newlib / picolibc packages. Can you reproduce the aforementioned errors? Any idea how we could fix the picolibc / newlibc issues with -march=rv32imac_zicsr
?