LLVM  14.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 
22 namespace llvm {
23 namespace orc {
24 
25 /// Remote-mapped RuntimeDyld-compatible memory manager.
27 public:
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 
49  operator=(const EPCGenericRTDyldMemoryManager &) = delete;
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, uint32_t CodeAlign,
64  uintptr_t RODataSize, uint32_t RODataAlign,
65  uintptr_t RWDataSize,
66  uint32_t 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 
79 private:
80  struct Alloc {
81  public:
82  Alloc(uint64_t Size, unsigned Align)
83  : Size(Size), Align(Align),
84  Contents(std::make_unique<uint8_t[]>(Size + Align - 1)) {}
85 
86  uint64_t Size;
87  unsigned Align;
88  std::unique_ptr<uint8_t[]> Contents;
89  ExecutorAddr RemoteAddr;
90  };
91 
92  struct EHFrame {
93  ExecutorAddr Addr;
94  uint64_t Size;
95  };
96 
97  // Group of section allocations to be allocated together in the executor. The
98  // RemoteCodeAddr will stand in as the id of the group for deallocation
99  // purposes.
100  struct AllocGroup {
101  AllocGroup() = default;
102  AllocGroup(const AllocGroup &) = delete;
103  AllocGroup &operator=(const AllocGroup &) = delete;
104  AllocGroup(AllocGroup &&) = default;
105  AllocGroup &operator=(AllocGroup &&) = default;
106 
107  ExecutorAddrRange RemoteCode;
108  ExecutorAddrRange RemoteROData;
109  ExecutorAddrRange RemoteRWData;
110  std::vector<EHFrame> UnfinalizedEHFrames;
111  std::vector<Alloc> CodeAllocs, RODataAllocs, RWDataAllocs;
112  };
113 
114  // Maps all allocations in Allocs to aligned blocks
115  void mapAllocsToRemoteAddrs(RuntimeDyld &Dyld, std::vector<Alloc> &Allocs,
116  ExecutorAddr NextAddr);
117 
118  ExecutorProcessControl &EPC;
119  SymbolAddrs SAs;
120 
121  std::mutex M;
122  std::vector<AllocGroup> Unmapped;
123  std::vector<AllocGroup> Unfinalized;
124  std::vector<ExecutorAddr> FinalizedAllocs;
125  std::string ErrMsg;
126 };
127 
128 } // end namespace orc
129 } // end namespace llvm
130 
131 #undef DEBUG_TYPE
132 
133 #endif // LLVM_EXECUTIONENGINE_ORC_EPCGENERICRTDYLDMEMORYMANAGER_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:37
llvm::orc::EPCGenericRTDyldMemoryManager::deregisterEHFrames
void deregisterEHFrames() override
Definition: EPCGenericRTDyldMemoryManager.cpp:183
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::orc::EPCGenericRTDyldMemoryManager::SymbolAddrs::DeregisterEHFrame
ExecutorAddr DeregisterEHFrame
Definition: EPCGenericRTDyldMemoryManager.h:35
llvm::orc::EPCGenericRTDyldMemoryManager::reserveAllocationSpace
void reserveAllocationSpace(uintptr_t CodeSize, uint32_t CodeAlign, uintptr_t RODataSize, uint32_t RODataAlign, uintptr_t RWDataSize, uint32_t RWDataAlign) override
Inform the memory manager about the total amount of memory required to allocate all sections to be lo...
Definition: EPCGenericRTDyldMemoryManager.cpp:96
llvm::orc::EPCGenericRTDyldMemoryManager::SymbolAddrs::Finalize
ExecutorAddr Finalize
Definition: EPCGenericRTDyldMemoryManager.h:32
llvm::orc::EPCGenericRTDyldMemoryManager::operator=
EPCGenericRTDyldMemoryManager & operator=(const EPCGenericRTDyldMemoryManager &)=delete
llvm::orc::EPCGenericRTDyldMemoryManager::allocateCodeSection
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.
Definition: EPCGenericRTDyldMemoryManager.cpp:62
llvm::orc::ExecutorProcessControl
ExecutorProcessControl supports interaction with a JIT target process.
Definition: ExecutorProcessControl.h:38
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::orc::EPCGenericRTDyldMemoryManager::notifyObjectLoaded
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 ...
Definition: EPCGenericRTDyldMemoryManager.cpp:187
RuntimeDyld.h
llvm::orc::EPCGenericRTDyldMemoryManager::CreateWithDefaultBootstrapSymbols
static Expected< std::unique_ptr< EPCGenericRTDyldMemoryManager > > CreateWithDefaultBootstrapSymbols(ExecutorProcessControl &EPC)
Create an EPCGenericRTDyldMemoryManager using the given EPC, looking up the default symbol names in t...
Definition: EPCGenericRTDyldMemoryManager.cpp:21
llvm::orc::EPCGenericRTDyldMemoryManager::SymbolAddrs
Symbol addresses for memory access.
Definition: EPCGenericRTDyldMemoryManager.h:29
llvm::orc::EPCGenericRTDyldMemoryManager::allocateDataSection
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.
Definition: EPCGenericRTDyldMemoryManager.cpp:77
llvm::orc::EPCGenericRTDyldMemoryManager::registerEHFrames
void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override
Register the EH frames with the runtime so that c++ exceptions work.
Definition: EPCGenericRTDyldMemoryManager.cpp:160
llvm::orc::EPCGenericRTDyldMemoryManager::needsToReserveAllocationSpace
bool needsToReserveAllocationSpace() override
Override to return true to enable the reserveAllocationSpace callback.
Definition: EPCGenericRTDyldMemoryManager.cpp:156
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::orc::EPCGenericRTDyldMemoryManager::SymbolAddrs::Reserve
ExecutorAddr Reserve
Definition: EPCGenericRTDyldMemoryManager.h:31
uint64_t
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::object::ObjectFile
This class is the base class for all object file types.
Definition: ObjectFile.h:228
uint32_t
llvm::orc::EPCGenericRTDyldMemoryManager::EPCGenericRTDyldMemoryManager
EPCGenericRTDyldMemoryManager(ExecutorProcessControl &EPC, SymbolAddrs SAs)
Create an EPCGenericRTDyldMemoryManager using the given EPC and symbol addrs.
Definition: EPCGenericRTDyldMemoryManager.cpp:38
llvm::orc::EPCGenericRTDyldMemoryManager::SymbolAddrs::Deallocate
ExecutorAddr Deallocate
Definition: EPCGenericRTDyldMemoryManager.h:33
llvm::orc::EPCGenericRTDyldMemoryManager::SymbolAddrs::Instance
ExecutorAddr Instance
Definition: EPCGenericRTDyldMemoryManager.h:30
std
Definition: BitVector.h:838
llvm::orc::EPCGenericRTDyldMemoryManager
Remote-mapped RuntimeDyld-compatible memory manager.
Definition: EPCGenericRTDyldMemoryManager.h:26
llvm::SectionName
Definition: DWARFSection.h:21
llvm::orc::EPCGenericRTDyldMemoryManager::SymbolAddrs::RegisterEHFrame
ExecutorAddr RegisterEHFrame
Definition: EPCGenericRTDyldMemoryManager.h:34
llvm::RuntimeDyld::MemoryManager::RuntimeDyld
friend class RuntimeDyld
Definition: RuntimeDyld.h:93
ExecutorProcessControl.h
llvm::RuntimeDyld
Definition: RuntimeDyld.h:58
llvm::orc::EPCGenericRTDyldMemoryManager::~EPCGenericRTDyldMemoryManager
~EPCGenericRTDyldMemoryManager()
Definition: EPCGenericRTDyldMemoryManager.cpp:44
llvm::orc::EPCGenericRTDyldMemoryManager::finalizeMemory
bool finalizeMemory(std::string *ErrMsg=nullptr) override
This method is called when object loading is complete and section page permissions can be applied.
Definition: EPCGenericRTDyldMemoryManager.cpp:203
llvm::RuntimeDyld::MemoryManager
Memory Management.
Definition: RuntimeDyld.h:92