LLVM API Documentation

RuntimeDyld.h
Go to the documentation of this file.
00001 //===-- RuntimeDyld.h - Run-time dynamic linker for MC-JIT ------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // Interface for the runtime dynamic linker facilities of the MC-JIT.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
00015 #define LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
00016 
00017 #include "llvm/ADT/StringRef.h"
00018 #include "llvm/ExecutionEngine/ObjectBuffer.h"
00019 #include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
00020 #include "llvm/Support/Memory.h"
00021 
00022 namespace llvm {
00023 
00024 namespace object {
00025   class ObjectFile;
00026 }
00027 
00028 class RuntimeDyldImpl;
00029 class RuntimeDyldCheckerImpl;
00030 class ObjectImage;
00031 
00032 class RuntimeDyld {
00033   friend class RuntimeDyldCheckerImpl;
00034 
00035   RuntimeDyld(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
00036   void operator=(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
00037 
00038   // RuntimeDyldImpl is the actual class. RuntimeDyld is just the public
00039   // interface.
00040   std::unique_ptr<RuntimeDyldImpl> Dyld;
00041   RTDyldMemoryManager *MM;
00042   bool ProcessAllSections;
00043   RuntimeDyldCheckerImpl *Checker;
00044 protected:
00045   // Change the address associated with a section when resolving relocations.
00046   // Any relocations already associated with the symbol will be re-resolved.
00047   void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
00048 public:
00049   RuntimeDyld(RTDyldMemoryManager *);
00050   ~RuntimeDyld();
00051 
00052   /// Prepare the object contained in the input buffer for execution.
00053   /// Ownership of the input buffer is transferred to the ObjectImage
00054   /// instance returned from this function if successful. In the case of load
00055   /// failure, the input buffer will be deleted.
00056   std::unique_ptr<ObjectImage>
00057   loadObject(std::unique_ptr<ObjectBuffer> InputBuffer);
00058 
00059   /// Prepare the referenced object file for execution.
00060   /// Ownership of the input object is transferred to the ObjectImage
00061   /// instance returned from this function if successful. In the case of load
00062   /// failure, the input object will be deleted.
00063   std::unique_ptr<ObjectImage>
00064   loadObject(std::unique_ptr<object::ObjectFile> InputObject);
00065 
00066   /// Get the address of our local copy of the symbol. This may or may not
00067   /// be the address used for relocation (clients can copy the data around
00068   /// and resolve relocatons based on where they put it).
00069   void *getSymbolAddress(StringRef Name) const;
00070 
00071   /// Get the address of the target copy of the symbol. This is the address
00072   /// used for relocation.
00073   uint64_t getSymbolLoadAddress(StringRef Name) const;
00074 
00075   /// Resolve the relocations for all symbols we currently know about.
00076   void resolveRelocations();
00077 
00078   /// Map a section to its target address space value.
00079   /// Map the address of a JIT section as returned from the memory manager
00080   /// to the address in the target process as the running code will see it.
00081   /// This is the address which will be used for relocation resolution.
00082   void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress);
00083 
00084   /// Register any EH frame sections that have been loaded but not previously
00085   /// registered with the memory manager.  Note, RuntimeDyld is responsible
00086   /// for identifying the EH frame and calling the memory manager with the
00087   /// EH frame section data.  However, the memory manager itself will handle
00088   /// the actual target-specific EH frame registration.
00089   void registerEHFrames();
00090 
00091   void deregisterEHFrames();
00092 
00093   bool hasError();
00094   StringRef getErrorString();
00095 
00096   /// By default, only sections that are "required for execution" are passed to
00097   /// the RTDyldMemoryManager, and other sections are discarded. Passing 'true'
00098   /// to this method will cause RuntimeDyld to pass all sections to its
00099   /// memory manager regardless of whether they are "required to execute" in the
00100   /// usual sense. This is useful for inspecting metadata sections that may not
00101   /// contain relocations, E.g. Debug info, stackmaps.
00102   ///
00103   /// Must be called before the first object file is loaded.
00104   void setProcessAllSections(bool ProcessAllSections) {
00105     assert(!Dyld && "setProcessAllSections must be called before loadObject.");
00106     this->ProcessAllSections = ProcessAllSections;
00107   }
00108 };
00109 
00110 } // end namespace llvm
00111 
00112 #endif