diff --git a/macho/dead-strip.cc b/macho/dead-strip.cc index 41aa2afd..2f198b70 100644 --- a/macho/dead-strip.cc +++ b/macho/dead-strip.cc @@ -30,6 +30,15 @@ static void visit(Context &ctx, Subsection &subsec) { visit(ctx, *rel.subsec); } } + + for (UnwindRecord &rec : subsec.get_unwind_records()) { + rec.is_alive = true; + visit(ctx, *rec.subsec); + if (rec.lsda) + visit(ctx, *rec.lsda); + if (Symbol *sym = rec.personality; sym && sym->subsec) + visit(ctx, *sym->subsec); + } } static void mark(Context &ctx, std::span rootset) { diff --git a/macho/mold.h b/macho/mold.h index 7a5a10fa..0330fc00 100644 --- a/macho/mold.h +++ b/macho/mold.h @@ -49,6 +49,7 @@ struct UnwindRecord { Symbol *personality = nullptr; Subsection *lsda = nullptr; u32 lsda_offset = 0; + bool is_alive = false; }; class InputFile { diff --git a/macho/output-chunks.cc b/macho/output-chunks.cc index 5f9c1ea1..85a03643 100644 --- a/macho/output-chunks.cc +++ b/macho/output-chunks.cc @@ -1142,7 +1142,8 @@ static std::vector construct_unwind_info(Context &ctx) { if (chunk->is_regular) for (Subsection *subsec : ((OutputSection *)chunk)->members) for (UnwindRecord &rec : subsec->get_unwind_records()) - records.push_back(rec); + if (!ctx.arg.dead_strip || rec.is_alive) + records.push_back(rec); return UnwindEncoder().encode(ctx, records); }