LLVM  3.7.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 
17 #include "RuntimeDyld.h"
18 #include "llvm-c/ExecutionEngine.h"
19 #include "llvm/ADT/StringRef.h"
21 #include "llvm/Support/Memory.h"
22 
23 namespace llvm {
24 
25 class ExecutionEngine;
26 
27  namespace object {
28  class ObjectFile;
29  }
30 
32 public:
33  /// This method is called after an object has been loaded into memory but
34  /// before relocations are applied to the loaded sections. The object load
35  /// may have been initiated by MCJIT to resolve an external symbol for another
36  /// object that is being finalized. In that case, the object about which
37  /// the memory manager is being notified will be finalized immediately after
38  /// the memory manager returns from this call.
39  ///
40  /// Memory managers which are preparing code for execution in an external
41  /// address space can use this call to remap the section addresses for the
42  /// newly loaded object.
44  const object::ObjectFile &) {}
45 };
46 
47 // RuntimeDyld clients often want to handle the memory management of
48 // what gets placed where. For JIT clients, this is the subset of
49 // JITMemoryManager required for dynamic loading of binaries.
50 //
51 // FIXME: As the RuntimeDyld fills out, additional routines will be needed
52 // for the varying types of objects to be allocated.
56  void operator=(const RTDyldMemoryManager&) = delete;
57 public:
59  ~RTDyldMemoryManager() override;
60 
61  void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override;
62  void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override;
63 
64  /// This method returns the address of the specified function or variable in
65  /// the current process.
66  static uint64_t getSymbolAddressInProcess(const std::string &Name);
67 
68  /// Legacy symbol lookup - DEPRECATED! Please override findSymbol instead.
69  ///
70  /// This method returns the address of the specified function or variable.
71  /// It is used to resolve symbols during module linking.
72  virtual uint64_t getSymbolAddress(const std::string &Name) {
73  return getSymbolAddressInProcess(Name);
74  }
75 
76  /// This method returns a RuntimeDyld::SymbolInfo for the specified function
77  /// or variable. It is used to resolve symbols during module linking.
78  ///
79  /// By default this falls back on the legacy lookup method:
80  /// 'getSymbolAddress'. The address returned by getSymbolAddress is treated as
81  /// a strong, exported symbol, consistent with historical treatment by
82  /// RuntimeDyld.
83  ///
84  /// Clients writing custom RTDyldMemoryManagers are encouraged to override
85  /// this method and return a SymbolInfo with the flags set correctly. This is
86  /// necessary for RuntimeDyld to correctly handle weak and non-exported symbols.
87  RuntimeDyld::SymbolInfo findSymbol(const std::string &Name) override {
90  }
91 
92  /// Legacy symbol lookup -- DEPRECATED! Please override
93  /// findSymbolInLogicalDylib instead.
94  ///
95  /// Default to treating all modules as separate.
96  virtual uint64_t getSymbolAddressInLogicalDylib(const std::string &Name) {
97  return 0;
98  }
99 
100  /// Default to treating all modules as separate.
101  ///
102  /// By default this falls back on the legacy lookup method:
103  /// 'getSymbolAddressInLogicalDylib'. The address returned by
104  /// getSymbolAddressInLogicalDylib is treated as a strong, exported symbol,
105  /// consistent with historical treatment by RuntimeDyld.
106  ///
107  /// Clients writing custom RTDyldMemoryManagers are encouraged to override
108  /// this method and return a SymbolInfo with the flags set correctly. This is
109  /// necessary for RuntimeDyld to correctly handle weak and non-exported symbols.
111  findSymbolInLogicalDylib(const std::string &Name) override {
114  }
115 
116  /// This method returns the address of the specified function. As such it is
117  /// only useful for resolving library symbols, not code generated symbols.
118  ///
119  /// If \p AbortOnFailure is false and no function with the given name is
120  /// found, this function returns a null pointer. Otherwise, it prints a
121  /// message to stderr and aborts.
122  ///
123  /// This function is deprecated for memory managers to be used with
124  /// MCJIT or RuntimeDyld. Use getSymbolAddress instead.
125  virtual void *getPointerToNamedFunction(const std::string &Name,
126  bool AbortOnFailure = true);
127 };
128 
129 // Create wrappers for C Binding types (see CBindingWrapping.h).
131  RTDyldMemoryManager, LLVMMCJITMemoryManagerRef)
132 
133 } // namespace llvm
134 
135 
136 #endif
RuntimeDyld::SymbolInfo 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.
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:176
struct LLVMOpaqueMCJITMemoryManager * LLVMMCJITMemoryManagerRef
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
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 ...
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.
Information about a named symbol.
Definition: RuntimeDyld.h:47
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name) override
This method returns a RuntimeDyld::SymbolInfo for the specified function or variable.
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...