1 //===-- RuntimeDyldCOFF.cpp - Run-time dynamic linker for MC-JIT -*- C++ -*-==// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // Implementation of COFF support for the MC-JIT runtime dynamic linker. 11 // 12 //===----------------------------------------------------------------------===// 13 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" 19 20 using namespace llvm; 21 using namespace llvm::object; 22 23 #define DEBUG_TYPE "dyld" 24 25 namespace { 26 27 class LoadedCOFFObjectInfo 28 : public RuntimeDyld::LoadedObjectInfoHelper<LoadedCOFFObjectInfo> { 29 public: 30 LoadedCOFFObjectInfo(RuntimeDyldImpl &RTDyld, unsigned BeginIdx, 31 unsigned EndIdx) 32 : LoadedObjectInfoHelper(RTDyld, BeginIdx, EndIdx) {} 33 34 OwningBinary<ObjectFile> 35 getObjectForDebug(const ObjectFile &Obj) const override { 36 return OwningBinary<ObjectFile>(); 37 } 38 }; 39 } 40 41 namespace llvm { 42 43 std::unique_ptr<RuntimeDyldCOFF> 44 llvm::RuntimeDyldCOFF::create(Triple::ArchType Arch, 45 RuntimeDyld::MemoryManager &MemMgr, 46 RuntimeDyld::SymbolResolver &Resolver) { 47 switch (Arch) { 48 default: 49 llvm_unreachable("Unsupported target for RuntimeDyldCOFF."); 50 break; 51 case Triple::x86_64: 52 return make_unique<RuntimeDyldCOFFX86_64>(MemMgr, Resolver); 53 } 54 } 55 56 std::unique_ptr<RuntimeDyld::LoadedObjectInfo> 57 RuntimeDyldCOFF::loadObject(const object::ObjectFile &O) { 58 unsigned SectionStartIdx, SectionEndIdx; 59 std::tie(SectionStartIdx, SectionEndIdx) = loadObjectImpl(O); 60 return llvm::make_unique<LoadedCOFFObjectInfo>(*this, SectionStartIdx, 61 SectionEndIdx); 62 } 63 64 uint64_t RuntimeDyldCOFF::getSymbolOffset(const SymbolRef &Sym) { 65 // The value in a relocatable COFF object is the offset. 66 return Sym.getValue(); 67 } 68 69 bool RuntimeDyldCOFF::isCompatibleFile(const object::ObjectFile &Obj) const { 70 return Obj.isCOFF(); 71 } 72 73 } // namespace llvm 74