blob: 3e0870da023be1442c411b2442c6a4a93746c0ef [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
Chandler Carruth802d7552012-12-04 07:12:27 +000017#include "RuntimeDyldImpl.h"
Eli Bendersky058d6472012-01-22 07:05:02 +000018#include "llvm/ADT/IndexedMap.h"
Rafael Espindola6e040c02013-04-26 20:07:33 +000019#include "llvm/Object/MachO.h"
Eli Bendersky058d6472012-01-22 07:05:02 +000020#include "llvm/Support/Format.h"
Eli Bendersky058d6472012-01-22 07:05:02 +000021
22using namespace llvm;
23using namespace llvm::object;
24
25
26namespace llvm {
27class RuntimeDyldMachO : public RuntimeDyldImpl {
Sean Callanana3759432012-03-26 20:45:52 +000028 bool resolveI386Relocation(uint8_t *LocalAddress,
29 uint64_t FinalAddress,
30 uint64_t Value,
31 bool isPCRel,
32 unsigned Type,
33 unsigned Size,
34 int64_t Addend);
Sean Callananca92a3d2012-03-07 23:05:25 +000035 bool resolveX86_64Relocation(uint8_t *LocalAddress,
36 uint64_t FinalAddress,
37 uint64_t Value,
38 bool isPCRel,
39 unsigned Type,
40 unsigned Size,
41 int64_t Addend);
42 bool resolveARMRelocation(uint8_t *LocalAddress,
43 uint64_t FinalAddress,
44 uint64_t Value,
45 bool isPCRel,
46 unsigned Type,
47 unsigned Size,
48 int64_t Addend);
Eli Bendersky058d6472012-01-22 07:05:02 +000049
Rafael Espindolaf1f1c622013-04-29 17:24:34 +000050 void resolveRelocation(const SectionEntry &Section,
51 uint64_t Offset,
52 uint64_t Value,
53 uint32_t Type,
54 int64_t Addend,
55 bool isPCRel,
56 unsigned Size);
Andrew Kaylor7bb13442013-10-11 21:25:48 +000057
Andrew Kaylor2ba21c52013-10-15 21:32:56 +000058 unsigned getMaxStubSize() {
59 if (Arch == Triple::arm || Arch == Triple::thumb)
60 return 8; // 32-bit instruction and 32-bit address
61 else if (Arch == Triple::x86_64)
62 return 8; // GOT entry
63 else
64 return 0;
65 }
66
67 unsigned getStubAlignment() {
68 return 1;
69 }
70
Andrew Kaylor7bb13442013-10-11 21:25:48 +000071 struct EHFrameRelatedSections {
72 EHFrameRelatedSections() : EHFrameSID(RTDYLD_INVALID_SECTION_ID),
73 TextSID(RTDYLD_INVALID_SECTION_ID),
74 ExceptTabSID(RTDYLD_INVALID_SECTION_ID) {}
NAKAMURA Takumi87e08802013-12-07 11:21:42 +000075 EHFrameRelatedSections(SID EH, SID T, SID Ex)
Andrew Kaylor7bb13442013-10-11 21:25:48 +000076 : EHFrameSID(EH), TextSID(T), ExceptTabSID(Ex) {}
77 SID EHFrameSID;
78 SID TextSID;
79 SID ExceptTabSID;
80 };
81
82 // When a module is loaded we save the SectionID of the EH frame section
83 // in a table until we receive a request to register all unregistered
84 // EH frame sections with the memory manager.
85 SmallVector<EHFrameRelatedSections, 2> UnregisteredEHFrameSections;
Eli Bendersky058d6472012-01-22 07:05:02 +000086public:
87 RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
88
Rafael Espindola2b065302013-04-29 22:06:33 +000089 virtual void resolveRelocation(const RelocationEntry &RE, uint64_t Value);
90 virtual void processRelocationRef(unsigned SectionID,
91 RelocationRef RelI,
92 ObjectImage &Obj,
93 ObjSectionToIDMap &ObjSectionToID,
94 const SymbolTableMap &Symbols,
95 StubMap &Stubs);
96 virtual bool isCompatibleFormat(const ObjectBuffer *Buffer) const;
Andrew Kaylor7bb13442013-10-11 21:25:48 +000097 virtual void registerEHFrames();
98 virtual void finalizeLoad(ObjSectionToIDMap &SectionMap);
Eli Bendersky058d6472012-01-22 07:05:02 +000099};
100
101} // end namespace llvm
102
103#endif