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_RUNTIME_DYLD_ELF_H
15 #define LLVM_RUNTIME_DYLD_ELF_H
17 #include "RuntimeDyldImpl.h"
18 #include "llvm/ADT/DenseMap.h"
23 using std::error_code;
26 // Helper for extensive error checking in debug builds.
27 error_code Check(error_code Err) {
29 report_fatal_error(Err.message());
33 } // end anonymous namespace
35 class RuntimeDyldELF : public RuntimeDyldImpl {
36 void resolveRelocation(const SectionEntry &Section, uint64_t Offset,
37 uint64_t Value, uint32_t Type, int64_t Addend,
38 uint64_t SymOffset = 0);
40 void resolveX86_64Relocation(const SectionEntry &Section, uint64_t Offset,
41 uint64_t Value, uint32_t Type, int64_t Addend,
44 void resolveX86Relocation(const SectionEntry &Section, uint64_t Offset,
45 uint32_t Value, uint32_t Type, int32_t Addend);
47 void resolveAArch64Relocation(const SectionEntry &Section, uint64_t Offset,
48 uint64_t Value, uint32_t Type, int64_t Addend);
50 void resolveARMRelocation(const SectionEntry &Section, uint64_t Offset,
51 uint32_t Value, uint32_t Type, int32_t Addend);
53 void resolveMIPSRelocation(const SectionEntry &Section, uint64_t Offset,
54 uint32_t Value, uint32_t Type, int32_t Addend);
56 void resolvePPC64Relocation(const SectionEntry &Section, uint64_t Offset,
57 uint64_t Value, uint32_t Type, int64_t Addend);
59 void resolveSystemZRelocation(const SectionEntry &Section, uint64_t Offset,
60 uint64_t Value, uint32_t Type, int64_t Addend);
62 unsigned getMaxStubSize() override {
63 if (Arch == Triple::aarch64 || Arch == Triple::arm64 ||
64 Arch == Triple::aarch64_be || Arch == Triple::arm64_be)
65 return 20; // movz; movk; movk; movk; br
66 if (Arch == Triple::arm || Arch == Triple::thumb)
67 return 8; // 32-bit instruction and 32-bit address
68 else if (Arch == Triple::mipsel || Arch == Triple::mips)
70 else if (Arch == Triple::ppc64 || Arch == Triple::ppc64le)
72 else if (Arch == Triple::x86_64)
73 return 6; // 2-byte jmp instruction + 32-bit relative address
74 else if (Arch == Triple::systemz)
80 unsigned getStubAlignment() override {
81 if (Arch == Triple::systemz)
87 uint64_t findPPC64TOC() const;
88 void findOPDEntrySection(ObjectImage &Obj, ObjSectionToIDMap &LocalSections,
89 RelocationValueRef &Rel);
91 uint64_t findGOTEntry(uint64_t LoadAddr, uint64_t Offset);
92 size_t getGOTEntrySize();
94 void updateGOTEntries(StringRef Name, uint64_t Addr) override;
96 // Relocation entries for symbols whose position-independent offset is
97 // updated in a global offset table.
98 typedef SmallVector<RelocationValueRef, 2> GOTRelocations;
99 GOTRelocations GOTEntries; // List of entries requiring finalization.
100 SmallVector<std::pair<SID, GOTRelocations>, 8> GOTs; // Allocated tables.
102 // When a module is loaded we save the SectionID of the EH frame section
103 // in a table until we receive a request to register all unregistered
104 // EH frame sections with the memory manager.
105 SmallVector<SID, 2> UnregisteredEHFrameSections;
106 SmallVector<SID, 2> RegisteredEHFrameSections;
109 RuntimeDyldELF(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
111 void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override;
113 processRelocationRef(unsigned SectionID, relocation_iterator RelI,
114 ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID,
115 const SymbolTableMap &Symbols, StubMap &Stubs) override;
116 bool isCompatibleFormat(const ObjectBuffer *Buffer) const override;
117 bool isCompatibleFile(const object::ObjectFile *Buffer) const override;
118 void registerEHFrames() override;
119 void deregisterEHFrames() override;
120 void finalizeLoad(ObjectImage &ObjImg,
121 ObjSectionToIDMap &SectionMap) override;
122 virtual ~RuntimeDyldELF();
124 static ObjectImage *createObjectImage(ObjectBuffer *InputBuffer);
125 static ObjectImage *createObjectImageFromFile(std::unique_ptr<object::ObjectFile> Obj);
128 } // end namespace llvm