aboutsummaryrefslogtreecommitdiff
path: root/src/arch/x86_64/CodeGen.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-08-13 10:39:49 +0200
committerJakub Konka <kubkon@jakubkonka.com>2024-08-13 13:30:24 +0200
commit57f72095082a5fadd6419d8176475f296a65bdbc (patch)
tree95e9ed910409b7595ab65cff697ed1f4e61d3968 /src/arch/x86_64/CodeGen.zig
parentce8886d57d1593a7eb4909e518fc49e1c95360dd (diff)
downloadzig-57f72095082a5fadd6419d8176475f296a65bdbc.tar.gz
zig-57f72095082a5fadd6419d8176475f296a65bdbc.zip
elf: replace use of linker_extern_fn with more generic Immediate.reloc
Diffstat (limited to 'src/arch/x86_64/CodeGen.zig')
-rw-r--r--src/arch/x86_64/CodeGen.zig30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig
index ea4c7ae358..116911c409 100644
--- a/src/arch/x86_64/CodeGen.zig
+++ b/src/arch/x86_64/CodeGen.zig
@@ -12357,7 +12357,16 @@ fn genCall(self: *Self, info: union(enum) {
});
} else unreachable;
},
- .@"extern" => |@"extern"| try self.genExternSymbolRef(
+ .@"extern" => |@"extern"| if (self.bin_file.cast(.elf)) |elf_file| {
+ const target_sym_index = try elf_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),
@"extern".name.toSlice(ip),
@@ -12369,7 +12378,13 @@ fn genCall(self: *Self, info: union(enum) {
try self.genSetReg(.rax, Type.usize, .{ .air_ref = callee }, .{});
try self.asmRegister(.{ ._, .call }, .rax);
},
- .lib => |lib| try self.genExternSymbolRef(.call, lib.lib, lib.callee),
+ .lib => |lib| if (self.bin_file.cast(.elf)) |elf_file| {
+ const target_sym_index = try elf_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;
}
@@ -15245,16 +15260,7 @@ fn genExternSymbolRef(
callee: []const u8,
) InnerError!void {
const atom_index = try self.owner.getSymbolIndex(self);
- if (self.bin_file.cast(.elf)) |elf_file| {
- _ = try self.addInst(.{
- .tag = tag,
- .ops = .extern_fn_reloc,
- .data = .{ .reloc = .{
- .atom_index = atom_index,
- .sym_index = try elf_file.getGlobalSymbol(callee, lib),
- } },
- });
- } else if (self.bin_file.cast(.coff)) |coff_file| {
+ if (self.bin_file.cast(.coff)) |coff_file| {
const global_index = try coff_file.getGlobalSymbol(callee, lib);
_ = try self.addInst(.{
.tag = .mov,