f123ffb803bda86ab5079a3dd935b2ff0558ef97
[oota-llvm.git] / include / llvm / ExecutionEngine / RuntimeDyld.h
1 //===-- RuntimeDyld.h - Run-time dynamic linker 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 for the runtime dynamic linker facilities of the MC-JIT.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
15 #define LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
16
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ExecutionEngine/ObjectBuffer.h"
19 #include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
20 #include "llvm/Support/Memory.h"
21
22 namespace llvm {
23
24 namespace object {
25   class ObjectFile;
26 }
27
28 class RuntimeDyldImpl;
29 class ObjectImage;
30
31 class RuntimeDyld {
32   friend class RuntimeDyldChecker;
33
34   RuntimeDyld(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
35   void operator=(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
36
37   // RuntimeDyldImpl is the actual class. RuntimeDyld is just the public
38   // interface.
39   RuntimeDyldImpl *Dyld;
40   RTDyldMemoryManager *MM;
41   bool ProcessAllSections;
42 protected:
43   // Change the address associated with a section when resolving relocations.
44   // Any relocations already associated with the symbol will be re-resolved.
45   void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
46 public:
47   RuntimeDyld(RTDyldMemoryManager *);
48   ~RuntimeDyld();
49
50   /// Prepare the object contained in the input buffer for execution.
51   /// Ownership of the input buffer is transferred to the ObjectImage
52   /// instance returned from this function if successful. In the case of load
53   /// failure, the input buffer will be deleted.
54   ObjectImage *loadObject(ObjectBuffer *InputBuffer);
55
56   /// Prepare the referenced object file for execution.
57   /// Ownership of the input object is transferred to the ObjectImage
58   /// instance returned from this function if successful. In the case of load
59   /// failure, the input object will be deleted.
60   ObjectImage *loadObject(std::unique_ptr<object::ObjectFile> InputObject);
61
62   /// Get the address of our local copy of the symbol. This may or may not
63   /// be the address used for relocation (clients can copy the data around
64   /// and resolve relocatons based on where they put it).
65   void *getSymbolAddress(StringRef Name);
66
67   /// Get the address of the target copy of the symbol. This is the address
68   /// used for relocation.
69   uint64_t getSymbolLoadAddress(StringRef Name);
70
71   /// Resolve the relocations for all symbols we currently know about.
72   void resolveRelocations();
73
74   /// Map a section to its target address space value.
75   /// Map the address of a JIT section as returned from the memory manager
76   /// to the address in the target process as the running code will see it.
77   /// This is the address which will be used for relocation resolution.
78   void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress);
79
80   /// Register any EH frame sections that have been loaded but not previously
81   /// registered with the memory manager.  Note, RuntimeDyld is responsible
82   /// for identifying the EH frame and calling the memory manager with the
83   /// EH frame section data.  However, the memory manager itself will handle
84   /// the actual target-specific EH frame registration.
85   void registerEHFrames();
86
87   void deregisterEHFrames();
88
89   bool hasError();
90   StringRef getErrorString();
91
92   /// By default, only sections that are "required for execution" are passed to
93   /// the RTDyldMemoryManager, and other sections are discarded. Passing 'true'
94   /// to this method will cause RuntimeDyld to pass all sections to its
95   /// memory manager regardless of whether they are "required to execute" in the
96   /// usual sense. This is useful for inspecting metadata sections that may not
97   /// contain relocations, E.g. Debug info, stackmaps.
98   ///
99   /// Must be called before the first object file is loaded.
100   void setProcessAllSections(bool ProcessAllSections) {
101     assert(!Dyld && "setProcessAllSections must be called before loadObject.");
102     this->ProcessAllSections = ProcessAllSections;
103   }
104 };
105
106 } // end namespace llvm
107
108 #endif