For Darwin/arm64 (including Apple Silicon Macs) this will enable exception
handling and stack unwinding in JIT'd code.
Darwin supports two unwind-info formats: DWARF eh-frames and compact-unwind. On
Darwin/x86-64 compilers usually produce both by default, and ORC supported
exceptions and unwinding via eh-frames (same as on Linux), discarding the
redundant compact-unwind info. On Darwin/arm64 compilers typically default to
producing compact-unwind only, with DWARF eh-frames as a fallback for functions
that can't be described in compact-unwind. Since ORC did not previously support
the compact-unwind format and eh-frames were not present ORC was unable to
handle exceptions or unwinding by default in Darwin/arm64 JIT'd code.
This patch enables support for the compact-unwind-info format, and contains
three major moving parts:
(1) The JITLink CompactUnwindManager class is responsible for transforming the
__compact_unwind records produced by the linker into the __unwind_info
tables that libunwind parses during unwinding. To enable this the
CompactUnwindManager class provides three JITLink passes: The
prepareForPrune pass that splits the __compact_unwind section into
single-record blocks, allowing unused records to be dead-stripped; the
processAndReserveUnwindInfo pass that reserves space for the final
__unwind_info section, and the writeUnwindInfo pass that writes the
__unwind_info section.
(2) The OrcTargetProcess UnwindInfoManager class maintains a table of
registered JIT'd __unwind_info and __eh_frame sections, and handles
requests from libunwind for unwind info sections (by registering a callback
with libunwind's __unw_add_find_dynamic_unwind_sections function).
(3) The Orc UnwindInfoRegistrationPlugin, which scans LinkGraphs for
__unwind_info and __eh_frame sections to register with the
UnwindInfoManager.
This commit adds the CompactUnwindManager passes to the default JITLink
pipelines for Darwin/arm64 and Darwin/x86-64, and UnwindInfoManager intances to
the SelfExecutorProcessControl class (when built for apple platforms) and the
llvm-jitlink-executor tool.
The LLJIT class will now create an UnwindInfoRegistrationPlugin when targeting
a process running on Darwin if it detects that an UnwindInfoManager is
available to handle the registrations.
The ORC runtime macho_platform class already supported libunwind callbacks, so
out-of-process execution and unwinding support will work when loading the ORC
runtime.
The llvm-jitlink tool will only support compact-unwind when the orc-runtime is
loaded, as the UnwindInfoRegistrationPlugin requires access to an IR compiler
to load a helper module and llvm-jitlink does not provide an IR compiler.
83 lines
3.6 KiB
C++
83 lines
3.6 KiB
C++
//===------ OrcRTBridge.cpp - Executor functions for bootstrap -----===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
|
|
|
|
namespace llvm {
|
|
namespace orc {
|
|
namespace rt {
|
|
|
|
const char *SimpleExecutorDylibManagerInstanceName =
|
|
"__llvm_orc_SimpleExecutorDylibManager_Instance";
|
|
const char *SimpleExecutorDylibManagerOpenWrapperName =
|
|
"__llvm_orc_SimpleExecutorDylibManager_open_wrapper";
|
|
const char *SimpleExecutorDylibManagerLookupWrapperName =
|
|
"__llvm_orc_SimpleExecutorDylibManager_lookup_wrapper";
|
|
|
|
const char *SimpleExecutorMemoryManagerInstanceName =
|
|
"__llvm_orc_SimpleExecutorMemoryManager_Instance";
|
|
const char *SimpleExecutorMemoryManagerReserveWrapperName =
|
|
"__llvm_orc_SimpleExecutorMemoryManager_reserve_wrapper";
|
|
const char *SimpleExecutorMemoryManagerFinalizeWrapperName =
|
|
"__llvm_orc_SimpleExecutorMemoryManager_finalize_wrapper";
|
|
const char *SimpleExecutorMemoryManagerDeallocateWrapperName =
|
|
"__llvm_orc_SimpleExecutorMemoryManager_deallocate_wrapper";
|
|
|
|
const char *ExecutorSharedMemoryMapperServiceInstanceName =
|
|
"__llvm_orc_ExecutorSharedMemoryMapperService_Instance";
|
|
const char *ExecutorSharedMemoryMapperServiceReserveWrapperName =
|
|
"__llvm_orc_ExecutorSharedMemoryMapperService_Reserve";
|
|
const char *ExecutorSharedMemoryMapperServiceInitializeWrapperName =
|
|
"__llvm_orc_ExecutorSharedMemoryMapperService_Initialize";
|
|
const char *ExecutorSharedMemoryMapperServiceDeinitializeWrapperName =
|
|
"__llvm_orc_ExecutorSharedMemoryMapperService_Deinitialize";
|
|
const char *ExecutorSharedMemoryMapperServiceReleaseWrapperName =
|
|
"__llvm_orc_ExecutorSharedMemoryMapperService_Release";
|
|
|
|
const char *MemoryWriteUInt8sWrapperName =
|
|
"__llvm_orc_bootstrap_mem_write_uint8s_wrapper";
|
|
const char *MemoryWriteUInt16sWrapperName =
|
|
"__llvm_orc_bootstrap_mem_write_uint16s_wrapper";
|
|
const char *MemoryWriteUInt32sWrapperName =
|
|
"__llvm_orc_bootstrap_mem_write_uint32s_wrapper";
|
|
const char *MemoryWriteUInt64sWrapperName =
|
|
"__llvm_orc_bootstrap_mem_write_uint64s_wrapper";
|
|
const char *MemoryWriteBuffersWrapperName =
|
|
"__llvm_orc_bootstrap_mem_write_buffers_wrapper";
|
|
const char *MemoryWritePointersWrapperName =
|
|
"__llvm_orc_bootstrap_mem_write_pointers_wrapper";
|
|
|
|
const char *RegisterEHFrameSectionWrapperName =
|
|
"llvm_orc_registerEHFrameSectionWrapper";
|
|
const char *DeregisterEHFrameSectionWrapperName =
|
|
"llvm_orc_deregisterEHFrameSectionWrapper";
|
|
|
|
const char *RunAsMainWrapperName = "__llvm_orc_bootstrap_run_as_main_wrapper";
|
|
const char *RunAsVoidFunctionWrapperName =
|
|
"__llvm_orc_bootstrap_run_as_void_function_wrapper";
|
|
const char *RunAsIntFunctionWrapperName =
|
|
"__llvm_orc_bootstrap_run_as_int_function_wrapper";
|
|
|
|
} // end namespace rt
|
|
namespace rt_alt {
|
|
const char *UnwindInfoManagerInstanceName =
|
|
"orc_rt_alt_UnwindInfoManager_Instance";
|
|
const char *UnwindInfoManagerFindSectionsHelperName =
|
|
"orc_rt_alt_UnwindInfoManager_findSectionsHelper";
|
|
const char *UnwindInfoManagerEnableWrapperName =
|
|
"orc_rt_alt_UnwindInfoManager_enable";
|
|
const char *UnwindInfoManagerDisableWrapperName =
|
|
"orc_rt_alt_UnwindInfoManager_disable";
|
|
const char *UnwindInfoManagerRegisterActionName =
|
|
"orc_rt_alt_UnwindInfoManager_register";
|
|
const char *UnwindInfoManagerDeregisterActionName =
|
|
"orc_rt_alt_UnwindInfoManager_deregister";
|
|
} // end namespace rt_alt
|
|
} // end namespace orc
|
|
} // end namespace llvm
|