[JITLink] Refactor EH-frame handling to support eh-frames with existing relocs.
authorLang Hames <lhames@gmail.com>
Tue, 5 Nov 2019 00:00:09 +0000 (16:00 -0800)
committerLang Hames <lhames@gmail.com>
Wed, 6 Nov 2019 22:30:26 +0000 (14:30 -0800)
commit76aee8a389447409905c58b178b0554c9bae8a0a
tree2959df9ba579588dffcab56a8bd2fb37fca4b79c
parent8243918f43c6eedc2b018c1edc9c6b72fe9b3c1e
[JITLink] Refactor EH-frame handling to support eh-frames with existing relocs.

Some targets (E.g. MachO/arm64) use relocations to fix some CFI record fields
in the eh-frame section. When relocations are used the initial (pre-relocation)
content of the eh-frame section can no longer be interpreted by following the
eh-frame specification. This causes errors in the existing eh-frame parser.

This patch moves eh-frame handling into two LinkGraph passes that are run after
relocations have been parsed (but before they are applied). The first] pass
breaks up blocks in the eh-frame section into per-CFI-record blocks, and the
second parses blocks of (potentially multiple) CFI records and adds the
appropriate edges to any CFI fields that do not have existing relocations.
These passes can be run independently of one another. By handling eh-frame
splitting/fixing with LinkGraph passes we can both re-use existing relocations
for CFI record fields and avoid applying eh-frame fixups before parsing the
section (which would complicate the linker and require extra temporary
allocations of working memory).
llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
llvm/lib/ExecutionEngine/JITLink/EHFrameSupportImpl.h
llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp
llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h
llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp
llvm/test/ExecutionEngine/JITLink/AArch64/Inputs/MachO_arm64_ehframe.o [new file with mode: 0644]
llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_ehframe.test [new file with mode: 0644]