ObjectImageCommon.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //===-- ObjectImageCommon.h - Format independent executuable object image -===//
  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. // This file declares a file format independent ObjectImage class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_RUNTIMEDYLD_OBJECTIMAGECOMMON_H
  14. #define LLVM_RUNTIMEDYLD_OBJECTIMAGECOMMON_H
  15. #include "llvm/ExecutionEngine/ObjectBuffer.h"
  16. #include "llvm/ExecutionEngine/ObjectImage.h"
  17. #include "llvm/Object/ObjectFile.h"
  18. namespace llvm {
  19. namespace object {
  20. class ObjectFile;
  21. }
  22. class ObjectImageCommon : public ObjectImage {
  23. ObjectImageCommon(); // = delete
  24. ObjectImageCommon(const ObjectImageCommon &other); // = delete
  25. virtual void anchor();
  26. protected:
  27. object::ObjectFile *ObjFile;
  28. // This form of the constructor allows subclasses to use
  29. // format-specific subclasses of ObjectFile directly
  30. ObjectImageCommon(ObjectBuffer *Input, object::ObjectFile *Obj)
  31. : ObjectImage(Input), // saves Input as Buffer and takes ownership
  32. ObjFile(Obj)
  33. {
  34. }
  35. public:
  36. ObjectImageCommon(ObjectBuffer* Input)
  37. : ObjectImage(Input) // saves Input as Buffer and takes ownership
  38. {
  39. ObjFile =
  40. object::ObjectFile::createObjectFile(Buffer->getMemBuffer()).get();
  41. }
  42. ObjectImageCommon(object::ObjectFile* Input)
  43. : ObjectImage(NULL), ObjFile(Input) {}
  44. virtual ~ObjectImageCommon() { delete ObjFile; }
  45. virtual object::symbol_iterator begin_symbols() const
  46. { return ObjFile->begin_symbols(); }
  47. virtual object::symbol_iterator end_symbols() const
  48. { return ObjFile->end_symbols(); }
  49. virtual object::section_iterator begin_sections() const
  50. { return ObjFile->begin_sections(); }
  51. virtual object::section_iterator end_sections() const
  52. { return ObjFile->end_sections(); }
  53. virtual /* Triple::ArchType */ unsigned getArch() const
  54. { return ObjFile->getArch(); }
  55. virtual StringRef getData() const { return ObjFile->getData(); }
  56. virtual object::ObjectFile* getObjectFile() const { return ObjFile; }
  57. // Subclasses can override these methods to update the image with loaded
  58. // addresses for sections and common symbols
  59. virtual void updateSectionAddress(const object::SectionRef &Sec,
  60. uint64_t Addr) {}
  61. virtual void updateSymbolAddress(const object::SymbolRef &Sym, uint64_t Addr)
  62. {}
  63. // Subclasses can override these methods to provide JIT debugging support
  64. virtual void registerWithDebugger() {}
  65. virtual void deregisterWithDebugger() {}
  66. };
  67. } // end namespace llvm
  68. #endif // LLVM_RUNTIMEDYLD_OBJECT_IMAGE_H