Coverage Report

Created: 2018-01-17 17:22

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/ELF/OutputSections.h
Line
Count
Source (jump to first uncovered line)
1
//===- OutputSections.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_ELF_OUTPUT_SECTIONS_H
11
#define LLD_ELF_OUTPUT_SECTIONS_H
12
13
#include "Config.h"
14
#include "InputSection.h"
15
#include "LinkerScript.h"
16
#include "Relocations.h"
17
18
#include "lld/Common/LLVM.h"
19
#include "llvm/MC/StringTableBuilder.h"
20
#include "llvm/Object/ELF.h"
21
22
namespace lld {
23
namespace elf {
24
25
struct PhdrEntry;
26
class Symbol;
27
struct EhSectionPiece;
28
class EhInputSection;
29
class InputSection;
30
class InputSectionBase;
31
class MergeInputSection;
32
class OutputSection;
33
template <class ELFT> class ObjFile;
34
template <class ELFT> class SharedFile;
35
class SharedSymbol;
36
class Defined;
37
38
// This represents a section in an output file.
39
// It is composed of multiple InputSections.
40
// The writer creates multiple OutputSections and assign them unique,
41
// non-overlapping file offsets and VAs.
42
class OutputSection final : public BaseCommand, public SectionBase {
43
public:
44
  OutputSection(StringRef Name, uint32_t Type, uint64_t Flags);
45
46
0
  static bool classof(const SectionBase *S) {
47
0
    return S->kind() == SectionBase::Output;
48
0
  }
49
50
  static bool classof(const BaseCommand *C);
51
52
6.81k
  uint64_t getLMA() const { return Addr + LMAOffset; }
53
  template <typename ELFT> void writeHeaderTo(typename ELFT::Shdr *SHdr);
54
55
  unsigned SectionIndex;
56
  unsigned SortRank;
57
58
  uint32_t getPhdrFlags() const;
59
60
  // Pointer to the PT_LOAD segment, which this section resides in. This field
61
  // is used to correctly compute file offset of a section. When two sections
62
  // share the same load segment, difference between their file offsets should
63
  // be equal to difference between their virtual addresses. To compute some
64
  // section offset we use the following formula: Off = Off_first + VA -
65
  // VA_first, where Off_first and VA_first is file offset and VA of first
66
  // section in PT_LOAD.
67
  PhdrEntry *PtLoad = nullptr;
68
69
  // Pointer to a relocation section for this section. Usually nullptr because
70
  // we consume relocations, but if --emit-relocs is specified (which is rare),
71
  // it may have a non-null value.
72
  OutputSection *RelocationSection = nullptr;
73
74
  // Initially this field is the number of InputSections that have been added to
75
  // the OutputSection so far. Later on, after a call to assignAddresses, it
76
  // corresponds to the Elf_Shdr member.
77
  uint64_t Size = 0;
78
79
  // The following fields correspond to Elf_Shdr members.
80
  uint64_t Offset = 0;
81
  uint64_t LMAOffset = 0;
82
  uint64_t Addr = 0;
83
  uint32_t ShName = 0;
84
85
  void addSection(InputSection *IS);
86
87
  // Location in the output buffer.
88
  uint8_t *Loc = nullptr;
89
90
  // The following members are normally only used in linker scripts.
91
  MemoryRegion *MemRegion = nullptr;
92
  Expr AddrExpr;
93
  Expr AlignExpr;
94
  Expr LMAExpr;
95
  Expr SubalignExpr;
96
  std::vector<BaseCommand *> SectionCommands;
97
  std::vector<StringRef> Phdrs;
98
  llvm::Optional<uint32_t> Filler;
99
  ConstraintKind Constraint = ConstraintKind::NoConstraint;
100
  std::string Location;
101
  std::string MemoryRegionName;
102
  std::string LMARegionName;
103
  bool Noload = false;
104
105
  template <class ELFT> void finalize();
106
  template <class ELFT> void writeTo(uint8_t *Buf);
107
  template <class ELFT> void maybeCompress();
108
109
  void sort(std::function<int(InputSectionBase *S)> Order);
110
  void sortInitFini();
111
  void sortCtorsDtors();
112
113
private:
114
  // Used for implementation of --compress-debug-sections option.
115
  std::vector<uint8_t> ZDebugHeader;
116
  llvm::SmallVector<char, 1> CompressedData;
117
118
  uint32_t getFiller();
119
};
120
121
int getPriority(StringRef S);
122
123
// All output sections that are handled by the linker specially are
124
// globally accessible. Writer initializes them, so don't use them
125
// until Writer is initialized.
126
struct Out {
127
  static uint8_t First;
128
  static OutputSection *Opd;
129
  static uint8_t *OpdBuf;
130
  static PhdrEntry *TlsPhdr;
131
  static OutputSection *DebugInfo;
132
  static OutputSection *ElfHeader;
133
  static OutputSection *ProgramHeaders;
134
  static OutputSection *PreinitArray;
135
  static OutputSection *InitArray;
136
  static OutputSection *FiniArray;
137
};
138
139
} // namespace elf
140
} // namespace lld
141
142
namespace lld {
143
namespace elf {
144
145
uint64_t getHeaderSize();
146
void sortByOrder(llvm::MutableArrayRef<InputSection *> In,
147
                 std::function<int(InputSectionBase *S)> Order);
148
149
extern std::vector<OutputSection *> OutputSections;
150
} // namespace elf
151
} // namespace lld
152
153
#endif