aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-04-01 06:49:01 +0200
committerJakub Konka <kubkon@jakubkonka.com>2023-04-01 14:22:44 +0200
commit2dd178443abcbd91a923c64a4fd066caef974a82 (patch)
tree8d406f7e0d647a6a44189fd4004c846220fbde8f /src
parent5d0bb50e3d0e87d1d8aad864559e10c83199b608 (diff)
downloadzig-2dd178443abcbd91a923c64a4fd066caef974a82.tar.gz
zig-2dd178443abcbd91a923c64a4fd066caef974a82.zip
macho: do not assume entrypoint is defined
Diffstat (limited to 'src')
-rw-r--r--src/link/MachO/dead_strip.zig20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/link/MachO/dead_strip.zig b/src/link/MachO/dead_strip.zig
index cd64e72170..66c644ec04 100644
--- a/src/link/MachO/dead_strip.zig
+++ b/src/link/MachO/dead_strip.zig
@@ -43,15 +43,19 @@ fn collectRoots(zld: *Zld, roots: *AtomTable) !void {
.Exe => {
// Add entrypoint as GC root
const global: SymbolWithLoc = zld.getEntryPoint();
- const object = zld.objects.items[global.getFile().?];
- const atom_index = object.getAtomIndexForSymbol(global.sym_index).?; // panic here means fatal error
- _ = try roots.getOrPut(atom_index);
+ if (global.getFile()) |file| {
+ const object = zld.objects.items[file];
+ const atom_index = object.getAtomIndexForSymbol(global.sym_index).?; // panic here means fatal error
+ _ = try roots.getOrPut(atom_index);
- log.debug("root(ATOM({d}, %{d}, {?d}))", .{
- atom_index,
- zld.getAtom(atom_index).sym_index,
- zld.getAtom(atom_index).getFile(),
- });
+ log.debug("root(ATOM({d}, %{d}, {?d}))", .{
+ atom_index,
+ zld.getAtom(atom_index).sym_index,
+ zld.getAtom(atom_index).getFile(),
+ });
+ } else {
+ assert(zld.getSymbol(global).undf()); // Stub as our entrypoint is in a dylib.
+ }
},
else => |other| {
assert(other == .Lib);