LLVM  10.0.0svn
RuntimeDyldCOFF.cpp
Go to the documentation of this file.
1 //===-- RuntimeDyldCOFF.cpp - Run-time dynamic linker for MC-JIT -*- C++ -*-==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Implementation of COFF support for the MC-JIT runtime dynamic linker.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "RuntimeDyldCOFF.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/Object/ObjectFile.h"
20 
21 using namespace llvm;
22 using namespace llvm::object;
23 
24 #define DEBUG_TYPE "dyld"
25 
26 namespace {
27 
28 class LoadedCOFFObjectInfo final
29  : public LoadedObjectInfoHelper<LoadedCOFFObjectInfo,
30  RuntimeDyld::LoadedObjectInfo> {
31 public:
32  LoadedCOFFObjectInfo(
33  RuntimeDyldImpl &RTDyld,
35  : LoadedObjectInfoHelper(RTDyld, std::move(ObjSecToIDMap)) {}
36 
38  getObjectForDebug(const ObjectFile &Obj) const override {
39  return OwningBinary<ObjectFile>();
40  }
41 };
42 }
43 
44 namespace llvm {
45 
46 std::unique_ptr<RuntimeDyldCOFF>
50  switch (Arch) {
51  default: llvm_unreachable("Unsupported target for RuntimeDyldCOFF.");
52  case Triple::x86:
53  return std::make_unique<RuntimeDyldCOFFI386>(MemMgr, Resolver);
54  case Triple::thumb:
55  return std::make_unique<RuntimeDyldCOFFThumb>(MemMgr, Resolver);
56  case Triple::x86_64:
57  return std::make_unique<RuntimeDyldCOFFX86_64>(MemMgr, Resolver);
58  }
59 }
60 
61 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
63  if (auto ObjSectionToIDOrErr = loadObjectImpl(O)) {
64  return std::make_unique<LoadedCOFFObjectInfo>(*this, *ObjSectionToIDOrErr);
65  } else {
66  HasError = true;
67  raw_string_ostream ErrStream(ErrorStr);
68  logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream);
69  return nullptr;
70  }
71 }
72 
74  // The value in a relocatable COFF object is the offset.
75  return Sym.getValue();
76 }
77 
79  return Obj.isCOFF();
80 }
81 
82 } // namespace llvm
bool isCompatibleFile(const object::ObjectFile &Obj) const override
This class represents lattice values for constants.
Definition: AllocatorList.h:23
uint64_t getValue() const
Return the value of the symbol depending on the object this can be an offset or a virtual address...
Definition: ObjectFile.h:383
This class is the base class for all object file types.
Definition: ObjectFile.h:221
uint64_t getSymbolOffset(const SymbolRef &Sym)
bool isCOFF() const
Definition: Binary.h:126
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:1864
Symbol resolution interface.
Definition: JITSymbol.h:325
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
Definition: Error.cpp:61
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is a value type class that represents a single symbol in the list of symbols in the object file...
Definition: ObjectFile.h:160
static std::unique_ptr< RuntimeDyldCOFF > create(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)
std::map< object::SectionRef, unsigned > ObjSectionToIDMap
Definition: RuntimeDyld.h:74
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:503
std::unique_ptr< RuntimeDyld::LoadedObjectInfo > loadObject(const object::ObjectFile &Obj) override