LLVM: lib/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
12
13#ifdef __APPLE__
14#include <dlfcn.h>
15#endif
16
17#define DEBUG_TYPE "orc"
18
19using namespace llvm;
22
25 size_t ArgSize) {
28
30 ArgData, ArgSize,
31 [](std::vector CodeRanges, ExecutorAddr DSOBase,
35 CodeRanges, DSOBase, DWARFRange, CompactUnwindRange);
36 })
38}
39
42 size_t ArgSize) {
44
46 ArgData, ArgSize,
47 [](std::vector CodeRanges) {
49 })
51}
52
54
55[[maybe_unused]] static const char *AddFnName =
56 "__unw_add_find_dynamic_unwind_sections";
58 "__unw_remove_find_dynamic_unwind_sections";
59static std::unique_ptr Instance;
61
64 (void)Err;
66 dbgs() << "Failed call to " << RemoveFnName << ": error = " << Err
67 << "\n";
68 });
69 (void)Err;
70 }
71}
72
74#ifdef __APPLE__
75 static std::mutex M;
76 std::lock_guardstd::mutex Lock(M);
77
79 return true;
80
81 auto AddFn = (int (*)(void *))dlsym(RTLD_DEFAULT, AddFnName);
82 if (!AddFn)
83 return false;
84
85 auto RemoveFn = (int (*)(void *))dlsym(RTLD_DEFAULT, RemoveFnName);
86 if (!RemoveFn)
87 return false;
88
90
91 if (auto Err = AddFn((void *)&findSections)) {
92 (void)Err;
94 dbgs() << "Failed call to " << AddFnName << ": error = " << Err << "\n";
95 });
97 return false;
98 }
99
101 return true;
102
103#else
104 return false;
105#endif
106}
107
114
118 return Instance->registerSectionsImpl(CodeRanges, DSOBase, DWARFEHFrame,
119 CompactUnwind);
120}
121
124 return Instance->deregisterSectionsImpl(CodeRanges);
125}
126
127int UnwindInfoManager::findSectionsImpl(uintptr_t Addr, UnwindSections *Info) {
128 std::lock_guardstd::mutex Lock(M);
129 auto I = UWSecs.upper_bound(Addr);
130 if (I == UWSecs.begin())
131 return 0;
132 --I;
133 *Info = I->second;
134 return 1;
135}
136
137int UnwindInfoManager::findSections(uintptr_t Addr, UnwindSections *Info) {
138 return Instance->findSectionsImpl(Addr, Info);
139}
140
141Error UnwindInfoManager::registerSectionsImpl(
144 std::lock_guardstd::mutex Lock(M);
145 for (auto &R : CodeRanges)
146 UWSecs[R.Start.getValue()] =
147 UnwindSections{static_cast<uintptr_t>(DSOBase.getValue()),
148 static_cast<uintptr_t>(DWARFEHFrame.Start.getValue()),
149 static_cast<size_t>(DWARFEHFrame.size()),
150 static_cast<uintptr_t>(CompactUnwind.Start.getValue()),
151 static_cast<size_t>(CompactUnwind.size())};
153}
154
155Error UnwindInfoManager::deregisterSectionsImpl(
157 std::lock_guardstd::mutex Lock(M);
158 for (auto &R : CodeRanges) {
159 auto I = UWSecs.find(R.Start.getValue());
160 if (I == UWSecs.end())
162 "No unwind-info sections registered for range " +
163 formatv("{0:x} - {1:x}", R.Start, R.End),
165 UWSecs.erase(I);
166 }
168}
169
170}
static orc::shared::CWrapperFunctionResult llvm_orc_rt_alt_UnwindInfoManager_register(const char *ArgData, size_t ArgSize)
Definition UnwindInfoManager.cpp:24
static orc::shared::CWrapperFunctionResult llvm_orc_rt_alt_UnwindInfoManager_deregister(const char *ArgData, size_t ArgSize)
Definition UnwindInfoManager.cpp:41
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Represents an address in the executor process.
uint64_t getValue() const
static ExecutorAddr fromPtr(T *Ptr, UnwrapFn &&Unwrap=UnwrapFn())
Create an ExecutorAddr from the given pointer.
static LLVM_ABI bool TryEnable()
If the libunwind find-dynamic-unwind-info callback registration APIs are available then this method w...
Definition UnwindInfoManager.cpp:73
UnwindInfoManager(UnwindInfoManager &&)=delete
static LLVM_ABI void addBootstrapSymbols(StringMap< ExecutorAddr > &M)
Definition UnwindInfoManager.cpp:108
static LLVM_ABI Error deregisterSections(ArrayRef< orc::ExecutorAddrRange > CodeRanges)
Definition UnwindInfoManager.cpp:122
LLVM_ABI ~UnwindInfoManager()
Definition UnwindInfoManager.cpp:62
static LLVM_ABI Error registerSections(ArrayRef< orc::ExecutorAddrRange > CodeRanges, orc::ExecutorAddr DSOBase, orc::ExecutorAddrRange DWARFEHFrame, orc::ExecutorAddrRange CompactUnwind)
Definition UnwindInfoManager.cpp:115
LLVM_ABI const char * UnwindInfoManagerDeregisterActionName
LLVM_ABI const char * UnwindInfoManagerRegisterActionName
static std::unique_ptr< UnwindInfoManager > Instance
Definition UnwindInfoManager.cpp:59
static const char * RemoveFnName
Definition UnwindInfoManager.cpp:57
static int(* RemoveFindDynamicUnwindSections)(void *)
Definition UnwindInfoManager.cpp:60
static const char * AddFnName
Definition UnwindInfoManager.cpp:55
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
ArrayRef(const T &OneElt) -> ArrayRef< T >
Represents an address range in the exceutor process.
ExecutorAddrDiff size() const