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 "JITSymbolFlags.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
20 #include "llvm/Support/Memory.h"
27 template <typename T> class OwningBinary;
30 class RuntimeDyldImpl;
31 class RuntimeDyldCheckerImpl;
34 friend class RuntimeDyldCheckerImpl;
36 RuntimeDyld(const RuntimeDyld &) = delete;
37 void operator=(const RuntimeDyld &) = delete;
39 // RuntimeDyldImpl is the actual class. RuntimeDyld is just the public
41 std::unique_ptr<RuntimeDyldImpl> Dyld;
42 RTDyldMemoryManager *MM;
43 bool ProcessAllSections;
44 RuntimeDyldCheckerImpl *Checker;
46 // Change the address associated with a section when resolving relocations.
47 // Any relocations already associated with the symbol will be re-resolved.
48 void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
51 /// \brief Information about a named symbol.
52 class SymbolInfo : public JITSymbolBase {
54 SymbolInfo(std::nullptr_t) : JITSymbolBase(JITSymbolFlags::None), Address(0) {}
55 SymbolInfo(uint64_t Address, JITSymbolFlags Flags)
56 : JITSymbolBase(Flags), Address(Address) {}
57 explicit operator bool() const { return Address != 0; }
58 uint64_t getAddress() const { return Address; }
63 /// \brief Information about the loaded object.
64 class LoadedObjectInfo {
65 friend class RuntimeDyldImpl;
67 LoadedObjectInfo(RuntimeDyldImpl &RTDyld, unsigned BeginIdx,
69 : RTDyld(RTDyld), BeginIdx(BeginIdx), EndIdx(EndIdx) { }
71 virtual ~LoadedObjectInfo() {}
73 virtual object::OwningBinary<object::ObjectFile>
74 getObjectForDebug(const object::ObjectFile &Obj) const = 0;
76 uint64_t getSectionLoadAddress(StringRef Name) const;
79 virtual void anchor();
81 RuntimeDyldImpl &RTDyld;
82 unsigned BeginIdx, EndIdx;
85 RuntimeDyld(RTDyldMemoryManager *);
88 /// Add the referenced object file to the list of objects to be loaded and
90 std::unique_ptr<LoadedObjectInfo> loadObject(const object::ObjectFile &O);
92 /// Get the address of our local copy of the symbol. This may or may not
93 /// be the address used for relocation (clients can copy the data around
94 /// and resolve relocatons based on where they put it).
95 void *getSymbolLocalAddress(StringRef Name) const;
97 /// Get the target address and flags for the named symbol.
98 /// This address is the one used for relocation.
99 SymbolInfo getSymbol(StringRef Name) const;
101 /// Resolve the relocations for all symbols we currently know about.
102 void resolveRelocations();
104 /// Map a section to its target address space value.
105 /// Map the address of a JIT section as returned from the memory manager
106 /// to the address in the target process as the running code will see it.
107 /// This is the address which will be used for relocation resolution.
108 void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress);
110 /// Register any EH frame sections that have been loaded but not previously
111 /// registered with the memory manager. Note, RuntimeDyld is responsible
112 /// for identifying the EH frame and calling the memory manager with the
113 /// EH frame section data. However, the memory manager itself will handle
114 /// the actual target-specific EH frame registration.
115 void registerEHFrames();
117 void deregisterEHFrames();
120 StringRef getErrorString();
122 /// By default, only sections that are "required for execution" are passed to
123 /// the RTDyldMemoryManager, and other sections are discarded. Passing 'true'
124 /// to this method will cause RuntimeDyld to pass all sections to its
125 /// memory manager regardless of whether they are "required to execute" in the
126 /// usual sense. This is useful for inspecting metadata sections that may not
127 /// contain relocations, E.g. Debug info, stackmaps.
129 /// Must be called before the first object file is loaded.
130 void setProcessAllSections(bool ProcessAllSections) {
131 assert(!Dyld && "setProcessAllSections must be called before loadObject.");
132 this->ProcessAllSections = ProcessAllSections;
136 } // end namespace llvm