diff --git a/src/arm.cpp b/src/arm.cpp index 2275737e8d..c026635ed4 100644 --- a/src/arm.cpp +++ b/src/arm.cpp @@ -1838,7 +1838,11 @@ class MyArchitecture: public Assembler::Architecture { return index; } - + + virtual bool hasLinkRegister() { + return true; + } + virtual unsigned stackAlignmentInWords() { return StackAlignmentInWords; } diff --git a/src/assembler.h b/src/assembler.h index d86a893760..15d08c130a 100644 --- a/src/assembler.h +++ b/src/assembler.h @@ -333,6 +333,8 @@ class Assembler { virtual unsigned argumentRegisterCount() = 0; virtual int argumentRegister(unsigned index) = 0; + virtual bool hasLinkRegister() = 0; + virtual unsigned stackAlignmentInWords() = 0; virtual bool matchCall(void* returnAddress, void* target) = 0; diff --git a/src/compile.cpp b/src/compile.cpp index f942a0b7ed..72490c8490 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -7706,7 +7706,15 @@ class MyProcessor: public Processor { } else if (isThunk(t, ip) or isVirtualThunk(t, ip)) { // we caught the thread in a thunk where the stack register // indicates the most recent Java frame on the stack - c.ip = getIp(t, link, stack); + + // On e.g. x86, the return address will have already been + // pushed onto the stack, in which case we use getIp to + // retrieve it. On e.g. PowerPC and ARM, it will be in the + // link register. Note that we can't just check if the link + // argument is null here, since we use ecx/rcx as a + // pseudo-link register on x86 for the purpose of tail + // calls. + c.ip = t->arch->hasLinkRegister() ? link : getIp(t, link, stack); c.stack = stack; } else { // we caught the thread in native code, and the most recent diff --git a/src/powerpc.cpp b/src/powerpc.cpp index 184f7ab124..6c721651ba 100644 --- a/src/powerpc.cpp +++ b/src/powerpc.cpp @@ -1952,6 +1952,10 @@ class MyArchitecture: public Assembler::Architecture { return index + 3; } + + virtual bool hasLinkRegister() { + return true; + } virtual unsigned stackAlignmentInWords() { return StackAlignmentInWords; diff --git a/src/x86.cpp b/src/x86.cpp index 0f2964e6c7..956d99b1c9 100644 --- a/src/x86.cpp +++ b/src/x86.cpp @@ -2846,6 +2846,10 @@ class MyArchitecture: public Assembler::Architecture { } } + virtual bool hasLinkRegister() { + return false; + } + virtual unsigned stackAlignmentInWords() { return StackAlignmentInWords; }