riscv-non-isa/riscv-arch-test

With newer compiler -march options may cause issues between DUT and Sail

Opened this issue · 10 comments

Sometime after gcc 10.2, the -march option has changed. For 10.2 rv64i also carried with it _zicsr.
This is no longer the case with gcc 12 and higher.

If a DUT outside of the test code (model.h) reads/writes a csr it will fail at compile under gcc 12. The -march is passed into the python prog/script that generates the Makefile. For example under I extension it uses rv64i.

If the DUT changes this in the python code to be hardcoded to some other value, this may and can modify the DUT generated code vs the Sail generated code resulting in a signature diff between the two.

I ran into this as I hardcoded the python to be -march=rv64imafdc_zicsr_zifencei. The jalr and jal opcodes under I failed. I could not figure out why as both codes if you followed the code execution came up with correct signatures for themselves but different for DUT and Sail.

I then noticed that the DUT code had compressed opcodes in it the Sail code did not. This was causing address differences that would make the signatures calulated based on the addresses in the code different.

asb commented

My concern is with gcc now changing the way -march is defined, and I understand there are more changes coming..

(Just a lurker here, but commenting from a Clang/LLVM perspective). The changes to move Zicsr out of RV32I/RV64I were an upstream spec change, and of course gave us a quandary from a toolchain perspective of what to do. If you do spot any planned changes likely to cause issues then please do feedback - much easier to know sooner rather than later if there's something we hadn't anticipated.

For what it's worth, on the Clang/LLVM side we so far allow instructions from zicsr and zifencei to be used unconditionally, even if not specified in the -march string on the basis that it seemed the least worst option available to us to avoid too much pain for end users.