Commit aa0906e9aa

joachimschmidt557 <joachim.schmidt557@outlook.com>
2021-01-02 18:53:11
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 parent 4400d2d
Changed files (1)
src/codegen.zig
@@ -543,13 +543,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
                         if (self.code.items.len >= math.maxInt(i32)) {
                             return self.fail(self.src, "unable to perform relocation: jump too far", .{});
                         }
-                        for (self.exitlude_jump_relocs.items) |jmp_reloc| {
+                        if (self.exitlude_jump_relocs.items.len == 1) {
+                            self.code.items.len -= 5;
+                        } else for (self.exitlude_jump_relocs.items) |jmp_reloc| {
                             const amt = self.code.items.len - (jmp_reloc + 4);
-                            // If it wouldn't jump at all, elide it.
-                            if (amt == 0) {
-                                self.code.items.len -= 5;
-                                continue;
-                            }
                             const s32_amt = @intCast(i32, amt);
                             mem.writeIntLittle(i32, self.code.items[jmp_reloc..][0..4], s32_amt);
                         }