diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2021-07-17 23:21:02 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2021-07-17 23:21:04 +0200 |
| commit | a095263462ebfc82f25bb421aae3992d9f77e980 (patch) | |
| tree | 386d7d5c9714d66bbbe07d43247cb572da9af091 /src | |
| parent | d8c4838c7da9efef07fcf5b8e709bb2a65cd2209 (diff) | |
| download | zig-a095263462ebfc82f25bb421aae3992d9f77e980.tar.gz zig-a095263462ebfc82f25bb421aae3992d9f77e980.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/MachO/Zld.zig | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/link/MachO/Zld.zig b/src/link/MachO/Zld.zig index 4d58de25c8..1bfd922c6f 100644 --- a/src/link/MachO/Zld.zig +++ b/src/link/MachO/Zld.zig @@ -1636,7 +1636,11 @@ fn resolveSymbols(self: *Zld) !void { } // Second pass, resolve symbols in static libraries. - loop: for (self.undefs.items) |sym| { + var next_sym: usize = 0; + loop: while (true) : (next_sym += 1) { + if (next_sym == self.undefs.items.len) break; + + const sym = self.undefs.items[next_sym]; if (symbolIsNull(sym)) continue; const sym_name = self.getString(sym.n_strx); @@ -1661,6 +1665,8 @@ fn resolveSymbols(self: *Zld) !void { // Convert any tentative definition into a regular symbol and allocate // text blocks for each tentative defintion. for (self.tentatives.items) |sym| { + if (symbolIsNull(sym)) continue; + const sym_name = self.getString(sym.n_strx); const match: MatchingSection = blk: { if (self.common_section_index == null) { @@ -1813,6 +1819,13 @@ fn resolveSymbols(self: *Zld) !void { .n_desc = macho.N_WEAK_DEF, .n_value = seg.inner.vmaddr, }); + undef.* = .{ + .n_strx = 0, + .n_type = macho.N_UNDF, + .n_sect = 0, + .n_desc = 0, + .n_value = 0, + }; resolv.* = .{ .where = .global, .where_index = global_sym_index, |
