riscv-software-src / riscv-pk

RISC-V Proxy Kernel
Other
595 stars 308 forks source link

machine: correct some additional cases of UB #246

Closed compnerd closed 3 years ago

compnerd commented 3 years ago

Use of asm aliased register variables in local scope can only be used for extended assembly parameters. This changes the few instances of this in the floating point emulation to use the GNU extended assembly syntax to access the tp register. This ensures that we do not rely on undefined behaviour. This was uncovered when building the Proxy kernel with clang and LLVM.

jrtc27 commented 3 years ago

The less-invasive fix that will be slightly more performant (allows eliding the mv) is to just declare tp at global scope; this is what we did downstream to build with Clang and apparently never upstreamed.

jrtc27 commented 3 years ago

(https://github.com/CTSRD-CHERI/riscv-pk/commit/0d1fdc2e24b7b6247a55d24c13ae85dca7f45695, though that should probably also be static)

aswaterman commented 3 years ago

Good point, I cherry-picked (CHERI-picked?) this alternative fix.

jrtc27 commented 3 years ago

Good point, I cherry-picked (CHERI-picked?) this alternative fix.

:) as you can imagine we have fun with such puns...

aswaterman commented 3 years ago

:)