blob: ab6b8bdaf3d44b238192334f575e5ecca14394fa [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"
Andrew Kaylor480dcb32013-10-05 01:52:09 +000018#include "llvm/ADT/DenseMap.h"
Eli Bendersky058d6472012-01-22 07:05:02 +000019
20using namespace llvm;
21
Eli Bendersky058d6472012-01-22 07:05:02 +000022namespace llvm {
Tim Northover94bc73d2012-10-29 10:47:04 +000023
24namespace {
25 // Helper for extensive error checking in debug builds.
26 error_code Check(error_code Err) {
27 if (Err) {
28 report_fatal_error(Err.message());
29 }
30 return Err;
31 }
32} // end anonymous namespace
33
Eli Bendersky058d6472012-01-22 07:05:02 +000034class RuntimeDyldELF : public RuntimeDyldImpl {
Rafael Espindolaf1f1c622013-04-29 17:24:34 +000035 void resolveRelocation(const SectionEntry &Section,
36 uint64_t Offset,
37 uint64_t Value,
38 uint32_t Type,
Andrew Kaylor4612fed2013-08-19 23:27:43 +000039 int64_t Addend,
40 uint64_t SymOffset=0);
Rafael Espindolaf1f1c622013-04-29 17:24:34 +000041
Andrew Kaylorfb05a502012-11-02 19:45:23 +000042 void resolveX86_64Relocation(const SectionEntry &Section,
43 uint64_t Offset,
Danil Malyshev70d22cc2012-03-30 16:45:19 +000044 uint64_t Value,
45 uint32_t Type,
Andrew Kaylor4612fed2013-08-19 23:27:43 +000046 int64_t Addend,
47 uint64_t SymOffset);
Eli Bendersky058d6472012-01-22 07:05:02 +000048
Andrew Kaylorfb05a502012-11-02 19:45:23 +000049 void resolveX86Relocation(const SectionEntry &Section,
50 uint64_t Offset,
Danil Malyshev70d22cc2012-03-30 16:45:19 +000051 uint32_t Value,
52 uint32_t Type,
53 int32_t Addend);
Eli Bendersky058d6472012-01-22 07:05:02 +000054
Tim Northoverfa1b2f82013-05-04 20:13:59 +000055 void resolveAArch64Relocation(const SectionEntry &Section,
56 uint64_t Offset,
57 uint64_t Value,
58 uint32_t Type,
59 int64_t Addend);
60
Andrew Kaylorfb05a502012-11-02 19:45:23 +000061 void resolveARMRelocation(const SectionEntry &Section,
62 uint64_t Offset,
Danil Malyshev70d22cc2012-03-30 16:45:19 +000063 uint32_t Value,
64 uint32_t Type,
65 int32_t Addend);
Eli Bendersky058d6472012-01-22 07:05:02 +000066
Andrew Kaylorfb05a502012-11-02 19:45:23 +000067 void resolveMIPSRelocation(const SectionEntry &Section,
68 uint64_t Offset,
Akira Hatanaka11dfbe12012-08-20 17:53:24 +000069 uint32_t Value,
70 uint32_t Type,
71 int32_t Addend);
Akira Hatanaka111174b2012-08-17 21:28:04 +000072
Andrew Kaylorfb05a502012-11-02 19:45:23 +000073 void resolvePPC64Relocation(const SectionEntry &Section,
74 uint64_t Offset,
Adhemerval Zanella5fc11b32012-10-25 13:13:48 +000075 uint64_t Value,
76 uint32_t Type,
77 int64_t Addend);
78
Richard Sandifordca044082013-05-03 14:15:35 +000079 void resolveSystemZRelocation(const SectionEntry &Section,
80 uint64_t Offset,
81 uint64_t Value,
82 uint32_t Type,
83 int64_t Addend);
Eli Bendersky058d6472012-01-22 07:05:02 +000084
Adhemerval Zanella5fc11b32012-10-25 13:13:48 +000085 uint64_t findPPC64TOC() const;
86 void findOPDEntrySection(ObjectImage &Obj,
87 ObjSectionToIDMap &LocalSections,
88 RelocationValueRef &Rel);
89
Andrew Kaylor4612fed2013-08-19 23:27:43 +000090 uint64_t findGOTEntry(uint64_t LoadAddr, uint64_t Offset);
91 size_t getGOTEntrySize();
92
93 virtual void updateGOTEntries(StringRef Name, uint64_t Addr);
94
Andrew Kaylor480dcb32013-10-05 01:52:09 +000095 // Relocation entries for symbols whose position-independant offset is
96 // updated in a global offset table.
Andrew Kaylor480dcb32013-10-05 01:52:09 +000097 typedef SmallVector<RelocationValueRef, 2> GOTRelocations;
98 GOTRelocations GOTEntries; // List of entries requiring finalization.
99 SmallVector<std::pair<SID, GOTRelocations>, 8> GOTs; // Allocated tables.
Andrew Kaylor4612fed2013-08-19 23:27:43 +0000100
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000101 // When a module is loaded we save the SectionID of the EH frame section
102 // in a table until we receive a request to register all unregistered
103 // EH frame sections with the memory manager.
104 SmallVector<SID, 2> UnregisteredEHFrameSections;
105
Eli Bendersky058d6472012-01-22 07:05:02 +0000106public:
Andrew Kaylor480dcb32013-10-05 01:52:09 +0000107 RuntimeDyldELF(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm)
Andrew Kaylor4612fed2013-08-19 23:27:43 +0000108 {}
Preston Gurdcc31af92012-04-16 22:12:58 +0000109
Rafael Espindola2b065302013-04-29 22:06:33 +0000110 virtual void resolveRelocation(const RelocationEntry &RE, uint64_t Value);
111 virtual void processRelocationRef(unsigned SectionID,
112 RelocationRef RelI,
113 ObjectImage &Obj,
114 ObjSectionToIDMap &ObjSectionToID,
115 const SymbolTableMap &Symbols,
116 StubMap &Stubs);
117 virtual bool isCompatibleFormat(const ObjectBuffer *Buffer) const;
118 virtual ObjectImage *createObjectImage(ObjectBuffer *InputBuffer);
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000119 virtual void registerEHFrames();
120 virtual void finalizeLoad(ObjSectionToIDMap &SectionMap);
Preston Gurdcc31af92012-04-16 22:12:58 +0000121 virtual ~RuntimeDyldELF();
Eli Bendersky058d6472012-01-22 07:05:02 +0000122};
123
124} // end namespace llvm
125
Danil Malyshev70d22cc2012-03-30 16:45:19 +0000126#endif