11#include "llvm/Config/config.h"
21#define DEBUG_TYPE "orc"
30#if defined(HAVE_REGISTER_FRAME) && defined(HAVE_DEREGISTER_FRAME) && \
31 !defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
53 static void((*RegisterFrame)(
const void *)) = 0;
56 *(
void **)&RegisterFrame =
64 return make_error<StringError>(
"could not register eh-frame: "
65 "__register_frame function not found",
70 static void((*DeregisterFrame)(
const void *)) = 0;
73 *(
void **)&DeregisterFrame =
75 "__deregister_frame");
77 if (DeregisterFrame) {
82 return make_error<StringError>(
"could not deregister eh-frame: "
83 "__deregister_frame function not found",
88#if defined(HAVE_UNW_ADD_DYNAMIC_FDE) || defined(__APPLE__)
90template <
typename HandleFDEFn>
91Error walkLibunwindEHFrameSection(
const char *
const SectionStart,
92 size_t SectionSize, HandleFDEFn HandleFDE) {
93 const char *CurCFIRecord = SectionStart;
97 while (CurCFIRecord !=
End &&
Size != 0) {
98 const char *OffsetField = CurCFIRecord + (
Size == 0xffffffff ? 12 : 4);
99 if (
Size == 0xffffffff)
100 Size = *
reinterpret_cast<const uint64_t *
>(CurCFIRecord + 4) + 12;
106 dbgs() <<
"Registering eh-frame section:\n";
107 dbgs() <<
"Processing " << (
Offset ?
"FDE" :
"CIE") <<
" @"
108 << (
void *)CurCFIRecord <<
": [";
109 for (
unsigned I = 0;
I <
Size; ++
I)
110 dbgs() <<
format(
" 0x%02" PRIx8, *(CurCFIRecord +
I));
115 if (
auto Err = HandleFDE(CurCFIRecord))
118 CurCFIRecord +=
Size;
120 Size = *
reinterpret_cast<const uint32_t *
>(CurCFIRecord);
129 size_t EHFrameSectionSize) {
132#if defined(HAVE_UNW_ADD_DYNAMIC_FDE) || defined(__APPLE__)
134 return walkLibunwindEHFrameSection(
135 static_cast<const char *
>(EHFrameSectionAddr), EHFrameSectionSize,
148 size_t EHFrameSectionSize) {
149#if defined(HAVE_UNW_ADD_DYNAMIC_FDE) || defined(__APPLE__)
150 return walkLibunwindEHFrameSection(
151 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