This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Emit personalities in compact unwind
ClosedPublic

Authored by int3 on Feb 1 2021, 11:53 AM.

Details

Reviewers
clayborg
Group Reviewers
Restricted Project
Commits
rG525bfa10ec1d: [lld-macho] Emit personalities in compact unwind
Summary

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.

Diff Detail

Event Timeline

int3 requested review of this revision.Feb 1 2021, 11:53 AM
int3 created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2021, 11:53 AM
clayborg added inline comments.Feb 1 2021, 12:17 PM
lld/MachO/UnwindInfoSection.cpp
108

Is there an assert or check you can put into the code to verify this assumption?

201

We don't seem to modify the "cuEntry" in the loop below, can be put the "const" back and revert this change?

int3 added a subscriber: gkm.Feb 1 2021, 12:30 PM
int3 added inline comments.
lld/MachO/UnwindInfoSection.cpp
108

I suppose we could be conservative and assert that the relocations only point within the __TEXT segment...

Note that problem already exists in the current implementation (which @gkm wrote) -- it calls compactUnwindSection->writeTo() instead of relocateCompactUnwind(), but writeTo() makes the same assumptions. Not sure if @gkm has thoughts on this.

201

oops yeah leftover change

int3 marked 2 inline comments as done.Feb 1 2021, 2:16 PM
int3 added inline comments.
lld/MachO/UnwindInfoSection.cpp
201

o wait, this is actually necessary. That's because I am now modifying the CU entries that I get from iterating over cuPtrVector, so they cannot be const, and since this loop populates the cuPtrVector, the cuEntrys cannot be const here.

int3 updated this revision to Diff 320599.Feb 1 2021, 2:16 PM

check that compact unwind entries only reference __TEXT

clayborg accepted this revision.Feb 3 2021, 4:35 PM
This revision is now accepted and ready to land.Feb 3 2021, 4:35 PM
int3 updated this revision to Diff 321893.Feb 5 2021, 4:16 PM
  • insert personality pointers into GOT earlier, since they determine whether a GOT is needed
  • dedup personality pointers
  • Add test for invalid compact unwind that references non-text segments
int3 updated this revision to Diff 321965.Feb 6 2021, 2:01 PM

try and fix tests

int3 updated this revision to Diff 322129.Feb 8 2021, 8:54 AM

rebase

This revision was landed with ongoing or failed builds.Feb 8 2021, 10:48 AM
This revision was automatically updated to reflect the committed changes.
lld/MachO/UnwindInfoSection.cpp