1234285Sdim//===-- RuntimeDyldMachO.h - Run-time dynamic linker for MC-JIT ---*- C++ -*-=// 2234285Sdim// 3234285Sdim// The LLVM Compiler Infrastructure 4234285Sdim// 5234285Sdim// This file is distributed under the University of Illinois Open Source 6234285Sdim// License. See LICENSE.TXT for details. 7234285Sdim// 8234285Sdim//===----------------------------------------------------------------------===// 9234285Sdim// 10234285Sdim// MachO support for MC-JIT runtime dynamic linker. 11234285Sdim// 12234285Sdim//===----------------------------------------------------------------------===// 13234285Sdim 14234285Sdim#ifndef LLVM_RUNTIME_DYLD_MACHO_H 15234285Sdim#define LLVM_RUNTIME_DYLD_MACHO_H 16234285Sdim 17249423Sdim#include "RuntimeDyldImpl.h" 18234285Sdim#include "llvm/ADT/IndexedMap.h" 19251662Sdim#include "llvm/Object/MachO.h" 20234285Sdim#include "llvm/Support/Format.h" 21234285Sdim 22234285Sdimusing namespace llvm; 23234285Sdimusing namespace llvm::object; 24234285Sdim 25234285Sdim 26234285Sdimnamespace llvm { 27234285Sdimclass RuntimeDyldMachO : public RuntimeDyldImpl { 28234285Sdim bool resolveI386Relocation(uint8_t *LocalAddress, 29234285Sdim uint64_t FinalAddress, 30234285Sdim uint64_t Value, 31234285Sdim bool isPCRel, 32234285Sdim unsigned Type, 33234285Sdim unsigned Size, 34234285Sdim int64_t Addend); 35234285Sdim bool resolveX86_64Relocation(uint8_t *LocalAddress, 36234285Sdim uint64_t FinalAddress, 37234285Sdim uint64_t Value, 38234285Sdim bool isPCRel, 39234285Sdim unsigned Type, 40234285Sdim unsigned Size, 41234285Sdim int64_t Addend); 42234285Sdim bool resolveARMRelocation(uint8_t *LocalAddress, 43234285Sdim uint64_t FinalAddress, 44234285Sdim uint64_t Value, 45234285Sdim bool isPCRel, 46234285Sdim unsigned Type, 47234285Sdim unsigned Size, 48234285Sdim int64_t Addend); 49234285Sdim 50251662Sdim void resolveRelocation(const SectionEntry &Section, 51251662Sdim uint64_t Offset, 52251662Sdim uint64_t Value, 53251662Sdim uint32_t Type, 54251662Sdim int64_t Addend, 55251662Sdim bool isPCRel, 56251662Sdim unsigned Size); 57263508Sdim 58263508Sdim unsigned getMaxStubSize() { 59263508Sdim if (Arch == Triple::arm || Arch == Triple::thumb) 60263508Sdim return 8; // 32-bit instruction and 32-bit address 61263508Sdim else if (Arch == Triple::x86_64) 62263508Sdim return 8; // GOT entry 63263508Sdim else 64263508Sdim return 0; 65263508Sdim } 66263508Sdim 67263508Sdim unsigned getStubAlignment() { 68263508Sdim return 1; 69263508Sdim } 70263508Sdim 71263508Sdim struct EHFrameRelatedSections { 72263508Sdim EHFrameRelatedSections() : EHFrameSID(RTDYLD_INVALID_SECTION_ID), 73263508Sdim TextSID(RTDYLD_INVALID_SECTION_ID), 74263508Sdim ExceptTabSID(RTDYLD_INVALID_SECTION_ID) {} 75263508Sdim EHFrameRelatedSections(SID EH, SID T, SID Ex) 76263508Sdim : EHFrameSID(EH), TextSID(T), ExceptTabSID(Ex) {} 77263508Sdim SID EHFrameSID; 78263508Sdim SID TextSID; 79263508Sdim SID ExceptTabSID; 80263508Sdim }; 81263508Sdim 82263508Sdim // When a module is loaded we save the SectionID of the EH frame section 83263508Sdim // in a table until we receive a request to register all unregistered 84263508Sdim // EH frame sections with the memory manager. 85263508Sdim SmallVector<EHFrameRelatedSections, 2> UnregisteredEHFrameSections; 86251662Sdimpublic: 87251662Sdim RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {} 88251662Sdim 89251662Sdim virtual void resolveRelocation(const RelocationEntry &RE, uint64_t Value); 90251662Sdim virtual void processRelocationRef(unsigned SectionID, 91251662Sdim RelocationRef RelI, 92234982Sdim ObjectImage &Obj, 93234285Sdim ObjSectionToIDMap &ObjSectionToID, 94239462Sdim const SymbolTableMap &Symbols, 95239462Sdim StubMap &Stubs); 96251662Sdim virtual bool isCompatibleFormat(const ObjectBuffer *Buffer) const; 97263508Sdim virtual void registerEHFrames(); 98263508Sdim virtual void finalizeLoad(ObjSectionToIDMap &SectionMap); 99234285Sdim}; 100234285Sdim 101234285Sdim} // end namespace llvm 102234285Sdim 103234285Sdim#endif 104