authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-22 22:00:34+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-29 11:39:34+02:00
log837114f019a5ba2695165030790fb162ca199151
treee5ce842de6e4221b30ac52632a4e203d4d9d5deb
parentda9e7e498af411de477a7b59e72ef763b22f4f5a

macho: change dyld_private_sym_index to dyld_private_atom_index in zld


1 files changed, 9 insertions(+), 19 deletions(-)

src/link/MachO/zld.zig+9-19
......@@ -73,7 +73,7 @@ pub const Zld = struct {
7373 mh_execute_header_index: ?u32 = null,
7474 dso_handle_index: ?u32 = null,
7575 dyld_stub_binder_index: ?u32 = null,
76 dyld_private_sym_index: ?u32 = null,
76 dyld_private_atom_index: ?Atom.Index = null,
7777 stub_helper_preamble_sym_index: ?u32 = null,
7878
7979 strtab: StringTable(.strtab) = .{},
......@@ -324,8 +324,6 @@ pub const Zld = struct {
324324 }
325325
326326 fn createDyldPrivateAtom(self: *Zld) !void {
327 if (self.dyld_stub_binder_index == null) return;
328
329327 const sym_index = try self.allocateSymbol();
330328 const atom_index = try self.createEmptyAtom(sym_index, @sizeOf(u64), 3);
331329 const sym = self.getSymbolPtr(.{ .sym_index = sym_index });
......@@ -333,8 +331,7 @@ pub const Zld = struct {
333331
334332 const sect_id = self.getSectionByName("__DATA", "__data") orelse try self.initSection("__DATA", "__data", .{});
335333 sym.n_sect = sect_id + 1;
336
337 self.dyld_private_sym_index = sym_index;
334 self.dyld_private_atom_index = atom_index;
338335
339336 self.addAtomToSection(atom_index);
340337 }
......@@ -378,7 +375,8 @@ pub const Zld = struct {
378375 break :blk sym.n_value;
379376 };
380377 const dyld_private_addr = blk: {
381 const sym = self.getSymbol(.{ .sym_index = self.dyld_private_sym_index.? });
378 const atom = self.getAtom(self.dyld_private_atom_index.?);
379 const sym = self.getSymbol(atom.getSymbolWithLoc());
382380 break :blk sym.n_value;
383381 };
384382 const dyld_stub_binder_got_addr = blk: {
......@@ -1054,13 +1052,9 @@ pub const Zld = struct {
10541052 const offset = buffer.items.len;
10551053
10561054 // TODO: move writing synthetic sections into a separate function
1057 if (atom.getFile() == null) outer: {
1058 if (self.dyld_private_sym_index) |sym_index| {
1059 if (atom.sym_index == sym_index) {
1060 buffer.appendSliceAssumeCapacity(&[_]u8{0} ** @sizeOf(u64));
1061 break :outer;
1062 }
1063 }
1055 if (atom_index == self.dyld_private_atom_index.?) {
1056 buffer.appendSliceAssumeCapacity(&[_]u8{0} ** @sizeOf(u64));
1057 } else if (atom.getFile() == null) outer: {
10641058 switch (header.type()) {
10651059 macho.S_NON_LAZY_SYMBOL_POINTERS => {
10661060 try self.writeGotPointer(count, buffer.writer());
......@@ -1544,9 +1538,7 @@ pub const Zld = struct {
15441538 const sym = self.getSymbol(atom.getSymbolWithLoc());
15451539
15461540 const should_rebase = blk: {
1547 if (self.dyld_private_sym_index) |sym_index| {
1548 if (atom.getFile() == null and atom.sym_index == sym_index) break :blk false;
1549 }
1541 if (atom_index == self.dyld_private_atom_index.?) break :blk false;
15501542 break :blk !sym.undf();
15511543 };
15521544
......@@ -1684,9 +1676,7 @@ pub const Zld = struct {
16841676 log.debug(" ATOM({d}, %{d}, '{s}')", .{ atom_index, atom.sym_index, self.getSymbolName(atom.getSymbolWithLoc()) });
16851677
16861678 const should_bind = blk: {
1687 if (self.dyld_private_sym_index) |sym_index| {
1688 if (atom.getFile() == null and atom.sym_index == sym_index) break :blk false;
1689 }
1679 if (atom_index == self.dyld_private_atom_index.?) break :blk false;
16901680 break :blk true;
16911681 };
16921682