LLVM  10.0.0
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"
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 LoadedObjectInfoHelper<LoadedCOFFObjectInfo,
31  RuntimeDyld::LoadedObjectInfo> {
32 public:
33  LoadedCOFFObjectInfo(
34  RuntimeDyldImpl &RTDyld,
36  : LoadedObjectInfoHelper(RTDyld, std::move(ObjSecToIDMap)) {}
37 
39  getObjectForDebug(const ObjectFile &Obj) const override {
40  return OwningBinary<ObjectFile>();
41  }
42 };
43 }
44 
45 namespace llvm {
46 
47 std::unique_ptr<RuntimeDyldCOFF>
51  switch (Arch) {
52  default: llvm_unreachable("Unsupported target for RuntimeDyldCOFF.");
53  case Triple::x86:
54  return std::make_unique<RuntimeDyldCOFFI386>(MemMgr, Resolver);
55  case Triple::thumb:
56  return std::make_unique<RuntimeDyldCOFFThumb>(MemMgr, Resolver);
57  case Triple::x86_64:
58  return std::make_unique<RuntimeDyldCOFFX86_64>(MemMgr, Resolver);
59  case Triple::aarch64:
60  return std::make_unique<RuntimeDyldCOFFAArch64>(MemMgr, Resolver);
61  }
62 }
63 
64 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
66  if (auto ObjSectionToIDOrErr = loadObjectImpl(O)) {
67  return std::make_unique<LoadedCOFFObjectInfo>(*this, *ObjSectionToIDOrErr);
68  } else {
69  HasError = true;
70  raw_string_ostream ErrStream(ErrorStr);
71  logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream);
72  return nullptr;
73  }
74 }
75 
77  // The value in a relocatable COFF object is the offset.
78  return Sym.getValue();
79 }
80 
82  return Obj.isCOFF();
83 }
84 
85 } // 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:385
This class is the base class for all object file types.
Definition: ObjectFile.h:223
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:1870
Symbol resolution interface.
Definition: JITSymbol.h:343
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:162
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:516
std::unique_ptr< RuntimeDyld::LoadedObjectInfo > loadObject(const object::ObjectFile &Obj) override