aboutsummaryrefslogtreecommitdiff
path: root/src/arch/x86_64/CodeGen.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-08-16 14:52:55 +0200
committerJakub Konka <kubkon@jakubkonka.com>2024-08-17 08:14:38 +0200
commit96441bd829b731cba080753c4833aff3f672a24a (patch)
treefc4d4d5eb4654d81dd09e91052be11b55fcb09f8 /src/arch/x86_64/CodeGen.zig
parentbb70501060a8bfff25818cf1d80491d724f8a634 (diff)
downloadzig-96441bd829b731cba080753c4833aff3f672a24a.tar.gz
zig-96441bd829b731cba080753c4833aff3f672a24a.zip
macho: update codegen and linker to distributed jump table approach
Diffstat (limited to 'src/arch/x86_64/CodeGen.zig')
-rw-r--r--src/arch/x86_64/CodeGen.zig48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig
index e18f1487c3..86fb2bf3e9 100644
--- a/src/arch/x86_64/CodeGen.zig
+++ b/src/arch/x86_64/CodeGen.zig
@@ -12364,13 +12364,10 @@ fn genCall(self: *Self, info: union(enum) {
const zo = macho_file.getZigObject().?;
const sym_index = try zo.getOrCreateMetadataForNav(macho_file, func.owner_nav);
const sym = zo.symbols.items[sym_index];
- try self.genSetReg(
- .rax,
- Type.usize,
- .{ .load_symbol = .{ .sym = sym.nlist_idx } },
- .{},
- );
- try self.asmRegister(.{ ._, .call }, .rax);
+ try self.asmImmediate(.{ ._, .call }, Immediate.rel(.{
+ .atom_index = try self.owner.getSymbolIndex(self),
+ .sym_index = sym.nlist_idx,
+ }));
} else if (self.bin_file.cast(.plan9)) |p9| {
const atom_index = try p9.seeNav(pt, func.owner_nav);
const atom = p9.getAtom(atom_index);
@@ -12392,6 +12389,15 @@ fn genCall(self: *Self, info: union(enum) {
.atom_index = try self.owner.getSymbolIndex(self),
.sym_index = target_sym_index,
}));
+ } else if (self.bin_file.cast(.macho)) |macho_file| {
+ const target_sym_index = try macho_file.getGlobalSymbol(
+ @"extern".name.toSlice(ip),
+ @"extern".lib_name.toSlice(ip),
+ );
+ try self.asmImmediate(.{ ._, .call }, Immediate.rel(.{
+ .atom_index = try self.owner.getSymbolIndex(self),
+ .sym_index = target_sym_index,
+ }));
} else try self.genExternSymbolRef(
.call,
@"extern".lib_name.toSlice(ip),
@@ -12410,6 +12416,12 @@ fn genCall(self: *Self, info: union(enum) {
.atom_index = try self.owner.getSymbolIndex(self),
.sym_index = target_sym_index,
}));
+ } else if (self.bin_file.cast(.macho)) |macho_file| {
+ const target_sym_index = try macho_file.getGlobalSymbol(lib.callee, lib.lib);
+ try self.asmImmediate(.{ ._, .call }, Immediate.rel(.{
+ .atom_index = try self.owner.getSymbolIndex(self),
+ .sym_index = target_sym_index,
+ }));
} else try self.genExternSymbolRef(.call, lib.lib, lib.callee),
}
return call_info.return_value.short;
@@ -15335,15 +15347,6 @@ fn genExternSymbolRef(
.call => try self.asmRegister(.{ ._, .call }, .rax),
else => unreachable,
}
- } else if (self.bin_file.cast(.macho)) |macho_file| {
- _ = try self.addInst(.{
- .tag = .call,
- .ops = .extern_fn_reloc,
- .data = .{ .reloc = .{
- .atom_index = atom_index,
- .sym_index = try macho_file.getGlobalSymbol(callee, lib),
- } },
- });
} else return self.fail("TODO implement calling extern functions", .{});
}
@@ -15434,13 +15437,12 @@ fn genLazySymbolRef(
return self.fail("{s} creating lazy symbol", .{@errorName(err)});
const sym = zo.symbols.items[sym_index];
switch (tag) {
- .lea, .call => try self.genSetReg(
- reg,
- Type.usize,
- .{ .load_symbol = .{ .sym = sym.nlist_idx } },
- .{},
- ),
- .mov => try self.genSetReg(reg, Type.usize, .{ .load_symbol = .{ .sym = sym.nlist_idx } }, .{}),
+ .lea, .call => try self.genSetReg(reg, Type.usize, .{
+ .lea_symbol = .{ .sym = sym.nlist_idx },
+ }, .{}),
+ .mov => try self.genSetReg(reg, Type.usize, .{
+ .load_symbol = .{ .sym = sym.nlist_idx },
+ }, .{}),
else => unreachable,
}
switch (tag) {