[lld-macho] Emit personalities in compact unwind
authorJez Ng <jezng@fb.com>
Mon, 8 Feb 2021 18:47:33 +0000 (13:47 -0500)
committerJez Ng <jezng@fb.com>
Mon, 8 Feb 2021 18:47:59 +0000 (13:47 -0500)
commit525bfa10ec1d4e3dfa3932a299cd67ffe59a5827
treed28c620e02f4c6e58666a033bf1255e62a34779d
parenta719b667a9794ec0dc820d0c5a3fd18340521ad9
[lld-macho] Emit personalities in compact unwind

Note that there is a triple indirection involved with
personalities and compact unwind:

1. Two bits of each CU encoding are used as an offset into the
   personality array.
2. Each entry of the personality array is an offset from the image base.
   The resulting address (after adding the image base) should point within the
   GOT.
3. The corresponding GOT entry contains the actual pointer to the
   personality function.

To further complicate things, when the personality function is in the
object file (as opposed to a dylib), its references in
`__compact_unwind` may refer to it via a section + offset relocation
instead of a symbol relocation. Since our GOT implementation can only
create entries for symbols, we have to create a synthetic symbol at the
given section offset.

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D95809
lld/MachO/SyntheticSections.cpp
lld/MachO/UnwindInfoSection.cpp
lld/MachO/UnwindInfoSection.h
lld/MachO/Writer.cpp
lld/test/MachO/compact-unwind-generated.test [moved from lld/test/MachO/compact-unwind.test with 100% similarity]
lld/test/MachO/compact-unwind-pie.s [deleted file]
lld/test/MachO/compact-unwind.s [new file with mode: 0644]
lld/test/MachO/invalid/compact-unwind-bad-reloc.s [new file with mode: 0644]
lld/test/MachO/invalid/compact-unwind-personalities.s [new file with mode: 0644]
lld/test/MachO/tools/validate-unwind-info.py