aboutsummaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-03-27 18:23:25 +0200
committerJakub Konka <kubkon@jakubkonka.com>2023-03-28 12:28:48 +0200
commit0dc210f950ff926fb8e57288a8ff257abc942b6d (patch)
tree6bcef8b17ff3c4210ece46c8bce99b17ae307b70 /src/arch
parentd2040b2763ad2684dcacce9acd8f8511bf9db397 (diff)
downloadzig-0dc210f950ff926fb8e57288a8ff257abc942b6d.tar.gz
zig-0dc210f950ff926fb8e57288a8ff257abc942b6d.zip
link: pass expected lib name as hint in getGlobalSymbol()
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/aarch64/CodeGen.zig14
-rw-r--r--src/arch/wasm/CodeGen.zig2
-rw-r--r--src/arch/x86_64/CodeGen.zig14
3 files changed, 9 insertions, 21 deletions
diff --git a/src/arch/aarch64/CodeGen.zig b/src/arch/aarch64/CodeGen.zig
index e2e2ce9ead..ee23696950 100644
--- a/src/arch/aarch64/CodeGen.zig
+++ b/src/arch/aarch64/CodeGen.zig
@@ -4318,16 +4318,10 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
});
} else if (func_value.castTag(.extern_fn)) |func_payload| {
const extern_fn = func_payload.data;
- const decl_name = mod.declPtr(extern_fn.owner_decl).name;
- if (extern_fn.lib_name) |lib_name| {
- log.debug("TODO enforce that '{s}' is expected in '{s}' library", .{
- decl_name,
- lib_name,
- });
- }
-
+ const decl_name = mem.sliceTo(mod.declPtr(extern_fn.owner_decl).name, 0);
+ const lib_name = mem.sliceTo(extern_fn.lib_name, 0);
if (self.bin_file.cast(link.File.MachO)) |macho_file| {
- const sym_index = try macho_file.getGlobalSymbol(mem.sliceTo(decl_name, 0));
+ const sym_index = try macho_file.getGlobalSymbol(decl_name, lib_name);
const atom = try macho_file.getOrCreateAtomForDecl(self.mod_fn.owner_decl);
const atom_index = macho_file.getAtom(atom).getSymbolIndex().?;
_ = try self.addInst(.{
@@ -4340,7 +4334,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
},
});
} else if (self.bin_file.cast(link.File.Coff)) |coff_file| {
- const sym_index = try coff_file.getGlobalSymbol(mem.sliceTo(decl_name, 0));
+ const sym_index = try coff_file.getGlobalSymbol(decl_name, lib_name);
try self.genSetReg(Type.initTag(.u64), .x30, .{
.linker_load = .{
.type = .import,
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig
index 9af66eb40c..199ddada65 100644
--- a/src/arch/wasm/CodeGen.zig
+++ b/src/arch/wasm/CodeGen.zig
@@ -6121,7 +6121,7 @@ fn callIntrinsic(
args: []const WValue,
) InnerError!WValue {
assert(param_types.len == args.len);
- const symbol_index = func.bin_file.base.getGlobalSymbol(name) catch |err| {
+ const symbol_index = func.bin_file.base.getGlobalSymbol(name, null) catch |err| {
return func.fail("Could not find or create global symbol '{s}'", .{@errorName(err)});
};
diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig
index b071d14447..5ddc9c77ca 100644
--- a/src/arch/x86_64/CodeGen.zig
+++ b/src/arch/x86_64/CodeGen.zig
@@ -5317,16 +5317,10 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
} else unreachable;
} else if (func_value.castTag(.extern_fn)) |func_payload| {
const extern_fn = func_payload.data;
- const decl_name = mod.declPtr(extern_fn.owner_decl).name;
- if (extern_fn.lib_name) |lib_name| {
- log.debug("TODO enforce that '{s}' is expected in '{s}' library", .{
- decl_name,
- lib_name,
- });
- }
-
+ const decl_name = mem.sliceTo(mod.declPtr(extern_fn.owner_decl).name, 0);
+ const lib_name = mem.sliceTo(extern_fn.lib_name, 0);
if (self.bin_file.cast(link.File.Coff)) |coff_file| {
- const sym_index = try coff_file.getGlobalSymbol(mem.sliceTo(decl_name, 0));
+ const sym_index = try coff_file.getGlobalSymbol(decl_name, lib_name);
try self.genSetReg(Type.initTag(.usize), .rax, .{
.linker_load = .{
.type = .import,
@@ -5335,7 +5329,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
});
try self.asmRegister(.call, .rax);
} else if (self.bin_file.cast(link.File.MachO)) |macho_file| {
- const sym_index = try macho_file.getGlobalSymbol(mem.sliceTo(decl_name, 0));
+ const sym_index = try macho_file.getGlobalSymbol(decl_name, lib_name);
const atom = try macho_file.getOrCreateAtomForDecl(self.mod_fn.owner_decl);
const atom_index = macho_file.getAtom(atom).getSymbolIndex().?;
_ = try self.addInst(.{