Coverage Report

Created: 2018-08-19 21:11

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