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
17252723Sdim#include "RuntimeDyldImpl.h"
18234285Sdim#include "llvm/ADT/IndexedMap.h"
19252723Sdim#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
50252723Sdim  void resolveRelocation(const SectionEntry &Section,
51252723Sdim                         uint64_t Offset,
52252723Sdim                         uint64_t Value,
53252723Sdim                         uint32_t Type,
54252723Sdim                         int64_t Addend,
55252723Sdim                         bool isPCRel,
56252723Sdim                         unsigned Size);
57263509Sdim
58263509Sdim  unsigned getMaxStubSize() {
59263509Sdim    if (Arch == Triple::arm || Arch == Triple::thumb)
60263509Sdim      return 8; // 32-bit instruction and 32-bit address
61263509Sdim    else if (Arch == Triple::x86_64)
62263509Sdim      return 8; // GOT entry
63263509Sdim    else
64263509Sdim      return 0;
65263509Sdim  }
66263509Sdim
67263509Sdim  unsigned getStubAlignment() {
68263509Sdim    return 1;
69263509Sdim  }
70263509Sdim
71263509Sdim  struct EHFrameRelatedSections {
72263509Sdim    EHFrameRelatedSections() : EHFrameSID(RTDYLD_INVALID_SECTION_ID),
73263509Sdim                               TextSID(RTDYLD_INVALID_SECTION_ID),
74263509Sdim                               ExceptTabSID(RTDYLD_INVALID_SECTION_ID) {}
75263509Sdim    EHFrameRelatedSections(SID EH, SID T, SID Ex)
76263509Sdim      : EHFrameSID(EH), TextSID(T), ExceptTabSID(Ex) {}
77263509Sdim    SID EHFrameSID;
78263509Sdim    SID TextSID;
79263509Sdim    SID ExceptTabSID;
80263509Sdim  };
81263509Sdim
82263509Sdim  // When a module is loaded we save the SectionID of the EH frame section
83263509Sdim  // in a table until we receive a request to register all unregistered
84263509Sdim  // EH frame sections with the memory manager.
85263509Sdim  SmallVector<EHFrameRelatedSections, 2> UnregisteredEHFrameSections;
86252723Sdimpublic:
87252723Sdim  RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
88252723Sdim
89252723Sdim  virtual void resolveRelocation(const RelocationEntry &RE, uint64_t Value);
90252723Sdim  virtual void processRelocationRef(unsigned SectionID,
91252723Sdim                                    RelocationRef RelI,
92235633Sdim                                    ObjectImage &Obj,
93234285Sdim                                    ObjSectionToIDMap &ObjSectionToID,
94245431Sdim                                    const SymbolTableMap &Symbols,
95245431Sdim                                    StubMap &Stubs);
96252723Sdim  virtual bool isCompatibleFormat(const ObjectBuffer *Buffer) const;
97263509Sdim  virtual void registerEHFrames();
98263509Sdim  virtual void finalizeLoad(ObjSectionToIDMap &SectionMap);
99234285Sdim};
100234285Sdim
101234285Sdim} // end namespace llvm
102234285Sdim
103234285Sdim#endif
104