[RuntimeDyld] clang-format files.
[oota-llvm.git] / lib / ExecutionEngine / RuntimeDyld / RuntimeDyldMachO.h
1 //===-- 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
17 #include "ObjectImageCommon.h"
18 #include "RuntimeDyldImpl.h"
19 #include "llvm/ADT/IndexedMap.h"
20 #include "llvm/Object/MachO.h"
21 #include "llvm/Support/Format.h"
22
23 using namespace llvm;
24 using namespace llvm::object;
25
26 namespace llvm {
27 class RuntimeDyldMachO : public RuntimeDyldImpl {
28   bool resolveI386Relocation(uint8_t *LocalAddress, uint64_t FinalAddress,
29                              uint64_t Value, bool isPCRel, unsigned Type,
30                              unsigned Size, int64_t Addend);
31   bool resolveX86_64Relocation(uint8_t *LocalAddress, uint64_t FinalAddress,
32                                uint64_t Value, bool isPCRel, unsigned Type,
33                                unsigned Size, int64_t Addend);
34   bool resolveARMRelocation(uint8_t *LocalAddress, uint64_t FinalAddress,
35                             uint64_t Value, bool isPCRel, unsigned Type,
36                             unsigned Size, int64_t Addend);
37
38   void resolveRelocation(const SectionEntry &Section, uint64_t Offset,
39                          uint64_t Value, uint32_t Type, int64_t Addend,
40                          bool isPCRel, unsigned Size);
41
42   unsigned getMaxStubSize() override {
43     if (Arch == Triple::arm || Arch == Triple::thumb)
44       return 8; // 32-bit instruction and 32-bit address
45     else if (Arch == Triple::x86_64)
46       return 8; // GOT entry
47     else
48       return 0;
49   }
50
51   unsigned getStubAlignment() override { return 1; }
52
53   struct EHFrameRelatedSections {
54     EHFrameRelatedSections()
55         : EHFrameSID(RTDYLD_INVALID_SECTION_ID),
56           TextSID(RTDYLD_INVALID_SECTION_ID),
57           ExceptTabSID(RTDYLD_INVALID_SECTION_ID) {}
58     EHFrameRelatedSections(SID EH, SID T, SID Ex)
59         : EHFrameSID(EH), TextSID(T), ExceptTabSID(Ex) {}
60     SID EHFrameSID;
61     SID TextSID;
62     SID ExceptTabSID;
63   };
64
65   // When a module is loaded we save the SectionID of the EH frame section
66   // in a table until we receive a request to register all unregistered
67   // EH frame sections with the memory manager.
68   SmallVector<EHFrameRelatedSections, 2> UnregisteredEHFrameSections;
69
70 public:
71   RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
72
73   void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override;
74   relocation_iterator
75   processRelocationRef(unsigned SectionID, relocation_iterator RelI,
76                        ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID,
77                        const SymbolTableMap &Symbols, StubMap &Stubs) override;
78   bool isCompatibleFormat(const ObjectBuffer *Buffer) const override;
79   bool isCompatibleFile(const object::ObjectFile *Obj) const override;
80   void registerEHFrames() override;
81   void finalizeLoad(ObjSectionToIDMap &SectionMap) override;
82
83   static ObjectImage *createObjectImage(ObjectBuffer *InputBuffer) {
84     return new ObjectImageCommon(InputBuffer);
85   }
86
87   static ObjectImage *
88   createObjectImageFromFile(object::ObjectFile *InputObject) {
89     return new ObjectImageCommon(InputObject);
90   }
91 };
92
93 } // end namespace llvm
94
95 #endif