]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/COFF/Writer.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / COFF / Writer.h
1 //===- Writer.h -------------------------------------------------*- C++ -*-===//
2 //
3 //                             The LLVM Linker
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLD_COFF_WRITER_H
11 #define LLD_COFF_WRITER_H
12
13 #include "Chunks.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Object/COFF.h"
16 #include <chrono>
17 #include <cstdint>
18 #include <vector>
19
20 namespace lld {
21 namespace coff {
22 static const int PageSize = 4096;
23
24 void writeResult();
25
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.
31 class OutputSection {
32 public:
33   OutputSection(llvm::StringRef N, uint32_t Chars) : Name(N) {
34     Header.Characteristics = Chars;
35   }
36   void addChunk(Chunk *C);
37   void insertChunkAtStart(Chunk *C);
38   void merge(OutputSection *Other);
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);
44
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
49   // of raw data).
50   uint64_t getVirtualSize() { return Header.VirtualSize; }
51
52   // Returns the size of the section in the output file.
53   uint64_t getRawSize() { return Header.SizeOfRawData; }
54
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; }
58
59   // N.B. The section index is one based.
60   uint32_t SectionIndex = 0;
61
62   llvm::StringRef Name;
63   llvm::object::coff_section Header = {};
64
65   std::vector<Chunk *> Chunks;
66   std::vector<Chunk *> OrigChunks;
67
68 private:
69   uint32_t StringTableOff = 0;
70 };
71
72 }
73 }
74
75 #endif