Skip to content

JITLink: __eh_frame emission/JIT EH frame registration on aarch64-darwin #52921

@dnadlinger

Description

@dnadlinger

To be able to unw_step through JIT-ed frames on aarch64-darwin, it is necessary to emit __eh_frame unwind information, as there is no way to register compact unwind info with libunwind.

However, JITLink drops all that unwind information on MachO-arm64, as the EHFrame{Splitter, EdgeFixer} passes are only added to the default link graph on x86_64. This effectively makes EHFrameRegistrationPlugin a no-op.

Just adding the passes the same way as on x86_64 appears to work, although I haven't checked whether there are any extra relocations to support, …:

commit 57eb8c10025bdbca8f8260bd43a46d0aca369fe8 (HEAD -> julia-main, dnadlinger/julia-main)
Author: David Nadlinger <[email protected]>
Date:   Thu Dec 30 04:23:23 2021 +0100

    [JITLink] Also include EHFrame* passes on MachO_arm64

    Without the non-compact unwind info there is no way to register
    the EH frames with libunwind (e.g. for backtrace generation).

diff --git a/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp b/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
index f2a029d35cd5..4d958b302ff9 100644
--- a/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
@@ -705,6 +705,10 @@ void link_MachO_arm64(std::unique_ptr<LinkGraph> G,
     Config.PrePrunePasses.push_back(
         CompactUnwindSplitter("__LD,__compact_unwind"));

+    Config.PrePrunePasses.push_back(EHFrameSplitter("__TEXT,__eh_frame"));
+    Config.PrePrunePasses.push_back(EHFrameEdgeFixer("__TEXT,__eh_frame",
+        8, Delta64, Delta32, NegDelta32));
+
     // Add an in-place GOT/Stubs pass.
     Config.PostPrunePasses.push_back(
         PerGraphGOTAndPLTStubsBuilder_MachO_arm64::asPass);

(There is also the somewhat related, non-JITLink-specific issue of __eh_frame sometimes being elided, for which Julia currently carries a patch: JuliaLang@60e0418.)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions