authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-11 06:40:53+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-18 09:13:08+02:00
log05a790d784e4f1258d550e31178cf1e163750b6b
treed6d8c878a59d9d9506a4aeb12020fed833f103be
parent18778e2a0aab02c88694bfed5623ef7c205e12c7

macho: link hello world in zig compiled with llvm


2 files changed, 6 insertions(+), 3 deletions(-)

src/link/MachO.zig+5-2
...@@ -1542,6 +1542,9 @@ fn scanRelocs(self: *MachO) !void {...@@ -1542,6 +1542,9 @@ fn scanRelocs(self: *MachO) !void {
1542 for (self.objects.items) |index| {1542 for (self.objects.items) |index| {
1543 try self.getFile(index).?.createSymbolIndirection(self);1543 try self.getFile(index).?.createSymbolIndirection(self);
1544 }1544 }
1545 for (self.dylibs.items) |index| {
1546 try self.getFile(index).?.createSymbolIndirection(self);
1547 }
1545 if (self.getInternalObject()) |obj| {1548 if (self.getInternalObject()) |obj| {
1546 try obj.asFile().createSymbolIndirection(self);1549 try obj.asFile().createSymbolIndirection(self);
1547 }1550 }
...@@ -2358,9 +2361,9 @@ fn allocateLinkeditSegment(self: *MachO) !void {...@@ -2358,9 +2361,9 @@ fn allocateLinkeditSegment(self: *MachO) !void {
23582361
2359fn resizeSections(self: *MachO) !void {2362fn resizeSections(self: *MachO) !void {
2360 const slice = self.sections.slice();2363 const slice = self.sections.slice();
2361 for (slice.items(.header), slice.items(.atoms), slice.items(.out)) |header, atoms, *out| {2364 for (slice.items(.header), slice.items(.out), 0..) |header, *out, n_sect| {
2362 if (atoms.items.len == 0) continue;
2363 if (header.isZerofill()) continue;2365 if (header.isZerofill()) continue;
2366 if (self.isZigSection(@intCast(n_sect))) continue; // TODO this is horrible
2364 const cpu_arch = self.getTarget().cpu.arch;2367 const cpu_arch = self.getTarget().cpu.arch;
2365 try out.resize(self.base.comp.gpa, header.size);2368 try out.resize(self.base.comp.gpa, header.size);
2366 const padding_byte: u8 = if (header.isCode() and cpu_arch == .x86_64) 0xcc else 0;2369 const padding_byte: u8 = if (header.isCode() and cpu_arch == .x86_64) 0xcc else 0;
src/link/MachO/synthetic.zig+1-1
...@@ -91,9 +91,9 @@ pub const ZigGotSection = struct {...@@ -91,9 +91,9 @@ pub const ZigGotSection = struct {
91 _ = unused_fmt_string;91 _ = unused_fmt_string;
92 const zig_got = ctx.zig_got;92 const zig_got = ctx.zig_got;
93 const macho_file = ctx.macho_file;93 const macho_file = ctx.macho_file;
94 const zo = macho_file.getZigObject().?;
95 try writer.writeAll("__zig_got\n");94 try writer.writeAll("__zig_got\n");
96 for (zig_got.entries.items, 0..) |entry, index| {95 for (zig_got.entries.items, 0..) |entry, index| {
96 const zo = macho_file.getZigObject().?;
97 const symbol = zo.symbols.items[entry];97 const symbol = zo.symbols.items[entry];
98 try writer.print(" {d}@0x{x} => {d}@0x{x} ({s})\n", .{98 try writer.print(" {d}@0x{x} => {d}@0x{x} ({s})\n", .{
99 index,99 index,