LLVM  4.0.0
RTDyldMemoryManager.h
Go to the documentation of this file.
1 //===-- RTDyldMemoryManager.cpp - Memory manager for MC-JIT -----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Interface of the runtime dynamic memory manager base class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_EXECUTIONENGINE_RTDYLDMEMORYMANAGER_H
15 #define LLVM_EXECUTIONENGINE_RTDYLDMEMORYMANAGER_H
16 
20 #include "llvm-c/ExecutionEngine.h"
21 #include <cstddef>
22 #include <cstdint>
23 #include <string>
24 
25 namespace llvm {
26 
27 class ExecutionEngine;
28 
29 namespace object {
30  class ObjectFile;
31 } // end namespace object
32 
34 public:
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 };
51 
52 // RuntimeDyld clients often want to handle the memory management of
53 // what gets placed where. For JIT clients, this is the subset of
54 // JITMemoryManager required for dynamic loading of binaries.
55 //
56 // FIXME: As the RuntimeDyld fills out, additional routines will be needed
57 // for the varying types of objects to be allocated.
59  public JITSymbolResolver {
60 public:
61  RTDyldMemoryManager() = default;
63  void operator=(const RTDyldMemoryManager&) = delete;
64  ~RTDyldMemoryManager() override;
65 
66  /// Register EH frames in the current process.
67  static void registerEHFramesInProcess(uint8_t *Addr, size_t Size);
68 
69  /// Deregister EH frames in the current proces.
70  static void deregisterEHFramesInProcess(uint8_t *Addr, size_t Size);
71 
72  void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override {
73  registerEHFramesInProcess(Addr, Size);
74  }
75 
76  void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override {
77  deregisterEHFramesInProcess(Addr, Size);
78  }
79 
80  /// This method returns the address of the specified function or variable in
81  /// the current process.
82  static uint64_t getSymbolAddressInProcess(const std::string &Name);
83 
84  /// Legacy symbol lookup - DEPRECATED! Please override findSymbol instead.
85  ///
86  /// This method returns the address of the specified function or variable.
87  /// It is used to resolve symbols during module linking.
88  virtual uint64_t getSymbolAddress(const std::string &Name) {
89  return getSymbolAddressInProcess(Name);
90  }
91 
92  /// This method returns a RuntimeDyld::SymbolInfo for the specified function
93  /// or variable. It is used to resolve symbols during module linking.
94  ///
95  /// By default this falls back on the legacy lookup method:
96  /// 'getSymbolAddress'. The address returned by getSymbolAddress is treated as
97  /// a strong, exported symbol, consistent with historical treatment by
98  /// RuntimeDyld.
99  ///
100  /// Clients writing custom RTDyldMemoryManagers are encouraged to override
101  /// this method and return a SymbolInfo with the flags set correctly. This is
102  /// necessary for RuntimeDyld to correctly handle weak and non-exported symbols.
103  JITSymbol findSymbol(const std::string &Name) override {
105  }
106 
107  /// Legacy symbol lookup -- DEPRECATED! Please override
108  /// findSymbolInLogicalDylib instead.
109  ///
110  /// Default to treating all modules as separate.
111  virtual uint64_t getSymbolAddressInLogicalDylib(const std::string &Name) {
112  return 0;
113  }
114 
115  /// Default to treating all modules as separate.
116  ///
117  /// By default this falls back on the legacy lookup method:
118  /// 'getSymbolAddressInLogicalDylib'. The address returned by
119  /// getSymbolAddressInLogicalDylib is treated as a strong, exported symbol,
120  /// consistent with historical treatment by RuntimeDyld.
121  ///
122  /// Clients writing custom RTDyldMemoryManagers are encouraged to override
123  /// this method and return a SymbolInfo with the flags set correctly. This is
124  /// necessary for RuntimeDyld to correctly handle weak and non-exported symbols.
125  JITSymbol
126  findSymbolInLogicalDylib(const std::string &Name) override {
129  }
130 
131  /// This method returns the address of the specified function. As such it is
132  /// only useful for resolving library symbols, not code generated symbols.
133  ///
134  /// If \p AbortOnFailure is false and no function with the given name is
135  /// found, this function returns a null pointer. Otherwise, it prints a
136  /// message to stderr and aborts.
137  ///
138  /// This function is deprecated for memory managers to be used with
139  /// MCJIT or RuntimeDyld. Use getSymbolAddress instead.
140  virtual void *getPointerToNamedFunction(const std::string &Name,
141  bool AbortOnFailure = true);
142 };
143 
144 // Create wrappers for C Binding types (see CBindingWrapping.h).
146  RTDyldMemoryManager, LLVMMCJITMemoryManagerRef)
147 
148 } // end namespace llvm
149 
150 #endif // LLVM_EXECUTIONENGINE_RTDYLDMEMORYMANAGER_H
Represents a symbol in the JIT.
Definition: JITSymbol.h:113
static void registerEHFramesInProcess(uint8_t *Addr, size_t Size)
Register EH frames in the current process.
void operator=(const RTDyldMemoryManager &)=delete
void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override
Register the EH frames with the runtime so that c++ exceptions work.
virtual uint64_t getSymbolAddress(const std::string &Name)
Legacy symbol lookup - DEPRECATED! Please override findSymbol instead.
This class is the base class for all object file types.
Definition: ObjectFile.h:178
struct LLVMOpaqueMCJITMemoryManager * LLVMMCJITMemoryManagerRef
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
static void deregisterEHFramesInProcess(uint8_t *Addr, size_t Size)
Deregister EH frames in the current proces.
void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override
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 ...
JITSymbol findSymbol(const std::string &Name) override
This method returns a RuntimeDyld::SymbolInfo for the specified function or variable.
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:178
Symbol resolution.
Definition: JITSymbol.h:165
Abstract interface for implementation execution of LLVM modules, designed to support both interpreter...
virtual uint64_t getSymbolAddressInLogicalDylib(const std::string &Name)
Legacy symbol lookup – DEPRECATED! Please override findSymbolInLogicalDylib instead.
JITSymbol findSymbolInLogicalDylib(const std::string &Name) override
Default to treating all modules as separate.
virtual void * getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure=true)
This method returns the address of the specified function.
static uint64_t getSymbolAddressInProcess(const std::string &Name)
This method returns the address of the specified function or variable in the current process...