macho: ensure we only ever put named symbols in the symtab

This commit is contained in:
Jakub Konka 2024-08-10 17:19:37 +02:00
parent 3f2a0c3de4
commit 421b105d85

View File

@ -550,6 +550,8 @@ pub fn calcSymtabSize(self: *ZigObject, macho_file: *MachO) void {
const file = ref.getFile(macho_file) orelse continue;
if (file.getIndex() != self.index) continue;
if (sym.getAtom(macho_file)) |atom| if (!atom.isAlive()) continue;
const name = sym.getName(macho_file);
assert(name.len > 0);
sym.flags.output_symtab = true;
if (sym.isLocal()) {
sym.addExtra(.{ .symtab = self.output_symtab_ctx.nlocals }, macho_file);
@ -562,7 +564,7 @@ pub fn calcSymtabSize(self: *ZigObject, macho_file: *MachO) void {
sym.addExtra(.{ .symtab = self.output_symtab_ctx.nimports }, macho_file);
self.output_symtab_ctx.nimports += 1;
}
self.output_symtab_ctx.strsize += @as(u32, @intCast(sym.getName(macho_file).len + 1));
self.output_symtab_ctx.strsize += @as(u32, @intCast(name.len + 1));
}
}