Writer.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //===- Writer.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_TOOLS_OBJCOPY_COFF_WRITER_H
  9. #define LLVM_TOOLS_OBJCOPY_COFF_WRITER_H
  10. #include "llvm/MC/StringTableBuilder.h"
  11. #include "llvm/Support/Error.h"
  12. #include "llvm/Support/MemoryBuffer.h"
  13. #include <cstddef>
  14. #include <utility>
  15. namespace llvm {
  16. namespace objcopy {
  17. namespace coff {
  18. struct Object;
  19. class COFFWriter {
  20. Object &Obj;
  21. std::unique_ptr<WritableMemoryBuffer> Buf;
  22. raw_ostream &Out;
  23. size_t FileSize;
  24. size_t FileAlignment;
  25. size_t SizeOfInitializedData;
  26. StringTableBuilder StrTabBuilder;
  27. template <class SymbolTy> std::pair<size_t, size_t> finalizeSymbolTable();
  28. Error finalizeRelocTargets();
  29. Error finalizeSymbolContents();
  30. void layoutSections();
  31. Expected<size_t> finalizeStringTable();
  32. Error finalize(bool IsBigObj);
  33. void writeHeaders(bool IsBigObj);
  34. void writeSections();
  35. template <class SymbolTy> void writeSymbolStringTables();
  36. Error write(bool IsBigObj);
  37. Error patchDebugDirectory();
  38. Expected<uint32_t> virtualAddressToFileAddress(uint32_t RVA);
  39. public:
  40. virtual ~COFFWriter() {}
  41. Error write();
  42. COFFWriter(Object &Obj, raw_ostream &Out)
  43. : Obj(Obj), Out(Out), StrTabBuilder(StringTableBuilder::WinCOFF) {}
  44. };
  45. } // end namespace coff
  46. } // end namespace objcopy
  47. } // end namespace llvm
  48. #endif // LLVM_TOOLS_OBJCOPY_COFF_WRITER_H