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/Object/MachO.h"
20 #include "llvm/Support/Format.h"
23 using namespace llvm::object;
26 class RuntimeDyldMachO : public RuntimeDyldImpl {
29 /// Write the least significant 'Size' bytes in 'Value' out at the address
30 /// pointed to by Addr.
31 bool applyRelocationValue(uint8_t *Addr, uint64_t Value, unsigned Size) {
32 for (unsigned i = 0; i < Size; ++i) {
33 *Addr++ = (uint8_t)Value;
40 bool resolveI386Relocation(const RelocationEntry &RE, uint64_t Value);
41 bool resolveX86_64Relocation(const RelocationEntry &RE, uint64_t Value);
42 bool resolveARMRelocation(const RelocationEntry &RE, uint64_t Value);
43 bool resolveAArch64Relocation(const RelocationEntry &RE, uint64_t Value);
45 // Populate stubs in __jump_table section.
46 void populateJumpTable(MachOObjectFile &Obj, const SectionRef &JTSection,
47 unsigned JTSectionID);
49 // Populate __pointers section.
50 void populatePointersSection(MachOObjectFile &Obj, const SectionRef &PTSection,
51 unsigned PTSectionID);
53 unsigned getMaxStubSize() override {
54 if (Arch == Triple::arm || Arch == Triple::thumb)
55 return 8; // 32-bit instruction and 32-bit address
56 else if (Arch == Triple::x86_64)
57 return 8; // GOT entry
58 else if (Arch == Triple::arm64)
59 return 8; // GOT entry
64 unsigned getStubAlignment() override {
65 if (Arch == Triple::arm || Arch == Triple::thumb)
67 else if (Arch == Triple::arm64)
73 relocation_iterator processSECTDIFFRelocation(
75 relocation_iterator RelI,
77 ObjSectionToIDMap &ObjSectionToID);
79 relocation_iterator processI386ScatteredVANILLA(
81 relocation_iterator RelI,
83 ObjSectionToIDMap &ObjSectionToID);
85 struct EHFrameRelatedSections {
86 EHFrameRelatedSections()
87 : EHFrameSID(RTDYLD_INVALID_SECTION_ID),
88 TextSID(RTDYLD_INVALID_SECTION_ID),
89 ExceptTabSID(RTDYLD_INVALID_SECTION_ID) {}
90 EHFrameRelatedSections(SID EH, SID T, SID Ex)
91 : EHFrameSID(EH), TextSID(T), ExceptTabSID(Ex) {}
97 // When a module is loaded we save the SectionID of the EH frame section
98 // in a table until we receive a request to register all unregistered
99 // EH frame sections with the memory manager.
100 SmallVector<EHFrameRelatedSections, 2> UnregisteredEHFrameSections;
103 RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
105 void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override;
107 processRelocationRef(unsigned SectionID, relocation_iterator RelI,
108 ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID,
109 const SymbolTableMap &Symbols, StubMap &Stubs) override;
110 bool isCompatibleFormat(const ObjectBuffer *Buffer) const override;
111 bool isCompatibleFile(const object::ObjectFile *Obj) const override;
112 void registerEHFrames() override;
113 void finalizeLoad(ObjectImage &ObjImg,
114 ObjSectionToIDMap &SectionMap) override;
116 static ObjectImage *createObjectImage(ObjectBuffer *Buffer);
118 createObjectImageFromFile(std::unique_ptr<object::ObjectFile> InputObject);
121 } // end namespace llvm