Skip to content

Fix crash of statically linked Linux binaries. - #44

Open
nbdd0121 wants to merge 1 commit into
larkmjc:masterfrom
nbdd0121:patch-1
Open

Fix crash of statically linked Linux binaries.#44
nbdd0121 wants to merge 1 commit into
larkmjc:masterfrom
nbdd0121:patch-1

Conversation

@nbdd0121

Copy link
Copy Markdown

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.
@larkmjc

larkmjc commented Feb 10, 2018

Copy link
Copy Markdown
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