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-05-09 00:11:18 +00:00
|
|
|
private:
|
2014-03-21 20:28:42 +00:00
|
|
|
|
2014-05-09 00:11:18 +00:00
|
|
|
/// Write the least significant 'Size' bytes in 'Value' out at the address
|
|
|
|
/// pointed to by Addr. Check for overflow.
|
|
|
|
bool applyRelocationValue(uint8_t *Addr, uint64_t Value, unsigned Size) {
|
|
|
|
for (unsigned i = 0; i < Size; ++i) {
|
|
|
|
*Addr++ = (uint8_t)Value;
|
|
|
|
Value >>= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Value) // Catch overflow
|
|
|
|
return Error("Relocation out of range.");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool resolveI386Relocation(const RelocationEntry &RE, uint64_t Value);
|
|
|
|
bool resolveX86_64Relocation(const RelocationEntry &RE, uint64_t Value);
|
|
|
|
bool resolveARMRelocation(const RelocationEntry &RE, uint64_t Value);
|
|
|
|
bool resolveARM64Relocation(const RelocationEntry &RE, uint64_t Value);
|
2013-10-11 21:25:48 +00:00
|
|
|
|
2014-05-12 21:39:59 +00:00
|
|
|
// Populate stubs in __jump_table section.
|
|
|
|
void populateJumpTable(MachOObjectFile &Obj, const SectionRef &JTSection,
|
|
|
|
unsigned JTSectionID);
|
|
|
|
|
|
|
|
// Populate __pointers section.
|
|
|
|
void populatePointersSection(MachOObjectFile &Obj, const SectionRef &PTSection,
|
|
|
|
unsigned PTSectionID);
|
|
|
|
|
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
|
|
|
|
2014-05-12 21:39:59 +00:00
|
|
|
relocation_iterator processSECTDIFFRelocation(
|
|
|
|
unsigned SectionID,
|
|
|
|
relocation_iterator RelI,
|
|
|
|
ObjectImage &ObjImg,
|
|
|
|
ObjSectionToIDMap &ObjSectionToID);
|
|
|
|
|
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;
|
2014-05-12 21:39:59 +00:00
|
|
|
void finalizeLoad(ObjectImage &ObjImg,
|
|
|
|
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 *
|
2014-04-29 21:52:46 +00:00
|
|
|
createObjectImageFromFile(std::unique_ptr<object::ObjectFile> InputObject) {
|
|
|
|
return new ObjectImageCommon(std::move(InputObject));
|
2014-03-08 18:45:12 +00:00
|
|
|
}
|
2012-01-22 07:05:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|