diff options
| author | 2025-11-15 18:53:50 +0100 | |
|---|---|---|
| committer | 2025-11-15 18:53:50 +0100 | |
| commit | 650de3195a9631c9f2c777df5ecf1c6ce26c0430 (patch) | |
| tree | 43ad4a1aade0a33aa5c5fdf5dabb0a7123183215 /amd64/emit.c | |
| parent | e4b27ef0fce135e9e5edb2e5c05a0542bc4850cc (diff) | |
emit: stack alignment edgecases
Diffstat (limited to 'amd64/emit.c')
| -rw-r--r-- | amd64/emit.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/amd64/emit.c b/amd64/emit.c index 30c0b99..d61c1d3 100644 --- a/amd64/emit.c +++ b/amd64/emit.c @@ -1252,17 +1252,21 @@ emitbin(struct function *fn) usebp = 1; /* push rbp; mov rbp, rsp */ DS("\x55\x48\x89\xE5"); - ++npush; } saverestore = calleesave(&npush, pcode, fn); - if (usebp) rbpoff = -(npush - 1)*8; + if (usebp) rbpoff = -npush*8; /* ensure stack is 16-byte aligned for function calls */ - if (!fn->isleaf && ((fn->stksiz + npush*8) & 0xF) != 0x8) { + if (!fn->isleaf && ((fn->stksiz + npush*8) & 0xF) != 0) { assert(usebp); - fn->stksiz += 8; + if ((rbpoff & 0xF) == 0) { + rbpoff -= 16; + fn->stksiz += 24; + } else { + rbpoff -= 8; + fn->stksiz += 8; + } } - rbpoff = alignup(rbpoff, 16); if (fn->stksiz != 0) { /* sub rsp, <stack size> */ |