[MachO] Don't fold compact unwind entries with LSDA
authorShoaib Meenai <smeenai@fb.com>
Sun, 28 Aug 2022 20:09:56 +0000 (01:09 +0500)
committerTobias Hieta <tobias@hieta.se>
Wed, 14 Sep 2022 06:14:57 +0000 (08:14 +0200)
commit6fe69891d15c69e2832e8158987f9d6179ce43bf
tree00d02c76c9bbf8f866c050ec1cb63cc11990324b
parenta5ae700c67ec3d814249b1edfb40e6ca39b94eac
[MachO] Don't fold compact unwind entries with LSDA

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.

Reviewed By: #lld-macho, thevinster

Differential Revision: https://reviews.llvm.org/D132845

(cherry picked from commit 56bd3185cdd8d79731acd6c75bf41869284a12ed)
lld/MachO/UnwindInfoSection.cpp
lld/test/MachO/compact-unwind-lsda-folding.s [new file with mode: 0644]