1*25d7b4fbSAlexey Lapshin //===- COFFWriter.h ---------------------------------------------*- C++ -*-===// 2*25d7b4fbSAlexey Lapshin // 3*25d7b4fbSAlexey Lapshin // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*25d7b4fbSAlexey Lapshin // See https://llvm.org/LICENSE.txt for license information. 5*25d7b4fbSAlexey Lapshin // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*25d7b4fbSAlexey Lapshin // 7*25d7b4fbSAlexey Lapshin //===----------------------------------------------------------------------===// 8*25d7b4fbSAlexey Lapshin 9*25d7b4fbSAlexey Lapshin #ifndef LLVM_LIB_OBJCOPY_COFF_COFFWRITER_H 10*25d7b4fbSAlexey Lapshin #define LLVM_LIB_OBJCOPY_COFF_COFFWRITER_H 11*25d7b4fbSAlexey Lapshin 12*25d7b4fbSAlexey Lapshin #include "llvm/MC/StringTableBuilder.h" 13*25d7b4fbSAlexey Lapshin #include "llvm/Support/Error.h" 14*25d7b4fbSAlexey Lapshin #include "llvm/Support/MemoryBuffer.h" 15*25d7b4fbSAlexey Lapshin #include <cstddef> 16*25d7b4fbSAlexey Lapshin #include <utility> 17*25d7b4fbSAlexey Lapshin 18*25d7b4fbSAlexey Lapshin namespace llvm { 19*25d7b4fbSAlexey Lapshin namespace objcopy { 20*25d7b4fbSAlexey Lapshin namespace coff { 21*25d7b4fbSAlexey Lapshin 22*25d7b4fbSAlexey Lapshin struct Object; 23*25d7b4fbSAlexey Lapshin 24*25d7b4fbSAlexey Lapshin class COFFWriter { 25*25d7b4fbSAlexey Lapshin Object &Obj; 26*25d7b4fbSAlexey Lapshin std::unique_ptr<WritableMemoryBuffer> Buf; 27*25d7b4fbSAlexey Lapshin raw_ostream &Out; 28*25d7b4fbSAlexey Lapshin 29*25d7b4fbSAlexey Lapshin size_t FileSize; 30*25d7b4fbSAlexey Lapshin size_t FileAlignment; 31*25d7b4fbSAlexey Lapshin size_t SizeOfInitializedData; 32*25d7b4fbSAlexey Lapshin StringTableBuilder StrTabBuilder; 33*25d7b4fbSAlexey Lapshin 34*25d7b4fbSAlexey Lapshin template <class SymbolTy> std::pair<size_t, size_t> finalizeSymbolTable(); 35*25d7b4fbSAlexey Lapshin Error finalizeRelocTargets(); 36*25d7b4fbSAlexey Lapshin Error finalizeSymbolContents(); 37*25d7b4fbSAlexey Lapshin void layoutSections(); 38*25d7b4fbSAlexey Lapshin Expected<size_t> finalizeStringTable(); 39*25d7b4fbSAlexey Lapshin 40*25d7b4fbSAlexey Lapshin Error finalize(bool IsBigObj); 41*25d7b4fbSAlexey Lapshin 42*25d7b4fbSAlexey Lapshin void writeHeaders(bool IsBigObj); 43*25d7b4fbSAlexey Lapshin void writeSections(); 44*25d7b4fbSAlexey Lapshin template <class SymbolTy> void writeSymbolStringTables(); 45*25d7b4fbSAlexey Lapshin 46*25d7b4fbSAlexey Lapshin Error write(bool IsBigObj); 47*25d7b4fbSAlexey Lapshin 48*25d7b4fbSAlexey Lapshin Error patchDebugDirectory(); 49*25d7b4fbSAlexey Lapshin Expected<uint32_t> virtualAddressToFileAddress(uint32_t RVA); 50*25d7b4fbSAlexey Lapshin 51*25d7b4fbSAlexey Lapshin public: ~COFFWriter()52*25d7b4fbSAlexey Lapshin virtual ~COFFWriter() {} 53*25d7b4fbSAlexey Lapshin Error write(); 54*25d7b4fbSAlexey Lapshin COFFWriter(Object & Obj,raw_ostream & Out)55*25d7b4fbSAlexey Lapshin COFFWriter(Object &Obj, raw_ostream &Out) 56*25d7b4fbSAlexey Lapshin : Obj(Obj), Out(Out), StrTabBuilder(StringTableBuilder::WinCOFF) {} 57*25d7b4fbSAlexey Lapshin }; 58*25d7b4fbSAlexey Lapshin 59*25d7b4fbSAlexey Lapshin } // end namespace coff 60*25d7b4fbSAlexey Lapshin } // end namespace objcopy 61*25d7b4fbSAlexey Lapshin } // end namespace llvm 62*25d7b4fbSAlexey Lapshin 63*25d7b4fbSAlexey Lapshin #endif // LLVM_LIB_OBJCOPY_COFF_COFFWRITER_H 64