authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-07-19 15:55:49+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-07-22 16:58:21+02:00
log39df241df4ac177503d899dd8b53a632e4e29334
tree853d25436b0afb913b5165aeb467e1b4817d2eff
parenta089a6dc4ff04a10360019185ecaacd0564eb84c

macho: do not GC local symbols unless reference dead symbols

If a local references another local, we keep it. If it doesn't reference anything, we keep it. Otherwise, we dead strip it.

4 files changed, 293 insertions(+), 196 deletions(-)

src/link/MachO.zig+251-164
......@@ -171,17 +171,19 @@ stub_helper_preamble_atom: ?*Atom = null,
171171
172172strtab: StringTable(.strtab) = .{},
173173
174// TODO I think synthetic tables are a perfect match for some generic refactoring,
175// and probably reusable between linker backends too.
174176tlv_ptr_entries: std.ArrayListUnmanaged(Entry) = .{},
175177tlv_ptr_entries_free_list: std.ArrayListUnmanaged(u32) = .{},
176tlv_ptr_entries_table: std.AutoArrayHashMapUnmanaged(SymbolWithLoc, u32) = .{},
178tlv_ptr_entries_table: std.AutoHashMapUnmanaged(SymbolWithLoc, u32) = .{},
177179
178180got_entries: std.ArrayListUnmanaged(Entry) = .{},
179181got_entries_free_list: std.ArrayListUnmanaged(u32) = .{},
180got_entries_table: std.AutoArrayHashMapUnmanaged(SymbolWithLoc, u32) = .{},
182got_entries_table: std.AutoHashMapUnmanaged(SymbolWithLoc, u32) = .{},
181183
182184stubs: std.ArrayListUnmanaged(Entry) = .{},
183185stubs_free_list: std.ArrayListUnmanaged(u32) = .{},
184stubs_table: std.AutoArrayHashMapUnmanaged(SymbolWithLoc, u32) = .{},
186stubs_table: std.AutoHashMapUnmanaged(SymbolWithLoc, u32) = .{},
185187
186188error_flags: File.ErrorFlags = File.ErrorFlags{},
187189
......@@ -251,7 +253,24 @@ decls: std.AutoArrayHashMapUnmanaged(Module.Decl.Index, ?MatchingSection) = .{},
251253
252254const Entry = struct {
253255 target: SymbolWithLoc,
254 atom: *Atom,
256 // Index into the synthetic symbol table (i.e., file == null).
257 sym_index: u32,
258
259 pub fn getSymbol(entry: Entry, macho_file: *MachO) macho.nlist_64 {
260 return macho_file.getSymbol(.{ .sym_index = entry.sym_index, .file = null });
261 }
262
263 pub fn getSymbolPtr(entry: Entry, macho_file: *MachO) *macho.nlist_64 {
264 return macho_file.getSymbolPtr(.{ .sym_index = entry.sym_index, .file = null });
265 }
266
267 pub fn getAtom(entry: Entry, macho_file: *MachO) *Atom {
268 return macho_file.getAtomForSymbol(.{ .sym_index = entry.sym_index, .file = null }).?;
269 }
270
271 pub fn getName(entry: Entry, macho_file: *MachO) []const u8 {
272 return macho_file.getSymbolName(.{ .sym_index = entry.sym_index, .file = null });
273 }
255274};
256275
257276const UnnamedConstTable = std.AutoHashMapUnmanaged(Module.Decl.Index, std.ArrayListUnmanaged(*Atom));
......@@ -1652,6 +1671,15 @@ fn parseDependentLibs(self: *MachO, syslibroot: ?[]const u8, dependent_libs: any
16521671pub const MatchingSection = struct {
16531672 seg: u16,
16541673 sect: u16,
1674
1675 pub fn eql(this: MatchingSection, other: struct {
1676 seg: ?u16,
1677 sect: ?u16,
1678 }) bool {
1679 const seg = other.seg orelse return false;
1680 const sect = other.sect orelse return false;
1681 return this.seg == seg and this.sect == sect;
1682 }
16551683};
16561684
16571685pub fn getMatchingSection(self: *MachO, sect: macho.section_64) !?MatchingSection {
......@@ -3153,8 +3181,7 @@ fn resolveSymbolsInDylibs(self: *MachO) !void {
31533181 const stub_helper_atom = try self.createStubHelperAtom();
31543182 const laptr_atom = try self.createLazyPointerAtom(stub_helper_atom.sym_index, global);
31553183 const stub_atom = try self.createStubAtom(laptr_atom.sym_index);
3156
3157 self.stubs.items[stub_index].atom = stub_atom;
3184 self.stubs.items[stub_index].sym_index = stub_atom.sym_index;
31583185 }
31593186
31603187 continue :loop;
......@@ -3251,7 +3278,7 @@ fn resolveDyldStubBinder(self: *MachO) !void {
32513278 // Add dyld_stub_binder as the final GOT entry.
32523279 const got_index = try self.allocateGotEntry(global);
32533280 const got_atom = try self.createGotAtom(global);
3254 self.got_entries.items[got_index].atom = got_atom;
3281 self.got_entries.items[got_index].sym_index = got_atom.sym_index;
32553282}
32563283
32573284fn addLoadDylibLC(self: *MachO, id: u16) !void {
......@@ -3288,11 +3315,7 @@ fn setEntryPoint(self: *MachO) !void {
32883315 if (self.base.options.output_mode != .Exe) return;
32893316
32903317 const seg = self.load_commands.items[self.text_segment_cmd_index.?].segment;
3291 const global = self.getEntryPoint() orelse {
3292 const name = self.base.options.entry orelse "_main";
3293 log.err("entrypoint '{s}' not found", .{name});
3294 return error.MissingMainEntrypoint;
3295 };
3318 const global = try self.getEntryPoint();
32963319 const sym = self.getSymbol(global);
32973320 const ec = &self.load_commands.items[self.main_cmd_index.?].main;
32983321 ec.entryoff = @intCast(u32, sym.n_value - seg.inner.vmaddr);
......@@ -3508,7 +3531,8 @@ fn allocateSymbol(self: *MachO) !u32 {
35083531}
35093532
35103533pub fn allocateGotEntry(self: *MachO, target: SymbolWithLoc) !u32 {
3511 try self.got_entries.ensureUnusedCapacity(self.base.allocator, 1);
3534 const gpa = self.base.allocator;
3535 try self.got_entries.ensureUnusedCapacity(gpa, 1);
35123536
35133537 const index = blk: {
35143538 if (self.got_entries_free_list.popOrNull()) |index| {
......@@ -3522,8 +3546,8 @@ pub fn allocateGotEntry(self: *MachO, target: SymbolWithLoc) !u32 {
35223546 }
35233547 };
35243548
3525 self.got_entries.items[index] = .{ .target = target, .atom = undefined };
3526 try self.got_entries_table.putNoClobber(self.base.allocator, target, index);
3549 self.got_entries.items[index] = .{ .target = target, .sym_index = 0 };
3550 try self.got_entries_table.putNoClobber(gpa, target, index);
35273551
35283552 return index;
35293553}
......@@ -3543,7 +3567,7 @@ pub fn allocateStubEntry(self: *MachO, target: SymbolWithLoc) !u32 {
35433567 }
35443568 };
35453569
3546 self.stubs.items[index] = .{ .target = target, .atom = undefined };
3570 self.stubs.items[index] = .{ .target = target, .sym_index = 0 };
35473571 try self.stubs_table.putNoClobber(self.base.allocator, target, index);
35483572
35493573 return index;
......@@ -3564,7 +3588,7 @@ pub fn allocateTlvPtrEntry(self: *MachO, target: SymbolWithLoc) !u32 {
35643588 }
35653589 };
35663590
3567 self.tlv_ptr_entries.items[index] = .{ .target = target, .atom = undefined };
3591 self.tlv_ptr_entries.items[index] = .{ .target = target, .sym_index = 0 };
35683592 try self.tlv_ptr_entries_table.putNoClobber(self.base.allocator, target, index);
35693593
35703594 return index;
......@@ -4029,7 +4053,7 @@ fn placeDecl(self: *MachO, decl_index: Module.Decl.Index, code_len: usize) !*mac
40294053 const got_target = SymbolWithLoc{ .sym_index = decl.link.macho.sym_index, .file = null };
40304054 const got_index = try self.allocateGotEntry(got_target);
40314055 const got_atom = try self.createGotAtom(got_target);
4032 self.got_entries.items[got_index].atom = got_atom;
4056 self.got_entries.items[got_index].sym_index = got_atom.sym_index;
40334057 }
40344058
40354059 return symbol;
......@@ -4219,9 +4243,9 @@ pub fn freeDecl(self: *MachO, decl_index: Module.Decl.Index) void {
42194243 self.got_entries_free_list.append(self.base.allocator, @intCast(u32, got_index)) catch {};
42204244 self.got_entries.items[got_index] = .{
42214245 .target = .{ .sym_index = 0, .file = null },
4222 .atom = undefined,
4246 .sym_index = 0,
42234247 };
4224 _ = self.got_entries_table.swapRemove(got_target);
4248 _ = self.got_entries_table.remove(got_target);
42254249
42264250 if (self.d_sym) |*d_sym| {
42274251 d_sym.swapRemoveRelocs(decl.link.macho.sym_index);
......@@ -5493,46 +5517,26 @@ fn gcAtoms(self: *MachO, gc_roots: *std.AutoHashMap(*Atom, void)) !void {
54935517
54945518 if (self.base.options.output_mode == .Exe) {
54955519 // Add entrypoint as GC root
5496 if (self.getEntryPoint()) |global| {
5497 if (self.getAtomForSymbol(global)) |gc_root| {
5498 _ = try gc_roots.getOrPut(gc_root);
5499 } else {
5500 log.debug("skipping {s}", .{self.getSymbolName(global)});
5501 }
5502 }
5520 const global = try self.getEntryPoint();
5521 const atom = self.getAtomForSymbol(global).?; // panic here means fatal error
5522 _ = try gc_roots.getOrPut(atom);
55035523 } else {
55045524 assert(self.base.options.output_mode == .Lib);
55055525 // Add exports as GC roots
55065526 for (self.globals.values()) |global| {
55075527 const sym = self.getSymbol(global);
55085528 if (!sym.sect()) continue;
5509 const gc_root = self.getAtomForSymbol(global) orelse {
5529 const atom = self.getAtomForSymbol(global) orelse {
55105530 log.debug("skipping {s}", .{self.getSymbolName(global)});
55115531 continue;
55125532 };
5513 _ = try gc_roots.getOrPut(gc_root);
5533 _ = try gc_roots.getOrPut(atom);
55145534 }
55155535 }
5516
5517 // Add any atom targeting an import as GC root
5518 var atoms_it = self.atoms.iterator();
5519 while (atoms_it.next()) |entry| {
5520 var atom = entry.value_ptr.*;
5521
5522 while (true) {
5523 for (atom.relocs.items) |rel| {
5524 if ((try rel.getTargetAtom(self)) == null) {
5525 const target_sym = self.getSymbol(rel.target);
5526 if (target_sym.undf()) {
5527 _ = try gc_roots.getOrPut(atom);
5528 break;
5529 }
5530 }
5531 }
5532
5533 if (atom.prev) |prev| {
5534 atom = prev;
5535 } else break;
5536 // TODO just a temp until we learn how to parse unwind records
5537 if (self.globals.get("___gxx_personality_v0")) |global| {
5538 if (self.getAtomForSymbol(global)) |atom| {
5539 _ = try gc_roots.getOrPut(atom);
55365540 }
55375541 }
55385542
......@@ -5540,80 +5544,80 @@ fn gcAtoms(self: *MachO, gc_roots: *std.AutoHashMap(*Atom, void)) !void {
55405544 defer stack.deinit();
55415545 try stack.ensureUnusedCapacity(gc_roots.count());
55425546
5543 var retained = std.AutoHashMap(*Atom, void).init(gpa);
5544 defer retained.deinit();
5545 try retained.ensureUnusedCapacity(gc_roots.count());
5547 var alive = std.AutoHashMap(*Atom, void).init(gpa);
5548 defer alive.deinit();
5549 try alive.ensureUnusedCapacity(gc_roots.count());
55465550
55475551 log.debug("GC roots:", .{});
55485552 var gc_roots_it = gc_roots.keyIterator();
55495553 while (gc_roots_it.next()) |gc_root| {
55505554 self.logAtom(gc_root.*);
5551
55525555 stack.appendAssumeCapacity(gc_root.*);
5553 retained.putAssumeCapacityNoClobber(gc_root.*, {});
5556 alive.putAssumeCapacity(gc_root.*, {});
55545557 }
55555558
5556 log.debug("walking tree...", .{});
55575559 while (stack.popOrNull()) |source_atom| {
55585560 for (source_atom.relocs.items) |rel| {
5559 if (try rel.getTargetAtom(self)) |target_atom| {
5560 const gop = try retained.getOrPut(target_atom);
5561 if (rel.getTargetAtom(self)) |target_atom| {
5562 const gop = try alive.getOrPut(target_atom);
55615563 if (!gop.found_existing) {
5562 log.debug(" RETAINED ATOM(%{d}) -> ATOM(%{d})", .{
5563 source_atom.sym_index,
5564 log.debug(" retained ATOM(%{d}, '{s}') in object({d})", .{
55645565 target_atom.sym_index,
5566 target_atom.getName(self),
5567 target_atom.file,
5568 });
5569 log.debug(" referenced by ATOM(%{d}, '{s}') in object({d})", .{
5570 source_atom.sym_index,
5571 source_atom.getName(self),
5572 source_atom.file,
55655573 });
55665574 try stack.append(target_atom);
55675575 }
55685576 }
55695577 }
55705578 }
5579 // TODO live support
55715580
55725581 // Any section that ends up here will be updated, that is,
55735582 // its size and alignment recalculated.
55745583 var gc_sections = std.AutoHashMap(MatchingSection, void).init(gpa);
55755584 defer gc_sections.deinit();
55765585
5577 atoms_it = self.atoms.iterator();
5578 while (atoms_it.next()) |entry| {
5579 const match = entry.key_ptr.*;
5580
5581 if (self.text_segment_cmd_index) |seg| {
5582 if (seg == match.seg) {
5583 if (self.eh_frame_section_index) |sect| {
5584 if (sect == match.sect) continue;
5585 }
5586 }
5587 }
5586 var loop: bool = true;
5587 while (loop) {
5588 loop = false;
55885589
5589 if (self.data_segment_cmd_index) |seg| {
5590 if (seg == match.seg) {
5591 if (self.rustc_section_index) |sect| {
5592 if (sect == match.sect) continue;
5593 }
5594 }
5595 }
5590 for (self.objects.items) |object| {
5591 for (object.getSourceSymtab()) |_, source_index| {
5592 const atom = object.getAtomForSymbol(@intCast(u32, source_index)) orelse continue;
5593 if (alive.contains(atom)) continue;
55965594
5597 const sect = self.getSectionPtr(match);
5598 var atom = entry.value_ptr.*;
5595 const global = atom.getSymbolWithLoc();
5596 const sym = atom.getSymbolPtr(self);
55995597
5600 log.debug("GCing atoms in {s},{s}", .{ sect.segName(), sect.sectName() });
5598 if (sym.n_desc == N_DESC_GCED) continue;
5599 if (!sym.ext()) {
5600 for (atom.relocs.items) |rel| {
5601 if (rel.getTargetAtom(self)) |target_atom| {
5602 const target_sym = target_atom.getSymbol(self);
5603 if (target_sym.n_desc == N_DESC_GCED) break;
5604 }
5605 } else continue;
5606 }
56015607
5602 while (true) {
5603 const orig_prev = atom.prev;
5608 loop = true;
5609 const match = self.getMatchingSectionFromOrdinal(sym.n_sect);
56045610
5605 if (!retained.contains(atom)) {
5606 // Dead atom; remove.
5607 log.debug(" DEAD ATOM(%{d})", .{atom.sym_index});
5611 // TODO don't dedup eh_frame info yet until we actually implement parsing unwind records
5612 if (match.eql(.{
5613 .seg = self.text_segment_cmd_index,
5614 .sect = self.eh_frame_section_index,
5615 })) continue;
56085616
5609 const sym = atom.getSymbolPtr(self);
5617 self.logAtom(atom);
56105618 sym.n_desc = N_DESC_GCED;
5611
5612 // TODO add full bookkeeping here
5613 const global = SymbolWithLoc{ .sym_index = atom.sym_index, .file = atom.file };
5614 _ = self.got_entries_table.swapRemove(global);
5615 _ = self.stubs_table.swapRemove(global);
5616 _ = self.tlv_ptr_entries_table.swapRemove(global);
5619 self.removeAtomFromSection(atom, match);
5620 _ = try gc_sections.put(match, {});
56175621
56185622 for (atom.contained.items) |sym_off| {
56195623 const inner = self.getSymbolPtr(.{
......@@ -5622,34 +5626,64 @@ fn gcAtoms(self: *MachO, gc_roots: *std.AutoHashMap(*Atom, void)) !void {
56225626 });
56235627 inner.n_desc = N_DESC_GCED;
56245628 }
5625 // If we want to enable GC for incremental codepath, we need to take into
5626 // account any padding that might have been left here.
5627 sect.size -= atom.size;
56285629
5629 _ = try gc_sections.put(match, {});
5630 if (self.got_entries_table.contains(global)) {
5631 const got_atom = self.getGotAtomForSymbol(global).?;
5632 const got_sym = got_atom.getSymbolPtr(self);
5633 got_sym.n_desc = N_DESC_GCED;
5634 }
56305635
5631 if (atom.prev) |prev| {
5632 prev.next = atom.next;
5636 if (self.stubs_table.contains(global)) {
5637 const stubs_atom = self.getStubsAtomForSymbol(global).?;
5638 const stubs_sym = stubs_atom.getSymbolPtr(self);
5639 stubs_sym.n_desc = N_DESC_GCED;
56335640 }
5634 if (atom.next) |next| {
5635 next.prev = atom.prev;
5636 } else {
5637 if (atom.prev) |prev| {
5638 entry.value_ptr.* = prev;
5639 } else {
5640 // The section will be GCed in the next step.
5641 entry.value_ptr.* = undefined;
5642 sect.size = 0;
5643 }
5641
5642 if (self.tlv_ptr_entries_table.contains(global)) {
5643 const tlv_ptr_atom = self.getTlvPtrAtomForSymbol(global).?;
5644 const tlv_ptr_sym = tlv_ptr_atom.getSymbolPtr(self);
5645 tlv_ptr_sym.n_desc = N_DESC_GCED;
56445646 }
56455647 }
5646
5647 if (orig_prev) |prev| {
5648 atom = prev;
5649 } else break;
56505648 }
56515649 }
56525650
5651 for (self.got_entries.items) |entry| {
5652 const sym = entry.getSymbol(self);
5653 if (sym.n_desc != N_DESC_GCED) continue;
5654
5655 // TODO tombstone
5656 const atom = entry.getAtom(self);
5657 const match = self.getMatchingSectionFromOrdinal(sym.n_sect);
5658 self.removeAtomFromSection(atom, match);
5659 _ = try gc_sections.put(match, {});
5660 _ = self.got_entries_table.remove(entry.target);
5661 }
5662
5663 for (self.stubs.items) |entry| {
5664 const sym = entry.getSymbol(self);
5665 if (sym.n_desc != N_DESC_GCED) continue;
5666
5667 // TODO tombstone
5668 const atom = entry.getAtom(self);
5669 const match = self.getMatchingSectionFromOrdinal(sym.n_sect);
5670 self.removeAtomFromSection(atom, match);
5671 _ = try gc_sections.put(match, {});
5672 _ = self.stubs_table.remove(entry.target);
5673 }
5674
5675 for (self.tlv_ptr_entries.items) |entry| {
5676 const sym = entry.getSymbol(self);
5677 if (sym.n_desc != N_DESC_GCED) continue;
5678
5679 // TODO tombstone
5680 const atom = entry.getAtom(self);
5681 const match = self.getMatchingSectionFromOrdinal(sym.n_sect);
5682 self.removeAtomFromSection(atom, match);
5683 _ = try gc_sections.put(match, {});
5684 _ = self.tlv_ptr_entries_table.remove(entry.target);
5685 }
5686
56535687 var gc_sections_it = gc_sections.iterator();
56545688 while (gc_sections_it.next()) |entry| {
56555689 const match = entry.key_ptr.*;
......@@ -5679,6 +5713,30 @@ fn gcAtoms(self: *MachO, gc_roots: *std.AutoHashMap(*Atom, void)) !void {
56795713 }
56805714}
56815715
5716fn removeAtomFromSection(self: *MachO, atom: *Atom, match: MatchingSection) void {
5717 const sect = self.getSectionPtr(match);
5718
5719 // If we want to enable GC for incremental codepath, we need to take into
5720 // account any padding that might have been left here.
5721 sect.size -= atom.size;
5722
5723 if (atom.prev) |prev| {
5724 prev.next = atom.next;
5725 }
5726 if (atom.next) |next| {
5727 next.prev = atom.prev;
5728 } else {
5729 const last = self.atoms.getPtr(match).?;
5730 if (atom.prev) |prev| {
5731 last.* = prev;
5732 } else {
5733 // The section will be GCed in the next step.
5734 last.* = undefined;
5735 sect.size = 0;
5736 }
5737 }
5738}
5739
56825740fn updateSectionOrdinals(self: *MachO) !void {
56835741 if (!self.sections_order_dirty) return;
56845742
......@@ -5849,7 +5907,7 @@ fn writeDyldInfoData(self: *MachO) !void {
58495907
58505908 if (self.base.options.output_mode == .Exe) {
58515909 for (&[_]SymbolWithLoc{
5852 self.getEntryPoint().?, // We would already errored out if no entrypoint was found.
5910 try self.getEntryPoint(),
58535911 self.globals.get("__mh_execute_header").?,
58545912 }) |global| {
58555913 const sym = self.getSymbol(global);
......@@ -6337,10 +6395,13 @@ fn writeSymtab(self: *MachO) !void {
63376395 .sect = stubs_section_index,
63386396 });
63396397 stubs.reserved1 = 0;
6340 for (self.stubs_table.keys()) |target| {
6341 const sym = self.getSymbol(target);
6342 assert(sym.undf());
6343 try writer.writeIntLittle(u32, dysymtab.iundefsym + imports_table.get(target).?);
6398 for (self.stubs.items) |entry| {
6399 if (entry.sym_index == 0) continue;
6400 const atom_sym = entry.getSymbol(self);
6401 if (atom_sym.n_desc == N_DESC_GCED) continue;
6402 const target_sym = self.getSymbol(entry.target);
6403 assert(target_sym.undf());
6404 try writer.writeIntLittle(u32, dysymtab.iundefsym + imports_table.get(entry.target).?);
63446405 }
63456406 }
63466407
......@@ -6351,10 +6412,13 @@ fn writeSymtab(self: *MachO) !void {
63516412 .sect = got_section_index,
63526413 });
63536414 got.reserved1 = nstubs;
6354 for (self.got_entries_table.keys()) |target| {
6355 const sym = self.getSymbol(target);
6356 if (sym.undf()) {
6357 try writer.writeIntLittle(u32, dysymtab.iundefsym + imports_table.get(target).?);
6415 for (self.got_entries.items) |entry| {
6416 if (entry.sym_index == 0) continue;
6417 const atom_sym = entry.getSymbol(self);
6418 if (atom_sym.n_desc == N_DESC_GCED) continue;
6419 const target_sym = self.getSymbol(entry.target);
6420 if (target_sym.undf()) {
6421 try writer.writeIntLittle(u32, dysymtab.iundefsym + imports_table.get(entry.target).?);
63586422 } else {
63596423 try writer.writeIntLittle(u32, macho.INDIRECT_SYMBOL_LOCAL);
63606424 }
......@@ -6368,10 +6432,13 @@ fn writeSymtab(self: *MachO) !void {
63686432 .sect = la_symbol_ptr_section_index,
63696433 });
63706434 la_symbol_ptr.reserved1 = nstubs + ngot_entries;
6371 for (self.stubs_table.keys()) |target| {
6372 const sym = self.getSymbol(target);
6373 assert(sym.undf());
6374 try writer.writeIntLittle(u32, dysymtab.iundefsym + imports_table.get(target).?);
6435 for (self.stubs.items) |entry| {
6436 if (entry.sym_index == 0) continue;
6437 const atom_sym = entry.getSymbol(self);
6438 if (atom_sym.n_desc == N_DESC_GCED) continue;
6439 const target_sym = self.getSymbol(entry.target);
6440 assert(target_sym.undf());
6441 try writer.writeIntLittle(u32, dysymtab.iundefsym + imports_table.get(entry.target).?);
63756442 }
63766443 }
63776444
......@@ -6623,7 +6690,7 @@ pub fn getSymbolName(self: *MachO, sym_with_loc: SymbolWithLoc) []const u8 {
66236690pub fn getAtomForSymbol(self: *MachO, sym_with_loc: SymbolWithLoc) ?*Atom {
66246691 if (sym_with_loc.file) |file| {
66256692 const object = self.objects.items[file];
6626 return object.atom_by_index_table.get(sym_with_loc.sym_index);
6693 return object.getAtomForSymbol(sym_with_loc.sym_index);
66276694 } else {
66286695 return self.atom_by_index_table.get(sym_with_loc.sym_index);
66296696 }
......@@ -6633,28 +6700,32 @@ pub fn getAtomForSymbol(self: *MachO, sym_with_loc: SymbolWithLoc) ?*Atom {
66336700/// Returns null otherwise.
66346701pub fn getGotAtomForSymbol(self: *MachO, sym_with_loc: SymbolWithLoc) ?*Atom {
66356702 const got_index = self.got_entries_table.get(sym_with_loc) orelse return null;
6636 return self.got_entries.items[got_index].atom;
6703 return self.got_entries.items[got_index].getAtom(self);
66376704}
66386705
66396706/// Returns stubs atom that references `sym_with_loc` if one exists.
66406707/// Returns null otherwise.
66416708pub fn getStubsAtomForSymbol(self: *MachO, sym_with_loc: SymbolWithLoc) ?*Atom {
66426709 const stubs_index = self.stubs_table.get(sym_with_loc) orelse return null;
6643 return self.stubs.items[stubs_index].atom;
6710 return self.stubs.items[stubs_index].getAtom(self);
66446711}
66456712
66466713/// Returns TLV pointer atom that references `sym_with_loc` if one exists.
66476714/// Returns null otherwise.
66486715pub fn getTlvPtrAtomForSymbol(self: *MachO, sym_with_loc: SymbolWithLoc) ?*Atom {
66496716 const tlv_ptr_index = self.tlv_ptr_entries_table.get(sym_with_loc) orelse return null;
6650 return self.tlv_ptr_entries.items[tlv_ptr_index].atom;
6717 return self.tlv_ptr_entries.items[tlv_ptr_index].getAtom(self);
66516718}
66526719
66536720/// Returns symbol location corresponding to the set entrypoint.
66546721/// Asserts output mode is executable.
6655pub fn getEntryPoint(self: MachO) ?SymbolWithLoc {
6722pub fn getEntryPoint(self: MachO) error{MissingMainEntrypoint}!SymbolWithLoc {
66566723 const entry_name = self.base.options.entry orelse "_main";
6657 return self.globals.get(entry_name);
6724 const global = self.globals.get(entry_name) orelse {
6725 log.err("entrypoint '{s}' not found", .{entry_name});
6726 return error.MissingMainEntrypoint;
6727 };
6728 return global;
66586729}
66596730
66606731pub fn findFirst(comptime T: type, haystack: []const T, start: usize, predicate: anytype) usize {
......@@ -6986,7 +7057,7 @@ fn snapshotState(self: *MachO) !void {
69867057 break :blk source_sym.n_value + rel.offset;
69877058 };
69887059 const target_addr = blk: {
6989 const target_atom = (try rel.getTargetAtom(self)) orelse {
7060 const target_atom = rel.getTargetAtom(self) orelse {
69907061 // If there is no atom for target, we still need to check for special, atom-less
69917062 // symbols such as `___dso_handle`.
69927063 const target_name = self.getSymbolName(rel.target);
......@@ -7119,8 +7190,9 @@ fn snapshotState(self: *MachO) !void {
71197190 try writer.writeByte(']');
71207191}
71217192
7122pub fn logSymAttributes(sym: macho.nlist_64, buf: *[4]u8) []const u8 {
7123 mem.set(u8, buf, '_');
7193fn logSymAttributes(sym: macho.nlist_64, buf: *[9]u8) []const u8 {
7194 mem.set(u8, buf[0..4], '_');
7195 mem.set(u8, buf[4..], ' ');
71247196 if (sym.sect()) {
71257197 buf[0] = 's';
71267198 }
......@@ -7137,11 +7209,14 @@ pub fn logSymAttributes(sym: macho.nlist_64, buf: *[4]u8) []const u8 {
71377209 if (sym.undf()) {
71387210 buf[3] = 'u';
71397211 }
7212 if (sym.n_desc == N_DESC_GCED) {
7213 mem.copy(u8, buf[5..], "DEAD");
7214 }
71407215 return buf[0..];
71417216}
71427217
71437218fn logSymtab(self: *MachO) void {
7144 var buf: [4]u8 = undefined;
7219 var buf: [9]u8 = undefined;
71457220
71467221 log.debug("symtab:", .{});
71477222 for (self.objects.items) |object, id| {
......@@ -7186,42 +7261,50 @@ fn logSymtab(self: *MachO) void {
71867261 }
71877262
71887263 log.debug("GOT entries:", .{});
7189 for (self.got_entries_table.values()) |value| {
7190 const target = self.got_entries.items[value].target;
7191 const target_sym = self.getSymbol(target);
7192 const atom = self.got_entries.items[value].atom;
7193 const atom_sym = atom.getSymbol(self);
7194
7264 for (self.got_entries.items) |entry, i| {
7265 const atom_sym = entry.getSymbol(self);
7266 if (atom_sym.n_desc == N_DESC_GCED) continue;
7267 const target_sym = self.getSymbol(entry.target);
71957268 if (target_sym.undf()) {
7196 log.debug(" {d}@{x} => import('{s}')", .{ value, atom_sym.n_value, self.getSymbolName(target) });
7269 log.debug(" {d}@{x} => import('{s}')", .{
7270 i,
7271 atom_sym.n_value,
7272 self.getSymbolName(entry.target),
7273 });
71977274 } else {
7198 log.debug(" {d}@{x} => local(%{d}) in object({d})", .{
7199 value,
7275 log.debug(" {d}@{x} => local(%{d}) in object({d}) {s}", .{
7276 i,
72007277 atom_sym.n_value,
7201 target.sym_index,
7202 target.file,
7278 entry.target.sym_index,
7279 entry.target.file,
7280 logSymAttributes(target_sym, &buf),
72037281 });
72047282 }
72057283 }
72067284
72077285 log.debug("__thread_ptrs entries:", .{});
7208 for (self.tlv_ptr_entries_table.values()) |value| {
7209 const target = self.tlv_ptr_entries.items[value].target;
7210 const target_sym = self.getSymbol(target);
7211 const atom = self.tlv_ptr_entries.items[value].atom;
7212 const atom_sym = atom.getSymbol(self);
7286 for (self.tlv_ptr_entries.items) |entry, i| {
7287 const atom_sym = entry.getSymbol(self);
7288 if (atom_sym.n_desc == N_DESC_GCED) continue;
7289 const target_sym = self.getSymbol(entry.target);
72137290 assert(target_sym.undf());
7214 log.debug(" {d}@{x} => import('{s}')", .{ value, atom_sym.n_value, self.getSymbolName(target) });
7291 log.debug(" {d}@{x} => import('{s}')", .{
7292 i,
7293 atom_sym.n_value,
7294 self.getSymbolName(entry.target),
7295 });
72157296 }
72167297
72177298 log.debug("stubs entries:", .{});
7218 for (self.stubs_table.values()) |value| {
7219 const target = self.stubs.items[value].target;
7220 const target_sym = self.getSymbol(target);
7221 const atom = self.stubs.items[value].atom;
7222 const atom_sym = atom.getSymbol(self);
7299 for (self.stubs.items) |entry, i| {
7300 const target_sym = self.getSymbol(entry.target);
7301 const atom_sym = entry.getSymbol(self);
72237302 assert(target_sym.undf());
7224 log.debug(" {d}@{x} => import('{s}')", .{ value, atom_sym.n_value, self.getSymbolName(target) });
7303 log.debug(" {d}@{x} => import('{s}')", .{
7304 i,
7305 atom_sym.n_value,
7306 self.getSymbolName(entry.target),
7307 });
72257308 }
72267309}
72277310
......@@ -7248,7 +7331,6 @@ fn logAtoms(self: *MachO) void {
72487331
72497332 while (true) {
72507333 self.logAtom(atom);
7251
72527334 if (atom.next) |next| {
72537335 atom = next;
72547336 } else break;
......@@ -7256,14 +7338,17 @@ fn logAtoms(self: *MachO) void {
72567338 }
72577339}
72587340
7259pub fn logAtom(self: *MachO, atom: *const Atom) void {
7341fn logAtom(self: *MachO, atom: *const Atom) void {
72607342 const sym = atom.getSymbol(self);
72617343 const sym_name = atom.getName(self);
7262 log.debug(" ATOM(%{d}, '{s}') @ {x} in object({d})", .{
7344 log.debug(" ATOM(%{d}, '{s}') @ {x} (sizeof({x}), alignof({x})) in object({d}) in sect({d})", .{
72637345 atom.sym_index,
72647346 sym_name,
72657347 sym.n_value,
7348 atom.size,
7349 atom.alignment,
72667350 atom.file,
7351 sym.n_sect,
72677352 });
72687353
72697354 for (atom.contained.items) |sym_off| {
......@@ -7271,13 +7356,15 @@ pub fn logAtom(self: *MachO, atom: *const Atom) void {
72717356 .sym_index = sym_off.sym_index,
72727357 .file = atom.file,
72737358 });
7274 const inner_sym_name = self.getSymbolName(.{ .sym_index = sym_off.sym_index, .file = atom.file });
7275 log.debug(" (%{d}, '{s}') @ {x} ({x}) in object({d})", .{
7359 const inner_sym_name = self.getSymbolName(.{
7360 .sym_index = sym_off.sym_index,
7361 .file = atom.file,
7362 });
7363 log.debug(" (%{d}, '{s}') @ {x} ({x})", .{
72767364 sym_off.sym_index,
72777365 inner_sym_name,
72787366 inner_sym.n_value,
72797367 sym_off.offset,
7280 atom.file,
72817368 });
72827369 }
72837370}
src/link/MachO/Atom.zig+23-19
......@@ -94,7 +94,7 @@ pub const Relocation = struct {
9494
9595 @"type": u4,
9696
97 pub fn getTargetAtom(self: Relocation, macho_file: *MachO) !?*Atom {
97 pub fn getTargetAtom(self: Relocation, macho_file: *MachO) ?*Atom {
9898 const is_via_got = got: {
9999 switch (macho_file.base.options.target.cpu.arch) {
100100 .aarch64 => break :got switch (@intToEnum(macho.reloc_type_arm64, self.@"type")) {
......@@ -112,21 +112,9 @@ pub const Relocation = struct {
112112 }
113113 };
114114
115 const target_sym = macho_file.getSymbol(self.target);
116115 if (is_via_got) {
117 const got_atom = macho_file.getGotAtomForSymbol(self.target) orelse {
118 log.err("expected GOT entry for symbol", .{});
119 if (target_sym.undf()) {
120 log.err(" import('{s}')", .{macho_file.getSymbolName(self.target)});
121 } else {
122 log.err(" local(%{d}) in object({d})", .{ self.target.sym_index, self.target.file });
123 }
124 log.err(" this is an internal linker error", .{});
125 return error.FailedToResolveRelocationTarget;
126 };
127 return got_atom;
116 return macho_file.getGotAtomForSymbol(self.target).?; // panic means fatal error
128117 }
129
130118 if (macho_file.getStubsAtomForSymbol(self.target)) |stubs_atom| return stubs_atom;
131119 if (macho_file.getTlvPtrAtomForSymbol(self.target)) |tlv_ptr_atom| return tlv_ptr_atom;
132120 return macho_file.getAtomForSymbol(self.target);
......@@ -174,6 +162,10 @@ pub fn getSymbolPtr(self: Atom, macho_file: *MachO) *macho.nlist_64 {
174162 });
175163}
176164
165pub fn getSymbolWithLoc(self: Atom) SymbolWithLoc {
166 return .{ .sym_index = self.sym_index, .file = self.file };
167}
168
177169/// Returns true if the symbol pointed at with `sym_loc` is contained within this atom.
178170/// WARNING this function assumes all atoms have been allocated in the virtual memory.
179171/// Calling it without allocating with `MachO.allocateSymbols` (or equivalent) will
......@@ -515,7 +507,7 @@ fn addTlvPtrEntry(target: MachO.SymbolWithLoc, context: RelocContext) !void {
515507
516508 const index = try context.macho_file.allocateTlvPtrEntry(target);
517509 const atom = try context.macho_file.createTlvPtrAtom(target);
518 context.macho_file.tlv_ptr_entries.items[index].atom = atom;
510 context.macho_file.tlv_ptr_entries.items[index].sym_index = atom.sym_index;
519511}
520512
521513fn addGotEntry(target: MachO.SymbolWithLoc, context: RelocContext) !void {
......@@ -523,7 +515,7 @@ fn addGotEntry(target: MachO.SymbolWithLoc, context: RelocContext) !void {
523515
524516 const index = try context.macho_file.allocateGotEntry(target);
525517 const atom = try context.macho_file.createGotAtom(target);
526 context.macho_file.got_entries.items[index].atom = atom;
518 context.macho_file.got_entries.items[index].sym_index = atom.sym_index;
527519}
528520
529521fn addStub(target: MachO.SymbolWithLoc, context: RelocContext) !void {
......@@ -536,7 +528,7 @@ fn addStub(target: MachO.SymbolWithLoc, context: RelocContext) !void {
536528 const laptr_atom = try context.macho_file.createLazyPointerAtom(stub_helper_atom.sym_index, target);
537529 const stub_atom = try context.macho_file.createStubAtom(laptr_atom.sym_index);
538530
539 context.macho_file.stubs.items[stub_index].atom = stub_atom;
531 context.macho_file.stubs.items[stub_index].sym_index = stub_atom.sym_index;
540532}
541533
542534pub fn resolveRelocs(self: *Atom, macho_file: *MachO) !void {
......@@ -578,7 +570,7 @@ pub fn resolveRelocs(self: *Atom, macho_file: *MachO) !void {
578570 break :is_tlv sect.type_() == macho.S_THREAD_LOCAL_VARIABLES;
579571 };
580572 const target_addr = blk: {
581 const target_atom = (try rel.getTargetAtom(macho_file)) orelse {
573 const target_atom = rel.getTargetAtom(macho_file) orelse {
582574 // If there is no atom for target, we still need to check for special, atom-less
583575 // symbols such as `___dso_handle`.
584576 const target_name = macho_file.getSymbolName(rel.target);
......@@ -597,6 +589,7 @@ pub fn resolveRelocs(self: *Atom, macho_file: *MachO) !void {
597589 macho_file.getSymbol(rel.target)
598590 else
599591 target_atom.getSymbol(macho_file);
592 assert(target_sym.n_desc != MachO.N_DESC_GCED);
600593 const base_address: u64 = if (is_tlv) base_address: {
601594 // For TLV relocations, the value specified as a relocation is the displacement from the
602595 // TLV initializer (either value in __thread_data or zero-init in __thread_bss) to the first
......@@ -624,12 +617,12 @@ pub fn resolveRelocs(self: *Atom, macho_file: *MachO) !void {
624617 };
625618
626619 log.debug(" | source_addr = 0x{x}", .{source_addr});
627 log.debug(" | target_addr = 0x{x}", .{target_addr});
628620
629621 switch (arch) {
630622 .aarch64 => {
631623 switch (@intToEnum(macho.reloc_type_arm64, rel.@"type")) {
632624 .ARM64_RELOC_BRANCH26 => {
625 log.debug(" | target_addr = 0x{x}", .{target_addr});
633626 const displacement = math.cast(
634627 i28,
635628 @intCast(i64, target_addr) - @intCast(i64, source_addr),
......@@ -658,6 +651,7 @@ pub fn resolveRelocs(self: *Atom, macho_file: *MachO) !void {
658651 .ARM64_RELOC_TLVP_LOAD_PAGE21,
659652 => {
660653 const actual_target_addr = @intCast(i64, target_addr) + rel.addend;
654 log.debug(" | target_addr = 0x{x}", .{actual_target_addr});
661655 const source_page = @intCast(i32, source_addr >> 12);
662656 const target_page = @intCast(i32, actual_target_addr >> 12);
663657 const pages = @bitCast(u21, @intCast(i21, target_page - source_page));
......@@ -675,6 +669,7 @@ pub fn resolveRelocs(self: *Atom, macho_file: *MachO) !void {
675669 .ARM64_RELOC_PAGEOFF12 => {
676670 const code = self.code.items[rel.offset..][0..4];
677671 const actual_target_addr = @intCast(i64, target_addr) + rel.addend;
672 log.debug(" | target_addr = 0x{x}", .{actual_target_addr});
678673 const narrowed = @truncate(u12, @intCast(u64, actual_target_addr));
679674 if (isArithmeticOp(self.code.items[rel.offset..][0..4])) {
680675 var inst = aarch64.Instruction{
......@@ -712,6 +707,7 @@ pub fn resolveRelocs(self: *Atom, macho_file: *MachO) !void {
712707 .ARM64_RELOC_GOT_LOAD_PAGEOFF12 => {
713708 const code = self.code.items[rel.offset..][0..4];
714709 const actual_target_addr = @intCast(i64, target_addr) + rel.addend;
710 log.debug(" | target_addr = 0x{x}", .{actual_target_addr});
715711 const narrowed = @truncate(u12, @intCast(u64, actual_target_addr));
716712 var inst: aarch64.Instruction = .{
717713 .load_store_register = mem.bytesToValue(meta.TagPayload(
......@@ -726,6 +722,7 @@ pub fn resolveRelocs(self: *Atom, macho_file: *MachO) !void {
726722 .ARM64_RELOC_TLVP_LOAD_PAGEOFF12 => {
727723 const code = self.code.items[rel.offset..][0..4];
728724 const actual_target_addr = @intCast(i64, target_addr) + rel.addend;
725 log.debug(" | target_addr = 0x{x}", .{actual_target_addr});
729726
730727 const RegInfo = struct {
731728 rd: u5,
......@@ -783,6 +780,7 @@ pub fn resolveRelocs(self: *Atom, macho_file: *MachO) !void {
783780 mem.writeIntLittle(u32, code, inst.toU32());
784781 },
785782 .ARM64_RELOC_POINTER_TO_GOT => {
783 log.debug(" | target_addr = 0x{x}", .{target_addr});
786784 const result = math.cast(i32, @intCast(i64, target_addr) - @intCast(i64, source_addr)) orelse return error.Overflow;
787785 mem.writeIntLittle(u32, self.code.items[rel.offset..][0..4], @bitCast(u32, result));
788786 },
......@@ -795,6 +793,7 @@ pub fn resolveRelocs(self: *Atom, macho_file: *MachO) !void {
795793 break :blk @intCast(i64, target_addr) + rel.addend;
796794 }
797795 };
796 log.debug(" | target_addr = 0x{x}", .{result});
798797
799798 if (rel.length == 3) {
800799 mem.writeIntLittle(u64, self.code.items[rel.offset..][0..8], @bitCast(u64, result));
......@@ -813,6 +812,7 @@ pub fn resolveRelocs(self: *Atom, macho_file: *MachO) !void {
813812 .x86_64 => {
814813 switch (@intToEnum(macho.reloc_type_x86_64, rel.@"type")) {
815814 .X86_64_RELOC_BRANCH => {
815 log.debug(" | target_addr = 0x{x}", .{target_addr});
816816 const displacement = math.cast(
817817 i32,
818818 @intCast(i64, target_addr) - @intCast(i64, source_addr) - 4 + rel.addend,
......@@ -820,6 +820,7 @@ pub fn resolveRelocs(self: *Atom, macho_file: *MachO) !void {
820820 mem.writeIntLittle(u32, self.code.items[rel.offset..][0..4], @bitCast(u32, displacement));
821821 },
822822 .X86_64_RELOC_GOT, .X86_64_RELOC_GOT_LOAD => {
823 log.debug(" | target_addr = 0x{x}", .{target_addr});
823824 const displacement = math.cast(
824825 i32,
825826 @intCast(i64, target_addr) - @intCast(i64, source_addr) - 4 + rel.addend,
......@@ -827,6 +828,7 @@ pub fn resolveRelocs(self: *Atom, macho_file: *MachO) !void {
827828 mem.writeIntLittle(u32, self.code.items[rel.offset..][0..4], @bitCast(u32, displacement));
828829 },
829830 .X86_64_RELOC_TLV => {
831 log.debug(" | target_addr = 0x{x}", .{target_addr});
830832 if (!macho_file.tlv_ptr_entries_table.contains(rel.target)) {
831833 // We need to rewrite the opcode from movq to leaq.
832834 self.code.items[rel.offset - 2] = 0x8d;
......@@ -850,6 +852,7 @@ pub fn resolveRelocs(self: *Atom, macho_file: *MachO) !void {
850852 else => unreachable,
851853 };
852854 const actual_target_addr = @intCast(i64, target_addr) + rel.addend;
855 log.debug(" | target_addr = 0x{x}", .{actual_target_addr});
853856 const displacement = math.cast(
854857 i32,
855858 actual_target_addr - @intCast(i64, source_addr + correction + 4),
......@@ -865,6 +868,7 @@ pub fn resolveRelocs(self: *Atom, macho_file: *MachO) !void {
865868 break :blk @intCast(i64, target_addr) + rel.addend;
866869 }
867870 };
871 log.debug(" | target_addr = 0x{x}", .{result});
868872
869873 if (rel.length == 3) {
870874 mem.writeIntLittle(u64, self.code.items[rel.offset..][0..8], @bitCast(u64, result));
src/link/MachO/DebugSymbols.zig+12-6
......@@ -275,9 +275,12 @@ pub fn flushModule(self: *DebugSymbols, allocator: Allocator, options: link.Opti
275275 const sym = switch (reloc.@"type") {
276276 .direct_load => self.base.getSymbol(.{ .sym_index = reloc.target, .file = null }),
277277 .got_load => blk: {
278 const got_index = self.base.got_entries_table.get(.{ .sym_index = reloc.target, .file = null }).?;
279 const got_atom = self.base.got_entries.items[got_index].atom;
280 break :blk got_atom.getSymbol(self.base);
278 const got_index = self.base.got_entries_table.get(.{
279 .sym_index = reloc.target,
280 .file = null,
281 }).?;
282 const got_entry = self.base.got_entries.items[got_index];
283 break :blk got_entry.getSymbol(self.base);
281284 },
282285 };
283286 if (sym.n_value == reloc.prev_vaddr) continue;
......@@ -285,9 +288,12 @@ pub fn flushModule(self: *DebugSymbols, allocator: Allocator, options: link.Opti
285288 const sym_name = switch (reloc.@"type") {
286289 .direct_load => self.base.getSymbolName(.{ .sym_index = reloc.target, .file = null }),
287290 .got_load => blk: {
288 const got_index = self.base.got_entries_table.get(.{ .sym_index = reloc.target, .file = null }).?;
289 const got_atom = self.base.got_entries.items[got_index].atom;
290 break :blk got_atom.getName(self.base);
291 const got_index = self.base.got_entries_table.get(.{
292 .sym_index = reloc.target,
293 .file = null,
294 }).?;
295 const got_entry = self.base.got_entries.items[got_index];
296 break :blk got_entry.getName(self.base);
291297 },
292298 };
293299 const seg = &self.load_commands.items[self.dwarf_segment_cmd_index.?].segment;
src/link/MachO/Object.zig+7-7
......@@ -410,7 +410,9 @@ pub fn splitIntoAtomsOneShot(
410410 next_sym_count += atom_syms.len;
411411
412412 assert(atom_syms.len > 0);
413 const sym_index = atom_syms[0].index;
413 const sym_index = for (atom_syms) |atom_sym| {
414 if (atom_sym.getSymbol(context).ext()) break atom_sym.index;
415 } else atom_syms[0].index;
414416 const atom_size = blk: {
415417 const end_addr = if (next_sym_count < filtered_syms.len)
416418 filtered_syms[next_sym_count].getSymbol(context).n_value
......@@ -570,12 +572,6 @@ fn createAtomFromSubsection(
570572 if (gc_roots) |gcr| {
571573 const is_gc_root = blk: {
572574 if (sect.isDontDeadStrip()) break :blk true;
573 if (sect.isDontDeadStripIfReferencesLive()) {
574 // TODO if isDontDeadStripIfReferencesLive we should analyse the edges
575 // before making it a GC root
576 break :blk true;
577 }
578 if (mem.eql(u8, "__StaticInit", sect.sectName())) break :blk true;
579575 switch (sect.type_()) {
580576 macho.S_MOD_INIT_FUNC_POINTERS,
581577 macho.S_MOD_TERM_FUNC_POINTERS,
......@@ -641,3 +637,7 @@ pub fn getSection(self: Object, n_sect: u16) macho.section_64 {
641637 assert(n_sect < seg.sections.items.len);
642638 return seg.sections.items[n_sect];
643639}
640
641pub fn getAtomForSymbol(self: Object, sym_index: u32) ?*Atom {
642 return self.atom_by_index_table.get(sym_index);
643}