diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2021-01-06 01:13:25 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2021-01-13 23:53:46 +0100 |
| commit | f44732c1b0d7516c4a8169f7381cbcf55e1ae460 (patch) | |
| tree | 380f49b549149f3d5033e1a2d9f2ec9a1e64fa12 /src/codegen.zig | |
| parent | 51a13f8ea6f1596a3163ac656e0ddb1156d1399a (diff) | |
| download | zig-f44732c1b0d7516c4a8169f7381cbcf55e1ae460.tar.gz zig-f44732c1b0d7516c4a8169f7381cbcf55e1ae460.zip | |
macho: populate stubs and stub_helper
Diffstat (limited to 'src/codegen.zig')
| -rw-r--r-- | src/codegen.zig | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index d83eba2219..7100227db0 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -1859,8 +1859,26 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { }, else => unreachable, // unsupported architecture on MachO } - } else if (func_value.castTag(.extern_fn)) |_| { - return self.fail(inst.base.src, "TODO implement calling extern functions", .{}); + } else if (func_value.castTag(.extern_fn)) |func_payload| { + const decl = func_payload.data; + const decl_name = try std.fmt.allocPrint(self.bin_file.allocator, "_{s}", .{decl.name}); + defer self.bin_file.allocator.free(decl_name); + const name = try macho_file.makeString(decl_name); + const symbol = macho_file.undef_symbols.items.len; + try macho_file.undef_symbols.append(self.bin_file.allocator, .{ + .n_strx = name, + .n_type = std.macho.N_UNDF | std.macho.N_EXT, + .n_sect = 0, + .n_desc = std.macho.REFERENCE_FLAG_UNDEFINED_NON_LAZY | std.macho.N_SYMBOL_RESOLVER, + .n_value = 0, + }); + try macho_file.stub_fixups.append(self.bin_file.allocator, .{ + .symbol = symbol, + .start = self.code.items.len, + .len = 4, + }); + // We mark the space and fix it up later. + writeInt(u32, try self.code.addManyAsArray(4), 0); } else { return self.fail(inst.base.src, "TODO implement calling bitcasted functions", .{}); } |
