OSDN Git Service

Don't use 'using std::error_code' in include/llvm.
[android-x86/external-llvm.git] / lib / ExecutionEngine / RuntimeDyld / RuntimeDyldELF.h
1 //===-- RuntimeDyldELF.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 // ELF support for MC-JIT runtime dynamic linker.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_RUNTIME_DYLD_ELF_H
15 #define LLVM_RUNTIME_DYLD_ELF_H
16
17 #include "RuntimeDyldImpl.h"
18 #include "llvm/ADT/DenseMap.h"
19
20 using namespace llvm;
21
22 namespace llvm {
23 using std::error_code;
24
25 namespace {
26 // Helper for extensive error checking in debug builds.
27 error_code Check(error_code Err) {
28   if (Err) {
29     report_fatal_error(Err.message());
30   }
31   return Err;
32 }
33 } // end anonymous namespace
34
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);
39
40   void resolveX86_64Relocation(const SectionEntry &Section, uint64_t Offset,
41                                uint64_t Value, uint32_t Type, int64_t Addend,
42                                uint64_t SymOffset);
43
44   void resolveX86Relocation(const SectionEntry &Section, uint64_t Offset,
45                             uint32_t Value, uint32_t Type, int32_t Addend);
46
47   void resolveAArch64Relocation(const SectionEntry &Section, uint64_t Offset,
48                                 uint64_t Value, uint32_t Type, int64_t Addend);
49
50   void resolveARMRelocation(const SectionEntry &Section, uint64_t Offset,
51                             uint32_t Value, uint32_t Type, int32_t Addend);
52
53   void resolveMIPSRelocation(const SectionEntry &Section, uint64_t Offset,
54                              uint32_t Value, uint32_t Type, int32_t Addend);
55
56   void resolvePPC64Relocation(const SectionEntry &Section, uint64_t Offset,
57                               uint64_t Value, uint32_t Type, int64_t Addend);
58
59   void resolveSystemZRelocation(const SectionEntry &Section, uint64_t Offset,
60                                 uint64_t Value, uint32_t Type, int64_t Addend);
61
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)
69       return 16;
70     else if (Arch == Triple::ppc64 || Arch == Triple::ppc64le)
71       return 44;
72     else if (Arch == Triple::x86_64)
73       return 6; // 2-byte jmp instruction + 32-bit relative address
74     else if (Arch == Triple::systemz)
75       return 16;
76     else
77       return 0;
78   }
79
80   unsigned getStubAlignment() override {
81     if (Arch == Triple::systemz)
82       return 8;
83     else
84       return 1;
85   }
86
87   uint64_t findPPC64TOC() const;
88   void findOPDEntrySection(ObjectImage &Obj, ObjSectionToIDMap &LocalSections,
89                            RelocationValueRef &Rel);
90
91   uint64_t findGOTEntry(uint64_t LoadAddr, uint64_t Offset);
92   size_t getGOTEntrySize();
93
94   void updateGOTEntries(StringRef Name, uint64_t Addr) override;
95
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.
101
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;
107
108 public:
109   RuntimeDyldELF(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
110
111   void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override;
112   relocation_iterator
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();
123
124   static ObjectImage *createObjectImage(ObjectBuffer *InputBuffer);
125   static ObjectImage *createObjectImageFromFile(std::unique_ptr<object::ObjectFile> Obj);
126 };
127
128 } // end namespace llvm
129
130 #endif