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