1 //===-- RuntimeDyldMachO.h - Run-time dynamic linker for MC-JIT ---*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // MachO support for MC-JIT runtime dynamic linker.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_RUNTIME_DYLD_MACHO_H
15 #define LLVM_RUNTIME_DYLD_MACHO_H
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"
24 using namespace llvm::object;
28 class RuntimeDyldMachO : public RuntimeDyldImpl {
29 bool resolveI386Relocation(uint8_t *LocalAddress,
30 uint64_t FinalAddress,
36 bool resolveX86_64Relocation(uint8_t *LocalAddress,
37 uint64_t FinalAddress,
43 bool resolveARMRelocation(uint8_t *LocalAddress,
44 uint64_t FinalAddress,
51 void resolveRelocation(const SectionEntry &Section,
59 unsigned getMaxStubSize() override {
60 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
68 unsigned getStubAlignment() override {
72 struct EHFrameRelatedSections {
73 EHFrameRelatedSections() : EHFrameSID(RTDYLD_INVALID_SECTION_ID),
74 TextSID(RTDYLD_INVALID_SECTION_ID),
75 ExceptTabSID(RTDYLD_INVALID_SECTION_ID) {}
76 EHFrameRelatedSections(SID EH, SID T, SID Ex)
77 : EHFrameSID(EH), TextSID(T), ExceptTabSID(Ex) {}
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;
88 RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
90 void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override;
91 void processRelocationRef(unsigned SectionID, RelocationRef RelI,
92 ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID,
93 const SymbolTableMap &Symbols,
94 StubMap &Stubs) override;
95 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;
101 static ObjectImage *createObjectImage(ObjectBuffer *InputBuffer) {
102 return new ObjectImageCommon(InputBuffer);
105 static ObjectImage *createObjectImageFromFile(object::ObjectFile *InputObject) {
106 return new ObjectImageCommon(InputObject);
110 } // end namespace llvm