LLVM 17.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
19
20#define DEBUG_TYPE "orc"
21
22namespace llvm {
23namespace orc {
24
25/// Remote-mapped RuntimeDyld-compatible memory manager.
27public:
28 /// Symbol addresses for memory access.
29 struct SymbolAddrs {
36 };
37
38 /// Create an EPCGenericRTDyldMemoryManager using the given EPC, looking up
39 /// the default symbol names in the bootstrap symbol set.
42
43 /// Create an EPCGenericRTDyldMemoryManager using the given EPC and symbol
44 /// addrs.
46
54
55 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
56 unsigned SectionID,
57 StringRef SectionName) override;
58
59 uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
60 unsigned SectionID, StringRef SectionName,
61 bool IsReadOnly) override;
62
63 void reserveAllocationSpace(uintptr_t CodeSize, Align CodeAlign,
64 uintptr_t RODataSize, Align RODataAlign,
65 uintptr_t RWDataSize, Align RWDataAlign) override;
66
67 bool needsToReserveAllocationSpace() override;
68
69 void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override;
70
71 void deregisterEHFrames() override;
72
74 const object::ObjectFile &Obj) override;
75
76 bool finalizeMemory(std::string *ErrMsg = nullptr) override;
77
78private:
79 struct SectionAlloc {
80 public:
81 SectionAlloc(uint64_t Size, unsigned Align)
82 : Size(Size), Align(Align),
83 Contents(std::make_unique<uint8_t[]>(Size + Align - 1)) {}
84
85 uint64_t Size;
86 unsigned Align;
87 std::unique_ptr<uint8_t[]> Contents;
88 ExecutorAddr RemoteAddr;
89 };
90
91 // Group of section allocations to be allocated together in the executor. The
92 // RemoteCodeAddr will stand in as the id of the group for deallocation
93 // purposes.
94 struct SectionAllocGroup {
95 SectionAllocGroup() = default;
96 SectionAllocGroup(const SectionAllocGroup &) = delete;
97 SectionAllocGroup &operator=(const SectionAllocGroup &) = delete;
98 SectionAllocGroup(SectionAllocGroup &&) = default;
99 SectionAllocGroup &operator=(SectionAllocGroup &&) = default;
100
101 ExecutorAddrRange RemoteCode;
102 ExecutorAddrRange RemoteROData;
103 ExecutorAddrRange RemoteRWData;
104 std::vector<ExecutorAddrRange> UnfinalizedEHFrames;
105 std::vector<SectionAlloc> CodeAllocs, RODataAllocs, RWDataAllocs;
106 };
107
108 // Maps all allocations in SectionAllocs to aligned blocks
109 void mapAllocsToRemoteAddrs(RuntimeDyld &Dyld,
110 std::vector<SectionAlloc> &SecAllocs,
111 ExecutorAddr NextAddr);
112
113 ExecutorProcessControl &EPC;
114 SymbolAddrs SAs;
115
116 std::mutex M;
117 std::vector<SectionAllocGroup> Unmapped;
118 std::vector<SectionAllocGroup> Unfinalized;
119 std::vector<ExecutorAddr> FinalizedAllocs;
120 std::string ErrMsg;
121};
122
123} // end namespace orc
124} // end namespace llvm
125
126#undef DEBUG_TYPE
127
128#endif // LLVM_EXECUTIONENGINE_ORC_EPCGENERICRTDYLDMEMORYMANAGER_H
uint64_t Addr
uint64_t Size
Tagged union holding either a T or a Error.
Definition: Error.h:470
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This class is the base class for all object file types.
Definition: ObjectFile.h:228
Remote-mapped RuntimeDyld-compatible memory manager.
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...
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.
Definition: AddressRanges.h:18
Definition: BitVector.h:851
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39