RuntimeDyldMachO.h revision 263508
197403Sobrien//===-- RuntimeDyldMachO.h - Run-time dynamic linker for MC-JIT ---*- C++ -*-=//
297403Sobrien//
3169691Skan//                     The LLVM Compiler Infrastructure
497403Sobrien//
597403Sobrien// This file is distributed under the University of Illinois Open Source
697403Sobrien// License. See LICENSE.TXT for details.
797403Sobrien//
897403Sobrien//===----------------------------------------------------------------------===//
997403Sobrien//
1097403Sobrien// MachO support for MC-JIT runtime dynamic linker.
1197403Sobrien//
1297403Sobrien//===----------------------------------------------------------------------===//
1397403Sobrien
1497403Sobrien#ifndef LLVM_RUNTIME_DYLD_MACHO_H
1597403Sobrien#define LLVM_RUNTIME_DYLD_MACHO_H
1697403Sobrien
1797403Sobrien#include "RuntimeDyldImpl.h"
18169691Skan#include "llvm/ADT/IndexedMap.h"
1997403Sobrien#include "llvm/Object/MachO.h"
2097403Sobrien#include "llvm/Support/Format.h"
2197403Sobrien
2297403Sobrienusing namespace llvm;
2397403Sobrienusing namespace llvm::object;
2497403Sobrien
2597403Sobrien
2697403Sobriennamespace llvm {
2797403Sobrienclass RuntimeDyldMachO : public RuntimeDyldImpl {
2897403Sobrien  bool resolveI386Relocation(uint8_t *LocalAddress,
2997403Sobrien                             uint64_t FinalAddress,
3097403Sobrien                             uint64_t Value,
3197403Sobrien                             bool isPCRel,
3297403Sobrien                             unsigned Type,
3397403Sobrien                             unsigned Size,
3497403Sobrien                             int64_t Addend);
3597403Sobrien  bool resolveX86_64Relocation(uint8_t *LocalAddress,
3697403Sobrien                               uint64_t FinalAddress,
3797403Sobrien                               uint64_t Value,
3897403Sobrien                               bool isPCRel,
3997403Sobrien                               unsigned Type,
4097403Sobrien                               unsigned Size,
4197403Sobrien                               int64_t Addend);
4297403Sobrien  bool resolveARMRelocation(uint8_t *LocalAddress,
4397403Sobrien                            uint64_t FinalAddress,
4497403Sobrien                            uint64_t Value,
4597403Sobrien                            bool isPCRel,
4697403Sobrien                            unsigned Type,
4797403Sobrien                            unsigned Size,
4897403Sobrien                            int64_t Addend);
4997403Sobrien
5097403Sobrien  void resolveRelocation(const SectionEntry &Section,
5197403Sobrien                         uint64_t Offset,
5297403Sobrien                         uint64_t Value,
5397403Sobrien                         uint32_t Type,
5497403Sobrien                         int64_t Addend,
5597403Sobrien                         bool isPCRel,
5697403Sobrien                         unsigned Size);
5797403Sobrien
58169691Skan  unsigned getMaxStubSize() {
5997403Sobrien    if (Arch == Triple::arm || Arch == Triple::thumb)
6097403Sobrien      return 8; // 32-bit instruction and 32-bit address
61132720Skan    else if (Arch == Triple::x86_64)
62132720Skan      return 8; // GOT entry
6397403Sobrien    else
64169691Skan      return 0;
65132720Skan  }
6697403Sobrien
6797403Sobrien  unsigned getStubAlignment() {
68169691Skan    return 1;
69169691Skan  }
70132720Skan
71132720Skan  struct EHFrameRelatedSections {
72132720Skan    EHFrameRelatedSections() : EHFrameSID(RTDYLD_INVALID_SECTION_ID),
73132720Skan                               TextSID(RTDYLD_INVALID_SECTION_ID),
7497403Sobrien                               ExceptTabSID(RTDYLD_INVALID_SECTION_ID) {}
75169691Skan    EHFrameRelatedSections(SID EH, SID T, SID Ex)
76169691Skan      : EHFrameSID(EH), TextSID(T), ExceptTabSID(Ex) {}
77169691Skan    SID EHFrameSID;
78169691Skan    SID TextSID;
79169691Skan    SID ExceptTabSID;
80169691Skan  };
81169691Skan
82169691Skan  // When a module is loaded we save the SectionID of the EH frame section
83169691Skan  // in a table until we receive a request to register all unregistered
84169691Skan  // EH frame sections with the memory manager.
85169691Skan  SmallVector<EHFrameRelatedSections, 2> UnregisteredEHFrameSections;
86169691Skanpublic:
87169691Skan  RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
88169691Skan
8997403Sobrien  virtual void resolveRelocation(const RelocationEntry &RE, uint64_t Value);
90169691Skan  virtual void processRelocationRef(unsigned SectionID,
91169691Skan                                    RelocationRef RelI,
92169691Skan                                    ObjectImage &Obj,
93169691Skan                                    ObjSectionToIDMap &ObjSectionToID,
9497403Sobrien                                    const SymbolTableMap &Symbols,
95169691Skan                                    StubMap &Stubs);
96169691Skan  virtual bool isCompatibleFormat(const ObjectBuffer *Buffer) const;
97169691Skan  virtual void registerEHFrames();
98169691Skan  virtual void finalizeLoad(ObjSectionToIDMap &SectionMap);
99169691Skan};
100169691Skan
101169691Skan} // end namespace llvm
102169691Skan
103169691Skan#endif
104169691Skan