MachOReader.h 1.9 KB

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