blob: a15e38141da451ec3ff26f2c354c12543c5e3446 [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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDELF_H
15#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDELF_H
Eli Bendersky058d6472012-01-22 07:05:02 +000016
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
Eli Bendersky058d6472012-01-22 07:05:02 +000024class RuntimeDyldELF : public RuntimeDyldImpl {
Lang Hamesb5c7b1f2014-11-26 16:54:40 +000025
Juergen Ributzka7608dc02014-03-21 20:28:42 +000026 void resolveRelocation(const SectionEntry &Section, uint64_t Offset,
27 uint64_t Value, uint32_t Type, int64_t Addend,
28 uint64_t SymOffset = 0);
Rafael Espindolaf1f1c622013-04-29 17:24:34 +000029
Juergen Ributzka7608dc02014-03-21 20:28:42 +000030 void resolveX86_64Relocation(const SectionEntry &Section, uint64_t Offset,
31 uint64_t Value, uint32_t Type, int64_t Addend,
Andrew Kaylor4612fed2013-08-19 23:27:43 +000032 uint64_t SymOffset);
Eli Bendersky058d6472012-01-22 07:05:02 +000033
Juergen Ributzka7608dc02014-03-21 20:28:42 +000034 void resolveX86Relocation(const SectionEntry &Section, uint64_t Offset,
35 uint32_t Value, uint32_t Type, int32_t Addend);
Eli Bendersky058d6472012-01-22 07:05:02 +000036
Juergen Ributzka7608dc02014-03-21 20:28:42 +000037 void resolveAArch64Relocation(const SectionEntry &Section, uint64_t Offset,
38 uint64_t Value, uint32_t Type, int64_t Addend);
Tim Northoverfa1b2f82013-05-04 20:13:59 +000039
Juergen Ributzka7608dc02014-03-21 20:28:42 +000040 void resolveARMRelocation(const SectionEntry &Section, uint64_t Offset,
41 uint32_t Value, uint32_t Type, int32_t Addend);
Eli Bendersky058d6472012-01-22 07:05:02 +000042
Juergen Ributzka7608dc02014-03-21 20:28:42 +000043 void resolveMIPSRelocation(const SectionEntry &Section, uint64_t Offset,
44 uint32_t Value, uint32_t Type, int32_t Addend);
Akira Hatanaka111174b2012-08-17 21:28:04 +000045
Juergen Ributzka7608dc02014-03-21 20:28:42 +000046 void resolvePPC64Relocation(const SectionEntry &Section, uint64_t Offset,
47 uint64_t Value, uint32_t Type, int64_t Addend);
Adhemerval Zanella5fc11b32012-10-25 13:13:48 +000048
Juergen Ributzka7608dc02014-03-21 20:28:42 +000049 void resolveSystemZRelocation(const SectionEntry &Section, uint64_t Offset,
50 uint64_t Value, uint32_t Type, int64_t Addend);
Eli Bendersky058d6472012-01-22 07:05:02 +000051
Craig Topperb51ff602014-03-08 07:51:20 +000052 unsigned getMaxStubSize() override {
Tim Northovere19bed72014-07-23 12:32:47 +000053 if (Arch == Triple::aarch64 || Arch == Triple::aarch64_be)
Andrew Kaylor2ba21c52013-10-15 21:32:56 +000054 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)
58 return 16;
59 else if (Arch == Triple::ppc64 || Arch == Triple::ppc64le)
60 return 44;
61 else if (Arch == Triple::x86_64)
62 return 6; // 2-byte jmp instruction + 32-bit relative address
63 else if (Arch == Triple::systemz)
64 return 16;
65 else
66 return 0;
67 }
68
Craig Topperb51ff602014-03-08 07:51:20 +000069 unsigned getStubAlignment() override {
Andrew Kaylor2ba21c52013-10-15 21:32:56 +000070 if (Arch == Triple::systemz)
71 return 8;
72 else
73 return 1;
74 }
75
Lang Hamesb5c7b1f2014-11-26 16:54:40 +000076 void findPPC64TOCSection(const ObjectFile &Obj,
77 ObjSectionToIDMap &LocalSections,
Ulrich Weigand8f1f87c2014-06-27 10:32:14 +000078 RelocationValueRef &Rel);
Lang Hamesb5c7b1f2014-11-26 16:54:40 +000079 void findOPDEntrySection(const ObjectFile &Obj,
80 ObjSectionToIDMap &LocalSections,
Adhemerval Zanella5fc11b32012-10-25 13:13:48 +000081 RelocationValueRef &Rel);
82
Andrew Kaylor4612fed2013-08-19 23:27:43 +000083 uint64_t findGOTEntry(uint64_t LoadAddr, uint64_t Offset);
84 size_t getGOTEntrySize();
85
Craig Topperb51ff602014-03-08 07:51:20 +000086 void updateGOTEntries(StringRef Name, uint64_t Addr) override;
Andrew Kaylor4612fed2013-08-19 23:27:43 +000087
Alp Tokercb402912014-01-24 17:20:08 +000088 // Relocation entries for symbols whose position-independent offset is
Andrew Kaylor480dcb32013-10-05 01:52:09 +000089 // updated in a global offset table.
Andrew Kaylor480dcb32013-10-05 01:52:09 +000090 typedef SmallVector<RelocationValueRef, 2> GOTRelocations;
91 GOTRelocations GOTEntries; // List of entries requiring finalization.
92 SmallVector<std::pair<SID, GOTRelocations>, 8> GOTs; // Allocated tables.
Andrew Kaylor4612fed2013-08-19 23:27:43 +000093
Andrew Kaylor7bb13442013-10-11 21:25:48 +000094 // When a module is loaded we save the SectionID of the EH frame section
95 // in a table until we receive a request to register all unregistered
96 // EH frame sections with the memory manager.
97 SmallVector<SID, 2> UnregisteredEHFrameSections;
Andrew Kaylorc442a762013-10-16 00:14:21 +000098 SmallVector<SID, 2> RegisteredEHFrameSections;
Andrew Kaylor7bb13442013-10-11 21:25:48 +000099
Eli Bendersky058d6472012-01-22 07:05:02 +0000100public:
Lang Hames633fe142015-03-30 03:37:06 +0000101 RuntimeDyldELF(RuntimeDyld::MemoryManager &MemMgr,
102 RuntimeDyld::SymbolResolver &Resolver);
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000103 virtual ~RuntimeDyldELF();
104
105 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
106 loadObject(const object::ObjectFile &O) override;
Preston Gurdcc31af92012-04-16 22:12:58 +0000107
Craig Topperb51ff602014-03-08 07:51:20 +0000108 void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override;
Juergen Ributzka046709f2014-03-21 07:26:41 +0000109 relocation_iterator
110 processRelocationRef(unsigned SectionID, relocation_iterator RelI,
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000111 const ObjectFile &Obj,
112 ObjSectionToIDMap &ObjSectionToID,
Lang Hamesa5cd9502014-11-27 05:40:13 +0000113 StubMap &Stubs) override;
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000114 bool isCompatibleFile(const object::ObjectFile &Obj) const override;
Craig Topperb51ff602014-03-08 07:51:20 +0000115 void registerEHFrames() override;
116 void deregisterEHFrames() override;
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000117 void finalizeLoad(const ObjectFile &Obj,
Lang Hames36072da2014-05-12 21:39:59 +0000118 ObjSectionToIDMap &SectionMap) override;
Eli Bendersky058d6472012-01-22 07:05:02 +0000119};
120
121} // end namespace llvm
122
Danil Malyshev70d22cc2012-03-30 16:45:19 +0000123#endif