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 {...@@ -1636,7 +1636,11 @@ fn resolveSymbols(self: *Zld) !void {
1636 }1636 }
16371637
1638 // Second pass, resolve symbols in static libraries.1638 // 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];
1640 if (symbolIsNull(sym)) continue;1644 if (symbolIsNull(sym)) continue;
16411645
1642 const sym_name = self.getString(sym.n_strx);1646 const sym_name = self.getString(sym.n_strx);
...@@ -1661,6 +1665,8 @@ fn resolveSymbols(self: *Zld) !void {...@@ -1661,6 +1665,8 @@ fn resolveSymbols(self: *Zld) !void {
1661 // Convert any tentative definition into a regular symbol and allocate1665 // Convert any tentative definition into a regular symbol and allocate
1662 // text blocks for each tentative defintion.1666 // text blocks for each tentative defintion.
1663 for (self.tentatives.items) |sym| {1667 for (self.tentatives.items) |sym| {
1668 if (symbolIsNull(sym)) continue;
1669
1664 const sym_name = self.getString(sym.n_strx);1670 const sym_name = self.getString(sym.n_strx);
1665 const match: MatchingSection = blk: {1671 const match: MatchingSection = blk: {
1666 if (self.common_section_index == null) {1672 if (self.common_section_index == null) {
...@@ -1813,6 +1819,13 @@ fn resolveSymbols(self: *Zld) !void {...@@ -1813,6 +1819,13 @@ fn resolveSymbols(self: *Zld) !void {
1813 .n_desc = macho.N_WEAK_DEF,1819 .n_desc = macho.N_WEAK_DEF,
1814 .n_value = seg.inner.vmaddr,1820 .n_value = seg.inner.vmaddr,
1815 });1821 });
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 };
1816 resolv.* = .{1829 resolv.* = .{
1817 .where = .global,1830 .where = .global,
1818 .where_index = global_sym_index,1831 .where_index = global_sym_index,