2012-01-22 07:05:02 +00:00
|
|
|
//===-- RuntimeDyldMachO.h - Run-time dynamic linker for MC-JIT ---*- C++ -*-=//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// MachO support for MC-JIT runtime dynamic linker.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_RUNTIME_DYLD_MACHO_H
|
|
|
|
#define LLVM_RUNTIME_DYLD_MACHO_H
|
|
|
|
|
2014-03-08 18:45:12 +00:00
|
|
|
#include "ObjectImageCommon.h"
|
2012-12-04 07:12:27 +00:00
|
|
|
#include "RuntimeDyldImpl.h"
|
2012-01-22 07:05:02 +00:00
|
|
|
#include "llvm/ADT/IndexedMap.h"
|
2013-04-26 20:07:33 +00:00
|
|
|
#include "llvm/Object/MachO.h"
|
2012-01-22 07:05:02 +00:00
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::object;
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class RuntimeDyldMachO : public RuntimeDyldImpl {
|
2014-03-21 20:28:42 +00:00
|
|
|
bool resolveI386Relocation(uint8_t *LocalAddress, uint64_t FinalAddress,
|
|
|
|
uint64_t Value, bool isPCRel, unsigned Type,
|
|
|
|
unsigned Size, int64_t Addend);
|
|
|
|
bool resolveX86_64Relocation(uint8_t *LocalAddress, uint64_t FinalAddress,
|
|
|
|
uint64_t Value, bool isPCRel, unsigned Type,
|
|
|
|
unsigned Size, int64_t Addend);
|
|
|
|
bool resolveARMRelocation(uint8_t *LocalAddress, uint64_t FinalAddress,
|
|
|
|
uint64_t Value, bool isPCRel, unsigned Type,
|
|
|
|
unsigned Size, int64_t Addend);
|
2014-03-29 10:18:08 +00:00
|
|
|
bool resolveARM64Relocation(uint8_t *LocalAddress, uint64_t FinalAddress,
|
|
|
|
uint64_t Value, bool IsPCRel, unsigned Type,
|
|
|
|
unsigned Size, int64_t Addend);
|
2014-03-21 20:28:42 +00:00
|
|
|
|
|
|
|
void resolveRelocation(const SectionEntry &Section, uint64_t Offset,
|
|
|
|
uint64_t Value, uint32_t Type, int64_t Addend,
|
|
|
|
bool isPCRel, unsigned Size);
|
2013-10-11 21:25:48 +00:00
|
|
|
|
2014-03-08 07:51:20 +00:00
|
|
|
unsigned getMaxStubSize() override {
|
2013-10-15 21:32:56 +00:00
|
|
|
if (Arch == Triple::arm || Arch == Triple::thumb)
|
|
|
|
return 8; // 32-bit instruction and 32-bit address
|
|
|
|
else if (Arch == Triple::x86_64)
|
|
|
|
return 8; // GOT entry
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-21 20:28:42 +00:00
|
|
|
unsigned getStubAlignment() override { return 1; }
|
2013-10-15 21:32:56 +00:00
|
|
|
|
2013-10-11 21:25:48 +00:00
|
|
|
struct EHFrameRelatedSections {
|
2014-03-21 20:28:42 +00:00
|
|
|
EHFrameRelatedSections()
|
|
|
|
: EHFrameSID(RTDYLD_INVALID_SECTION_ID),
|
|
|
|
TextSID(RTDYLD_INVALID_SECTION_ID),
|
|
|
|
ExceptTabSID(RTDYLD_INVALID_SECTION_ID) {}
|
2013-12-07 11:21:42 +00:00
|
|
|
EHFrameRelatedSections(SID EH, SID T, SID Ex)
|
2014-03-21 20:28:42 +00:00
|
|
|
: EHFrameSID(EH), TextSID(T), ExceptTabSID(Ex) {}
|
2013-10-11 21:25:48 +00:00
|
|
|
SID EHFrameSID;
|
|
|
|
SID TextSID;
|
|
|
|
SID ExceptTabSID;
|
|
|
|
};
|
|
|
|
|
|
|
|
// When a module is loaded we save the SectionID of the EH frame section
|
|
|
|
// in a table until we receive a request to register all unregistered
|
|
|
|
// EH frame sections with the memory manager.
|
|
|
|
SmallVector<EHFrameRelatedSections, 2> UnregisteredEHFrameSections;
|
2014-03-21 20:28:42 +00:00
|
|
|
|
2012-01-22 07:05:02 +00:00
|
|
|
public:
|
|
|
|
RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
|
|
|
|
|
2014-03-08 07:51:20 +00:00
|
|
|
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override;
|
2014-03-21 07:26:41 +00:00
|
|
|
relocation_iterator
|
|
|
|
processRelocationRef(unsigned SectionID, relocation_iterator RelI,
|
|
|
|
ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID,
|
|
|
|
const SymbolTableMap &Symbols, StubMap &Stubs) override;
|
2014-03-08 07:51:20 +00:00
|
|
|
bool isCompatibleFormat(const ObjectBuffer *Buffer) const override;
|
|
|
|
bool isCompatibleFile(const object::ObjectFile *Obj) const override;
|
|
|
|
void registerEHFrames() override;
|
|
|
|
void finalizeLoad(ObjSectionToIDMap &SectionMap) override;
|
2014-03-08 18:45:12 +00:00
|
|
|
|
|
|
|
static ObjectImage *createObjectImage(ObjectBuffer *InputBuffer) {
|
|
|
|
return new ObjectImageCommon(InputBuffer);
|
|
|
|
}
|
|
|
|
|
2014-03-21 20:28:42 +00:00
|
|
|
static ObjectImage *
|
|
|
|
createObjectImageFromFile(object::ObjectFile *InputObject) {
|
2014-03-08 18:45:12 +00:00
|
|
|
return new ObjectImageCommon(InputObject);
|
|
|
|
}
|
2012-01-22 07:05:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|