1 //===- Writer.h -------------------------------------------------*- C++ -*-===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLD_COFF_WRITER_H
11 #define LLD_COFF_WRITER_H
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Object/COFF.h"
22 static const int PageSize = 4096;
26 // OutputSection represents a section in an output file. It's a
27 // container of chunks. OutputSection and Chunk are 1:N relationship.
28 // Chunks cannot belong to more than one OutputSections. The writer
29 // creates multiple OutputSections and assign them unique,
30 // non-overlapping file offsets and RVAs.
33 OutputSection(llvm::StringRef N, uint32_t Chars) : Name(N) {
34 Header.Characteristics = Chars;
36 void addChunk(Chunk *C);
37 void merge(OutputSection *Other);
38 ArrayRef<Chunk *> getChunks() { return Chunks; }
39 void addPermissions(uint32_t C);
40 void setPermissions(uint32_t C);
41 uint64_t getRVA() { return Header.VirtualAddress; }
42 uint64_t getFileOff() { return Header.PointerToRawData; }
43 void writeHeaderTo(uint8_t *Buf);
45 // Returns the size of this section in an executable memory image.
46 // This may be smaller than the raw size (the raw size is multiple
47 // of disk sector size, so there may be padding at end), or may be
48 // larger (if that's the case, the loader reserves spaces after end
50 uint64_t getVirtualSize() { return Header.VirtualSize; }
52 // Returns the size of the section in the output file.
53 uint64_t getRawSize() { return Header.SizeOfRawData; }
55 // Set offset into the string table storing this section name.
56 // Used only when the name is longer than 8 bytes.
57 void setStringTableOff(uint32_t V) { StringTableOff = V; }
59 // N.B. The section index is one based.
60 uint32_t SectionIndex = 0;
63 llvm::object::coff_section Header = {};
66 uint32_t StringTableOff = 0;
67 std::vector<Chunk *> Chunks;