rv8 icon indicating copy to clipboard operation
rv8 copied to clipboard

Fix crash of statically linked Linux binaries.

Open nbdd0121 opened this issue 7 years ago • 1 comments

Statically linked binaries will cause RV8 to crash. I searched for the cause for a while and it turns out that the source code of the glibc port (see https://github.com/riscv/riscv-glibc/blob/riscv-glibc-2.26/sysdeps/riscv/start.S) says a0 will be registered as an exit handler (probably for vDSO cleanup, though I cannot actually find anywhere in the ABI). Setting it to zero will fix the issue.

nbdd0121 avatar Feb 10 '18 21:02 nbdd0121

Thanks for looking into this.

I think the change should be in processor-proxy.h as it is only specific to the user-mode syscall proxy. e.g.

diff --git a/src/emu/processor-proxy.h b/src/emu/processor-proxy.h
index 8349c9e..ac610e5 100644
--- a/src/emu/processor-proxy.h
+++ b/src/emu/processor-proxy.h
@@ -22,7 +22,10 @@ namespace riscv {
 
                const char* name() { return "rv-sim"; }
 
-               void init() {}
+               void init()
+               {
+                       P::ireg[rv_ireg_a0].r.xu.val = 0;
+               }
 
                void destroy()
                {

michaeljclark avatar Feb 10 '18 23:02 michaeljclark