1 //===- elfnix_platform.h ----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // ORC Runtime support for dynamic loading features on ELF-based platforms.
11 //===----------------------------------------------------------------------===//
13 #ifndef ORC_RT_ELFNIX_PLATFORM_H
14 #define ORC_RT_ELFNIX_PLATFORM_H
17 #include "executor_address.h"
20 ORC_RT_INTERFACE
int __orc_rt_elfnix_cxa_atexit(void (*func
)(void *), void *arg
,
22 ORC_RT_INTERFACE
int __orc_rt_elfnix_atexit(void (*func
)(void *));
23 ORC_RT_INTERFACE
void __orc_rt_elfnix_cxa_finalize(void *dso_handle
);
26 ORC_RT_INTERFACE
const char *__orc_rt_elfnix_jit_dlerror();
27 ORC_RT_INTERFACE
void *__orc_rt_elfnix_jit_dlopen(const char *path
, int mode
);
28 ORC_RT_INTERFACE
int __orc_rt_elfnix_jit_dlclose(void *dso_handle
);
29 ORC_RT_INTERFACE
void *__orc_rt_elfnix_jit_dlsym(void *dso_handle
,
35 struct ELFNixPerObjectSectionsToRegister
{
36 ExecutorAddrRange EHFrameSection
;
37 ExecutorAddrRange ThreadDataSection
;
40 struct ELFNixJITDylibInitializers
{
41 using SectionList
= std::vector
<ExecutorAddrRange
>;
43 ELFNixJITDylibInitializers() = default;
44 ELFNixJITDylibInitializers(std::string Name
, ExecutorAddr DSOHandleAddress
)
45 : Name(std::move(Name
)), DSOHandleAddress(std::move(DSOHandleAddress
)) {}
48 ExecutorAddr DSOHandleAddress
;
50 std::vector
<std::pair
<std::string
, SectionList
>> InitSections
;
53 class ELFNixJITDylibDeinitializers
{};
55 using ELFNixJITDylibInitializerSequence
=
56 std::vector
<ELFNixJITDylibInitializers
>;
58 using ELFNixJITDylibDeinitializerSequence
=
59 std::vector
<ELFNixJITDylibDeinitializers
>;
61 enum 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
68 } // end namespace elfnix
70 using SPSELFNixPerObjectSectionsToRegister
=
71 SPSTuple
<SPSExecutorAddrRange
, SPSExecutorAddrRange
>;
74 class SPSSerializationTraits
<SPSELFNixPerObjectSectionsToRegister
,
75 elfnix::ELFNixPerObjectSectionsToRegister
> {
78 static size_t size(const elfnix::ELFNixPerObjectSectionsToRegister
&MOPOSR
) {
79 return SPSELFNixPerObjectSectionsToRegister::AsArgList::size(
80 MOPOSR
.EHFrameSection
, MOPOSR
.ThreadDataSection
);
84 serialize(SPSOutputBuffer
&OB
,
85 const elfnix::ELFNixPerObjectSectionsToRegister
&MOPOSR
) {
86 return SPSELFNixPerObjectSectionsToRegister::AsArgList::serialize(
87 OB
, MOPOSR
.EHFrameSection
, MOPOSR
.ThreadDataSection
);
90 static bool deserialize(SPSInputBuffer
&IB
,
91 elfnix::ELFNixPerObjectSectionsToRegister
&MOPOSR
) {
92 return SPSELFNixPerObjectSectionsToRegister::AsArgList::deserialize(
93 IB
, MOPOSR
.EHFrameSection
, MOPOSR
.ThreadDataSection
);
97 using SPSNamedExecutorAddrRangeSequenceMap
=
98 SPSSequence
<SPSTuple
<SPSString
, SPSExecutorAddrRangeSequence
>>;
100 using SPSELFNixJITDylibInitializers
=
101 SPSTuple
<SPSString
, SPSExecutorAddr
, SPSNamedExecutorAddrRangeSequenceMap
>;
103 using SPSELFNixJITDylibInitializerSequence
=
104 SPSSequence
<SPSELFNixJITDylibInitializers
>;
106 /// Serialization traits for ELFNixJITDylibInitializers.
108 class SPSSerializationTraits
<SPSELFNixJITDylibInitializers
,
109 elfnix::ELFNixJITDylibInitializers
> {
111 static size_t size(const elfnix::ELFNixJITDylibInitializers
&MOJDIs
) {
112 return SPSELFNixJITDylibInitializers::AsArgList::size(
113 MOJDIs
.Name
, MOJDIs
.DSOHandleAddress
, MOJDIs
.InitSections
);
116 static bool serialize(SPSOutputBuffer
&OB
,
117 const elfnix::ELFNixJITDylibInitializers
&MOJDIs
) {
118 return SPSELFNixJITDylibInitializers::AsArgList::serialize(
119 OB
, MOJDIs
.Name
, MOJDIs
.DSOHandleAddress
, MOJDIs
.InitSections
);
122 static bool deserialize(SPSInputBuffer
&IB
,
123 elfnix::ELFNixJITDylibInitializers
&MOJDIs
) {
124 return SPSELFNixJITDylibInitializers::AsArgList::deserialize(
125 IB
, MOJDIs
.Name
, MOJDIs
.DSOHandleAddress
, MOJDIs
.InitSections
);
129 } // end namespace __orc_rt
131 #endif // ORC_RT_ELFNIX_PLATFORM_H