LLVM 22.0.0git
RTDyldMemoryManager.h
Go to the documentation of this file.
1//===-- RTDyldMemoryManager.cpp - Memory manager for MC-JIT -----*- 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// Interface of the runtime dynamic memory manager base class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_RTDYLDMEMORYMANAGER_H
14#define LLVM_EXECUTIONENGINE_RTDYLDMEMORYMANAGER_H
15
21#include <cstddef>
22#include <cstdint>
23#include <string>
24
25namespace llvm {
26
27class ExecutionEngine;
28
29namespace object {
30 class ObjectFile;
31} // end namespace object
32
34public:
35 // Don't hide the notifyObjectLoaded method from RuntimeDyld::MemoryManager.
37
38 /// This method is called after an object has been loaded into memory but
39 /// before relocations are applied to the loaded sections. The object load
40 /// may have been initiated by MCJIT to resolve an external symbol for another
41 /// object that is being finalized. In that case, the object about which
42 /// the memory manager is being notified will be finalized immediately after
43 /// the memory manager returns from this call.
44 ///
45 /// Memory managers which are preparing code for execution in an external
46 /// address space can use this call to remap the section addresses for the
47 /// newly loaded object.
49 const object::ObjectFile &) {}
50
51private:
52 void anchor() override;
53};
54
55// RuntimeDyld clients often want to handle the memory management of
56// what gets placed where. For JIT clients, this is the subset of
57// JITMemoryManager required for dynamic loading of binaries.
58//
59// FIXME: As the RuntimeDyld fills out, additional routines will be needed
60// for the varying types of objects to be allocated.
63public:
66 void operator=(const RTDyldMemoryManager&) = delete;
68
69 /// Register EH frames in the current process.
70 static void registerEHFramesInProcess(uint8_t *Addr, size_t Size);
71
72 /// Deregister EH frames in the current process.
73 static void deregisterEHFramesInProcess(uint8_t *Addr, size_t Size);
74
75 void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override;
76 void deregisterEHFrames() override;
77
78 /// This method returns the address of the specified function or variable in
79 /// the current process.
80 static uint64_t getSymbolAddressInProcess(const std::string &Name);
81
82 /// Legacy symbol lookup - DEPRECATED! Please override findSymbol instead.
83 ///
84 /// This method returns the address of the specified function or variable.
85 /// It is used to resolve symbols during module linking.
86 virtual uint64_t getSymbolAddress(const std::string &Name) {
87 return getSymbolAddressInProcess(Name);
88 }
89
90 /// This method returns a RuntimeDyld::SymbolInfo for the specified function
91 /// or variable. It is used to resolve symbols during module linking.
92 ///
93 /// By default this falls back on the legacy lookup method:
94 /// 'getSymbolAddress'. The address returned by getSymbolAddress is treated as
95 /// a strong, exported symbol, consistent with historical treatment by
96 /// RuntimeDyld.
97 ///
98 /// Clients writing custom RTDyldMemoryManagers are encouraged to override
99 /// this method and return a SymbolInfo with the flags set correctly. This is
100 /// necessary for RuntimeDyld to correctly handle weak and non-exported symbols.
101 JITSymbol findSymbol(const std::string &Name) override {
103 }
104
105 /// Legacy symbol lookup -- DEPRECATED! Please override
106 /// findSymbolInLogicalDylib instead.
107 ///
108 /// Default to treating all modules as separate.
109 virtual uint64_t getSymbolAddressInLogicalDylib(const std::string &Name) {
110 return 0;
111 }
112
113 /// Default to treating all modules as separate.
114 ///
115 /// By default this falls back on the legacy lookup method:
116 /// 'getSymbolAddressInLogicalDylib'. The address returned by
117 /// getSymbolAddressInLogicalDylib is treated as a strong, exported symbol,
118 /// consistent with historical treatment by RuntimeDyld.
119 ///
120 /// Clients writing custom RTDyldMemoryManagers are encouraged to override
121 /// this method and return a SymbolInfo with the flags set correctly. This is
122 /// necessary for RuntimeDyld to correctly handle weak and non-exported symbols.
124 findSymbolInLogicalDylib(const std::string &Name) override {
127 }
128
129 /// This method returns the address of the specified function. As such it is
130 /// only useful for resolving library symbols, not code generated symbols.
131 ///
132 /// If \p AbortOnFailure is false and no function with the given name is
133 /// found, this function returns a null pointer. Otherwise, it prints a
134 /// message to stderr and aborts.
135 ///
136 /// This function is deprecated for memory managers to be used with
137 /// MCJIT or RuntimeDyld. Use getSymbolAddress instead.
138 virtual void *getPointerToNamedFunction(const std::string &Name,
139 bool AbortOnFailure = true);
140
141protected:
142 struct EHFrame {
144 size_t Size;
145 };
146 typedef std::vector<EHFrame> EHFrameInfos;
148
149private:
150 void anchor() override;
151};
152
153// Create wrappers for C Binding types (see CBindingWrapping.h).
156
157} // end namespace llvm
158
159#endif // LLVM_EXECUTIONENGINE_RTDYLDMEMORYMANAGER_H
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
#define LLVM_ABI
Definition Compiler.h:213
Abstract interface for implementation execution of LLVM modules, designed to support both interpreter...
Represents a symbol in the JIT.
Definition JITSymbol.h:267
Legacy symbol resolution interface.
Definition JITSymbol.h:403
virtual void notifyObjectLoaded(ExecutionEngine *EE, const object::ObjectFile &)
This method is called after an object has been loaded into memory but before relocations are applied ...
static void deregisterEHFramesInProcess(uint8_t *Addr, size_t Size)
Deregister EH frames in the current process.
JITSymbol findSymbolInLogicalDylib(const std::string &Name) override
Default to treating all modules as separate.
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 operator=(const RTDyldMemoryManager &)=delete
virtual uint64_t getSymbolAddress(const std::string &Name)
Legacy symbol lookup - DEPRECATED!
static uint64_t getSymbolAddressInProcess(const std::string &Name)
This method returns the address of the specified function or variable in the current process.
JITSymbol findSymbol(const std::string &Name) override
This method returns a RuntimeDyld::SymbolInfo for the specified function or variable.
static void registerEHFramesInProcess(uint8_t *Addr, size_t Size)
Register EH frames in the current process.
virtual uint64_t getSymbolAddressInLogicalDylib(const std::string &Name)
Legacy symbol lookup – DEPRECATED!
RTDyldMemoryManager(const RTDyldMemoryManager &)=delete
std::vector< EHFrame > EHFrameInfos
virtual void notifyObjectLoaded(RuntimeDyld &RTDyld, const object::ObjectFile &Obj)
This method is called after an object has been loaded into memory but before relocations are applied ...
This class is the base class for all object file types.
Definition ObjectFile.h:231
struct LLVMOpaqueMCJITMemoryManager * LLVMMCJITMemoryManagerRef
This is an optimization pass for GlobalISel generic memory operations.