The commit ca0b4d58eaad405ea74b4db82ecb14b3cfdeccb7 (https://reviews.llvm.org/D136264) added a code path that uses the csrr instruction to read the vector length. This works fine when compiling under risc-v with the -g arch, such as rv32gc or rv64gc. However it will fail to compile when using a newer compiler under targets such rv32imac.
This patch adds a check for __riscv_zicsr as a compiler define.
Another alternative is using .insn for this to prevent any dependency of extension, this should be generally OK since when program hit there means vector extension is enabled, which means csrr is available, and AArch64 has use this trick in their libgcc implementation[1], although I guess their intention is compatibility issue with older binutils , but I think we could use same trick.
This might be more robust implantation since we also treat UNW_RISCV_VLENB as valid register in other place like line 4088.
So I think either:
[1] https://github.com/gcc-mirror/gcc/blob/master/libgcc/config/aarch64/value-unwind.h#L38