[RuntimeDyld] Track symbol visibility in RuntimeDyld.
[oota-llvm.git] / include / llvm / ExecutionEngine / RuntimeDyld.h
index 30c0d49ade038c142b4c809fbd981151aedc9364..720429e7b5c03e79877ded56ea91214f98573072 100644 (file)
 #define LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
 
 #include "llvm/ADT/StringRef.h"
-#include "llvm/ExecutionEngine/ObjectBuffer.h"
 #include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
 #include "llvm/Support/Memory.h"
+#include <memory>
 
 namespace llvm {
 
 namespace object {
   class ObjectFile;
+  template <typename T> class OwningBinary;
 }
 
 class RuntimeDyldImpl;
-class ObjectImage;
+class RuntimeDyldCheckerImpl;
 
 class RuntimeDyld {
+  friend class RuntimeDyldCheckerImpl;
+
   RuntimeDyld(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
   void operator=(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
 
   // RuntimeDyldImpl is the actual class. RuntimeDyld is just the public
   // interface.
-  RuntimeDyldImpl *Dyld;
+  std::unique_ptr<RuntimeDyldImpl> Dyld;
   RTDyldMemoryManager *MM;
   bool ProcessAllSections;
+  RuntimeDyldCheckerImpl *Checker;
 protected:
   // Change the address associated with a section when resolving relocations.
   // Any relocations already associated with the symbol will be re-resolved.
   void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
 public:
+
+  /// \brief Information about the loaded object.
+  class LoadedObjectInfo {
+    friend class RuntimeDyldImpl;
+  public:
+    LoadedObjectInfo(RuntimeDyldImpl &RTDyld, unsigned BeginIdx,
+                     unsigned EndIdx)
+      : RTDyld(RTDyld), BeginIdx(BeginIdx), EndIdx(EndIdx) { }
+
+    virtual ~LoadedObjectInfo() {}
+
+    virtual object::OwningBinary<object::ObjectFile>
+    getObjectForDebug(const object::ObjectFile &Obj) const = 0;
+
+    uint64_t getSectionLoadAddress(StringRef Name) const;
+
+  protected:
+    virtual void anchor();
+
+    RuntimeDyldImpl &RTDyld;
+    unsigned BeginIdx, EndIdx;
+  };
+
   RuntimeDyld(RTDyldMemoryManager *);
   ~RuntimeDyld();
 
-  /// Prepare the object contained in the input buffer for execution.
-  /// Ownership of the input buffer is transferred to the ObjectImage
-  /// instance returned from this function if successful. In the case of load
-  /// failure, the input buffer will be deleted.
-  ObjectImage *loadObject(ObjectBuffer *InputBuffer);
-
-  /// Prepare the referenced object file for execution.
-  /// Ownership of the input object is transferred to the ObjectImage
-  /// instance returned from this function if successful. In the case of load
-  /// failure, the input object will be deleted.
-  ObjectImage *loadObject(std::unique_ptr<object::ObjectFile> InputObject);
+  /// Add the referenced object file to the list of objects to be loaded and
+  /// relocated.
+  std::unique_ptr<LoadedObjectInfo> loadObject(const object::ObjectFile &O);
 
   /// Get the address of our local copy of the symbol. This may or may not
   /// be the address used for relocation (clients can copy the data around
   /// and resolve relocatons based on where they put it).
-  void *getSymbolAddress(StringRef Name);
+  void *getSymbolAddress(StringRef Name) const;
+
+  /// Get the address of the target copy of the symbol (works for both exported
+  /// and non-exported symbols). This is the address used for relocation.
+  uint64_t getSymbolLoadAddress(StringRef Name) const;
 
-  /// Get the address of the target copy of the symbol. This is the address
-  /// used for relocation.
-  uint64_t getSymbolLoadAddress(StringRef Name);
+  /// Get the address of the target copy of the symbol (works for exported
+  /// symbols only). This is the address used for relocation.
+  uint64_t getExportedSymbolLoadAddress(StringRef Name) const;
 
   /// Resolve the relocations for all symbols we currently know about.
   void resolveRelocations();