Home | History | Annotate | Download | only in RuntimeDyld
      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/RuntimeDyldCOFFI386.h"
     16 #include "Targets/RuntimeDyldCOFFThumb.h"
     17 #include "Targets/RuntimeDyldCOFFX86_64.h"
     18 #include "llvm/ADT/STLExtras.h"
     19 #include "llvm/ADT/Triple.h"
     20 #include "llvm/Object/ObjectFile.h"
     21 
     22 using namespace llvm;
     23 using namespace llvm::object;
     24 
     25 #define DEBUG_TYPE "dyld"
     26 
     27 namespace {
     28 
     29 class LoadedCOFFObjectInfo final
     30     : public RuntimeDyld::LoadedObjectInfoHelper<LoadedCOFFObjectInfo> {
     31 public:
     32   LoadedCOFFObjectInfo(RuntimeDyldImpl &RTDyld, ObjSectionToIDMap ObjSecToIDMap)
     33       : LoadedObjectInfoHelper(RTDyld, std::move(ObjSecToIDMap)) {}
     34 
     35   OwningBinary<ObjectFile>
     36   getObjectForDebug(const ObjectFile &Obj) const override {
     37     return OwningBinary<ObjectFile>();
     38   }
     39 };
     40 }
     41 
     42 namespace llvm {
     43 
     44 std::unique_ptr<RuntimeDyldCOFF>
     45 llvm::RuntimeDyldCOFF::create(Triple::ArchType Arch,
     46                               RuntimeDyld::MemoryManager &MemMgr,
     47                               RuntimeDyld::SymbolResolver &Resolver) {
     48   switch (Arch) {
     49   default: llvm_unreachable("Unsupported target for RuntimeDyldCOFF.");
     50   case Triple::x86:
     51     return make_unique<RuntimeDyldCOFFI386>(MemMgr, Resolver);
     52   case Triple::thumb:
     53     return make_unique<RuntimeDyldCOFFThumb>(MemMgr, Resolver);
     54   case Triple::x86_64:
     55     return make_unique<RuntimeDyldCOFFX86_64>(MemMgr, Resolver);
     56   }
     57 }
     58 
     59 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
     60 RuntimeDyldCOFF::loadObject(const object::ObjectFile &O) {
     61   if (auto ObjSectionToIDOrErr = loadObjectImpl(O)) {
     62     return llvm::make_unique<LoadedCOFFObjectInfo>(*this, *ObjSectionToIDOrErr);
     63   } else {
     64     HasError = true;
     65     raw_string_ostream ErrStream(ErrorStr);
     66     logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream, "");
     67     return nullptr;
     68   }
     69 }
     70 
     71 uint64_t RuntimeDyldCOFF::getSymbolOffset(const SymbolRef &Sym) {
     72   // The value in a relocatable COFF object is the offset.
     73   return Sym.getValue();
     74 }
     75 
     76 bool RuntimeDyldCOFF::isCompatibleFile(const object::ObjectFile &Obj) const {
     77   return Obj.isCOFF();
     78 }
     79 
     80 } // namespace llvm
     81