MachOWriter.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "MachOLayoutBuilder.h"
  9. #include "MachOObjcopy.h"
  10. #include "Object.h"
  11. #include "llvm/BinaryFormat/MachO.h"
  12. #include "llvm/Object/MachO.h"
  13. namespace llvm {
  14. class Error;
  15. namespace objcopy {
  16. namespace macho {
  17. class MachOWriter {
  18. Object &O;
  19. bool Is64Bit;
  20. bool IsLittleEndian;
  21. uint64_t PageSize;
  22. std::unique_ptr<WritableMemoryBuffer> Buf;
  23. raw_ostream &Out;
  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 writeLinkerOptimizationHint();
  46. void writeFunctionStartsData();
  47. void writeChainedFixupsData();
  48. void writeExportsTrieData();
  49. void writeTail();
  50. public:
  51. MachOWriter(Object &O, bool Is64Bit, bool IsLittleEndian,
  52. StringRef OutputFileName, uint64_t PageSize, raw_ostream &Out)
  53. : O(O), Is64Bit(Is64Bit), IsLittleEndian(IsLittleEndian),
  54. PageSize(PageSize), Out(Out),
  55. LayoutBuilder(O, Is64Bit, OutputFileName, PageSize) {}
  56. size_t totalSize() const;
  57. Error finalize();
  58. Error write();
  59. };
  60. } // end namespace macho
  61. } // end namespace objcopy
  62. } // end namespace llvm