RuntimeDyldCOFF.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include "RuntimeDyldCOFF.h"
  14. #include "Targets/RuntimeDyldCOFFX86_64.h"
  15. #include "llvm/ADT/STLExtras.h"
  16. #include "llvm/ADT/Triple.h"
  17. #include "llvm/Object/ObjectFile.h"
  18. using namespace llvm;
  19. using namespace llvm::object;
  20. #define DEBUG_TYPE "dyld"
  21. namespace {
  22. class LoadedCOFFObjectInfo
  23. : public RuntimeDyld::LoadedObjectInfoHelper<LoadedCOFFObjectInfo> {
  24. public:
  25. LoadedCOFFObjectInfo(RuntimeDyldImpl &RTDyld, unsigned BeginIdx,
  26. unsigned EndIdx)
  27. : LoadedObjectInfoHelper(RTDyld, BeginIdx, EndIdx) {}
  28. OwningBinary<ObjectFile>
  29. getObjectForDebug(const ObjectFile &Obj) const override {
  30. return OwningBinary<ObjectFile>();
  31. }
  32. };
  33. }
  34. namespace llvm {
  35. std::unique_ptr<RuntimeDyldCOFF>
  36. llvm::RuntimeDyldCOFF::create(Triple::ArchType Arch,
  37. RuntimeDyld::MemoryManager &MemMgr,
  38. RuntimeDyld::SymbolResolver &Resolver) {
  39. switch (Arch) {
  40. default:
  41. llvm_unreachable("Unsupported target for RuntimeDyldCOFF.");
  42. break;
  43. case Triple::x86_64:
  44. return make_unique<RuntimeDyldCOFFX86_64>(MemMgr, Resolver);
  45. }
  46. }
  47. std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
  48. RuntimeDyldCOFF::loadObject(const object::ObjectFile &O) {
  49. unsigned SectionStartIdx, SectionEndIdx;
  50. std::tie(SectionStartIdx, SectionEndIdx) = loadObjectImpl(O);
  51. return llvm::make_unique<LoadedCOFFObjectInfo>(*this, SectionStartIdx,
  52. SectionEndIdx);
  53. }
  54. uint64_t RuntimeDyldCOFF::getSymbolOffset(const SymbolRef &Sym) {
  55. // The value in a relocatable COFF object is the offset.
  56. return Sym.getValue();
  57. }
  58. bool RuntimeDyldCOFF::isCompatibleFile(const object::ObjectFile &Obj) const {
  59. return Obj.isCOFF();
  60. }
  61. } // namespace llvm