aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2020-09-30 23:17:40 +0200
committerJakub Konka <kubkon@jakubkonka.com>2020-10-04 15:31:47 +0200
commitf8dd48bcd257a5a6a893c11b89af21b7e2ca9a79 (patch)
treefc8edef1c994776860a533ce44954da99eedda45 /src/codegen.zig
parent5a7105401cda94fa82f07630672559659d875854 (diff)
downloadzig-f8dd48bcd257a5a6a893c11b89af21b7e2ca9a79.tar.gz
zig-f8dd48bcd257a5a6a893c11b89af21b7e2ca9a79.zip
Fix after rebase and enable stage2 tests for macOS
Also, rewrites codegen section to store symbol address in a register to then later invoke `callq` on the register.
Diffstat (limited to 'src/codegen.zig')
-rw-r--r--src/codegen.zig12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/codegen.zig b/src/codegen.zig
index a1d3cc2fc4..919d1ef457 100644
--- a/src/codegen.zig
+++ b/src/codegen.zig
@@ -1532,12 +1532,12 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
if (func_inst.val.cast(Value.Payload.Function)) |func_val| {
const func = func_val.func;
const got = &macho_file.sections.items[macho_file.got_section_index.?];
- const ptr_bytes = 8;
- const got_addr = @intCast(u32, got.addr + func.owner_decl.link.macho.offset_table_index.? * ptr_bytes);
- // ff 14 25 xx xx xx xx call [addr]
- try self.code.ensureCapacity(self.code.items.len + 7);
- self.code.appendSliceAssumeCapacity(&[3]u8{ 0xff, 0x14, 0x25 });
- mem.writeIntLittle(u32, self.code.addManyAsArrayAssumeCapacity(4), got_addr);
+ const got_addr = got.addr + func.owner_decl.link.macho.offset_table_index.? * @sizeOf(u64);
+ // Here, we store the got address in %rax, and then call %rax
+ // movabsq [addr], %rax
+ try self.genSetReg(inst.base.src, .rax, .{ .memory = got_addr });
+ // callq *%rax
+ self.code.appendSliceAssumeCapacity(&[2]u8{ 0xff, 0xd0 });
} else {
return self.fail(inst.base.src, "TODO implement calling bitcasted functions", .{});
}