MachOReader.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //===- MachOReader.h --------------------------------------------*- 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. #ifndef LLVM_LIB_OBJCOPY_MACHO_MACHOREADER_H
  9. #define LLVM_LIB_OBJCOPY_MACHO_MACHOREADER_H
  10. #include "MachOObject.h"
  11. #include "llvm/BinaryFormat/MachO.h"
  12. #include "llvm/ObjCopy/MachO/MachOObjcopy.h"
  13. #include "llvm/Object/MachO.h"
  14. #include <memory>
  15. namespace llvm {
  16. namespace objcopy {
  17. namespace macho {
  18. // The hierarchy of readers is responsible for parsing different inputs:
  19. // raw binaries and regular MachO object files.
  20. class Reader {
  21. public:
  22. virtual ~Reader(){};
  23. virtual Expected<std::unique_ptr<Object>> create() const = 0;
  24. };
  25. class MachOReader : public Reader {
  26. const object::MachOObjectFile &MachOObj;
  27. void readHeader(Object &O) const;
  28. Error readLoadCommands(Object &O) const;
  29. void readSymbolTable(Object &O) const;
  30. void setSymbolInRelocationInfo(Object &O) const;
  31. void readRebaseInfo(Object &O) const;
  32. void readBindInfo(Object &O) const;
  33. void readWeakBindInfo(Object &O) const;
  34. void readLazyBindInfo(Object &O) const;
  35. void readExportInfo(Object &O) const;
  36. void readLinkData(Object &O, std::optional<size_t> LCIndex,
  37. LinkData &LD) const;
  38. void readCodeSignature(Object &O) const;
  39. void readDataInCodeData(Object &O) const;
  40. void readLinkerOptimizationHint(Object &O) const;
  41. void readFunctionStartsData(Object &O) const;
  42. void readDylibCodeSignDRs(Object &O) const;
  43. void readExportsTrie(Object &O) const;
  44. void readChainedFixups(Object &O) const;
  45. void readIndirectSymbolTable(Object &O) const;
  46. void readSwiftVersion(Object &O) const;
  47. public:
  48. explicit MachOReader(const object::MachOObjectFile &Obj) : MachOObj(Obj) {}
  49. Expected<std::unique_ptr<Object>> create() const override;
  50. };
  51. } // end namespace macho
  52. } // end namespace objcopy
  53. } // end namespace llvm
  54. #endif // LLVM_LIB_OBJCOPY_MACHO_MACHOREADER_H