diff mbox

[04/10] tcg/mips: don't use global pointer

Message ID 1348245809-13482-5-git-send-email-aurelien@aurel32.net
State New
Headers show

Commit Message

Aurelien Jarno Sept. 21, 2012, 4:43 p.m. UTC
Don't use the global pointer in TCG, in case helpers try access global
variables.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 tcg/mips/tcg-target.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Richard Henderson Sept. 21, 2012, 6:18 p.m. UTC | #1
On 09/21/2012 09:43 AM, Aurelien Jarno wrote:
> Don't use the global pointer in TCG, in case helpers try access global
> variables.

Err.. isn't the GP computed at the entry point of functions that need to use it?

That said, under n32 and n64 abis it is call-saved; under o32 it's call-clobbered.
So by itself this is still a fix for new-abis, since we don't save it in the
prologue.  OTOH, this does suggest an alternate solution... ;-)


r~
Aurelien Jarno Sept. 21, 2012, 9:13 p.m. UTC | #2
On Fri, Sep 21, 2012 at 11:18:39AM -0700, Richard Henderson wrote:
> On 09/21/2012 09:43 AM, Aurelien Jarno wrote:
> > Don't use the global pointer in TCG, in case helpers try access global
> > variables.
> 
> Err.. isn't the GP computed at the entry point of functions that need to use it?

I read that GP should be preserved when checking the MIPS ABI for other
things. But you are right, GCC emit code to recompute GP at the entry point
of the function when used later. I guess I checked the wrong ABI.

> That said, under n32 and n64 abis it is call-saved; under o32 it's call-clobbered.
> So by itself this is still a fix for new-abis, since we don't save it in the
> prologue.  OTOH, this does suggest an alternate solution... ;-)
> 

Supporting n32 or n64 implies a lot more things than that. So I guess
I'll just drop that patch for now.
diff mbox

Patch

diff --git a/tcg/mips/tcg-target.c b/tcg/mips/tcg-target.c
index 8b38f98..0ea6a76 100644
--- a/tcg/mips/tcg-target.c
+++ b/tcg/mips/tcg-target.c
@@ -1529,7 +1529,6 @@  static int tcg_target_callee_save_regs[] = {
     TCG_REG_S5,
     TCG_REG_S6,
     TCG_REG_S7,
-    TCG_REG_GP,
     TCG_REG_FP,
     TCG_REG_RA,       /* should be last for ABI compliance */
 };
@@ -1595,6 +1594,7 @@  static void tcg_target_init(TCGContext *s)
     tcg_regset_set_reg(s->reserved_regs, TCG_REG_T0);   /* internal use */
     tcg_regset_set_reg(s->reserved_regs, TCG_REG_RA);   /* return address */
     tcg_regset_set_reg(s->reserved_regs, TCG_REG_SP);   /* stack pointer */
+    tcg_regset_set_reg(s->reserved_regs, TCG_REG_GP);   /* global pointer */
 
     tcg_add_target_add_op_defs(mips_op_defs);
     tcg_set_frame(s, TCG_AREG0, offsetof(CPUArchState, temp_buf),