authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2021-01-02 18:53:11+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-03 19:54:12-08:00
logaa0906e9aaaf36bc928b5502bdb34e7a0409b2c0
treed6f669cebdae86ea204b4db4086cdd44bdcc8b87
parent4400d2d7abb3be8c7b9fde9754fc58d4510c5107

stage2 x86_64: fix bug in Function.gen

Previously, the x86_64 backend would remove code for exitlude relocs if the jump amount were 0. This causes issues as earlier jumps rely on the jump being present at the same address.

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

src/codegen.zig+3-6
...@@ -543,13 +543,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -543,13 +543,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
543 if (self.code.items.len >= math.maxInt(i32)) {543 if (self.code.items.len >= math.maxInt(i32)) {
544 return self.fail(self.src, "unable to perform relocation: jump too far", .{});544 return self.fail(self.src, "unable to perform relocation: jump too far", .{});
545 }545 }
546 for (self.exitlude_jump_relocs.items) |jmp_reloc| {546 if (self.exitlude_jump_relocs.items.len == 1) {
547 self.code.items.len -= 5;
548 } else for (self.exitlude_jump_relocs.items) |jmp_reloc| {
547 const amt = self.code.items.len - (jmp_reloc + 4);549 const amt = self.code.items.len - (jmp_reloc + 4);
548 // If it wouldn't jump at all, elide it.
549 if (amt == 0) {
550 self.code.items.len -= 5;
551 continue;
552 }
553 const s32_amt = @intCast(i32, amt);550 const s32_amt = @intCast(i32, amt);
554 mem.writeIntLittle(i32, self.code.items[jmp_reloc..][0..4], s32_amt);551 mem.writeIntLittle(i32, self.code.items[jmp_reloc..][0..4], s32_amt);
555 }552 }