authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-01-20 11:00:08+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-01-20 11:00:08+01:00
loge17c551a2e3a0130339b6f1e5817fea2214c260f
treeae7be51a6c6212a7d12c10f65d13167e90a9d2c4
parentdcdbfba770089dbd087840495d8faf5e9ad79c1e

macho: revert ordering tweak of lazy bind pointers and add logging


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

src/link/MachO.zig+9-5
...@@ -1393,7 +1393,7 @@ pub fn createLazyPointerAtom(self: *MachO, stub_sym_index: u32, target: SymbolWi...@@ -1393,7 +1393,7 @@ pub fn createLazyPointerAtom(self: *MachO, stub_sym_index: u32, target: SymbolWi
1393 try self.atom_by_index_table.putNoClobber(gpa, sym_index, atom);1393 try self.atom_by_index_table.putNoClobber(gpa, sym_index, atom);
13941394
1395 sym.n_value = try self.allocateAtom(atom, atom.size, @alignOf(u64));1395 sym.n_value = try self.allocateAtom(atom, atom.size, @alignOf(u64));
1396 log.debug("allocated lazy pointer atom at 0x{x}", .{sym.n_value});1396 log.warn("allocated lazy pointer atom at 0x{x} ({s})", .{ sym.n_value, self.getSymbolName(target) });
1397 try self.writePtrWidthAtom(atom);1397 try self.writePtrWidthAtom(atom);
13981398
1399 return atom;1399 return atom;
...@@ -3422,13 +3422,17 @@ fn populateLazyBindOffsetsInStubHelper(self: *MachO, lazy_bind: LazyBind) !void...@@ -3422,13 +3422,17 @@ fn populateLazyBindOffsetsInStubHelper(self: *MachO, lazy_bind: LazyBind) !void
3422 const header = section.header;3422 const header = section.header;
3423 var atom = section.last_atom.?;3423 var atom = section.last_atom.?;
34243424
3425 var index: usize = 0;3425 var index: usize = lazy_bind.offsets.items.len;
3426 while (index < lazy_bind.offsets.items.len) : (index += 1) {3426 while (index > 0) : (index -= 1) {
3427 const sym = atom.getSymbol(self);3427 const sym = atom.getSymbol(self);
3428 const file_offset = header.offset + sym.n_value - header.addr + stub_offset;3428 const file_offset = header.offset + sym.n_value - header.addr + stub_offset;
3429 const bind_offset = lazy_bind.offsets.items[index];3429 const bind_offset = lazy_bind.offsets.items[index - 1];
34303430
3431 log.debug("writing lazy bind offset 0x{x} in stub helper at 0x{x}", .{ bind_offset, file_offset });3431 log.warn("writing lazy bind offset 0x{x} ({s}) in stub helper at 0x{x}", .{
3432 bind_offset,
3433 self.getSymbolName(lazy_bind.entries.items[index - 1].target),
3434 file_offset,
3435 });
34323436
3433 try self.base.file.?.pwriteAll(mem.asBytes(&bind_offset), file_offset);3437 try self.base.file.?.pwriteAll(mem.asBytes(&bind_offset), file_offset);
34343438