[lld-macho] Support EH frames under arm64
authorJez Ng <jezng@fb.com>
Thu, 9 Jun 2022 03:41:29 +0000 (23:41 -0400)
committerJez Ng <jezng@fb.com>
Thu, 9 Jun 2022 03:41:29 +0000 (23:41 -0400)
commit977d62c33e3343a394777c1754682761eebb66cd
tree04541d2cc9cc102075c98bbf7dd62bfb99d94c73
parent826be330af9c0a8553a5b32718ecd2d97e10438e
[lld-macho] Support EH frames under arm64

For arm64, llvm-mc emits relocations for the target function
address like so:

  ltmp:
    <CIE start>
    ...
    <CIE end>
    ... multiple FDEs ...
    <FDE start>
    <target function address - (ltmp + pcrel offset)>
    ...

If any of the FDEs in `multiple FDEs` get dead-stripped, then `FDE start`
will move to an earlier address, and `ltmp + pcrel offset` will no longer
reflect an accurate pcrel value. To avoid this problem, we "canonicalize"
our relocation by adding an `EH_Frame` symbol at `FDE start`, and updating
the reloc to be `target function address - (EH_Frame + new pcrel offset)`.

Reviewed By: #lld-macho, Roger

Differential Revision: https://reviews.llvm.org/D124561
lld/MachO/InputFiles.cpp
lld/test/MachO/Inputs/eh-frame-arm64-r.o [new file with mode: 0644]
lld/test/MachO/eh-frame.s