MachOWriter.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //===- MachOWriter.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 "../Buffer.h"
  9. #include "MachOLayoutBuilder.h"
  10. #include "MachOObjcopy.h"
  11. #include "Object.h"
  12. #include "llvm/BinaryFormat/MachO.h"
  13. #include "llvm/Object/MachO.h"
  14. namespace llvm {
  15. class Error;
  16. namespace objcopy {
  17. namespace macho {
  18. class MachOWriter {
  19. Object &O;
  20. bool Is64Bit;
  21. bool IsLittleEndian;
  22. uint64_t PageSize;
  23. Buffer &B;
  24. MachOLayoutBuilder LayoutBuilder;
  25. size_t headerSize() const;
  26. size_t loadCommandsSize() const;
  27. size_t symTableSize() const;
  28. size_t strTableSize() const;
  29. void writeHeader();
  30. void writeLoadCommands();
  31. template <typename StructType>
  32. void writeSectionInLoadCommand(const Section &Sec, uint8_t *&Out);
  33. void writeSections();
  34. void writeSymbolTable();
  35. void writeStringTable();
  36. void writeRebaseInfo();
  37. void writeBindInfo();
  38. void writeWeakBindInfo();
  39. void writeLazyBindInfo();
  40. void writeExportInfo();
  41. void writeIndirectSymbolTable();
  42. void writeLinkData(Optional<size_t> LCIndex, const LinkData &LD);
  43. void writeCodeSignatureData();
  44. void writeDataInCodeData();
  45. void writeFunctionStartsData();
  46. void writeTail();
  47. public:
  48. MachOWriter(Object &O, bool Is64Bit, bool IsLittleEndian, uint64_t PageSize,
  49. Buffer &B)
  50. : O(O), Is64Bit(Is64Bit), IsLittleEndian(IsLittleEndian),
  51. PageSize(PageSize), B(B), LayoutBuilder(O, Is64Bit, PageSize) {}
  52. size_t totalSize() const;
  53. Error finalize();
  54. Error write();
  55. };
  56. } // end namespace macho
  57. } // end namespace objcopy
  58. } // end namespace llvm