#include "elfnix_platform.h"
#include "common.h"
#include "compiler.h"
#include "error.h"
#include "jit_dispatch.h"
#include "record_section_tracker.h"
#include "wrapper_function_utils.h"
#include <algorithm>
#include <map>
#include <mutex>
#include <sstream>
#include <string_view>
#include <unordered_map>
#include <vector>
usingnamespaceorc_rt;
usingnamespaceorc_rt::elfnix;
ORC_RT_JIT_DISPATCH_TAG(__orc_rt_elfnix_push_initializers_tag)
ORC_RT_JIT_DISPATCH_TAG(__orc_rt_elfnix_symbol_lookup_tag)
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 {
struct TLSInfoEntry { … };
struct TLSDescriptor { … };
class ELFNixPlatformRuntimeState { … };
ELFNixPlatformRuntimeState *ELFNixPlatformRuntimeState::MOPS = …;
void ELFNixPlatformRuntimeState::initialize(void *DSOHandle) { … }
ELFNixPlatformRuntimeState &ELFNixPlatformRuntimeState::get() { … }
void ELFNixPlatformRuntimeState::destroy() { … }
ELFNixPlatformRuntimeState::ELFNixPlatformRuntimeState(void *DSOHandle)
: … { … }
Error ELFNixPlatformRuntimeState::registerObjectSections(
ELFNixPerObjectSectionsToRegister POSR) { … }
Error ELFNixPlatformRuntimeState::deregisterObjectSections(
ELFNixPerObjectSectionsToRegister POSR) { … }
Error ELFNixPlatformRuntimeState::registerJITDylib(std::string &Name,
void *Handle) { … }
Error ELFNixPlatformRuntimeState::deregisterJITDylib(void *Handle) { … }
Error ELFNixPlatformRuntimeState::registerInits(
ExecutorAddr HeaderAddr, std::vector<ExecutorAddrRange> Inits) { … }
Error ELFNixPlatformRuntimeState::deregisterInits(
ExecutorAddr HeaderAddr, std::vector<ExecutorAddrRange> Inits) { … }
const char *ELFNixPlatformRuntimeState::dlerror() { … }
void *ELFNixPlatformRuntimeState::dlopen(std::string_view Path, int Mode) { … }
int ELFNixPlatformRuntimeState::dlclose(void *DSOHandle) { … }
void *ELFNixPlatformRuntimeState::dlsym(void *DSOHandle,
std::string_view Symbol) { … }
int ELFNixPlatformRuntimeState::registerAtExit(void (*F)(void *), void *Arg,
void *DSOHandle) { … }
void ELFNixPlatformRuntimeState::runAtExits(void *DSOHandle) { … }
void ELFNixPlatformRuntimeState::runAtExits(
std::unique_lock<std::recursive_mutex> &JDStateLock,
PerJITDylibState &JDS) { … }
Expected<std::pair<const char *, size_t>>
ELFNixPlatformRuntimeState::getThreadDataSectionFor(const char *ThreadData) { … }
ELFNixPlatformRuntimeState::PerJITDylibState *
ELFNixPlatformRuntimeState::getJITDylibStateByHeaderAddr(void *DSOHandle) { … }
ELFNixPlatformRuntimeState::PerJITDylibState *
ELFNixPlatformRuntimeState::getJITDylibStateByName(std::string_view Name) { … }
Error ELFNixPlatformRuntimeState::registerThreadDataSection(
span<const char> ThreadDataSection) { … }
Expected<ExecutorAddr>
ELFNixPlatformRuntimeState::lookupSymbolInJITDylib(void *DSOHandle,
std::string_view Sym) { … }
Error ELFNixPlatformRuntimeState::runInits(
std::unique_lock<std::recursive_mutex> &JDStatesLock,
PerJITDylibState &JDS) { … }
Expected<void *> ELFNixPlatformRuntimeState::dlopenImpl(std::string_view Path,
int Mode) { … }
Error ELFNixPlatformRuntimeState::dlopenFull(
std::unique_lock<std::recursive_mutex> &JDStateLock,
PerJITDylibState &JDS) { … }
Error ELFNixPlatformRuntimeState::dlopenInitialize(
std::unique_lock<std::recursive_mutex> &JDStatesLock, PerJITDylibState &JDS,
ELFNixJITDylibDepInfoMap &DepInfo) { … }
Error ELFNixPlatformRuntimeState::dlcloseImpl(void *DSOHandle) { … }
Error ELFNixPlatformRuntimeState::dlcloseInitialize(
std::unique_lock<std::recursive_mutex> &JDStatesLock,
PerJITDylibState &JDS) { … }
class ELFNixPlatformRuntimeTLVManager { … };
void *ELFNixPlatformRuntimeTLVManager::getInstance(const char *ThreadData) { … }
void destroyELFNixTLVMgr(void *ELFNixTLVMgr) { … }
}
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
__orc_rt_elfnix_platform_bootstrap(char *ArgData, size_t ArgSize) { … }
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
__orc_rt_elfnix_platform_shutdown(char *ArgData, size_t ArgSize) { … }
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
__orc_rt_elfnix_register_jitdylib(char *ArgData, size_t ArgSize) { … }
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
__orc_rt_elfnix_deregister_jitdylib(char *ArgData, size_t ArgSize) { … }
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
__orc_rt_elfnix_register_init_sections(char *ArgData, size_t ArgSize) { … }
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
__orc_rt_elfnix_deregister_init_sections(char *ArgData, size_t ArgSize) { … }
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
__orc_rt_elfnix_register_object_sections(char *ArgData, size_t ArgSize) { … }
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
__orc_rt_elfnix_deregister_object_sections(char *ArgData, size_t ArgSize) { … }
ORC_RT_INTERFACE void *__orc_rt_elfnix_tls_get_addr_impl(TLSInfoEntry *D) { … }
ORC_RT_INTERFACE ptrdiff_t ___orc_rt_elfnix_tlsdesc_resolver_impl(
TLSDescriptor *D, const char *ThreadPointer) { … }
ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
__orc_rt_elfnix_create_pthread_key(char *ArgData, size_t ArgSize) { … }
int __orc_rt_elfnix_cxa_atexit(void (*func)(void *), void *arg,
void *dso_handle) { … }
int __orc_rt_elfnix_atexit(void (*func)(void *)) { … }
void __orc_rt_elfnix_cxa_finalize(void *dso_handle) { … }
const char *__orc_rt_elfnix_jit_dlerror() { … }
void *__orc_rt_elfnix_jit_dlopen(const char *path, int mode) { … }
int __orc_rt_elfnix_jit_dlclose(void *dso_handle) { … }
void *__orc_rt_elfnix_jit_dlsym(void *dso_handle, const char *symbol) { … }
ORC_RT_INTERFACE int64_t __orc_rt_elfnix_run_program(
const char *JITDylibName, const char *EntrySymbolName, int argc,
char *argv[]) { … }