11#include "llvm/Config/config.h"
16#define DEBUG_TYPE "orc"
25#if defined(HAVE_REGISTER_FRAME) && defined(HAVE_DEREGISTER_FRAME) && \
26 !defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
48 static void((*RegisterFrame)(
const void *)) = 0;
51 *(
void **)&RegisterFrame =
59 return make_error<StringError>(
"could not register eh-frame: "
60 "__register_frame function not found",
65 static void((*DeregisterFrame)(
const void *)) = 0;
68 *(
void **)&DeregisterFrame =
70 "__deregister_frame");
72 if (DeregisterFrame) {
77 return make_error<StringError>(
"could not deregister eh-frame: "
78 "__deregister_frame function not found",
83#if defined(HAVE_UNW_ADD_DYNAMIC_FDE) || defined(__APPLE__)
85template <
typename HandleFDEFn>
86Error walkLibunwindEHFrameSection(
const char *
const SectionStart,
87 size_t SectionSize, HandleFDEFn HandleFDE) {
88 const char *CurCFIRecord = SectionStart;
92 while (CurCFIRecord !=
End &&
Size != 0) {
93 const char *OffsetField = CurCFIRecord + (
Size == 0xffffffff ? 12 : 4);
94 if (
Size == 0xffffffff)
95 Size = *
reinterpret_cast<const uint64_t *
>(CurCFIRecord + 4) + 12;
101 dbgs() <<
"Registering eh-frame section:\n";
102 dbgs() <<
"Processing " << (
Offset ?
"FDE" :
"CIE") <<
" @"
103 << (
void *)CurCFIRecord <<
": [";
104 for (
unsigned I = 0;
I <
Size; ++
I)
105 dbgs() <<
format(
" 0x%02" PRIx8, *(CurCFIRecord +
I));
110 if (
auto Err = HandleFDE(CurCFIRecord))
113 CurCFIRecord +=
Size;
115 Size = *
reinterpret_cast<const uint32_t *
>(CurCFIRecord);
124 size_t EHFrameSectionSize) {
127#if defined(HAVE_UNW_ADD_DYNAMIC_FDE) || defined(__APPLE__)
129 return walkLibunwindEHFrameSection(
130 static_cast<const char *
>(EHFrameSectionAddr), EHFrameSectionSize,
143 size_t EHFrameSectionSize) {
144#if defined(HAVE_UNW_ADD_DYNAMIC_FDE) || defined(__APPLE__)
145 return walkLibunwindEHFrameSection(
146 static_cast<const char *
>(EHFrameSectionAddr), EHFrameSectionSize,
orc::shared::CWrapperFunctionResult llvm_orc_registerEHFrameSectionWrapper(const char *Data, uint64_t Size)
static Error deregisterEHFrameWrapper(ExecutorAddrRange EHFrame)
orc::shared::CWrapperFunctionResult llvm_orc_deregisterEHFrameSectionWrapper(const char *Data, uint64_t Size)
static Error registerEHFrameWrapper(ExecutorAddrRange EHFrame)
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
std::enable_if_t< std::is_pointer< T >::value, T > toPtr(WrapFn &&Wrap=WrapFn()) const
Cast this ExecutorAddr to a pointer of the given type.
static void * SearchForAddressOfSymbol(const char *symbolName)
This function will search through all previously loaded dynamic libraries for the symbol symbolName.
Error registerFrameWrapper(const void *P)
Error deregisterEHFrameSection(const void *EHFrameSectionAddr, size_t EHFrameSectionSize)
Unregister frames in the given eh-frame section with libunwind.
void __deregister_frame(const void *)
Error registerEHFrameSection(const void *EHFrameSectionAddr, size_t EHFrameSectionSize)
Register frames in the given eh-frame section with libunwind.
void __register_frame(const void *)
Error deregisterFrameWrapper(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Represents an address range in the exceutor process.
ExecutorAddrDiff size() const