1 //===-- RuntimeDyldELF.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 // ELF support for MC-JIT runtime dynamic linker.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDELF_H
15 #define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDELF_H
17 #include "RuntimeDyldImpl.h"
18 #include "llvm/ADT/DenseMap.h"
24 class RuntimeDyldELF : public RuntimeDyldImpl {
26 void resolveRelocation(const SectionEntry &Section, uint64_t Offset,
27 uint64_t Value, uint32_t Type, int64_t Addend,
28 uint64_t SymOffset = 0);
30 void resolveX86_64Relocation(const SectionEntry &Section, uint64_t Offset,
31 uint64_t Value, uint32_t Type, int64_t Addend,
34 void resolveX86Relocation(const SectionEntry &Section, uint64_t Offset,
35 uint32_t Value, uint32_t Type, int32_t Addend);
37 void resolveAArch64Relocation(const SectionEntry &Section, uint64_t Offset,
38 uint64_t Value, uint32_t Type, int64_t Addend);
40 void resolveARMRelocation(const SectionEntry &Section, uint64_t Offset,
41 uint32_t Value, uint32_t Type, int32_t Addend);
43 void resolveMIPSRelocation(const SectionEntry &Section, uint64_t Offset,
44 uint32_t Value, uint32_t Type, int32_t Addend);
46 void resolvePPC64Relocation(const SectionEntry &Section, uint64_t Offset,
47 uint64_t Value, uint32_t Type, int64_t Addend);
49 void resolveSystemZRelocation(const SectionEntry &Section, uint64_t Offset,
50 uint64_t Value, uint32_t Type, int64_t Addend);
52 unsigned getMaxStubSize() override {
53 if (Arch == Triple::aarch64 || Arch == Triple::aarch64_be)
54 return 20; // movz; movk; movk; movk; br
55 if (Arch == Triple::arm || Arch == Triple::thumb)
56 return 8; // 32-bit instruction and 32-bit address
57 else if (Arch == Triple::mipsel || Arch == Triple::mips)
59 else if (Arch == Triple::ppc64 || Arch == Triple::ppc64le)
61 else if (Arch == Triple::x86_64)
62 return 6; // 2-byte jmp instruction + 32-bit relative address
63 else if (Arch == Triple::systemz)
69 unsigned getStubAlignment() override {
70 if (Arch == Triple::systemz)
76 void findPPC64TOCSection(const ObjectFile &Obj,
77 ObjSectionToIDMap &LocalSections,
78 RelocationValueRef &Rel);
79 void findOPDEntrySection(const ObjectFile &Obj,
80 ObjSectionToIDMap &LocalSections,
81 RelocationValueRef &Rel);
83 size_t getGOTEntrySize();
85 SectionEntry &getSection(unsigned SectionID) { return Sections[SectionID]; }
87 // Allocate no GOT entries for use in the given section.
88 uint64_t allocateGOTEntries(unsigned SectionID, unsigned no);
90 // Resolve the relvative address of GOTOffset in Section ID and place
91 // it at the given Offset
92 void resolveGOTOffsetRelocation(unsigned SectionID, uint64_t Offset,
95 // For a GOT entry referenced from SectionID, compute a relocation entry
96 // that will place the final resolved value in the GOT slot
97 RelocationEntry computeGOTOffsetRE(unsigned SectionID,
99 uint64_t SymbolOffset,
102 // The tentative ID for the GOT section
103 unsigned GOTSectionID;
105 // Records the current number of allocated slots in the GOT
106 // (This would be equivalent to GOTEntries.size() were it not for relocations
107 // that consume more than one slot)
108 unsigned CurrentGOTIndex;
110 // When a module is loaded we save the SectionID of the EH frame section
111 // in a table until we receive a request to register all unregistered
112 // EH frame sections with the memory manager.
113 SmallVector<SID, 2> UnregisteredEHFrameSections;
114 SmallVector<SID, 2> RegisteredEHFrameSections;
117 RuntimeDyldELF(RuntimeDyld::MemoryManager &MemMgr,
118 RuntimeDyld::SymbolResolver &Resolver);
119 ~RuntimeDyldELF() override;
121 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
122 loadObject(const object::ObjectFile &O) override;
124 void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override;
126 processRelocationRef(unsigned SectionID, relocation_iterator RelI,
127 const ObjectFile &Obj,
128 ObjSectionToIDMap &ObjSectionToID,
129 StubMap &Stubs) override;
130 bool isCompatibleFile(const object::ObjectFile &Obj) const override;
131 void registerEHFrames() override;
132 void deregisterEHFrames() override;
133 void finalizeLoad(const ObjectFile &Obj,
134 ObjSectionToIDMap &SectionMap) override;
137 } // end namespace llvm