| ... | ... | @@ -73,7 +73,7 @@ pub const Zld = struct { |
| 73 | 73 | mh_execute_header_index: ?u32 = null, |
| 74 | 74 | dso_handle_index: ?u32 = null, |
| 75 | 75 | dyld_stub_binder_index: ?u32 = null, |
| 76 | | dyld_private_sym_index: ?u32 = null, |
| 76 | dyld_private_atom_index: ?Atom.Index = null, |
| 77 | 77 | stub_helper_preamble_sym_index: ?u32 = null, |
| 78 | 78 | |
| 79 | 79 | strtab: StringTable(.strtab) = .{}, |
| ... | ... | @@ -324,8 +324,6 @@ pub const Zld = struct { |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | fn createDyldPrivateAtom(self: *Zld) !void { |
| 327 | | if (self.dyld_stub_binder_index == null) return; |
| 328 | | |
| 329 | 327 | const sym_index = try self.allocateSymbol(); |
| 330 | 328 | const atom_index = try self.createEmptyAtom(sym_index, @sizeOf(u64), 3); |
| 331 | 329 | const sym = self.getSymbolPtr(.{ .sym_index = sym_index }); |
| ... | ... | @@ -333,8 +331,7 @@ pub const Zld = struct { |
| 333 | 331 | |
| 334 | 332 | const sect_id = self.getSectionByName("__DATA", "__data") orelse try self.initSection("__DATA", "__data", .{}); |
| 335 | 333 | sym.n_sect = sect_id + 1; |
| 336 | | |
| 337 | | self.dyld_private_sym_index = sym_index; |
| 334 | self.dyld_private_atom_index = atom_index; |
| 338 | 335 | |
| 339 | 336 | self.addAtomToSection(atom_index); |
| 340 | 337 | } |
| ... | ... | @@ -378,7 +375,8 @@ pub const Zld = struct { |
| 378 | 375 | break :blk sym.n_value; |
| 379 | 376 | }; |
| 380 | 377 | 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()); |
| 382 | 380 | break :blk sym.n_value; |
| 383 | 381 | }; |
| 384 | 382 | const dyld_stub_binder_got_addr = blk: { |
| ... | ... | @@ -1054,13 +1052,9 @@ pub const Zld = struct { |
| 1054 | 1052 | const offset = buffer.items.len; |
| 1055 | 1053 | |
| 1056 | 1054 | // 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: { |
| 1064 | 1058 | switch (header.type()) { |
| 1065 | 1059 | macho.S_NON_LAZY_SYMBOL_POINTERS => { |
| 1066 | 1060 | try self.writeGotPointer(count, buffer.writer()); |
| ... | ... | @@ -1544,9 +1538,7 @@ pub const Zld = struct { |
| 1544 | 1538 | const sym = self.getSymbol(atom.getSymbolWithLoc()); |
| 1545 | 1539 | |
| 1546 | 1540 | 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; |
| 1550 | 1542 | break :blk !sym.undf(); |
| 1551 | 1543 | }; |
| 1552 | 1544 | |
| ... | ... | @@ -1684,9 +1676,7 @@ pub const Zld = struct { |
| 1684 | 1676 | log.debug(" ATOM({d}, %{d}, '{s}')", .{ atom_index, atom.sym_index, self.getSymbolName(atom.getSymbolWithLoc()) }); |
| 1685 | 1677 | |
| 1686 | 1678 | 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; |
| 1690 | 1680 | break :blk true; |
| 1691 | 1681 | }; |
| 1692 | 1682 | |