1 //===-- RuntimeDyld.h - Run-time dynamic linker for MC-JIT ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Interface for the runtime dynamic linker facilities of the MC-JIT.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
15 #define LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ExecutionEngine/ObjectBuffer.h"
19 #include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
20 #include "llvm/Support/Memory.h"
28 class RuntimeDyldImpl;
29 class RuntimeDyldCheckerImpl;
33 friend class RuntimeDyldCheckerImpl;
35 RuntimeDyld(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
36 void operator=(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
38 // RuntimeDyldImpl is the actual class. RuntimeDyld is just the public
40 std::unique_ptr<RuntimeDyldImpl> Dyld;
41 RTDyldMemoryManager *MM;
42 bool ProcessAllSections;
43 RuntimeDyldCheckerImpl *Checker;
45 // Change the address associated with a section when resolving relocations.
46 // Any relocations already associated with the symbol will be re-resolved.
47 void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
49 RuntimeDyld(RTDyldMemoryManager *);
52 /// Prepare the object contained in the input buffer for execution.
53 /// Ownership of the input buffer is transferred to the ObjectImage
54 /// instance returned from this function if successful. In the case of load
55 /// failure, the input buffer will be deleted.
56 std::unique_ptr<ObjectImage>
57 loadObject(std::unique_ptr<ObjectBuffer> InputBuffer);
59 /// Prepare the referenced object file for execution.
60 /// Ownership of the input object is transferred to the ObjectImage
61 /// instance returned from this function if successful. In the case of load
62 /// failure, the input object will be deleted.
63 std::unique_ptr<ObjectImage>
64 loadObject(std::unique_ptr<object::ObjectFile> InputObject);
66 /// Get the address of our local copy of the symbol. This may or may not
67 /// be the address used for relocation (clients can copy the data around
68 /// and resolve relocatons based on where they put it).
69 void *getSymbolAddress(StringRef Name);
71 /// Get the address of the target copy of the symbol. This is the address
72 /// used for relocation.
73 uint64_t getSymbolLoadAddress(StringRef Name);
75 /// Resolve the relocations for all symbols we currently know about.
76 void resolveRelocations();
78 /// Map a section to its target address space value.
79 /// Map the address of a JIT section as returned from the memory manager
80 /// to the address in the target process as the running code will see it.
81 /// This is the address which will be used for relocation resolution.
82 void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress);
84 /// Register any EH frame sections that have been loaded but not previously
85 /// registered with the memory manager. Note, RuntimeDyld is responsible
86 /// for identifying the EH frame and calling the memory manager with the
87 /// EH frame section data. However, the memory manager itself will handle
88 /// the actual target-specific EH frame registration.
89 void registerEHFrames();
91 void deregisterEHFrames();
94 StringRef getErrorString();
96 /// By default, only sections that are "required for execution" are passed to
97 /// the RTDyldMemoryManager, and other sections are discarded. Passing 'true'
98 /// to this method will cause RuntimeDyld to pass all sections to its
99 /// memory manager regardless of whether they are "required to execute" in the
100 /// usual sense. This is useful for inspecting metadata sections that may not
101 /// contain relocations, E.g. Debug info, stackmaps.
103 /// Must be called before the first object file is loaded.
104 void setProcessAllSections(bool ProcessAllSections) {
105 assert(!Dyld && "setProcessAllSections must be called before loadObject.");
106 this->ProcessAllSections = ProcessAllSections;
110 } // end namespace llvm