From e3461957f62d11904ff8c17aab584fbb4510824a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 11 Jun 2008 12:37:24 -0700 Subject: [PATCH] fix stack alignment for Apple 32-bit ABI 2008-06-11 Paolo Bonzini * lightning/i386/core-32.h: Use separate __APPLE__ and SysV prolog/ret macros. Subtract 12 bytes in __APPLE__ case to keep stack aligned, and always use LEAVE in the epilog. --- ChangeLog | 6 ++++++ lightning/i386/core-32.h | 14 +++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d75ae755a..0d87a2b6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-06-11 Paolo Bonzini + + * lightning/i386/core-32.h: Use separate __APPLE__ and SysV + prolog/ret macros. Subtract 12 bytes in __APPLE__ case to + keep stack aligned, and always use LEAVE in the epilog. + 2008-06-11 Paolo Bonzini * lightning/i386/core-i386.h: Fix C++ incompatibility. diff --git a/lightning/i386/core-32.h b/lightning/i386/core-32.h index 217658959..52015d9fa 100644 --- a/lightning/i386/core-32.h +++ b/lightning/i386/core-32.h @@ -46,8 +46,11 @@ struct jit_local_state { int alloca_slack; }; -#define jit_base_prolog() (PUSHLr(_EBX), PUSHLr(_ESI), PUSHLr(_EDI), PUSHLr(_EBP), MOVLrr(_ESP, _EBP)) -#define jit_prolog(n) (_jitl.framesize = 20, _jitl.alloca_offset = 0, jit_base_prolog()) +#define jit_base_prolog() (_jitl.framesize = 20, _jitl.alloca_offset = 0, \ + PUSHLr(_EBX), PUSHLr(_ESI), PUSHLr(_EDI), PUSHLr(_EBP), MOVLrr(_ESP, _EBP)) +#define jit_ret(ofs) \ + (((ofs) < 0 ? LEAVE_() : POPLr(_EBP)), \ + POPLr(_EDI), POPLr(_ESI), POPLr(_EBX), RET_()) /* Used internally. SLACK is used by the Darwin ABI which keeps the stack aligned to 16-bytes. */ @@ -78,11 +81,17 @@ struct jit_local_state { #define jit_allocai(n) \ jit_allocai_internal ((n), (_jitl.alloca_slack - (n)) & 15) +#define jit_prolog(n) (jit_base_prolog(), jit_subi_i (JIT_SP, JIT_SP, 12)) +#define jit_ret() jit_base_ret (-12) + #else # define jit_prepare_i(ni) (_jitl.argssize += (ni)) #define jit_allocai(n) \ jit_allocai_internal ((n), 0) + +#define jit_prolog(n) jit_base_prolog() +#define jit_ret() jit_base_ret (_jitl.alloca_offset) #endif #define jit_calli(label) (CALLm( ((unsigned long) (label))), _jit.x.pc) @@ -105,7 +114,6 @@ struct jit_local_state { #define jit_movi_p(d, is) (jit_movi_l(d, ((long)(is))), _jit.x.pc) #define jit_patch_long_at(jump_pc,v) (*_PSL((jump_pc) - sizeof(long)) = _jit_SL((jit_insn *)(v) - (jump_pc))) #define jit_patch_at(jump_pc,v) jit_patch_long_at(jump_pc, v) -#define jit_ret() ((_jitl.alloca_offset < 0 ? LEAVE_() : POPLr(_EBP)), POPLr(_EDI), POPLr(_ESI), POPLr(_EBX), RET_()) /* Memory */