1//===- elfnix_platform.h ----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// ORC Runtime support for dynamic loading features on ELF-based platforms.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef ORC_RT_ELFNIX_PLATFORM_H
14#define ORC_RT_ELFNIX_PLATFORM_H
15
16#include "common.h"
17#include "executor_address.h"
18
19// Atexit functions.
20ORC_RT_INTERFACE int __orc_rt_elfnix_cxa_atexit(void (*func)(void *), void *arg,
21 void *dso_handle);
22ORC_RT_INTERFACE int __orc_rt_elfnix_atexit(void (*func)(void *));
23ORC_RT_INTERFACE void __orc_rt_elfnix_cxa_finalize(void *dso_handle);
24
25// dlfcn functions.
26ORC_RT_INTERFACE const char *__orc_rt_elfnix_jit_dlerror();
27ORC_RT_INTERFACE void *__orc_rt_elfnix_jit_dlopen(const char *path, int mode);
28ORC_RT_INTERFACE int __orc_rt_elfnix_jit_dlclose(void *dso_handle);
29ORC_RT_INTERFACE void *__orc_rt_elfnix_jit_dlsym(void *dso_handle,
30 const char *symbol);
31
32namespace __orc_rt {
33namespace elfnix {
34
35struct ELFNixPerObjectSectionsToRegister {
36 ExecutorAddrRange EHFrameSection;
37 ExecutorAddrRange ThreadDataSection;
38};
39
40struct ELFNixJITDylibInitializers {
41 using SectionList = std::vector<ExecutorAddrRange>;
42
43 ELFNixJITDylibInitializers() = default;
44 ELFNixJITDylibInitializers(std::string Name, ExecutorAddr DSOHandleAddress)
45 : Name(std::move(t&: Name)), DSOHandleAddress(std::move(t&: DSOHandleAddress)) {}
46
47 std::string Name;
48 ExecutorAddr DSOHandleAddress;
49
50 std::vector<std::pair<std::string, SectionList>> InitSections;
51};
52
53class ELFNixJITDylibDeinitializers {};
54
55using ELFNixJITDylibInitializerSequence =
56 std::vector<ELFNixJITDylibInitializers>;
57
58using ELFNixJITDylibDeinitializerSequence =
59 std::vector<ELFNixJITDylibDeinitializers>;
60
61enum dlopen_mode : int {
62 ORC_RT_RTLD_LAZY = 0x1,
63 ORC_RT_RTLD_NOW = 0x2,
64 ORC_RT_RTLD_LOCAL = 0x4,
65 ORC_RT_RTLD_GLOBAL = 0x8
66};
67
68} // end namespace elfnix
69
70using SPSELFNixPerObjectSectionsToRegister =
71 SPSTuple<SPSExecutorAddrRange, SPSExecutorAddrRange>;
72
73template <>
74class SPSSerializationTraits<SPSELFNixPerObjectSectionsToRegister,
75 elfnix::ELFNixPerObjectSectionsToRegister> {
76
77public:
78 static size_t size(const elfnix::ELFNixPerObjectSectionsToRegister &MOPOSR) {
79 return SPSELFNixPerObjectSectionsToRegister::AsArgList::size(
80 Arg: MOPOSR.EHFrameSection, Args: MOPOSR.ThreadDataSection);
81 }
82
83 static bool
84 serialize(SPSOutputBuffer &OB,
85 const elfnix::ELFNixPerObjectSectionsToRegister &MOPOSR) {
86 return SPSELFNixPerObjectSectionsToRegister::AsArgList::serialize(
87 OB, Arg: MOPOSR.EHFrameSection, Args: MOPOSR.ThreadDataSection);
88 }
89
90 static bool deserialize(SPSInputBuffer &IB,
91 elfnix::ELFNixPerObjectSectionsToRegister &MOPOSR) {
92 return SPSELFNixPerObjectSectionsToRegister::AsArgList::deserialize(
93 IB, Arg&: MOPOSR.EHFrameSection, Args&: MOPOSR.ThreadDataSection);
94 }
95};
96
97using SPSNamedExecutorAddrRangeSequenceMap =
98 SPSSequence<SPSTuple<SPSString, SPSExecutorAddrRangeSequence>>;
99
100using SPSELFNixJITDylibInitializers =
101 SPSTuple<SPSString, SPSExecutorAddr, SPSNamedExecutorAddrRangeSequenceMap>;
102
103using SPSELFNixJITDylibInitializerSequence =
104 SPSSequence<SPSELFNixJITDylibInitializers>;
105
106/// Serialization traits for ELFNixJITDylibInitializers.
107template <>
108class SPSSerializationTraits<SPSELFNixJITDylibInitializers,
109 elfnix::ELFNixJITDylibInitializers> {
110public:
111 static size_t size(const elfnix::ELFNixJITDylibInitializers &MOJDIs) {
112 return SPSELFNixJITDylibInitializers::AsArgList::size(
113 Arg: MOJDIs.Name, Args: MOJDIs.DSOHandleAddress, Args: MOJDIs.InitSections);
114 }
115
116 static bool serialize(SPSOutputBuffer &OB,
117 const elfnix::ELFNixJITDylibInitializers &MOJDIs) {
118 return SPSELFNixJITDylibInitializers::AsArgList::serialize(
119 OB, Arg: MOJDIs.Name, Args: MOJDIs.DSOHandleAddress, Args: MOJDIs.InitSections);
120 }
121
122 static bool deserialize(SPSInputBuffer &IB,
123 elfnix::ELFNixJITDylibInitializers &MOJDIs) {
124 return SPSELFNixJITDylibInitializers::AsArgList::deserialize(
125 IB, Arg&: MOJDIs.Name, Args&: MOJDIs.DSOHandleAddress, Args&: MOJDIs.InitSections);
126 }
127};
128
129} // end namespace __orc_rt
130
131#endif // ORC_RT_ELFNIX_PLATFORM_H
132

source code of compiler-rt/lib/orc/elfnix_platform.h