authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-07-17 23:21:02+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-07-17 23:21:04+02:00
loga095263462ebfc82f25bb421aae3992d9f77e980
tree386d7d5c9714d66bbbe07d43247cb572da9af091
parentd8c4838c7da9efef07fcf5b8e709bb2a65cd2209

zld: more fixes todo with symbol resolution

namely, fixes proper symbol reolution when scanning and including objects from static archives, and properly discard any null symbols when a tentative definition was substituted by a defined, global symbol.

1 files changed, 14 insertions(+), 1 deletions(-)

src/link/MachO/Zld.zig+14-1
......@@ -1636,7 +1636,11 @@ fn resolveSymbols(self: *Zld) !void {
16361636 }
16371637
16381638 // Second pass, resolve symbols in static libraries.
1639 loop: for (self.undefs.items) |sym| {
1639 var next_sym: usize = 0;
1640 loop: while (true) : (next_sym += 1) {
1641 if (next_sym == self.undefs.items.len) break;
1642
1643 const sym = self.undefs.items[next_sym];
16401644 if (symbolIsNull(sym)) continue;
16411645
16421646 const sym_name = self.getString(sym.n_strx);
......@@ -1661,6 +1665,8 @@ fn resolveSymbols(self: *Zld) !void {
16611665 // Convert any tentative definition into a regular symbol and allocate
16621666 // text blocks for each tentative defintion.
16631667 for (self.tentatives.items) |sym| {
1668 if (symbolIsNull(sym)) continue;
1669
16641670 const sym_name = self.getString(sym.n_strx);
16651671 const match: MatchingSection = blk: {
16661672 if (self.common_section_index == null) {
......@@ -1813,6 +1819,13 @@ fn resolveSymbols(self: *Zld) !void {
18131819 .n_desc = macho.N_WEAK_DEF,
18141820 .n_value = seg.inner.vmaddr,
18151821 });
1822 undef.* = .{
1823 .n_strx = 0,
1824 .n_type = macho.N_UNDF,
1825 .n_sect = 0,
1826 .n_desc = 0,
1827 .n_value = 0,
1828 };
18161829 resolv.* = .{
18171830 .where = .global,
18181831 .where_index = global_sym_index,