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 {
15421542 for (self.objects.items) |index| {
15431543 try self.getFile(index).?.createSymbolIndirection(self);
15441544 }
1545 for (self.dylibs.items) |index| {
1546 try self.getFile(index).?.createSymbolIndirection(self);
1547 }
15451548 if (self.getInternalObject()) |obj| {
15461549 try obj.asFile().createSymbolIndirection(self);
15471550 }
......@@ -2358,9 +2361,9 @@ fn allocateLinkeditSegment(self: *MachO) !void {
23582361
23592362fn resizeSections(self: *MachO) !void {
23602363 const slice = self.sections.slice();
2361 for (slice.items(.header), slice.items(.atoms), slice.items(.out)) |header, atoms, *out| {
2362 if (atoms.items.len == 0) continue;
2364 for (slice.items(.header), slice.items(.out), 0..) |header, *out, n_sect| {
23632365 if (header.isZerofill()) continue;
2366 if (self.isZigSection(@intCast(n_sect))) continue; // TODO this is horrible
23642367 const cpu_arch = self.getTarget().cpu.arch;
23652368 try out.resize(self.base.comp.gpa, header.size);
23662369 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 {
9191 _ = unused_fmt_string;
9292 const zig_got = ctx.zig_got;
9393 const macho_file = ctx.macho_file;
94 const zo = macho_file.getZigObject().?;
9594 try writer.writeAll("__zig_got\n");
9695 for (zig_got.entries.items, 0..) |entry, index| {
96 const zo = macho_file.getZigObject().?;
9797 const symbol = zo.symbols.items[entry];
9898 try writer.print(" {d}@0x{x} => {d}@0x{x} ({s})\n", .{
9999 index,