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 {...@@ -73,7 +73,7 @@ pub const Zld = struct {
73 mh_execute_header_index: ?u32 = null,73 mh_execute_header_index: ?u32 = null,
74 dso_handle_index: ?u32 = null,74 dso_handle_index: ?u32 = null,
75 dyld_stub_binder_index: ?u32 = null,75 dyld_stub_binder_index: ?u32 = null,
76 dyld_private_sym_index: ?u32 = null,76 dyld_private_atom_index: ?Atom.Index = null,
77 stub_helper_preamble_sym_index: ?u32 = null,77 stub_helper_preamble_sym_index: ?u32 = null,
7878
79 strtab: StringTable(.strtab) = .{},79 strtab: StringTable(.strtab) = .{},
...@@ -324,8 +324,6 @@ pub const Zld = struct {...@@ -324,8 +324,6 @@ pub const Zld = struct {
324 }324 }
325325
326 fn createDyldPrivateAtom(self: *Zld) !void {326 fn createDyldPrivateAtom(self: *Zld) !void {
327 if (self.dyld_stub_binder_index == null) return;
328
329 const sym_index = try self.allocateSymbol();327 const sym_index = try self.allocateSymbol();
330 const atom_index = try self.createEmptyAtom(sym_index, @sizeOf(u64), 3);328 const atom_index = try self.createEmptyAtom(sym_index, @sizeOf(u64), 3);
331 const sym = self.getSymbolPtr(.{ .sym_index = sym_index });329 const sym = self.getSymbolPtr(.{ .sym_index = sym_index });
...@@ -333,8 +331,7 @@ pub const Zld = struct {...@@ -333,8 +331,7 @@ pub const Zld = struct {
333331
334 const sect_id = self.getSectionByName("__DATA", "__data") orelse try self.initSection("__DATA", "__data", .{});332 const sect_id = self.getSectionByName("__DATA", "__data") orelse try self.initSection("__DATA", "__data", .{});
335 sym.n_sect = sect_id + 1;333 sym.n_sect = sect_id + 1;
336334 self.dyld_private_atom_index = atom_index;
337 self.dyld_private_sym_index = sym_index;
338335
339 self.addAtomToSection(atom_index);336 self.addAtomToSection(atom_index);
340 }337 }
...@@ -378,7 +375,8 @@ pub const Zld = struct {...@@ -378,7 +375,8 @@ pub const Zld = struct {
378 break :blk sym.n_value;375 break :blk sym.n_value;
379 };376 };
380 const dyld_private_addr = blk: {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 break :blk sym.n_value;380 break :blk sym.n_value;
383 };381 };
384 const dyld_stub_binder_got_addr = blk: {382 const dyld_stub_binder_got_addr = blk: {
...@@ -1054,13 +1052,9 @@ pub const Zld = struct {...@@ -1054,13 +1052,9 @@ pub const Zld = struct {
1054 const offset = buffer.items.len;1052 const offset = buffer.items.len;
10551053
1056 // TODO: move writing synthetic sections into a separate function1054 // TODO: move writing synthetic sections into a separate function
1057 if (atom.getFile() == null) outer: {1055 if (atom_index == self.dyld_private_atom_index.?) {
1058 if (self.dyld_private_sym_index) |sym_index| {1056 buffer.appendSliceAssumeCapacity(&[_]u8{0} ** @sizeOf(u64));
1059 if (atom.sym_index == sym_index) {1057 } else if (atom.getFile() == null) outer: {
1060 buffer.appendSliceAssumeCapacity(&[_]u8{0} ** @sizeOf(u64));
1061 break :outer;
1062 }
1063 }
1064 switch (header.type()) {1058 switch (header.type()) {
1065 macho.S_NON_LAZY_SYMBOL_POINTERS => {1059 macho.S_NON_LAZY_SYMBOL_POINTERS => {
1066 try self.writeGotPointer(count, buffer.writer());1060 try self.writeGotPointer(count, buffer.writer());
...@@ -1544,9 +1538,7 @@ pub const Zld = struct {...@@ -1544,9 +1538,7 @@ pub const Zld = struct {
1544 const sym = self.getSymbol(atom.getSymbolWithLoc());1538 const sym = self.getSymbol(atom.getSymbolWithLoc());
15451539
1546 const should_rebase = blk: {1540 const should_rebase = blk: {
1547 if (self.dyld_private_sym_index) |sym_index| {1541 if (atom_index == self.dyld_private_atom_index.?) break :blk false;
1548 if (atom.getFile() == null and atom.sym_index == sym_index) break :blk false;
1549 }
1550 break :blk !sym.undf();1542 break :blk !sym.undf();
1551 };1543 };
15521544
...@@ -1684,9 +1676,7 @@ pub const Zld = struct {...@@ -1684,9 +1676,7 @@ pub const Zld = struct {
1684 log.debug(" ATOM({d}, %{d}, '{s}')", .{ atom_index, atom.sym_index, self.getSymbolName(atom.getSymbolWithLoc()) });1676 log.debug(" ATOM({d}, %{d}, '{s}')", .{ atom_index, atom.sym_index, self.getSymbolName(atom.getSymbolWithLoc()) });
16851677
1686 const should_bind = blk: {1678 const should_bind = blk: {
1687 if (self.dyld_private_sym_index) |sym_index| {1679 if (atom_index == self.dyld_private_atom_index.?) break :blk false;
1688 if (atom.getFile() == null and atom.sym_index == sym_index) break :blk false;
1689 }
1690 break :blk true;1680 break :blk true;
1691 };1681 };
16921682