Skip to content

Commit

Permalink
fix stack alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed May 2, 2012
1 parent b4ab1b0 commit 0afd6b1
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/backend/cod3.c
Expand Up @@ -2822,12 +2822,22 @@ code *prolog()
)
)
{
unsigned spalign = 0;
#if 1
int sz = Poff + (needframe ? 0 : -REGSIZE) + localsize;
if (STACKALIGN == 16 && (sz & (STACKALIGN - 1)))
spalign = STACKALIGN - (sz & (STACKALIGN - 1));
#else
if (STACKALIGN == 16 && npush)
spalign = npush * REGSIZE;
#endif

if (spalign)
{ /* This could be avoided by moving the function call to after the
* registers are saved. But I don't remember why the call is here
* and not there.
*/
c = genc2(c,0x81,modregrm(3,5,SP),npush * REGSIZE); // SUB ESP,npush * REGSIZE
c = genc2(c,0x81,modregrm(3,5,SP),spalign); // SUB ESP,spalign
if (I64)
code_orrex(c, REX_W);
}
Expand All @@ -2841,6 +2851,7 @@ code *prolog()
* makes disassembling the code annoying.
*/
#if ELFOBJ || MACHOBJ
// Generate length prefixed name that is recognized by profiler
size_t len = strlen(funcsym_p->Sident);
char *buffer = (char *)malloc(len + 4);
assert(buffer);
Expand All @@ -2865,9 +2876,9 @@ code *prolog()
assert(len < sizeof(name));
genasm(c,name,len); // append func name
#endif
if (STACKALIGN == 16 && npush)
if (spalign)
{
c = genc2(c,0x81,modregrm(3,0,SP),npush * REGSIZE); // ADD ESP,npush * REGSIZE
c = genc2(c,0x81,modregrm(3,0,SP),spalign); // ADD ESP,npush * REGSIZE
if (I64)
code_orrex(c, REX_W);
}
Expand Down

0 comments on commit 0afd6b1

Please sign in to comment.