forked from llvm/llvm-project
- Notifications
You must be signed in to change notification settings - Fork 339
/
Copy pathOutputSections.h
147 lines (118 loc) · 4.58 KB
/
OutputSections.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//===- OutputSections.h -----------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_ELF_OUTPUT_SECTIONS_H
#defineLLD_ELF_OUTPUT_SECTIONS_H
#include"Config.h"
#include"InputSection.h"
#include"LinkerScript.h"
#include"Relocations.h"
#include"lld/Common/LLVM.h"
#include"llvm/MC/StringTableBuilder.h"
#include"llvm/Object/ELF.h"
#include<array>
namespacelld {
namespaceelf {
structPhdrEntry;
classInputSection;
classInputSectionBase;
// This represents a section in an output file.
// It is composed of multiple InputSections.
// The writer creates multiple OutputSections and assign them unique,
// non-overlapping file offsets and VAs.
classOutputSectionfinal : public BaseCommand, public SectionBase {
public:
OutputSection(StringRef Name, uint32_t Type, uint64_t Flags);
staticboolclassof(const SectionBase *S) {
return S->kind() == SectionBase::Output;
}
staticboolclassof(const BaseCommand *C);
uint64_tgetLMA() const { return PtLoad ? Addr + PtLoad->LMAOffset : Addr; }
template <typename ELFT> voidwriteHeaderTo(typename ELFT::Shdr *SHdr);
uint32_t SectionIndex = UINT32_MAX;
unsigned SortRank;
uint32_tgetPhdrFlags() const;
// Pointer to the PT_LOAD segment, which this section resides in. This field
// is used to correctly compute file offset of a section. When two sections
// share the same load segment, difference between their file offsets should
// be equal to difference between their virtual addresses. To compute some
// section offset we use the following formula: Off = Off_first + VA -
// VA_first, where Off_first and VA_first is file offset and VA of first
// section in PT_LOAD.
PhdrEntry *PtLoad = nullptr;
// Pointer to a relocation section for this section. Usually nullptr because
// we consume relocations, but if --emit-relocs is specified (which is rare),
// it may have a non-null value.
OutputSection *RelocationSection = nullptr;
// Initially this field is the number of InputSections that have been added to
// the OutputSection so far. Later on, after a call to assignAddresses, it
// corresponds to the Elf_Shdr member.
uint64_tSize = 0;
// The following fields correspond to Elf_Shdr members.
uint64_t Offset = 0;
uint64_t Addr = 0;
uint32_t ShName = 0;
voidaddSection(InputSection *IS);
// The following members are normally only used in linker scripts.
MemoryRegion *MemRegion = nullptr;
MemoryRegion *LMARegion = nullptr;
Expr AddrExpr;
Expr AlignExpr;
Expr LMAExpr;
Expr SubalignExpr;
std::vector<BaseCommand *> SectionCommands;
std::vector<StringRef> Phdrs;
llvm::Optional<std::array<uint8_t, 4>> Filler;
ConstraintKind Constraint = ConstraintKind::NoConstraint;
std::string Location;
std::string MemoryRegionName;
std::string LMARegionName;
bool NonAlloc = false;
bool Noload = false;
bool ExpressionsUseSymbols = false;
bool UsedInExpression = false;
bool InOverlay = false;
// Tracks whether the section has ever had an input section added to it, even
// if the section was later removed (e.g. because it is a synthetic section
// that wasn't needed). This is needed for orphan placement.
bool HasInputSections = false;
voidfinalize();
template <classELFT> voidwriteTo(uint8_t *Buf);
template <classELFT> voidmaybeCompress();
voidsort(llvm::function_ref<int(InputSectionBase *S)> Order);
voidsortInitFini();
voidsortCtorsDtors();
private:
// Used for implementation of --compress-debug-sections option.
std::vector<uint8_t> ZDebugHeader;
llvm::SmallVector<char, 1> CompressedData;
std::array<uint8_t, 4> getFiller();
};
intgetPriority(StringRef S);
std::vector<InputSection *> getInputSections(OutputSection* OS);
// All output sections that are handled by the linker specially are
// globally accessible. Writer initializes them, so don't use them
// until Writer is initialized.
structOut {
staticuint8_t *BufferStart;
staticuint8_t First;
static PhdrEntry *TlsPhdr;
static OutputSection *ElfHeader;
static OutputSection *ProgramHeaders;
static OutputSection *PreinitArray;
static OutputSection *InitArray;
static OutputSection *FiniArray;
};
} // namespace elf
} // namespace lld
namespacelld {
namespaceelf {
uint64_tgetHeaderSize();
extern std::vector<OutputSection *> OutputSections;
} // namespace elf
} // namespace lld
#endif