1 //===-- RuntimeDyldCOFF.cpp - Run-time dynamic linker for MC-JIT -*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Implementation of COFF support for the MC-JIT runtime dynamic linker.
12 //===----------------------------------------------------------------------===//
14 #include "RuntimeDyldCOFF.h"
15 #include "Targets/RuntimeDyldCOFFX86_64.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/ADT/Triple.h"
18 #include "llvm/Object/ObjectFile.h"
21 using namespace llvm::object;
23 #define DEBUG_TYPE "dyld"
27 class LoadedCOFFObjectInfo : public RuntimeDyld::LoadedObjectInfo {
29 LoadedCOFFObjectInfo(RuntimeDyldImpl &RTDyld, unsigned BeginIdx,
31 : RuntimeDyld::LoadedObjectInfo(RTDyld, BeginIdx, EndIdx) {}
33 OwningBinary<ObjectFile>
34 getObjectForDebug(const ObjectFile &Obj) const override {
35 return OwningBinary<ObjectFile>();
42 std::unique_ptr<RuntimeDyldCOFF>
43 llvm::RuntimeDyldCOFF::create(Triple::ArchType Arch,
44 RuntimeDyld::MemoryManager &MemMgr,
45 RuntimeDyld::SymbolResolver &Resolver) {
48 llvm_unreachable("Unsupported target for RuntimeDyldCOFF.");
51 return make_unique<RuntimeDyldCOFFX86_64>(MemMgr, Resolver);
55 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
56 RuntimeDyldCOFF::loadObject(const object::ObjectFile &O) {
57 unsigned SectionStartIdx, SectionEndIdx;
58 std::tie(SectionStartIdx, SectionEndIdx) = loadObjectImpl(O);
59 return llvm::make_unique<LoadedCOFFObjectInfo>(*this, SectionStartIdx,
63 uint64_t RuntimeDyldCOFF::getSymbolOffset(const SymbolRef &Sym) {
65 if (Sym.getAddress(Address))
66 return UnknownAddressOrSize;
68 if (Address == UnknownAddressOrSize)
69 return UnknownAddressOrSize;
71 const ObjectFile *Obj = Sym.getObject();
72 section_iterator SecI(Obj->section_end());
73 if (Sym.getSection(SecI))
74 return UnknownAddressOrSize;
76 if (SecI == Obj->section_end())
77 return UnknownAddressOrSize;
79 uint64_t SectionAddress = SecI->getAddress();
80 return Address - SectionAddress;
83 bool RuntimeDyldCOFF::isCompatibleFile(const object::ObjectFile &Obj) const {