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;
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 bool resolveARM64Relocation(uint8_t *LocalAddress, uint64_t FinalAddress,
38 uint64_t Value, bool IsPCRel, unsigned Type,
39 unsigned Size, int64_t Addend);
41 void resolveRelocation(const SectionEntry &Section, uint64_t Offset,
42 uint64_t Value, uint32_t Type, int64_t Addend,
43 bool isPCRel, unsigned Size);
45 unsigned getMaxStubSize() override {
46 if (Arch == Triple::arm || Arch == Triple::thumb)
47 return 8; // 32-bit instruction and 32-bit address
48 else if (Arch == Triple::x86_64)
49 return 8; // GOT entry
54 unsigned getStubAlignment() override { return 1; }
56 struct EHFrameRelatedSections {
57 EHFrameRelatedSections()
58 : EHFrameSID(RTDYLD_INVALID_SECTION_ID),
59 TextSID(RTDYLD_INVALID_SECTION_ID),
60 ExceptTabSID(RTDYLD_INVALID_SECTION_ID) {}
61 EHFrameRelatedSections(SID EH, SID T, SID Ex)
62 : EHFrameSID(EH), TextSID(T), ExceptTabSID(Ex) {}
68 // When a module is loaded we save the SectionID of the EH frame section
69 // in a table until we receive a request to register all unregistered
70 // EH frame sections with the memory manager.
71 SmallVector<EHFrameRelatedSections, 2> UnregisteredEHFrameSections;
74 RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
76 void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override;
78 processRelocationRef(unsigned SectionID, relocation_iterator RelI,
79 ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID,
80 const SymbolTableMap &Symbols, StubMap &Stubs) override;
81 bool isCompatibleFormat(const ObjectBuffer *Buffer) const override;
82 bool isCompatibleFile(const object::ObjectFile *Obj) const override;
83 void registerEHFrames() override;
84 void finalizeLoad(ObjSectionToIDMap &SectionMap) override;
86 static ObjectImage *createObjectImage(ObjectBuffer *InputBuffer) {
87 return new ObjectImageCommon(InputBuffer);
91 createObjectImageFromFile(std::unique_ptr<object::ObjectFile> InputObject) {
92 return new ObjectImageCommon(std::move(InputObject));
96 } // end namespace llvm