LLVM 24.0.0git
EPCGenericRTDyldMemoryManager.h
Go to the documentation of this file.
1//===---- EPCGenericRTDyldMemoryManager.h - EPC-based MemMgr ----*- 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// Defines a RuntimeDyld::MemoryManager that uses EPC and the ORC runtime
10// bootstrap functions.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_EXECUTIONENGINE_ORC_EPCGENERICRTDYLDMEMORYMANAGER_H
15#define LLVM_EXECUTIONENGINE_ORC_EPCGENERICRTDYLDMEMORYMANAGER_H
16
21
22#define DEBUG_TYPE "orc"
23
24namespace llvm {
25namespace orc {
26
27/// Remote-mapped RuntimeDyld-compatible memory manager.
30public:
31 /// Bindings to the executor-side memory manager, plus the EH-frame
32 /// registration alloc-action wrappers.
38
39 /// Create an EPCGenericRTDyldMemoryManager using the given EPC, looking up
40 /// the default symbol names in the bootstrap symbol set.
43
44 /// Create an EPCGenericRTDyldMemoryManager using the given EPC and symbol
45 /// addrs.
47
55
56 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
57 unsigned SectionID,
58 StringRef SectionName) override;
59
60 uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
61 unsigned SectionID, StringRef SectionName,
62 bool IsReadOnly) override;
63
65 uintptr_t RODataSize, Align RODataAlign,
66 uintptr_t RWDataSize, Align RWDataAlign) override;
67
68 bool needsToReserveAllocationSpace() override;
69
70 void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override;
71
72 void deregisterEHFrames() override;
73
75 const object::ObjectFile &Obj) override;
76
77 bool finalizeMemory(std::string *ErrMsg = nullptr) override;
78
79private:
80 struct SectionAlloc {
81 public:
82 SectionAlloc(uint64_t Size, unsigned Align)
83 : Size(Size), Align(Align),
84 Contents(std::make_unique<uint8_t[]>(Size + Align - 1)) {}
85
87 unsigned Align;
88 std::unique_ptr<uint8_t[]> Contents;
89 ExecutorAddr RemoteAddr;
90 };
91
92 // Group of section allocations to be allocated together in the executor. The
93 // RemoteCodeAddr will stand in as the id of the group for deallocation
94 // purposes.
95 struct SectionAllocGroup {
96 SectionAllocGroup() = default;
97 SectionAllocGroup(const SectionAllocGroup &) = delete;
98 SectionAllocGroup &operator=(const SectionAllocGroup &) = delete;
99 SectionAllocGroup(SectionAllocGroup &&) = default;
100 SectionAllocGroup &operator=(SectionAllocGroup &&) = default;
101
102 ExecutorAddrRange RemoteCode;
103 ExecutorAddrRange RemoteROData;
104 ExecutorAddrRange RemoteRWData;
105 std::vector<ExecutorAddrRange> UnfinalizedEHFrames;
106 std::vector<SectionAlloc> CodeAllocs, RODataAllocs, RWDataAllocs;
107 };
108
109 // Maps all allocations in SectionAllocs to aligned blocks
110 void mapAllocsToRemoteAddrs(RuntimeDyld &Dyld,
111 std::vector<SectionAlloc> &SecAllocs,
112 ExecutorAddr NextAddr);
113
114 ExecutorProcessControl &EPC;
115 SymbolAddrs SAs;
116
117 std::mutex M;
118 std::vector<SectionAllocGroup> Unmapped;
119 std::vector<SectionAllocGroup> Unfinalized;
120 std::vector<ExecutorAddr> FinalizedAllocs;
121 std::string ErrMsg;
122};
123
124} // end namespace orc
125} // end namespace llvm
126
127#undef DEBUG_TYPE
128
129#endif // LLVM_EXECUTIONENGINE_ORC_EPCGENERICRTDYLDMEMORYMANAGER_H
unsigned uint64_t
#define LLVM_ABI
Definition Compiler.h:215
Tagged union holding either a T or a Error.
Definition Error.h:485
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
This class is the base class for all object file types.
Definition ObjectFile.h:231
uint8_t * allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName, bool IsReadOnly) override
Allocate a memory block of (at least) the given size suitable for data.
bool finalizeMemory(std::string *ErrMsg=nullptr) override
This method is called when object loading is complete and section page permissions can be applied.
bool needsToReserveAllocationSpace() override
Override to return true to enable the reserveAllocationSpace callback.
static Expected< std::unique_ptr< EPCGenericRTDyldMemoryManager > > CreateWithDefaultBootstrapSymbols(ExecutorProcessControl &EPC)
Create an EPCGenericRTDyldMemoryManager using the given EPC, looking up the default symbol names in t...
EPCGenericRTDyldMemoryManager(ExecutorProcessControl &EPC, SymbolAddrs SAs)
Create an EPCGenericRTDyldMemoryManager using the given EPC and symbol addrs.
void reserveAllocationSpace(uintptr_t CodeSize, Align CodeAlign, uintptr_t RODataSize, Align RODataAlign, uintptr_t RWDataSize, Align RWDataAlign) override
Inform the memory manager about the total amount of memory required to allocate all sections to be lo...
void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override
Register the EH frames with the runtime so that c++ exceptions work.
void notifyObjectLoaded(RuntimeDyld &Dyld, const object::ObjectFile &Obj) override
This method is called after an object has been loaded into memory but before relocations are applied ...
EPCGenericRTDyldMemoryManager & operator=(EPCGenericRTDyldMemoryManager &&)=delete
uint8_t * allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName) override
Allocate a memory block of (at least) the given size suitable for executable code.
EPCGenericRTDyldMemoryManager(const EPCGenericRTDyldMemoryManager &)=delete
EPCGenericRTDyldMemoryManager & operator=(const EPCGenericRTDyldMemoryManager &)=delete
EPCGenericRTDyldMemoryManager(EPCGenericRTDyldMemoryManager &&)=delete
Represents an address in the executor process.
ExecutorProcessControl supports interaction with a JIT target process.
This is an optimization pass for GlobalISel generic memory operations.
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Bindings to the executor-side memory manager, plus the EH-frame registration alloc-action wrappers.
The resolved controller-side handle to an executor-side memory manager: the address of the manager in...