blob: 14fb5740e5f3c061364a1adae9d5d1db9e83c748 [file] [log] [blame]
Eli Bendersky058d6472012-01-22 07:05:02 +00001//===-- 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
19using namespace llvm;
20
Eli Bendersky058d6472012-01-22 07:05:02 +000021namespace llvm {
Tim Northover94bc73d2012-10-29 10:47:04 +000022
23namespace {
24 // Helper for extensive error checking in debug builds.
25 error_code Check(error_code Err) {
26 if (Err) {
27 report_fatal_error(Err.message());
28 }
29 return Err;
30 }
31} // end anonymous namespace
32
Eli Bendersky058d6472012-01-22 07:05:02 +000033class RuntimeDyldELF : public RuntimeDyldImpl {
Rafael Espindolaf1f1c622013-04-29 17:24:34 +000034 void resolveRelocation(const SectionEntry &Section,
35 uint64_t Offset,
36 uint64_t Value,
37 uint32_t Type,
Andrew Kaylor4612fed2013-08-19 23:27:43 +000038 int64_t Addend,
39 uint64_t SymOffset=0);
Rafael Espindolaf1f1c622013-04-29 17:24:34 +000040
Andrew Kaylorfb05a502012-11-02 19:45:23 +000041 void resolveX86_64Relocation(const SectionEntry &Section,
42 uint64_t Offset,
Danil Malyshev70d22cc2012-03-30 16:45:19 +000043 uint64_t Value,
44 uint32_t Type,
Andrew Kaylor4612fed2013-08-19 23:27:43 +000045 int64_t Addend,
46 uint64_t SymOffset);
Eli Bendersky058d6472012-01-22 07:05:02 +000047
Andrew Kaylorfb05a502012-11-02 19:45:23 +000048 void resolveX86Relocation(const SectionEntry &Section,
49 uint64_t Offset,
Danil Malyshev70d22cc2012-03-30 16:45:19 +000050 uint32_t Value,
51 uint32_t Type,
52 int32_t Addend);
Eli Bendersky058d6472012-01-22 07:05:02 +000053
Tim Northoverfa1b2f82013-05-04 20:13:59 +000054 void resolveAArch64Relocation(const SectionEntry &Section,
55 uint64_t Offset,
56 uint64_t Value,
57 uint32_t Type,
58 int64_t Addend);
59
Andrew Kaylorfb05a502012-11-02 19:45:23 +000060 void resolveARMRelocation(const SectionEntry &Section,
61 uint64_t Offset,
Danil Malyshev70d22cc2012-03-30 16:45:19 +000062 uint32_t Value,
63 uint32_t Type,
64 int32_t Addend);
Eli Bendersky058d6472012-01-22 07:05:02 +000065
Andrew Kaylorfb05a502012-11-02 19:45:23 +000066 void resolveMIPSRelocation(const SectionEntry &Section,
67 uint64_t Offset,
Akira Hatanaka11dfbe12012-08-20 17:53:24 +000068 uint32_t Value,
69 uint32_t Type,
70 int32_t Addend);
Akira Hatanaka111174b2012-08-17 21:28:04 +000071
Andrew Kaylorfb05a502012-11-02 19:45:23 +000072 void resolvePPC64Relocation(const SectionEntry &Section,
73 uint64_t Offset,
Adhemerval Zanella5fc11b32012-10-25 13:13:48 +000074 uint64_t Value,
75 uint32_t Type,
76 int64_t Addend);
77
Richard Sandifordca044082013-05-03 14:15:35 +000078 void resolveSystemZRelocation(const SectionEntry &Section,
79 uint64_t Offset,
80 uint64_t Value,
81 uint32_t Type,
82 int64_t Addend);
Eli Bendersky058d6472012-01-22 07:05:02 +000083
Adhemerval Zanella5fc11b32012-10-25 13:13:48 +000084 uint64_t findPPC64TOC() const;
85 void findOPDEntrySection(ObjectImage &Obj,
86 ObjSectionToIDMap &LocalSections,
87 RelocationValueRef &Rel);
88
Andrew Kaylor4612fed2013-08-19 23:27:43 +000089 uint64_t findGOTEntry(uint64_t LoadAddr, uint64_t Offset);
90 size_t getGOTEntrySize();
91
92 virtual void updateGOTEntries(StringRef Name, uint64_t Addr);
93
94 SmallVector<RelocationValueRef, 2> GOTEntries;
95 unsigned GOTSectionID;
96
Eli Bendersky058d6472012-01-22 07:05:02 +000097public:
Andrew Kaylor4612fed2013-08-19 23:27:43 +000098 RuntimeDyldELF(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm),
99 GOTSectionID(0)
100 {}
Preston Gurdcc31af92012-04-16 22:12:58 +0000101
Rafael Espindola2b065302013-04-29 22:06:33 +0000102 virtual void resolveRelocation(const RelocationEntry &RE, uint64_t Value);
103 virtual void processRelocationRef(unsigned SectionID,
104 RelocationRef RelI,
105 ObjectImage &Obj,
106 ObjSectionToIDMap &ObjSectionToID,
107 const SymbolTableMap &Symbols,
108 StubMap &Stubs);
109 virtual bool isCompatibleFormat(const ObjectBuffer *Buffer) const;
110 virtual ObjectImage *createObjectImage(ObjectBuffer *InputBuffer);
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000111 virtual StringRef getEHFrameSection();
Andrew Kaylor4612fed2013-08-19 23:27:43 +0000112 virtual void finalizeLoad();
Preston Gurdcc31af92012-04-16 22:12:58 +0000113 virtual ~RuntimeDyldELF();
Eli Bendersky058d6472012-01-22 07:05:02 +0000114};
115
116} // end namespace llvm
117
Danil Malyshev70d22cc2012-03-30 16:45:19 +0000118#endif