diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-05-27 18:44:32 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-05-27 18:44:32 +0000 | 
| commit | 5a5ac124e1efaf208671f01c46edb15f29ed2a0b (patch) | |
| tree | a6140557876943cdd800ee997c9317283394b22c /include/llvm/ExecutionEngine/RTDyldMemoryManager.h | |
| parent | f03b5bed27d0d2eafd68562ce14f8b5e3f1f0801 (diff) | |
Notes
Diffstat (limited to 'include/llvm/ExecutionEngine/RTDyldMemoryManager.h')
| -rw-r--r-- | include/llvm/ExecutionEngine/RTDyldMemoryManager.h | 133 | 
1 files changed, 67 insertions, 66 deletions
| diff --git a/include/llvm/ExecutionEngine/RTDyldMemoryManager.h b/include/llvm/ExecutionEngine/RTDyldMemoryManager.h index ef81cd328bdb..207bad06c239 100644 --- a/include/llvm/ExecutionEngine/RTDyldMemoryManager.h +++ b/include/llvm/ExecutionEngine/RTDyldMemoryManager.h @@ -14,6 +14,7 @@  #ifndef LLVM_EXECUTIONENGINE_RTDYLDMEMORYMANAGER_H  #define LLVM_EXECUTIONENGINE_RTDYLDMEMORYMANAGER_H +#include "RuntimeDyld.h"  #include "llvm-c/ExecutionEngine.h"  #include "llvm/ADT/StringRef.h"  #include "llvm/Support/CBindingWrapping.h" @@ -27,68 +28,91 @@ class ExecutionEngine;      class ObjectFile;    } +class MCJITMemoryManager : public RuntimeDyld::MemoryManager { +public: +  /// This method is called after an object has been loaded into memory but +  /// before relocations are applied to the loaded sections.  The object load +  /// may have been initiated by MCJIT to resolve an external symbol for another +  /// object that is being finalized.  In that case, the object about which +  /// the memory manager is being notified will be finalized immediately after +  /// the memory manager returns from this call. +  /// +  /// Memory managers which are preparing code for execution in an external +  /// address space can use this call to remap the section addresses for the +  /// newly loaded object. +  virtual void notifyObjectLoaded(ExecutionEngine *EE, +                                  const object::ObjectFile &) {} +}; +  // RuntimeDyld clients often want to handle the memory management of  // what gets placed where. For JIT clients, this is the subset of  // JITMemoryManager required for dynamic loading of binaries.  //  // FIXME: As the RuntimeDyld fills out, additional routines will be needed  //        for the varying types of objects to be allocated. -class RTDyldMemoryManager { -  RTDyldMemoryManager(const RTDyldMemoryManager&) LLVM_DELETED_FUNCTION; -  void operator=(const RTDyldMemoryManager&) LLVM_DELETED_FUNCTION; +class RTDyldMemoryManager : public MCJITMemoryManager, +                            public RuntimeDyld::SymbolResolver { +  RTDyldMemoryManager(const RTDyldMemoryManager&) = delete; +  void operator=(const RTDyldMemoryManager&) = delete;  public:    RTDyldMemoryManager() {} -  virtual ~RTDyldMemoryManager(); - -  /// Allocate a memory block of (at least) the given size suitable for -  /// executable code. The SectionID is a unique identifier assigned by the JIT -  /// engine, and optionally recorded by the memory manager to access a loaded -  /// section. -  virtual uint8_t *allocateCodeSection( -    uintptr_t Size, unsigned Alignment, unsigned SectionID, -    StringRef SectionName) = 0; - -  /// Allocate a memory block of (at least) the given size suitable for data. -  /// The SectionID is a unique identifier assigned by the JIT engine, and -  /// optionally recorded by the memory manager to access a loaded section. -  virtual uint8_t *allocateDataSection( -    uintptr_t Size, unsigned Alignment, unsigned SectionID, -    StringRef SectionName, bool IsReadOnly) = 0; - -  /// Inform the memory manager about the total amount of memory required to -  /// allocate all sections to be loaded: -  /// \p CodeSize - the total size of all code sections -  /// \p DataSizeRO - the total size of all read-only data sections -  /// \p DataSizeRW - the total size of all read-write data sections -  ///  -  /// Note that by default the callback is disabled. To enable it -  /// redefine the method needsToReserveAllocationSpace to return true. -  virtual void reserveAllocationSpace( -    uintptr_t CodeSize, uintptr_t DataSizeRO, uintptr_t DataSizeRW) { } -   -  /// Override to return true to enable the reserveAllocationSpace callback. -  virtual bool needsToReserveAllocationSpace() { return false; } - -  /// Register the EH frames with the runtime so that c++ exceptions work. -  /// -  /// \p Addr parameter provides the local address of the EH frame section -  /// data, while \p LoadAddr provides the address of the data in the target -  /// address space.  If the section has not been remapped (which will usually -  /// be the case for local execution) these two values will be the same. -  virtual void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size); +  ~RTDyldMemoryManager() override; -  virtual void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size); +  void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override; +  void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override;    /// This method returns the address of the specified function or variable in    /// the current process.    static uint64_t getSymbolAddressInProcess(const std::string &Name); +  /// Legacy symbol lookup - DEPRECATED! Please override findSymbol instead. +  ///    /// This method returns the address of the specified function or variable.    /// It is used to resolve symbols during module linking.    virtual uint64_t getSymbolAddress(const std::string &Name) {      return getSymbolAddressInProcess(Name);    } +  /// This method returns a RuntimeDyld::SymbolInfo for the specified function +  /// or variable. It is used to resolve symbols during module linking. +  /// +  /// By default this falls back on the legacy lookup method: +  /// 'getSymbolAddress'. The address returned by getSymbolAddress is treated as +  /// a strong, exported symbol, consistent with historical treatment by +  /// RuntimeDyld. +  /// +  /// Clients writing custom RTDyldMemoryManagers are encouraged to override +  /// this method and return a SymbolInfo with the flags set correctly. This is +  /// necessary for RuntimeDyld to correctly handle weak and non-exported symbols. +  RuntimeDyld::SymbolInfo findSymbol(const std::string &Name) override { +    return RuntimeDyld::SymbolInfo(getSymbolAddress(Name), +                                   JITSymbolFlags::Exported); +  } + +  /// Legacy symbol lookup -- DEPRECATED! Please override +  /// findSymbolInLogicalDylib instead. +  /// +  /// Default to treating all modules as separate. +  virtual uint64_t getSymbolAddressInLogicalDylib(const std::string &Name) { +    return 0; +  } + +  /// Default to treating all modules as separate. +  /// +  /// By default this falls back on the legacy lookup method: +  /// 'getSymbolAddressInLogicalDylib'. The address returned by +  /// getSymbolAddressInLogicalDylib is treated as a strong, exported symbol, +  /// consistent with historical treatment by RuntimeDyld. +  /// +  /// Clients writing custom RTDyldMemoryManagers are encouraged to override +  /// this method and return a SymbolInfo with the flags set correctly. This is +  /// necessary for RuntimeDyld to correctly handle weak and non-exported symbols. +  RuntimeDyld::SymbolInfo +  findSymbolInLogicalDylib(const std::string &Name) override { +    return RuntimeDyld::SymbolInfo(getSymbolAddressInLogicalDylib(Name), +                                   JITSymbolFlags::Exported); +  } +    /// This method returns the address of the specified function. As such it is    /// only useful for resolving library symbols, not code generated symbols.    /// @@ -100,30 +124,6 @@ public:    /// MCJIT or RuntimeDyld.  Use getSymbolAddress instead.    virtual void *getPointerToNamedFunction(const std::string &Name,                                            bool AbortOnFailure = true); - -  /// This method is called after an object has been loaded into memory but -  /// before relocations are applied to the loaded sections.  The object load -  /// may have been initiated by MCJIT to resolve an external symbol for another -  /// object that is being finalized.  In that case, the object about which -  /// the memory manager is being notified will be finalized immediately after -  /// the memory manager returns from this call. -  /// -  /// Memory managers which are preparing code for execution in an external -  /// address space can use this call to remap the section addresses for the -  /// newly loaded object. -  virtual void notifyObjectLoaded(ExecutionEngine *EE, -                                  const object::ObjectFile &) {} - -  /// This method is called when object loading is complete and section page -  /// permissions can be applied.  It is up to the memory manager implementation -  /// to decide whether or not to act on this method.  The memory manager will -  /// typically allocate all sections as read-write and then apply specific -  /// permissions when this method is called.  Code sections cannot be executed -  /// until this function has been called.  In addition, any cache coherency -  /// operations needed to reliably use the memory are also performed. -  /// -  /// Returns true if an error occurred, false otherwise. -  virtual bool finalizeMemory(std::string *ErrMsg = nullptr) = 0;  };  // Create wrappers for C Binding types (see CBindingWrapping.h). @@ -132,4 +132,5 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(  } // namespace llvm +  #endif | 
