Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash of statically linked Linux binaries. #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nbdd0121
Copy link

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.

a0 will be registered as an exit handler (see https://github.com/riscv/riscv-glibc/blob/riscv-glibc-2.26/sysdeps/riscv/start.S). Setting it to zero will fix the issue.
@michaeljclark
Copy link
Owner

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()
                {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants