authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-04-01 06:49:01+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-04-01 14:22:44+02:00
log2dd178443abcbd91a923c64a4fd066caef974a82
tree8d406f7e0d647a6a44189fd4004c846220fbde8f
parent5d0bb50e3d0e87d1d8aad864559e10c83199b608

macho: do not assume entrypoint is defined


1 files changed, 12 insertions(+), 8 deletions(-)

src/link/MachO/dead_strip.zig+12-8
......@@ -43,15 +43,19 @@ fn collectRoots(zld: *Zld, roots: *AtomTable) !void {
4343 .Exe => {
4444 // Add entrypoint as GC root
4545 const global: SymbolWithLoc = zld.getEntryPoint();
46 const object = zld.objects.items[global.getFile().?];
47 const atom_index = object.getAtomIndexForSymbol(global.sym_index).?; // panic here means fatal error
48 _ = try roots.getOrPut(atom_index);
46 if (global.getFile()) |file| {
47 const object = zld.objects.items[file];
48 const atom_index = object.getAtomIndexForSymbol(global.sym_index).?; // panic here means fatal error
49 _ = try roots.getOrPut(atom_index);
4950
50 log.debug("root(ATOM({d}, %{d}, {?d}))", .{
51 atom_index,
52 zld.getAtom(atom_index).sym_index,
53 zld.getAtom(atom_index).getFile(),
54 });
51 log.debug("root(ATOM({d}, %{d}, {?d}))", .{
52 atom_index,
53 zld.getAtom(atom_index).sym_index,
54 zld.getAtom(atom_index).getFile(),
55 });
56 } else {
57 assert(zld.getSymbol(global).undf()); // Stub as our entrypoint is in a dylib.
58 }
5559 },
5660 else => |other| {
5761 assert(other == .Lib);