blob: 48b0481ce58e0697b3310695922f75b2e1e2fec2 [file] [log] [blame]
Eli Bendersky058d6472012-01-22 07:05:02 +00001//===-- RuntimeDyldMachO.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// MachO support for MC-JIT runtime dynamic linker.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_RUNTIME_DYLD_MACHO_H
15#define LLVM_RUNTIME_DYLD_MACHO_H
16
Lang Hames951b2352014-03-08 18:45:12 +000017#include "ObjectImageCommon.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000018#include "RuntimeDyldImpl.h"
Eli Bendersky058d6472012-01-22 07:05:02 +000019#include "llvm/ADT/IndexedMap.h"
Rafael Espindola6e040c02013-04-26 20:07:33 +000020#include "llvm/Object/MachO.h"
Eli Bendersky058d6472012-01-22 07:05:02 +000021#include "llvm/Support/Format.h"
Eli Bendersky058d6472012-01-22 07:05:02 +000022
23using namespace llvm;
24using namespace llvm::object;
25
26
27namespace llvm {
28class RuntimeDyldMachO : public RuntimeDyldImpl {
Sean Callanana3759432012-03-26 20:45:52 +000029 bool resolveI386Relocation(uint8_t *LocalAddress,
30 uint64_t FinalAddress,
31 uint64_t Value,
32 bool isPCRel,
33 unsigned Type,
34 unsigned Size,
35 int64_t Addend);
Sean Callananca92a3d2012-03-07 23:05:25 +000036 bool resolveX86_64Relocation(uint8_t *LocalAddress,
37 uint64_t FinalAddress,
38 uint64_t Value,
39 bool isPCRel,
40 unsigned Type,
41 unsigned Size,
42 int64_t Addend);
43 bool resolveARMRelocation(uint8_t *LocalAddress,
44 uint64_t FinalAddress,
45 uint64_t Value,
46 bool isPCRel,
47 unsigned Type,
48 unsigned Size,
49 int64_t Addend);
Eli Bendersky058d6472012-01-22 07:05:02 +000050
Rafael Espindolaf1f1c622013-04-29 17:24:34 +000051 void resolveRelocation(const SectionEntry &Section,
52 uint64_t Offset,
53 uint64_t Value,
54 uint32_t Type,
55 int64_t Addend,
56 bool isPCRel,
57 unsigned Size);
Andrew Kaylor7bb13442013-10-11 21:25:48 +000058
Craig Topperb51ff602014-03-08 07:51:20 +000059 unsigned getMaxStubSize() override {
Andrew Kaylor2ba21c52013-10-15 21:32:56 +000060 if (Arch == Triple::arm || Arch == Triple::thumb)
61 return 8; // 32-bit instruction and 32-bit address
62 else if (Arch == Triple::x86_64)
63 return 8; // GOT entry
64 else
65 return 0;
66 }
67
Craig Topperb51ff602014-03-08 07:51:20 +000068 unsigned getStubAlignment() override {
Andrew Kaylor2ba21c52013-10-15 21:32:56 +000069 return 1;
70 }
71
Andrew Kaylor7bb13442013-10-11 21:25:48 +000072 struct EHFrameRelatedSections {
73 EHFrameRelatedSections() : EHFrameSID(RTDYLD_INVALID_SECTION_ID),
74 TextSID(RTDYLD_INVALID_SECTION_ID),
75 ExceptTabSID(RTDYLD_INVALID_SECTION_ID) {}
NAKAMURA Takumi87e08802013-12-07 11:21:42 +000076 EHFrameRelatedSections(SID EH, SID T, SID Ex)
Andrew Kaylor7bb13442013-10-11 21:25:48 +000077 : EHFrameSID(EH), TextSID(T), ExceptTabSID(Ex) {}
78 SID EHFrameSID;
79 SID TextSID;
80 SID ExceptTabSID;
81 };
82
83 // When a module is loaded we save the SectionID of the EH frame section
84 // in a table until we receive a request to register all unregistered
85 // EH frame sections with the memory manager.
86 SmallVector<EHFrameRelatedSections, 2> UnregisteredEHFrameSections;
Eli Bendersky058d6472012-01-22 07:05:02 +000087public:
88 RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
89
Craig Topperb51ff602014-03-08 07:51:20 +000090 void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override;
Juergen Ributzka046709f2014-03-21 07:26:41 +000091 relocation_iterator
92 processRelocationRef(unsigned SectionID, relocation_iterator RelI,
93 ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID,
94 const SymbolTableMap &Symbols, StubMap &Stubs) override;
Craig Topperb51ff602014-03-08 07:51:20 +000095 bool isCompatibleFormat(const ObjectBuffer *Buffer) const override;
96 bool isCompatibleFile(const object::ObjectFile *Obj) const override;
97 void registerEHFrames() override;
98 void finalizeLoad(ObjSectionToIDMap &SectionMap) override;
Lang Hames951b2352014-03-08 18:45:12 +000099
100
101 static ObjectImage *createObjectImage(ObjectBuffer *InputBuffer) {
102 return new ObjectImageCommon(InputBuffer);
103 }
104
105 static ObjectImage *createObjectImageFromFile(object::ObjectFile *InputObject) {
106 return new ObjectImageCommon(InputObject);
107 }
Eli Bendersky058d6472012-01-22 07:05:02 +0000108};
109
110} // end namespace llvm
111
112#endif