RuntimeDyldCOFF.cpp revision 296417
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/RuntimeDyldCOFFX86_64.h"
17#include "llvm/ADT/STLExtras.h"
18#include "llvm/ADT/Triple.h"
19#include "llvm/Object/ObjectFile.h"
20
21using namespace llvm;
22using namespace llvm::object;
23
24#define DEBUG_TYPE "dyld"
25
26namespace {
27
28class LoadedCOFFObjectInfo final
29    : public RuntimeDyld::LoadedObjectInfoHelper<LoadedCOFFObjectInfo> {
30public:
31  LoadedCOFFObjectInfo(RuntimeDyldImpl &RTDyld, ObjSectionToIDMap ObjSecToIDMap)
32      : LoadedObjectInfoHelper(RTDyld, std::move(ObjSecToIDMap)) {}
33
34  OwningBinary<ObjectFile>
35  getObjectForDebug(const ObjectFile &Obj) const override {
36    return OwningBinary<ObjectFile>();
37  }
38};
39}
40
41namespace llvm {
42
43std::unique_ptr<RuntimeDyldCOFF>
44llvm::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:
52    return make_unique<RuntimeDyldCOFFI386>(MemMgr, Resolver);
53  case Triple::x86_64:
54    return make_unique<RuntimeDyldCOFFX86_64>(MemMgr, Resolver);
55  }
56}
57
58std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
59RuntimeDyldCOFF::loadObject(const object::ObjectFile &O) {
60  return llvm::make_unique<LoadedCOFFObjectInfo>(*this, loadObjectImpl(O));
61}
62
63uint64_t RuntimeDyldCOFF::getSymbolOffset(const SymbolRef &Sym) {
64  // The value in a relocatable COFF object is the offset.
65  return Sym.getValue();
66}
67
68bool RuntimeDyldCOFF::isCompatibleFile(const object::ObjectFile &Obj) const {
69  return Obj.isCOFF();
70}
71
72} // namespace llvm
73