summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h4
-rw-r--r--llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.h52
-rw-r--r--llvm/include/llvm/ExecutionEngine/Orc/UnwindInfoRegistrationPlugin.h25
-rw-r--r--llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp5
-rw-r--r--llvm/lib/ExecutionEngine/Orc/LLJIT.cpp4
-rw-r--r--llvm/lib/ExecutionEngine/Orc/Shared/OrcRTBridge.cpp8
-rw-r--r--llvm/lib/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.cpp181
-rw-r--r--llvm/lib/ExecutionEngine/Orc/UnwindInfoRegistrationPlugin.cpp138
-rw-r--r--llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp5
-rw-r--r--llvm/tools/llvm-jitlink/llvm-jitlink.cpp14
10 files changed, 146 insertions, 290 deletions
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h
index db5ff135a716..0f59edd42933 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h
@@ -90,10 +90,6 @@ using SPSRunAsIntFunctionSignature = int32_t(shared::SPSExecutorAddr, int32_t);
} // end namespace rt
namespace rt_alt {
-extern const char *UnwindInfoManagerInstanceName;
-extern const char *UnwindInfoManagerFindSectionsHelperName;
-extern const char *UnwindInfoManagerEnableWrapperName;
-extern const char *UnwindInfoManagerDisableWrapperName;
extern const char *UnwindInfoManagerRegisterActionName;
extern const char *UnwindInfoManagerDeregisterActionName;
} // end namespace rt_alt
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.h
index fc7719f28212..847c340eff17 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.h
@@ -15,14 +15,13 @@
#define LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_UNWINDINFOMANAGER_H
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
-#include "llvm/ExecutionEngine/Orc/TargetProcess/ExecutorBootstrapService.h"
#include "llvm/Support/Error.h"
#include <map>
#include <mutex>
namespace llvm::orc {
-class UnwindInfoManager : public ExecutorBootstrapService {
+class UnwindInfoManager {
public:
// This struct's layout should match the unw_dynamic_unwind_sections struct
// from libunwind/src/libunwid_ext.h.
@@ -34,43 +33,40 @@ public:
size_t compact_unwind_section_length;
};
+ UnwindInfoManager(UnwindInfoManager &&) = delete;
+ UnwindInfoManager &operator=(UnwindInfoManager &&) = delete;
+ ~UnwindInfoManager();
+
/// If the libunwind find-dynamic-unwind-info callback registration APIs are
- /// available then this method will return an UnwindInfoManager instance,
- /// otherwise it will return nullptr.
- static std::unique_ptr<UnwindInfoManager> TryCreate();
+ /// available then this method will instantiate a global UnwindInfoManager
+ /// instance suitable for the process and return true. Otherwise it will
+ /// return false.
+ static bool TryEnable();
- Error shutdown() override;
- void addBootstrapSymbols(StringMap<ExecutorAddr> &M) override;
+ static void addBootstrapSymbols(StringMap<ExecutorAddr> &M);
- Error enable(void *FindDynamicUnwindSections);
- Error disable(void);
+ static Error registerSections(ArrayRef<orc::ExecutorAddrRange> CodeRanges,
+ orc::ExecutorAddr DSOBase,
+ orc::ExecutorAddrRange DWARFEHFrame,
+ orc::ExecutorAddrRange CompactUnwind);
- Error registerSections(ArrayRef<orc::ExecutorAddrRange> CodeRanges,
- orc::ExecutorAddr DSOBase,
- orc::ExecutorAddrRange DWARFEHFrame,
- orc::ExecutorAddrRange CompactUnwind);
+ static Error deregisterSections(ArrayRef<orc::ExecutorAddrRange> CodeRanges);
- Error deregisterSections(ArrayRef<orc::ExecutorAddrRange> CodeRanges);
+private:
+ UnwindInfoManager() = default;
- int findSections(uintptr_t Addr, UnwindSections *Info);
+ int findSectionsImpl(uintptr_t Addr, UnwindSections *Info);
+ static int findSections(uintptr_t Addr, UnwindSections *Info);
-private:
- UnwindInfoManager(int (*AddFindDynamicUnwindSections)(void *),
- int (*RemoveFindDynamicUnwindSections)(void *))
- : AddFindDynamicUnwindSections(AddFindDynamicUnwindSections),
- RemoveFindDynamicUnwindSections(RemoveFindDynamicUnwindSections) {}
+ Error registerSectionsImpl(ArrayRef<orc::ExecutorAddrRange> CodeRanges,
+ orc::ExecutorAddr DSOBase,
+ orc::ExecutorAddrRange DWARFEHFrame,
+ orc::ExecutorAddrRange CompactUnwind);
- static int findSectionsHelper(UnwindInfoManager *Instance, uintptr_t Addr,
- UnwindSections *Info);
+ Error deregisterSectionsImpl(ArrayRef<orc::ExecutorAddrRange> CodeRanges);
std::mutex M;
std::map<uintptr_t, UnwindSections> UWSecs;
-
- int (*AddFindDynamicUnwindSections)(void *) = nullptr;
- int (*RemoveFindDynamicUnwindSections)(void *) = nullptr;
- void *FindDynamicUnwindSections = nullptr;
-
- static const char *AddFnName, *RemoveFnName;
};
} // namespace llvm::orc
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/UnwindInfoRegistrationPlugin.h b/llvm/include/llvm/ExecutionEngine/Orc/UnwindInfoRegistrationPlugin.h
index eb883a79a93d..65f20ad3b216 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/UnwindInfoRegistrationPlugin.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/UnwindInfoRegistrationPlugin.h
@@ -19,15 +19,17 @@ namespace llvm::orc {
class UnwindInfoRegistrationPlugin : public LinkGraphLinkingLayer::Plugin {
public:
- static Expected<std::shared_ptr<UnwindInfoRegistrationPlugin>>
- Create(IRLayer &IRL, JITDylib &PlatformJD, ExecutorAddr Instance,
- ExecutorAddr FindHelper, ExecutorAddr Enable, ExecutorAddr Disable,
- ExecutorAddr Register, ExecutorAddr Deregister);
+ UnwindInfoRegistrationPlugin(ExecutionSession &ES, ExecutorAddr Register,
+ ExecutorAddr Deregister)
+ : ES(ES), Register(Register), Deregister(Deregister) {
+ DSOBaseName = ES.intern("__jitlink$libunwind_dso_base");
+ }
static Expected<std::shared_ptr<UnwindInfoRegistrationPlugin>>
- Create(IRLayer &IRL, JITDylib &PlatformJD);
+ Create(ExecutionSession &ES, ExecutorAddr Register, ExecutorAddr Deregister);
- ~UnwindInfoRegistrationPlugin();
+ static Expected<std::shared_ptr<UnwindInfoRegistrationPlugin>>
+ Create(ExecutionSession &ES);
void modifyPassConfig(MaterializationResponsibility &MR,
jitlink::LinkGraph &G,
@@ -49,20 +51,11 @@ public:
ResourceKey SrcKey) override {}
private:
- UnwindInfoRegistrationPlugin(ExecutionSession &ES, ExecutorAddr Instance,
- ExecutorAddr Disable, ExecutorAddr Register,
- ExecutorAddr Deregister)
- : ES(ES), Instance(Instance), Disable(Disable), Register(Register),
- Deregister(Deregister) {
- DSOBaseName = ES.intern("__jitlink$libunwind_dso_base");
- }
-
- static Expected<ThreadSafeModule> makeBouncerModule(ExecutionSession &ES);
Error addUnwindInfoRegistrationActions(jitlink::LinkGraph &G);
ExecutionSession &ES;
SymbolStringPtr DSOBaseName;
- ExecutorAddr Instance, Disable, Register, Deregister;
+ ExecutorAddr Register, Deregister;
};
} // namespace llvm::orc
diff --git a/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp
index 7b38150ab4b6..45cb28af5605 100644
--- a/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp
@@ -54,9 +54,8 @@ SelfExecutorProcessControl::SelfExecutorProcessControl(
// FIXME: Don't add an UnwindInfoManager by default -- it's redundant when
// the ORC runtime is loaded. We'll need a way to document this and
// allow clients to choose.
- this->UnwindInfoMgr = UnwindInfoManager::TryCreate();
- if (this->UnwindInfoMgr)
- this->UnwindInfoMgr->addBootstrapSymbols(this->BootstrapSymbols);
+ if (UnwindInfoManager::TryEnable())
+ UnwindInfoManager::addBootstrapSymbols(this->BootstrapSymbols);
#endif // __APPLE__
}
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index dd844ae3a42b..972c24abc750 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -1241,8 +1241,8 @@ Expected<JITDylibSP> setUpGenericLLVMIRPlatform(LLJIT &J) {
// If UseEHFrames hasn't been set then we're good to use compact-unwind.
if (!UseEHFrames) {
- if (auto UIRP = UnwindInfoRegistrationPlugin::Create(
- J.getIRCompileLayer(), PlatformJD)) {
+ if (auto UIRP =
+ UnwindInfoRegistrationPlugin::Create(J.getExecutionSession())) {
OLL->addPlugin(std::move(*UIRP));
LLVM_DEBUG(dbgs() << "Enabled compact-unwind support.\n");
} else
diff --git a/llvm/lib/ExecutionEngine/Orc/Shared/OrcRTBridge.cpp b/llvm/lib/ExecutionEngine/Orc/Shared/OrcRTBridge.cpp
index fef3ff989a52..d3b3f121cfcd 100644
--- a/llvm/lib/ExecutionEngine/Orc/Shared/OrcRTBridge.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Shared/OrcRTBridge.cpp
@@ -65,14 +65,6 @@ const char *RunAsIntFunctionWrapperName =
} // 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 =
diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.cpp
index 9f748154c03e..d67cbb807f2c 100644
--- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.cpp
@@ -9,7 +9,10 @@
#include "llvm/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.h"
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
#include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h"
-#include "llvm/Support/DynamicLibrary.h"
+
+#ifdef __APPLE__
+#include <dlfcn.h>
+#endif // __APPLE__
#define DEBUG_TYPE "orc"
@@ -18,39 +21,16 @@ using namespace llvm::orc;
using namespace llvm::orc::shared;
static orc::shared::CWrapperFunctionResult
-llvm_orc_rt_alt_UnwindInfoManager_enable(const char *Data, uint64_t Size) {
- return WrapperFunction<SPSError(SPSExecutorAddr, SPSExecutorAddr)>::handle(
- Data, Size,
- [](ExecutorAddr Instance, ExecutorAddr FindFn) {
- return Instance.toPtr<UnwindInfoManager *>()->enable(
- FindFn.toPtr<void *>());
- })
- .release();
-}
-
-static orc::shared::CWrapperFunctionResult
-llvm_orc_rt_alt_UnwindInfoManager_disable(const char *Data, uint64_t Size) {
- return WrapperFunction<SPSError(SPSExecutorAddr)>::handle(
- Data, Size,
- [](ExecutorAddr Instance) {
- return Instance.toPtr<UnwindInfoManager *>()->disable();
- })
- .release();
-}
-
-static orc::shared::CWrapperFunctionResult
llvm_orc_rt_alt_UnwindInfoManager_register(const char *Data, uint64_t Size) {
- using SPSSig =
- SPSError(SPSExecutorAddr, SPSSequence<SPSExecutorAddrRange>,
- SPSExecutorAddr, SPSExecutorAddrRange, SPSExecutorAddrRange);
+ using SPSSig = SPSError(SPSSequence<SPSExecutorAddrRange>, SPSExecutorAddr,
+ SPSExecutorAddrRange, SPSExecutorAddrRange);
return WrapperFunction<SPSSig>::handle(
Data, Size,
- [](ExecutorAddr Instance,
- std::vector<ExecutorAddrRange> CodeRanges, ExecutorAddr DSOBase,
+ [](std::vector<ExecutorAddrRange> CodeRanges, ExecutorAddr DSOBase,
ExecutorAddrRange DWARFRange,
ExecutorAddrRange CompactUnwindRange) {
- return Instance.toPtr<UnwindInfoManager *>()->registerSections(
+ return UnwindInfoManager::registerSections(
CodeRanges, DSOBase, DWARFRange, CompactUnwindRange);
})
.release();
@@ -58,89 +38,100 @@ llvm_orc_rt_alt_UnwindInfoManager_register(const char *Data, uint64_t Size) {
static orc::shared::CWrapperFunctionResult
llvm_orc_rt_alt_UnwindInfoManager_deregister(const char *Data, uint64_t Size) {
- using SPSSig = SPSError(SPSExecutorAddr, SPSSequence<SPSExecutorAddrRange>);
+ using SPSSig = SPSError(SPSSequence<SPSExecutorAddrRange>);
return WrapperFunction<SPSSig>::handle(
Data, Size,
- [](ExecutorAddr Instance,
- std::vector<ExecutorAddrRange> CodeRanges) {
- return Instance.toPtr<UnwindInfoManager *>()->deregisterSections(
- CodeRanges);
+ [](std::vector<ExecutorAddrRange> CodeRanges) {
+ return UnwindInfoManager::deregisterSections(CodeRanges);
})
.release();
}
namespace llvm::orc {
-const char *UnwindInfoManager::AddFnName =
- "__unw_add_find_dynamic_unwind_sections";
-const char *UnwindInfoManager::RemoveFnName =
- "__unw_remove_find_dynamic_unwind_sections";
-
-std::unique_ptr<UnwindInfoManager> UnwindInfoManager::TryCreate() {
- std::string ErrMsg;
- auto DL = sys::DynamicLibrary::getPermanentLibrary(nullptr, &ErrMsg);
- if (!DL.isValid())
- return nullptr;
-
- auto AddFindDynamicUnwindSections =
- (int (*)(void *))DL.getAddressOfSymbol(AddFnName);
- if (!AddFindDynamicUnwindSections)
- return nullptr;
-
- auto RemoveFindDynamicUnwindSections =
- (int (*)(void *))DL.getAddressOfSymbol(RemoveFnName);
- if (!RemoveFindDynamicUnwindSections)
- return nullptr;
-
- return std::unique_ptr<UnwindInfoManager>(new UnwindInfoManager(
- AddFindDynamicUnwindSections, RemoveFindDynamicUnwindSections));
+static const char *AddFnName = "__unw_add_find_dynamic_unwind_sections";
+static const char *RemoveFnName = "__unw_remove_find_dynamic_unwind_sections";
+static std::unique_ptr<UnwindInfoManager> Instance;
+static int (*RemoveFindDynamicUnwindSections)(void *) = nullptr;
+
+UnwindInfoManager::~UnwindInfoManager() {
+ if (int Err = RemoveFindDynamicUnwindSections((void *)&findSections)) {
+ LLVM_DEBUG({
+ dbgs() << "Failed call to " << RemoveFnName << ": error = " << Err
+ << "\n";
+ });
+ }
}
-Error UnwindInfoManager::shutdown() { return Error::success(); }
+bool UnwindInfoManager::TryEnable() {
+#ifdef __APPLE__
+ static std::mutex M;
+ std::lock_guard<std::mutex> Lock(M);
+
+ if (Instance)
+ return true;
+
+ auto AddFn = (int (*)(void *))dlsym(RTLD_DEFAULT, AddFnName);
+ if (!AddFn)
+ return false;
+
+ auto RemoveFn = (int (*)(void *))dlsym(RTLD_DEFAULT, RemoveFnName);
+ if (!RemoveFn)
+ return false;
+
+ Instance.reset(new UnwindInfoManager());
+
+ if (auto Err = AddFn((void *)&findSections)) {
+ LLVM_DEBUG({
+ dbgs() << "Failed call to " << AddFnName << ": error = " << Err << "\n";
+ });
+ Instance = nullptr;
+ return false;
+ }
+
+ RemoveFindDynamicUnwindSections = RemoveFn;
+ return true;
+
+#else
+ return false;
+#endif // __APPLE__
+}
void UnwindInfoManager::addBootstrapSymbols(StringMap<ExecutorAddr> &M) {
- M[rt_alt::UnwindInfoManagerInstanceName] = ExecutorAddr::fromPtr(this);
- M[rt_alt::UnwindInfoManagerFindSectionsHelperName] =
- ExecutorAddr::fromPtr(&findSectionsHelper);
- M[rt_alt::UnwindInfoManagerEnableWrapperName] =
- ExecutorAddr::fromPtr(llvm_orc_rt_alt_UnwindInfoManager_enable);
- M[rt_alt::UnwindInfoManagerDisableWrapperName] =
- ExecutorAddr::fromPtr(llvm_orc_rt_alt_UnwindInfoManager_disable);
M[rt_alt::UnwindInfoManagerRegisterActionName] =
ExecutorAddr::fromPtr(llvm_orc_rt_alt_UnwindInfoManager_register);
M[rt_alt::UnwindInfoManagerDeregisterActionName] =
ExecutorAddr::fromPtr(llvm_orc_rt_alt_UnwindInfoManager_deregister);
}
-Error UnwindInfoManager::enable(void *FindDynamicUnwindSections) {
- LLVM_DEBUG(dbgs() << "Enabling UnwindInfoManager.\n");
-
- if (auto Err = AddFindDynamicUnwindSections(FindDynamicUnwindSections))
- return make_error<StringError>(Twine("Could not register function via ") +
- AddFnName +
- ", error code = " + Twine(Err),
- inconvertibleErrorCode());
-
- this->FindDynamicUnwindSections = FindDynamicUnwindSections;
- return Error::success();
+Error UnwindInfoManager::registerSections(
+ ArrayRef<orc::ExecutorAddrRange> CodeRanges, orc::ExecutorAddr DSOBase,
+ orc::ExecutorAddrRange DWARFEHFrame, orc::ExecutorAddrRange CompactUnwind) {
+ return Instance->registerSectionsImpl(CodeRanges, DSOBase, DWARFEHFrame,
+ CompactUnwind);
}
-Error UnwindInfoManager::disable(void) {
- LLVM_DEBUG(dbgs() << "Disabling UnwindInfoManager.\n");
+Error UnwindInfoManager::deregisterSections(
+ ArrayRef<orc::ExecutorAddrRange> CodeRanges) {
+ return Instance->deregisterSectionsImpl(CodeRanges);
+}
- if (FindDynamicUnwindSections)
- if (auto Err = RemoveFindDynamicUnwindSections(FindDynamicUnwindSections))
- return make_error<StringError>(
- Twine("Could not deregister function via ") + RemoveFnName +
- "error code = " + Twine(Err),
- inconvertibleErrorCode());
+int UnwindInfoManager::findSectionsImpl(uintptr_t Addr, UnwindSections *Info) {
+ std::lock_guard<std::mutex> Lock(M);
+ auto I = UWSecs.upper_bound(Addr);
+ if (I == UWSecs.begin())
+ return 0;
+ --I;
+ *Info = I->second;
+ return 1;
+}
- FindDynamicUnwindSections = nullptr;
- return Error::success();
+int UnwindInfoManager::findSections(uintptr_t Addr, UnwindSections *Info) {
+ return Instance->findSectionsImpl(Addr, Info);
}
-Error UnwindInfoManager::registerSections(
+Error UnwindInfoManager::registerSectionsImpl(
ArrayRef<ExecutorAddrRange> CodeRanges, ExecutorAddr DSOBase,
ExecutorAddrRange DWARFEHFrame, ExecutorAddrRange CompactUnwind) {
std::lock_guard<std::mutex> Lock(M);
@@ -154,7 +145,7 @@ Error UnwindInfoManager::registerSections(
return Error::success();
}
-Error UnwindInfoManager::deregisterSections(
+Error UnwindInfoManager::deregisterSectionsImpl(
ArrayRef<ExecutorAddrRange> CodeRanges) {
std::lock_guard<std::mutex> Lock(M);
for (auto &R : CodeRanges) {
@@ -169,20 +160,4 @@ Error UnwindInfoManager::deregisterSections(
return Error::success();
}
-int UnwindInfoManager::findSections(uintptr_t Addr, UnwindSections *Info) {
- std::lock_guard<std::mutex> Lock(M);
- auto I = UWSecs.upper_bound(Addr);
- if (I == UWSecs.begin())
- return 0;
- --I;
- *Info = I->second;
- return 1;
-}
-
-int UnwindInfoManager::findSectionsHelper(UnwindInfoManager *Instance,
- uintptr_t Addr,
- UnwindSections *Info) {
- return Instance->findSections(Addr, Info);
-}
-
} // namespace llvm::orc
diff --git a/llvm/lib/ExecutionEngine/Orc/UnwindInfoRegistrationPlugin.cpp b/llvm/lib/ExecutionEngine/Orc/UnwindInfoRegistrationPlugin.cpp
index ae1f3f98269d..4482eedc0070 100644
--- a/llvm/lib/ExecutionEngine/Orc/UnwindInfoRegistrationPlugin.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/UnwindInfoRegistrationPlugin.cpp
@@ -9,7 +9,6 @@
#include "llvm/ExecutionEngine/Orc/UnwindInfoRegistrationPlugin.h"
#include "llvm/ADT/ScopeExit.h"
-#include "llvm/ExecutionEngine/Orc/AbsoluteSymbols.h"
#include "llvm/ExecutionEngine/Orc/Shared/MachOObjectFormat.h"
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
#include "llvm/IR/IRBuilder.h"
@@ -19,95 +18,21 @@
using namespace llvm::jitlink;
-static const char *FindDynamicUnwindSectionsFunctionName =
- "_orc_rt_alt_find_dynamic_unwind_sections";
-
namespace llvm::orc {
Expected<std::shared_ptr<UnwindInfoRegistrationPlugin>>
-UnwindInfoRegistrationPlugin::Create(IRLayer &IRL, JITDylib &PlatformJD,
- ExecutorAddr Instance,
- ExecutorAddr FindHelper,
- ExecutorAddr Enable, ExecutorAddr Disable,
- ExecutorAddr Register,
- ExecutorAddr Deregister) {
-
- auto &ES = IRL.getExecutionSession();
-
- // Build bouncer module.
- auto M = makeBouncerModule(ES);
- if (!M)
- return M.takeError();
-
- auto BouncerRT = PlatformJD.createResourceTracker();
- auto RemoveBouncerModule = make_scope_exit([&]() {
- if (auto Err = BouncerRT->remove())
- ES.reportError(std::move(Err));
- });
-
- if (auto Err = PlatformJD.define(absoluteSymbols(
- {{ES.intern(rt_alt::UnwindInfoManagerInstanceName),
- ExecutorSymbolDef(Instance, JITSymbolFlags())},
- {ES.intern(rt_alt::UnwindInfoManagerFindSectionsHelperName),
- ExecutorSymbolDef(FindHelper, JITSymbolFlags::Callable)}})))
- return std::move(Err);
-
- if (auto Err = IRL.add(BouncerRT, std::move(*M)))
- return Err;
-
- auto FindUnwindSections =
- ES.lookup({&PlatformJD}, FindDynamicUnwindSectionsFunctionName);
- if (!FindUnwindSections)
- return FindUnwindSections.takeError();
-
- using namespace shared;
- using SPSEnableSig = SPSError(SPSExecutorAddr, SPSExecutorAddr);
- Error CallErr = Error::success();
- if (auto Err = ES.callSPSWrapper<SPSEnableSig>(
- Enable, CallErr, Instance, FindUnwindSections->getAddress())) {
- consumeError(std::move(CallErr));
- return std::move(Err);
- }
-
- if (CallErr)
- return std::move(CallErr);
-
- RemoveBouncerModule.release();
-
- return std::shared_ptr<UnwindInfoRegistrationPlugin>(
- new UnwindInfoRegistrationPlugin(ES, Instance, Disable, Register,
- Deregister));
-}
-
-Expected<std::shared_ptr<UnwindInfoRegistrationPlugin>>
-UnwindInfoRegistrationPlugin::Create(IRLayer &IRL, JITDylib &PlatformJD) {
+UnwindInfoRegistrationPlugin::Create(ExecutionSession &ES) {
- ExecutorAddr Instance, FindHelper, Enable, Disable, Register, Deregister;
+ ExecutorAddr Register, Deregister;
- auto &EPC = IRL.getExecutionSession().getExecutorProcessControl();
+ auto &EPC = ES.getExecutorProcessControl();
if (auto Err = EPC.getBootstrapSymbols(
- {{Instance, rt_alt::UnwindInfoManagerInstanceName},
- {FindHelper, rt_alt::UnwindInfoManagerFindSectionsHelperName},
- {Enable, rt_alt::UnwindInfoManagerEnableWrapperName},
- {Disable, rt_alt::UnwindInfoManagerDisableWrapperName},
- {Register, rt_alt::UnwindInfoManagerRegisterActionName},
+ {{Register, rt_alt::UnwindInfoManagerRegisterActionName},
{Deregister, rt_alt::UnwindInfoManagerDeregisterActionName}}))
return std::move(Err);
- return Create(IRL, PlatformJD, Instance, FindHelper, Enable, Disable,
- Register, Deregister);
-}
-
-UnwindInfoRegistrationPlugin::~UnwindInfoRegistrationPlugin() {
- using namespace shared;
- using SPSDisableSig = SPSError(SPSExecutorAddr);
- Error CallErr = Error::success();
- if (auto Err = ES.callSPSWrapper<SPSDisableSig>(Disable, CallErr, Instance)) {
- consumeError(std::move(CallErr));
- ES.reportError(std::move(Err));
- }
- if (CallErr)
- ES.reportError(std::move(CallErr));
+ return std::make_shared<UnwindInfoRegistrationPlugin>(ES, Register,
+ Deregister);
}
void UnwindInfoRegistrationPlugin::modifyPassConfig(
@@ -118,43 +43,6 @@ void UnwindInfoRegistrationPlugin::modifyPassConfig(
[this](LinkGraph &G) { return addUnwindInfoRegistrationActions(G); });
}
-Expected<ThreadSafeModule>
-UnwindInfoRegistrationPlugin::makeBouncerModule(ExecutionSession &ES) {
- auto Ctx = std::make_unique<LLVMContext>();
- auto M = std::make_unique<Module>("__libunwind_find_unwind_bouncer", *Ctx);
- M->setTargetTriple(ES.getTargetTriple().str());
-
- auto EscapeName = [](const char *N) { return std::string("\01") + N; };
-
- auto *PtrTy = PointerType::getUnqual(*Ctx);
- auto *OpaqueStructTy = StructType::create(*Ctx, "UnwindInfoMgr");
- auto *UnwindMgrInstance = new GlobalVariable(
- *M, OpaqueStructTy, true, GlobalValue::ExternalLinkage, nullptr,
- EscapeName(rt_alt::UnwindInfoManagerInstanceName));
-
- auto *Int64Ty = Type::getInt64Ty(*Ctx);
- auto *FindHelperTy = FunctionType::get(Int64Ty, {PtrTy, PtrTy, PtrTy}, false);
- auto *FindHelperFn = Function::Create(
- FindHelperTy, GlobalValue::ExternalLinkage,
- EscapeName(rt_alt::UnwindInfoManagerFindSectionsHelperName), *M);
-
- auto *FindFnTy = FunctionType::get(Int64Ty, {PtrTy, PtrTy}, false);
- auto *FindFn =
- Function::Create(FindFnTy, GlobalValue::ExternalLinkage,
- EscapeName(FindDynamicUnwindSectionsFunctionName), *M);
- auto *EntryBlock = BasicBlock::Create(M->getContext(), StringRef(), FindFn);
- IRBuilder<> IB(EntryBlock);
-
- std::vector<Value *> FindHelperArgs;
- FindHelperArgs.push_back(UnwindMgrInstance);
- for (auto &Arg : FindFn->args())
- FindHelperArgs.push_back(&Arg);
-
- IB.CreateRet(IB.CreateCall(FindHelperFn, FindHelperArgs));
-
- return ThreadSafeModule(std::move(M), std::move(Ctx));
-}
-
Error UnwindInfoRegistrationPlugin::addUnwindInfoRegistrationActions(
LinkGraph &G) {
ExecutorAddrRange EHFrameRange, UnwindInfoRange;
@@ -220,17 +108,15 @@ Error UnwindInfoRegistrationPlugin::addUnwindInfoRegistrationActions(
using namespace shared;
using SPSRegisterArgs =
- SPSArgList<SPSExecutorAddr, SPSSequence<SPSExecutorAddrRange>,
- SPSExecutorAddr, SPSExecutorAddrRange, SPSExecutorAddrRange>;
- using SPSDeregisterArgs =
- SPSArgList<SPSExecutorAddr, SPSSequence<SPSExecutorAddrRange>>;
+ SPSArgList<SPSSequence<SPSExecutorAddrRange>, SPSExecutorAddr,
+ SPSExecutorAddrRange, SPSExecutorAddrRange>;
+ using SPSDeregisterArgs = SPSArgList<SPSSequence<SPSExecutorAddrRange>>;
G.allocActions().push_back(
{cantFail(WrapperFunctionCall::Create<SPSRegisterArgs>(
- Register, Instance, CodeRanges, DSOBase, EHFrameRange,
- UnwindInfoRange)),
- cantFail(WrapperFunctionCall::Create<SPSDeregisterArgs>(
- Deregister, Instance, CodeRanges))});
+ Register, CodeRanges, DSOBase, EHFrameRange, UnwindInfoRange)),
+ cantFail(WrapperFunctionCall::Create<SPSDeregisterArgs>(Deregister,
+ CodeRanges))});
return Error::success();
}
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
index dbdec7732777..8553eb70ebe4 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
@@ -18,6 +18,7 @@
#include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/SimpleRemoteEPCServer.h"
+#include "llvm/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DynamicLibrary.h"
@@ -190,6 +191,10 @@ int main(int argc, char *argv[]) {
SimpleRemoteEPCServer::defaultBootstrapSymbols();
addDefaultBootstrapValuesForHostProcess(S.bootstrapMap(),
S.bootstrapSymbols());
+#ifdef __APPLE__
+ if (UnwindInfoManager::TryEnable())
+ UnwindInfoManager::addBootstrapSymbols(S.bootstrapSymbols());
+#endif // __APPLE__
S.services().push_back(
std::make_unique<rt_bootstrap::SimpleExecutorMemoryManager>());
S.services().push_back(
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index a7ab7554902f..9e6d3df297fc 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -44,6 +44,7 @@
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderPerf.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"
+#include "llvm/ExecutionEngine/Orc/UnwindInfoRegistrationPlugin.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
@@ -1204,6 +1205,19 @@ Session::Session(std::unique_ptr<ExecutorProcessControl> EPC, Error &Err)
inconvertibleErrorCode());
return;
}
+ } else if (TT.isOSBinFormatMachO()) {
+ if (!NoExec) {
+ std::optional<bool> ForceEHFrames;
+ if ((Err = ES.getBootstrapMapValue<bool, bool>("darwin-use-ehframes-only",
+ ForceEHFrames)))
+ return;
+ bool UseEHFrames = ForceEHFrames ? *ForceEHFrames : false;
+ if (!UseEHFrames)
+ ObjLayer.addPlugin(ExitOnErr(UnwindInfoRegistrationPlugin::Create(ES)));
+ else
+ ObjLayer.addPlugin(std::make_unique<EHFrameRegistrationPlugin>(
+ ES, ExitOnErr(EPCEHFrameRegistrar::Create(ES))));
+ }
} else if (TT.isOSBinFormatELF()) {
if (!NoExec)
ObjLayer.addPlugin(std::make_unique<EHFrameRegistrationPlugin>(