Coverage Report

Created: 2019-05-19 14:56

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/COFF/Writer.h
Line
Count
Source
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
9
#ifndef LLD_COFF_WRITER_H
10
#define LLD_COFF_WRITER_H
11
12
#include "Chunks.h"
13
#include "llvm/ADT/StringRef.h"
14
#include "llvm/Object/COFF.h"
15
#include <chrono>
16
#include <cstdint>
17
#include <vector>
18
19
namespace lld {
20
namespace coff {
21
static const int PageSize = 4096;
22
23
void writeResult();
24
25
class PartialSection {
26
public:
27
  PartialSection(StringRef N, uint32_t Chars)
28
1.65k
      : Name(N), Characteristics(Chars) {}
29
  StringRef Name;
30
  unsigned Characteristics;
31
  std::vector<Chunk *> Chunks;
32
};
33
34
// OutputSection represents a section in an output file. It's a
35
// container of chunks. OutputSection and Chunk are 1:N relationship.
36
// Chunks cannot belong to more than one OutputSections. The writer
37
// creates multiple OutputSections and assign them unique,
38
// non-overlapping file offsets and RVAs.
39
class OutputSection {
40
public:
41
7.21k
  OutputSection(llvm::StringRef N, uint32_t Chars) : Name(N) {
42
7.21k
    Header.Characteristics = Chars;
43
7.21k
  }
44
  void addChunk(Chunk *C);
45
  void insertChunkAtStart(Chunk *C);
46
  void merge(OutputSection *Other);
47
  void setPermissions(uint32_t C);
48
6.49k
  uint64_t getRVA() { return Header.VirtualAddress; }
49
1.38k
  uint64_t getFileOff() { return Header.PointerToRawData; }
50
  void writeHeaderTo(uint8_t *Buf);
51
  void addContributingPartialSection(PartialSection *Sec);
52
53
  // Returns the size of this section in an executable memory image.
54
  // This may be smaller than the raw size (the raw size is multiple
55
  // of disk sector size, so there may be padding at end), or may be
56
  // larger (if that's the case, the loader reserves spaces after end
57
  // of raw data).
58
3.87k
  uint64_t getVirtualSize() { return Header.VirtualSize; }
59
60
  // Returns the size of the section in the output file.
61
1.65k
  uint64_t getRawSize() { return Header.SizeOfRawData; }
62
63
  // Set offset into the string table storing this section name.
64
  // Used only when the name is longer than 8 bytes.
65
18
  void setStringTableOff(uint32_t V) { StringTableOff = V; }
66
67
  // N.B. The section index is one based.
68
  uint32_t SectionIndex = 0;
69
70
  llvm::StringRef Name;
71
  llvm::object::coff_section Header = {};
72
73
  std::vector<Chunk *> Chunks;
74
  std::vector<Chunk *> OrigChunks;
75
76
  std::vector<PartialSection *> ContribSections;
77
78
private:
79
  uint32_t StringTableOff = 0;
80
};
81
82
} // namespace coff
83
} // namespace lld
84
85
#endif