#include "elfnix_platform.h"
#include "common.h"
+#include "compiler.h"
#include "error.h"
#include "wrapper_function_utils.h"
// eh-frame registration functions, made available via aliases
// installed by the Platform
-extern "C" void __orc_rt_register_eh_frame_section(const void *);
-extern "C" void __orc_rt_deregister_eh_frame_section(const void *);
+extern "C" void __register_frame(const void *);
+extern "C" void __deregister_frame(const void *);
+
+extern "C" void
+__unw_add_dynamic_eh_frame_section(const void *) ORC_RT_WEAK_IMPORT;
+extern "C" void
+__unw_remove_dynamic_eh_frame_section(const void *) ORC_RT_WEAK_IMPORT;
namespace {
static ELFNixPlatformRuntimeState &get();
static void destroy();
- ELFNixPlatformRuntimeState(void *DSOHandle)
- : PlatformJDDSOHandle(DSOHandle) {}
+ ELFNixPlatformRuntimeState(void *DSOHandle);
// Delete copy and move constructors.
ELFNixPlatformRuntimeState(const ELFNixPlatformRuntimeState &) = delete;
void *PlatformJDDSOHandle;
+ // Frame registration functions:
+ void (*registerEHFrameSection)(const void *) = nullptr;
+ void (*deregisterEHFrameSection)(const void *) = nullptr;
+
// FIXME: Move to thread-state.
std::string DLFcnError;
delete MOPS;
}
+ELFNixPlatformRuntimeState::ELFNixPlatformRuntimeState(void *DSOHandle)
+ : PlatformJDDSOHandle(DSOHandle) {
+ if (__unw_add_dynamic_eh_frame_section &&
+ __unw_remove_dynamic_eh_frame_section) {
+ registerEHFrameSection = __unw_add_dynamic_eh_frame_section;
+ deregisterEHFrameSection = __unw_remove_dynamic_eh_frame_section;
+ } else {
+ registerEHFrameSection = __register_frame;
+ deregisterEHFrameSection = __deregister_frame;
+ }
+}
+
Error ELFNixPlatformRuntimeState::registerObjectSections(
ELFNixPerObjectSectionsToRegister POSR) {
if (POSR.EHFrameSection.Start)
- __orc_rt_register_eh_frame_section(
- POSR.EHFrameSection.Start.toPtr<const char *>());
+ registerEHFrameSection(POSR.EHFrameSection.Start.toPtr<const char *>());
if (POSR.ThreadDataSection.Start) {
if (auto Err = registerThreadDataSection(
Error ELFNixPlatformRuntimeState::deregisterObjectSections(
ELFNixPerObjectSectionsToRegister POSR) {
if (POSR.EHFrameSection.Start)
- __orc_rt_deregister_eh_frame_section(
- POSR.EHFrameSection.Start.toPtr<const char *>());
+ deregisterEHFrameSection(POSR.EHFrameSection.Start.toPtr<const char *>());
return Error::success();
}
SymbolAliasMap Aliases;
addAliases(ES, Aliases, requiredCXXAliases());
addAliases(ES, Aliases, standardRuntimeUtilityAliases());
-
- // Determine whether or not the libunwind extended-API function for
- // dynamically registering an entire .eh_frame section is available.
- // If it is not, we assume that libgcc_s is being used, and alias to
- // its __register_frame with the same functionality.
- auto RTRegisterFrame = ES.intern("__orc_rt_register_eh_frame_section");
- auto LibUnwindRegisterFrame = ES.intern("__unw_add_dynamic_eh_frame_section");
- auto RTDeregisterFrame = ES.intern("__orc_rt_deregister_eh_frame_section");
- auto LibUnwindDeregisterFrame =
- ES.intern("__unw_remove_dynamic_eh_frame_section");
- auto SM = ES.lookup(makeJITDylibSearchOrder(&PlatformJD),
- SymbolLookupSet()
- .add(LibUnwindRegisterFrame,
- SymbolLookupFlags::WeaklyReferencedSymbol)
- .add(LibUnwindDeregisterFrame,
- SymbolLookupFlags::WeaklyReferencedSymbol));
- if (!SM) { // Weak-ref means no "missing symbol" errors, so this must be
- // something more serious that we should report.
- return SM.takeError();
- } else if (SM->size() == 2) {
- LLVM_DEBUG({
- dbgs() << "Using libunwind " << LibUnwindRegisterFrame
- << " for unwind info registration\n";
- });
- Aliases[std::move(RTRegisterFrame)] = {LibUnwindRegisterFrame,
- JITSymbolFlags::Exported};
- Aliases[std::move(RTDeregisterFrame)] = {LibUnwindDeregisterFrame,
- JITSymbolFlags::Exported};
- } else {
- // Since LLVM libunwind is not present, we assume that unwinding
- // is provided by libgcc
- LLVM_DEBUG({
- dbgs() << "Using libgcc __register_frame for unwind info registration\n";
- });
- Aliases[std::move(RTRegisterFrame)] = {ES.intern("__register_frame"),
- JITSymbolFlags::Exported};
- Aliases[std::move(RTDeregisterFrame)] = {ES.intern("__deregister_frame"),
- JITSymbolFlags::Exported};
- }
-
return Aliases;
}