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