diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-10-30 00:09:32 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-10-30 00:09:32 +0100 |
| commit | 2e690f5c74cbfd16757cc301ac0d899caa8b2fb3 (patch) | |
| tree | ad622a039430932b24f69d968d73c3e4fb8c8ed8 /src/arch | |
| parent | 71dfea1f174b0531139e33e8aa4fe86ccd9f23dd (diff) | |
| download | zig-2e690f5c74cbfd16757cc301ac0d899caa8b2fb3.tar.gz zig-2e690f5c74cbfd16757cc301ac0d899caa8b2fb3.zip | |
macho: implement enough of extern handling to pass comptime export tests
Diffstat (limited to 'src/arch')
| -rw-r--r-- | src/arch/x86_64/CodeGen.zig | 3 | ||||
| -rw-r--r-- | src/arch/x86_64/Emit.zig | 11 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index 18011fc054..d6ac3fb36b 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -13080,12 +13080,13 @@ fn genExternSymbolRef( else => unreachable, } } else if (self.bin_file.cast(link.File.MachO)) |macho_file| { + const global_index = try macho_file.getGlobalSymbol(callee, lib); _ = try self.addInst(.{ .tag = .call, .ops = .extern_fn_reloc, .data = .{ .reloc = .{ .atom_index = atom_index, - .sym_index = try macho_file.getGlobalSymbol(callee, lib), + .sym_index = link.File.MachO.global_symbol_bit | global_index, } }, }); } else return self.fail("TODO implement calling extern functions", .{}); diff --git a/src/arch/x86_64/Emit.zig b/src/arch/x86_64/Emit.zig index 38ac99819a..8201eb4b9a 100644 --- a/src/arch/x86_64/Emit.zig +++ b/src/arch/x86_64/Emit.zig @@ -52,7 +52,10 @@ pub fn emitMir(emit: *Emit) Error!void { // Add relocation to the decl. const atom_index = macho_file.getAtomIndexForSymbol(.{ .sym_index = symbol.atom_index }).?; - const target = macho_file.getGlobalByIndex(symbol.sym_index); + const target = if (link.File.MachO.global_symbol_bit & symbol.sym_index != 0) + macho_file.getGlobalByIndex(link.File.MachO.global_symbol_mask & symbol.sym_index) + else + link.File.MachO.SymbolWithLoc{ .sym_index = symbol.sym_index }; try link.File.MachO.Atom.addRelocation(macho_file, atom_index, .{ .type = .branch, .target = target, @@ -116,6 +119,10 @@ pub fn emitMir(emit: *Emit) Error!void { } else if (emit.lower.bin_file.cast(link.File.MachO)) |macho_file| { const atom_index = macho_file.getAtomIndexForSymbol(.{ .sym_index = symbol.atom_index }).?; + const target = if (link.File.MachO.global_symbol_bit & symbol.sym_index != 0) + macho_file.getGlobalByIndex(link.File.MachO.global_symbol_mask & symbol.sym_index) + else + link.File.MachO.SymbolWithLoc{ .sym_index = symbol.sym_index }; try link.File.MachO.Atom.addRelocation(macho_file, atom_index, .{ .type = switch (lowered_relocs[0].target) { .linker_got => .got, @@ -123,7 +130,7 @@ pub fn emitMir(emit: *Emit) Error!void { .linker_tlv => .tlv, else => unreachable, }, - .target = .{ .sym_index = symbol.sym_index }, + .target = target, .offset = @as(u32, @intCast(end_offset - 4)), .addend = 0, .pcrel = true, |
