| ... | ... | @@ -3266,6 +3266,7 @@ fn collectRebaseData(self: *MachO, rebase: *Rebase) !void { |
| 3266 | 3266 | } |
| 3267 | 3267 | |
| 3268 | 3268 | // Gather GOT pointers |
| 3269 | try rebase.entries.ensureUnusedCapacity(gpa, self.got_table.entries.items.len); |
| 3269 | 3270 | const segment_index = self.sections.items(.segment_index)[self.got_section_index.?]; |
| 3270 | 3271 | for (self.got_table.entries.items, 0..) |entry, i| { |
| 3271 | 3272 | if (!self.got_table.lookup.contains(entry)) continue; |
| ... | ... | @@ -3324,6 +3325,7 @@ fn collectBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void { |
| 3324 | 3325 | } |
| 3325 | 3326 | |
| 3326 | 3327 | // Gather GOT pointers |
| 3328 | try bind.entries.ensureUnusedCapacity(gpa, self.got_table.entries.items.len); |
| 3327 | 3329 | const segment_index = self.sections.items(.segment_index)[self.got_section_index.?]; |
| 3328 | 3330 | for (self.got_table.entries.items, 0..) |entry, i| { |
| 3329 | 3331 | if (!self.got_table.lookup.contains(entry)) continue; |
| ... | ... | @@ -3352,6 +3354,50 @@ fn collectBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void { |
| 3352 | 3354 | try bind.finalize(gpa, self); |
| 3353 | 3355 | } |
| 3354 | 3356 | |
| 3357 | fn collectLazyBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void { |
| 3358 | const gpa = self.base.allocator; |
| 3359 | const slice = self.sections.slice(); |
| 3360 | |
| 3361 | for (raw_bindings.keys(), 0..) |atom_index, i| { |
| 3362 | const atom = self.getAtom(atom_index); |
| 3363 | log.debug(" ATOM(%{?d}, '{s}')", .{ atom.getSymbolIndex(), atom.getName(self) }); |
| 3364 | |
| 3365 | const sym = atom.getSymbol(self); |
| 3366 | const segment_index = slice.items(.segment_index)[sym.n_sect - 1]; |
| 3367 | const seg = self.getSegment(sym.n_sect - 1); |
| 3368 | |
| 3369 | const base_offset = sym.n_value - seg.vmaddr; |
| 3370 | |
| 3371 | const bindings = raw_bindings.values()[i]; |
| 3372 | try bind.entries.ensureUnusedCapacity(gpa, bindings.items.len); |
| 3373 | |
| 3374 | for (bindings.items) |binding| { |
| 3375 | const bind_sym = self.getSymbol(binding.target); |
| 3376 | const bind_sym_name = self.getSymbolName(binding.target); |
| 3377 | const dylib_ordinal = @divTrunc( |
| 3378 | @bitCast(i16, bind_sym.n_desc), |
| 3379 | macho.N_SYMBOL_RESOLVER, |
| 3380 | ); |
| 3381 | log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{ |
| 3382 | binding.offset + base_offset, |
| 3383 | bind_sym_name, |
| 3384 | dylib_ordinal, |
| 3385 | }); |
| 3386 | if (bind_sym.weakRef()) { |
| 3387 | log.debug(" | marking as weak ref ", .{}); |
| 3388 | } |
| 3389 | bind.entries.appendAssumeCapacity(.{ |
| 3390 | .target = binding.target, |
| 3391 | .offset = binding.offset + base_offset, |
| 3392 | .segment_id = segment_index, |
| 3393 | .addend = 0, |
| 3394 | }); |
| 3395 | } |
| 3396 | } |
| 3397 | |
| 3398 | try bind.finalize(gpa, self); |
| 3399 | } |
| 3400 | |
| 3355 | 3401 | fn collectExportData(self: *MachO, trie: *Trie) !void { |
| 3356 | 3402 | const gpa = self.base.allocator; |
| 3357 | 3403 | |
| ... | ... | @@ -3395,7 +3441,7 @@ fn writeDyldInfoData(self: *MachO) !void { |
| 3395 | 3441 | |
| 3396 | 3442 | var lazy_bind = LazyBind{}; |
| 3397 | 3443 | defer lazy_bind.deinit(gpa); |
| 3398 | | try self.collectBindData(&lazy_bind, self.lazy_bindings); |
| 3444 | try self.collectLazyBindData(&lazy_bind, self.lazy_bindings); |
| 3399 | 3445 | |
| 3400 | 3446 | var trie: Trie = .{}; |
| 3401 | 3447 | defer trie.deinit(gpa); |