riscv-software-src / riscv-pk

RISC-V Proxy Kernel
Other
579 stars 306 forks source link

machine: fix a case of undefined behaviour with SP handling #245

Closed compnerd closed 3 years ago

compnerd commented 3 years ago

The use of asm for register aliasing is supported in two different contexts:

The two options here is to either to hoist the variable out into a global variable, but then it should not be in a header due to fears of ODR in case the optimizer does not inline it away, and thus becomes a bit more tricky. The alternative that this change actually adopts is to explicitly use a move to copy the value out via the GNU extended assembly syntax.

With this change, it is now possible to build the Proxy Kernel completely with clang/LLVM and link with LLD. The generated kernel also runs under SPIKE and behaves as expected in a simple smoke test (without any executable prints the expected message, and runs a trivial RVV example).

aswaterman commented 3 years ago

Cool.

jrtc27 commented 3 years ago

This should have used __builtin_frame_address(0) as we did downstream and failed to upstream (https://github.com/CTSRD-CHERI/riscv-pk/commit/595d003bb1ea4134caefb930e48a6e5135477489). It avoids the use of opaque inline assembly and is more portable (since for CHERI the stack pointer is a capability and thus in csp not sp).

aswaterman commented 3 years ago

Ah, nice.