aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2021-09-15 13:15:15 +0200
committerJakub Konka <kubkon@jakubkonka.com>2021-09-15 16:51:56 +0200
commit25416d8121d14ec6a2a94943cfa4e2fb944e215b (patch)
treeb257177adba5bf20807c6f687e96d2da91bcdf82 /src/codegen.zig
parent0395b35cee8d4082cc40b0dcd0298f797f42309d (diff)
downloadzig-25416d8121d14ec6a2a94943cfa4e2fb944e215b.tar.gz
zig-25416d8121d14ec6a2a94943cfa4e2fb944e215b.zip
macho: when adding extern fn, check if already resolved
This way, we will generate valid relocation info in the codegen.
Diffstat (limited to 'src/codegen.zig')
-rw-r--r--src/codegen.zig9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/codegen.zig b/src/codegen.zig
index 511d4c2301..e79003f728 100644
--- a/src/codegen.zig
+++ b/src/codegen.zig
@@ -2840,7 +2840,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
}
} else if (func_value.castTag(.extern_fn)) |func_payload| {
const decl = func_payload.data;
- const where_index = try macho_file.addExternFn(mem.spanZ(decl.name));
+ const resolv = try macho_file.addExternFn(mem.spanZ(decl.name));
const offset = blk: {
switch (arch) {
.x86_64 => {
@@ -2861,8 +2861,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
// Add relocation to the decl.
try macho_file.active_decl.?.link.macho.relocs.append(self.bin_file.allocator, .{
.offset = offset,
- .where = .undef,
- .where_index = where_index,
+ .where = switch (resolv.where) {
+ .local => .local,
+ .undef => .undef,
+ },
+ .where_index = resolv.where_index,
.payload = .{ .branch = .{
.arch = arch,
} },