authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-01-19 18:59:46+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-01-19 20:21:05+01:00
log7c831cc2663ba4e0ce2cf29ca4a3bd9a4a074f5c
tree02bea370f0f6220f0ab02c04935a2208a2b3d97f
parentdf6c0067b26ca1b6798612631b26b167e9fe287a

stage2: add tweak to please Apple re stack alignment

This is more like a temp hack than anything else - I think the mechanism we use for adjusting the stack when pushing args onto the stack could/should be reused - i.e., we should just calculate the stack alignment before each call and then reset the `rsp` rather than relying on the current hack in `gen()` logic.

1 files changed, 3 insertions(+), 1 deletions(-)

src/arch/x86_64/CodeGen.zig+3-1
...@@ -512,9 +512,11 @@ fn gen(self: *Self) InnerError!void {...@@ -512,9 +512,11 @@ fn gen(self: *Self) InnerError!void {
512 });512 });
513 }513 }
514 while (self.stack_args_relocs.popOrNull()) |index| {514 while (self.stack_args_relocs.popOrNull()) |index| {
515 // TODO like above, gotta figure out the alignment shenanigans for macOS, etc.
516 const adjustment = if (self.target.isDarwin()) 2 * stack_adjustment else stack_adjustment;
515 // +16 bytes to account for saved return address of the `call` instruction and517 // +16 bytes to account for saved return address of the `call` instruction and
516 // `push rbp`.518 // `push rbp`.
517 self.mir_instructions.items(.data)[index].imm += stack_adjustment + aligned_stack_end + 16;519 self.mir_instructions.items(.data)[index].imm += adjustment + aligned_stack_end + 16;
518 }520 }
519 } else {521 } else {
520 _ = try self.addInst(.{522 _ = try self.addInst(.{