This is an archive of the discontinued LLVM Phabricator instance.

[MachO] Don't fold compact unwind entries with LSDA
ClosedPublic

Authored by smeenai on Aug 29 2022, 4:19 AM.

Details

Summary

Folding them will cause the unwinder to compute the incorrect function
start address for the folded entries, which in turn will cause the
personality function to interpret the LSDA incorrectly and break
exception handling.

You can verify the end-to-end flow by creating a simple C++ file:

void h();
int main() { h(); }

and then linking this file against the liblsda.dylib produced by the
test case added here. Before this change, running the resulting program
would result in a program termination with an uncaught exception.
Afterwards, it works correctly.

Diff Detail

Event Timeline

smeenai created this revision.Aug 29 2022, 4:19 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript
smeenai requested review of this revision.Aug 29 2022, 4:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2022, 4:19 AM

Some minor comments. Overall, LGTM, I'll leave it to people more familiar with the code to stamp.

lld/MachO/UnwindInfoSection.cpp
466

In what scenario would we have compact unwind entries without LSDA? I'm wondering if this is now effectively a condition that will never be hit and thus dead code now.

lld/test/MachO/compact-unwind-lsda-folding.s
2

Should we also have a test for when they can be folded?

ributzka resigned from this revision.Aug 29 2022, 9:55 AM
smeenai added inline comments.Aug 29 2022, 11:45 AM
lld/MachO/UnwindInfoSection.cpp
466

It's pretty common to have compact unwind entries without LSDA :) You only need LSDA when you have language-specific actions to take during unwinding, e.g. running destructors or a catch statement. In the test below, you'll notice that g and h have indices 0 and 1 in the LSDA descriptors but 1 and 2 in the second level indices; that's because f has the compact unwind entry at index 0 but no LSDA.

lld/test/MachO/compact-unwind-lsda-folding.s
2

compact-unwind-generated.test handles that via tools/validate-unwind-info.py.

thevinster accepted this revision.Aug 29 2022, 11:51 AM
This revision is now accepted and ready to land.Aug 29 2022, 11:51 AM
smeenai marked 2 inline comments as done.Aug 29 2022, 12:44 PM
This revision was automatically updated to reflect the committed changes.