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>();
38 RuntimeDyld::LoadedObjectInfo *clone() const { return new LoadedCOFFObjectInfo(*this); }
44 std::unique_ptr<RuntimeDyldCOFF>
45 llvm::RuntimeDyldCOFF::create(Triple::ArchType Arch,
46 RuntimeDyld::MemoryManager &MemMgr,
47 RuntimeDyld::SymbolResolver &Resolver) {
50 llvm_unreachable("Unsupported target for RuntimeDyldCOFF.");
53 return make_unique<RuntimeDyldCOFFX86_64>(MemMgr, Resolver);
57 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
58 RuntimeDyldCOFF::loadObject(const object::ObjectFile &O) {
59 unsigned SectionStartIdx, SectionEndIdx;
60 std::tie(SectionStartIdx, SectionEndIdx) = loadObjectImpl(O);
61 return llvm::make_unique<LoadedCOFFObjectInfo>(*this, SectionStartIdx,
65 uint64_t RuntimeDyldCOFF::getSymbolOffset(const SymbolRef &Sym) {
67 if (Sym.getAddress(Address))
68 return UnknownAddressOrSize;
70 if (Address == UnknownAddressOrSize)
71 return UnknownAddressOrSize;
73 const ObjectFile *Obj = Sym.getObject();
74 section_iterator SecI(Obj->section_end());
75 if (Sym.getSection(SecI))
76 return UnknownAddressOrSize;
78 if (SecI == Obj->section_end())
79 return UnknownAddressOrSize;
81 uint64_t SectionAddress = SecI->getAddress();
82 return Address - SectionAddress;
85 bool RuntimeDyldCOFF::isCompatibleFile(const object::ObjectFile &Obj) const {