aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2021-01-10 00:21:34 +0100
committerJakub Konka <kubkon@jakubkonka.com>2021-01-13 23:55:37 +0100
commitf0d7ec6f33634edb0ddb3ba5d5b306e9f2de5418 (patch)
tree0e0d7082e8d828d9dcefc668634e2aba45059643 /src/codegen.zig
parent1b91a9f4c840741e77e5c7ce826c5f80c9f9ee80 (diff)
downloadzig-f0d7ec6f33634edb0ddb3ba5d5b306e9f2de5418.tar.gz
zig-f0d7ec6f33634edb0ddb3ba5d5b306e9f2de5418.zip
macho: add x86_64 support
Diffstat (limited to 'src/codegen.zig')
-rw-r--r--src/codegen.zig22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/codegen.zig b/src/codegen.zig
index 05898c77c8..bfb1540e40 100644
--- a/src/codegen.zig
+++ b/src/codegen.zig
@@ -1876,14 +1876,30 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
});
break :blk index;
};
+ const start = self.code.items.len;
+ const len: usize = blk: {
+ switch (arch) {
+ .x86_64 => {
+ // callq
+ try self.code.ensureCapacity(self.code.items.len + 5);
+ self.code.appendSliceAssumeCapacity(&[5]u8{ 0xe8, 0x0, 0x0, 0x0, 0x0 });
+ break :blk 5;
+ },
+ .aarch64 => {
+ // bl
+ writeInt(u32, try self.code.addManyAsArray(4), 0);
+ break :blk 4;
+ },
+ else => unreachable, // unsupported architecture on MachO
+ }
+ };
try macho_file.stub_fixups.append(self.bin_file.allocator, .{
.symbol = symbol,
.already_defined = already_defined,
- .start = self.code.items.len,
- .len = 4,
+ .start = start,
+ .len = len,
});
// We mark the space and fix it up later.
- writeInt(u32, try self.code.addManyAsArray(4), 0);
} else {
return self.fail(inst.base.src, "TODO implement calling bitcasted functions", .{});
}