MachOWriter.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifndef LLVM_LIB_OBJCOPY_MACHO_MACHOWRITER_H
  9. #define LLVM_LIB_OBJCOPY_MACHO_MACHOWRITER_H
  10. #include "MachOLayoutBuilder.h"
  11. #include "MachOObject.h"
  12. #include "llvm/BinaryFormat/MachO.h"
  13. #include "llvm/ObjCopy/MachO/MachOObjcopy.h"
  14. #include "llvm/Object/MachO.h"
  15. namespace llvm {
  16. class Error;
  17. namespace objcopy {
  18. namespace macho {
  19. class MachOWriter {
  20. Object &O;
  21. bool Is64Bit;
  22. bool IsLittleEndian;
  23. uint64_t PageSize;
  24. std::unique_ptr<WritableMemoryBuffer> Buf;
  25. raw_ostream &Out;
  26. MachOLayoutBuilder LayoutBuilder;
  27. size_t headerSize() const;
  28. size_t loadCommandsSize() const;
  29. size_t symTableSize() const;
  30. size_t strTableSize() const;
  31. void writeHeader();
  32. void writeLoadCommands();
  33. template <typename StructType>
  34. void writeSectionInLoadCommand(const Section &Sec, uint8_t *&Out);
  35. void writeSections();
  36. void writeSymbolTable();
  37. void writeStringTable();
  38. void writeRebaseInfo();
  39. void writeBindInfo();
  40. void writeWeakBindInfo();
  41. void writeLazyBindInfo();
  42. void writeExportInfo();
  43. void writeIndirectSymbolTable();
  44. void writeLinkData(std::optional<size_t> LCIndex, const LinkData &LD);
  45. void writeCodeSignatureData();
  46. void writeDataInCodeData();
  47. void writeLinkerOptimizationHint();
  48. void writeFunctionStartsData();
  49. void writeDylibCodeSignDRsData();
  50. void writeChainedFixupsData();
  51. void writeExportsTrieData();
  52. void writeTail();
  53. public:
  54. MachOWriter(Object &O, bool Is64Bit, bool IsLittleEndian,
  55. StringRef OutputFileName, uint64_t PageSize, raw_ostream &Out)
  56. : O(O), Is64Bit(Is64Bit), IsLittleEndian(IsLittleEndian),
  57. PageSize(PageSize), Out(Out),
  58. LayoutBuilder(O, Is64Bit, OutputFileName, PageSize) {}
  59. size_t totalSize() const;
  60. Error finalize();
  61. Error write();
  62. };
  63. } // end namespace macho
  64. } // end namespace objcopy
  65. } // end namespace llvm
  66. #endif // LLVM_LIB_OBJCOPY_MACHO_MACHOWRITER_H