blob: 1afd8bf8631155eb249f94728e61c1b8a6aa878d [file] [log] [blame]
Rafael Espindola5805c4f2015-09-21 21:38:08 +00001//===- 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 "lld/Core/LLVM.h"
14
Rafael Espindolac159c962015-10-19 21:00:02 +000015#include "llvm/ADT/MapVector.h"
Rafael Espindola5805c4f2015-09-21 21:38:08 +000016#include "llvm/MC/StringTableBuilder.h"
17#include "llvm/Object/ELF.h"
18
Davide Italiano85121bb2015-09-25 03:56:11 +000019#include "Config.h"
20
Rafael Espindola5805c4f2015-09-21 21:38:08 +000021#include <type_traits>
22
23namespace lld {
24namespace elf2 {
25
26class SymbolBody;
Rui Ueyama3ce825e2015-10-09 21:07:25 +000027template <class ELFT> class SymbolTable;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000028template <class ELFT> class SymbolTableSection;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +000029template <class ELFT> class StringTableSection;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000030template <class ELFT> class InputSection;
Rafael Espindolac159c962015-10-19 21:00:02 +000031template <class ELFT> class MergeInputSection;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000032template <class ELFT> class OutputSection;
33template <class ELFT> class ObjectFile;
34template <class ELFT> class DefinedRegular;
Rafael Espindolacd076f02015-09-25 18:19:03 +000035template <class ELFT> class ELFSymbolBody;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000036
Rafael Espindola5805c4f2015-09-21 21:38:08 +000037template <class ELFT>
Rafael Espindola932efcf2015-10-19 20:24:44 +000038static inline typename llvm::object::ELFFile<ELFT>::uintX_t
39getAddend(const typename llvm::object::ELFFile<ELFT>::Elf_Rel &Rel) {
40 return 0;
41}
Rafael Espindola5805c4f2015-09-21 21:38:08 +000042
43template <class ELFT>
Rafael Espindola932efcf2015-10-19 20:24:44 +000044static inline typename llvm::object::ELFFile<ELFT>::uintX_t
45getAddend(const typename llvm::object::ELFFile<ELFT>::Elf_Rela &Rel) {
46 return Rel.r_addend;
47}
48
49template <class ELFT>
50typename llvm::object::ELFFile<ELFT>::uintX_t getSymVA(const SymbolBody &S);
51
52template <class ELFT, bool IsRela>
Rafael Espindola5805c4f2015-09-21 21:38:08 +000053typename llvm::object::ELFFile<ELFT>::uintX_t
Rui Ueyama126d08f2015-10-12 20:28:22 +000054getLocalRelTarget(const ObjectFile<ELFT> &File,
Rafael Espindola932efcf2015-10-19 20:24:44 +000055 const llvm::object::Elf_Rel_Impl<ELFT, IsRela> &Rel);
Rafael Espindolacc6ebb82015-10-14 18:42:16 +000056bool canBePreempted(const SymbolBody *Body, bool NeedsGot);
Rafael Espindola4f674ed2015-10-05 15:24:04 +000057template <class ELFT> bool includeInSymtab(const SymbolBody &B);
58
Rafael Espindola05a3dd22015-09-22 23:38:23 +000059bool includeInDynamicSymtab(const SymbolBody &B);
Rafael Espindolad1cf4212015-10-05 16:25:43 +000060
61template <class ELFT>
62bool shouldKeepInSymtab(
Rafael Espindola444576d2015-10-09 19:25:07 +000063 const ObjectFile<ELFT> &File, StringRef Name,
64 const typename llvm::object::ELFFile<ELFT>::Elf_Sym &Sym);
Davide Italiano85121bb2015-09-25 03:56:11 +000065
Rafael Espindola71675852015-09-22 00:16:19 +000066// This represents a section in an output file.
67// Different sub classes represent different types of sections. Some contain
68// input sections, others are created by the linker.
69// The writer creates multiple OutputSections and assign them unique,
Rafael Espindola5805c4f2015-09-21 21:38:08 +000070// non-overlapping file offsets and VAs.
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +000071template <class ELFT> class OutputSectionBase {
Rafael Espindola5805c4f2015-09-21 21:38:08 +000072public:
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +000073 typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
74 typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000075
76 OutputSectionBase(StringRef Name, uint32_t sh_type, uintX_t sh_flags);
77 void setVA(uintX_t VA) { Header.sh_addr = VA; }
78 uintX_t getVA() const { return Header.sh_addr; }
79 void setFileOffset(uintX_t Off) { Header.sh_offset = Off; }
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +000080 void writeHeaderTo(Elf_Shdr *SHdr);
Rafael Espindola5805c4f2015-09-21 21:38:08 +000081 StringRef getName() { return Name; }
Rafael Espindola5805c4f2015-09-21 21:38:08 +000082
Rui Ueyama2317d0d2015-10-15 20:55:22 +000083 unsigned SectionIndex;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000084
85 // Returns the size of the section in the output file.
Rafael Espindola77572242015-10-02 19:37:55 +000086 uintX_t getSize() const { return Header.sh_size; }
Rafael Espindola5805c4f2015-09-21 21:38:08 +000087 void setSize(uintX_t Val) { Header.sh_size = Val; }
88 uintX_t getFlags() { return Header.sh_flags; }
89 uintX_t getFileOff() { return Header.sh_offset; }
90 uintX_t getAlign() {
91 // The ELF spec states that a value of 0 means the section has no alignment
92 // constraits.
93 return std::max<uintX_t>(Header.sh_addralign, 1);
94 }
95 uint32_t getType() { return Header.sh_type; }
Rafael Espindola115f0f32015-11-03 14:13:40 +000096 void updateAlign(uintX_t Align) {
97 if (Align > Header.sh_addralign)
98 Header.sh_addralign = Align;
99 }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000100
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000101 virtual void finalize() {}
102 virtual void writeTo(uint8_t *Buf) = 0;
103
104protected:
105 StringRef Name;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000106 Elf_Shdr Header;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000107 ~OutputSectionBase() = default;
108};
109
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000110template <class ELFT> class GotSection final : public OutputSectionBase<ELFT> {
111 typedef OutputSectionBase<ELFT> Base;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000112 typedef typename Base::uintX_t uintX_t;
113
114public:
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000115 GotSection();
Igor Kudrin15cd9ff2015-11-06 07:43:03 +0000116 void finalize() override;
Rafael Espindolaa6627382015-10-06 23:56:53 +0000117 void writeTo(uint8_t *Buf) override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000118 void addEntry(SymbolBody *Sym);
Michael J. Spencer1e225612015-11-11 01:00:24 +0000119 uint32_t addLocalModuleTlsIndex();
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000120 bool empty() const { return Entries.empty(); }
121 uintX_t getEntryAddr(const SymbolBody &B) const;
122
123private:
124 std::vector<const SymbolBody *> Entries;
125};
126
George Rimar648a2c32015-10-20 08:54:27 +0000127template <class ELFT>
128class GotPltSection final : public OutputSectionBase<ELFT> {
129 typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
130
131public:
132 GotPltSection();
133 void finalize() override;
134 void writeTo(uint8_t *Buf) override;
135 void addEntry(SymbolBody *Sym);
136 bool empty() const;
137 uintX_t getEntryAddr(const SymbolBody &B) const;
138
139private:
140 std::vector<const SymbolBody *> Entries;
141};
142
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000143template <class ELFT> class PltSection final : public OutputSectionBase<ELFT> {
144 typedef OutputSectionBase<ELFT> Base;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000145 typedef typename Base::uintX_t uintX_t;
146
147public:
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000148 PltSection();
Hal Finkel6c2a3b82015-10-08 21:51:31 +0000149 void finalize() override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000150 void writeTo(uint8_t *Buf) override;
151 void addEntry(SymbolBody *Sym);
152 bool empty() const { return Entries.empty(); }
153 uintX_t getEntryAddr(const SymbolBody &B) const;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000154
155private:
156 std::vector<const SymbolBody *> Entries;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000157};
158
159template <class ELFT> struct DynamicReloc {
160 typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel;
161 const InputSection<ELFT> &C;
162 const Elf_Rel &RI;
163};
164
165template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000166class SymbolTableSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000167public:
168 typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
169 typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
170 typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym_Range Elf_Sym_Range;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000171 typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
Rui Ueyama3ce825e2015-10-09 21:07:25 +0000172 SymbolTableSection(SymbolTable<ELFT> &Table,
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000173 StringTableSection<ELFT> &StrTabSec);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000174
Rui Ueyama0db335f2015-10-07 16:58:54 +0000175 void finalize() override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000176 void writeTo(uint8_t *Buf) override;
Igor Kudrinab665fc2015-10-20 21:47:58 +0000177 void addLocalSymbol(StringRef Name);
178 void addSymbol(SymbolBody *Body);
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000179 StringTableSection<ELFT> &getStrTabSec() const { return StrTabSec; }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000180 unsigned getNumSymbols() const { return NumVisible + 1; }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000181
Igor Kudrinf1d60292015-10-28 07:05:56 +0000182 ArrayRef<SymbolBody *> getSymbols() const { return Symbols; }
Igor Kudrinab665fc2015-10-20 21:47:58 +0000183
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000184private:
Rui Ueyama8ddfa812015-09-30 00:32:10 +0000185 void writeLocalSymbols(uint8_t *&Buf);
Igor Kudrinea6a8352015-10-19 08:01:51 +0000186 void writeGlobalSymbols(uint8_t *Buf);
Rui Ueyama8ddfa812015-09-30 00:32:10 +0000187
Igor Kudrin853b88d2015-10-20 20:52:14 +0000188 static uint8_t getSymbolBinding(SymbolBody *Body);
189
Rui Ueyama3ce825e2015-10-09 21:07:25 +0000190 SymbolTable<ELFT> &Table;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000191 StringTableSection<ELFT> &StrTabSec;
Igor Kudrinf1d60292015-10-28 07:05:56 +0000192 std::vector<SymbolBody *> Symbols;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000193 unsigned NumVisible = 0;
194 unsigned NumLocals = 0;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000195};
196
197template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000198class RelocationSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000199 typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel;
200 typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela;
Rafael Espindola3c83e2b2015-10-05 21:09:37 +0000201 typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000202
203public:
George Rimar648a2c32015-10-20 08:54:27 +0000204 RelocationSection(StringRef Name, bool IsRela);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000205 void addReloc(const DynamicReloc<ELFT> &Reloc) { Relocs.push_back(Reloc); }
206 void finalize() override;
207 void writeTo(uint8_t *Buf) override;
208 bool hasRelocs() const { return !Relocs.empty(); }
209 bool isRela() const { return IsRela; }
210
211private:
212 std::vector<DynamicReloc<ELFT>> Relocs;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000213 const bool IsRela;
214};
215
216template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000217class OutputSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000218public:
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000219 typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
220 typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
221 typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel;
222 typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000223 typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000224 OutputSection(StringRef Name, uint32_t sh_type, uintX_t sh_flags);
Rafael Espindola71675852015-09-22 00:16:19 +0000225 void addSection(InputSection<ELFT> *C);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000226 void writeTo(uint8_t *Buf) override;
227
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000228private:
Rafael Espindola71675852015-09-22 00:16:19 +0000229 std::vector<InputSection<ELFT> *> Sections;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000230};
231
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000232template <class ELFT>
Rafael Espindolac159c962015-10-19 21:00:02 +0000233class MergeOutputSection final : public OutputSectionBase<ELFT> {
234 typedef typename OutputSectionBase<ELFT>::uintX_t uintX_t;
235
Rafael Espindolaf82ed2a2015-10-24 22:51:01 +0000236 bool shouldTailMerge() const;
237
Rafael Espindolac159c962015-10-19 21:00:02 +0000238public:
239 MergeOutputSection(StringRef Name, uint32_t sh_type, uintX_t sh_flags);
240 void addSection(MergeInputSection<ELFT> *S);
241 void writeTo(uint8_t *Buf) override;
Rafael Espindolaf82ed2a2015-10-24 22:51:01 +0000242 unsigned getOffset(StringRef Val);
243 void finalize() override;
Rafael Espindolac159c962015-10-19 21:00:02 +0000244
245private:
Rafael Espindolaf82ed2a2015-10-24 22:51:01 +0000246 llvm::StringTableBuilder Builder{llvm::StringTableBuilder::RAW};
Rafael Espindolac159c962015-10-19 21:00:02 +0000247};
248
249template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000250class InterpSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000251public:
252 InterpSection();
Eugene Zelenko6e43b492015-11-04 02:11:57 +0000253 void writeTo(uint8_t *Buf) override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000254};
255
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000256template <class ELFT>
257class StringTableSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000258public:
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000259 typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
George Rimar0f5ac9f2015-10-20 17:21:35 +0000260 StringTableSection(StringRef Name, bool Dynamic);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000261 void add(StringRef S) { StrTabBuilder.add(S); }
Rui Ueyama9fbb3d82015-10-24 17:44:52 +0000262 size_t getOffset(StringRef S) const { return StrTabBuilder.getOffset(S); }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000263 StringRef data() const { return StrTabBuilder.data(); }
264 void writeTo(uint8_t *Buf) override;
265
266 void finalize() override {
Rafael Espindola6779a232015-10-23 21:48:35 +0000267 StrTabBuilder.finalize();
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000268 this->Header.sh_size = StrTabBuilder.data().size();
269 }
270
271 bool isDynamic() const { return Dynamic; }
272
273private:
274 const bool Dynamic;
Rafael Espindola6779a232015-10-23 21:48:35 +0000275 llvm::StringTableBuilder StrTabBuilder{llvm::StringTableBuilder::ELF};
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000276};
277
278template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000279class HashTableSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000280 typedef typename llvm::object::ELFFile<ELFT>::Elf_Word Elf_Word;
281
282public:
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000283 HashTableSection();
Rui Ueyama0db335f2015-10-07 16:58:54 +0000284 void finalize() override;
285 void writeTo(uint8_t *Buf) override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000286};
287
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000288// Outputs GNU Hash section. For detailed explanation see:
289// https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections
290template <class ELFT>
291class GnuHashTableSection final : public OutputSectionBase<ELFT> {
292 typedef typename llvm::object::ELFFile<ELFT>::Elf_Off Elf_Off;
293 typedef typename llvm::object::ELFFile<ELFT>::Elf_Word Elf_Word;
294 typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
295
296public:
297 GnuHashTableSection();
298 void finalize() override;
299 void writeTo(uint8_t *Buf) override;
300
Igor Kudrinf1d60292015-10-28 07:05:56 +0000301 // Adds symbols to the hash table.
302 // Sorts the input to satisfy GNU hash section requirements.
303 void addSymbols(std::vector<SymbolBody *> &Symbols);
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000304
305private:
Igor Kudrinf1d60292015-10-28 07:05:56 +0000306 static unsigned calcNBuckets(unsigned NumHashed);
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000307 static unsigned calcMaskWords(unsigned NumHashed);
308
309 void writeHeader(uint8_t *&Buf);
310 void writeBloomFilter(uint8_t *&Buf);
311 void writeHashTable(uint8_t *Buf);
312
Igor Kudrinf1d60292015-10-28 07:05:56 +0000313 struct HashedSymbolData {
314 SymbolBody *Body;
315 uint32_t Hash;
316 };
317
318 std::vector<HashedSymbolData> HashedSymbols;
319
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000320 unsigned MaskWords;
321 unsigned NBuckets;
322 unsigned Shift2;
323};
324
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000325template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000326class DynamicSection final : public OutputSectionBase<ELFT> {
327 typedef OutputSectionBase<ELFT> Base;
328 typedef typename llvm::object::ELFFile<ELFT>::Elf_Dyn Elf_Dyn;
Rui Ueyama2dfd74f2015-09-30 21:57:53 +0000329 typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel;
330 typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000331 typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
Rui Ueyama2dfd74f2015-09-30 21:57:53 +0000332 typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000333
334public:
Rui Ueyama3ce825e2015-10-09 21:07:25 +0000335 DynamicSection(SymbolTable<ELFT> &SymTab);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000336 void finalize() override;
337 void writeTo(uint8_t *Buf) override;
338
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000339 OutputSectionBase<ELFT> *PreInitArraySec = nullptr;
340 OutputSectionBase<ELFT> *InitArraySec = nullptr;
341 OutputSectionBase<ELFT> *FiniArraySec = nullptr;
Rafael Espindola77572242015-10-02 19:37:55 +0000342
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000343private:
Rui Ueyama3ce825e2015-10-09 21:07:25 +0000344 SymbolTable<ELFT> &SymTab;
Igor Kudrinb1f2b512015-10-05 10:29:46 +0000345 const ELFSymbolBody<ELFT> *InitSym = nullptr;
346 const ELFSymbolBody<ELFT> *FiniSym = nullptr;
Rui Ueyamac96d0dd2015-10-21 17:47:10 +0000347 uint32_t DtFlags = 0;
348 uint32_t DtFlags1 = 0;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000349};
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000350
351// All output sections that are hadnled by the linker specially are
352// globally accessible. Writer initializes them, so don't use them
353// until Writer is initialized.
354template <class ELFT> struct Out {
Michael J. Spencerd77f0d22015-11-03 22:39:09 +0000355 typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
Rafael Espindolaea7a1e902015-11-06 22:14:44 +0000356 typedef typename llvm::object::ELFFile<ELFT>::Elf_Phdr Elf_Phdr;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000357 static DynamicSection<ELFT> *Dynamic;
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000358 static GnuHashTableSection<ELFT> *GnuHashTab;
George Rimar648a2c32015-10-20 08:54:27 +0000359 static GotPltSection<ELFT> *GotPlt;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000360 static GotSection<ELFT> *Got;
361 static HashTableSection<ELFT> *HashTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000362 static InterpSection<ELFT> *Interp;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000363 static OutputSection<ELFT> *Bss;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000364 static OutputSectionBase<ELFT> *Opd;
Hal Finkeldaedc122015-10-12 23:16:53 +0000365 static uint8_t *OpdBuf;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000366 static PltSection<ELFT> *Plt;
367 static RelocationSection<ELFT> *RelaDyn;
George Rimar648a2c32015-10-20 08:54:27 +0000368 static RelocationSection<ELFT> *RelaPlt;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000369 static StringTableSection<ELFT> *DynStrTab;
George Rimar0f5ac9f2015-10-20 17:21:35 +0000370 static StringTableSection<ELFT> *ShStrTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000371 static StringTableSection<ELFT> *StrTab;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000372 static SymbolTableSection<ELFT> *DynSymTab;
373 static SymbolTableSection<ELFT> *SymTab;
Rafael Espindolaea7a1e902015-11-06 22:14:44 +0000374 static Elf_Phdr *TlsPhdr;
Michael J. Spencer1e225612015-11-11 01:00:24 +0000375 static uint32_t LocalModuleTlsIndexOffset;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000376};
Rui Ueyamad888d102015-10-09 19:34:55 +0000377
378template <class ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic;
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000379template <class ELFT> GnuHashTableSection<ELFT> *Out<ELFT>::GnuHashTab;
George Rimar648a2c32015-10-20 08:54:27 +0000380template <class ELFT> GotPltSection<ELFT> *Out<ELFT>::GotPlt;
Rui Ueyamad888d102015-10-09 19:34:55 +0000381template <class ELFT> GotSection<ELFT> *Out<ELFT>::Got;
382template <class ELFT> HashTableSection<ELFT> *Out<ELFT>::HashTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000383template <class ELFT> InterpSection<ELFT> *Out<ELFT>::Interp;
Rafael Espindolad7a267b2015-11-03 22:01:20 +0000384template <class ELFT> OutputSection<ELFT> *Out<ELFT>::Bss;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000385template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::Opd;
Hal Finkeldaedc122015-10-12 23:16:53 +0000386template <class ELFT> uint8_t *Out<ELFT>::OpdBuf;
Rui Ueyamad888d102015-10-09 19:34:55 +0000387template <class ELFT> PltSection<ELFT> *Out<ELFT>::Plt;
388template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaDyn;
George Rimar648a2c32015-10-20 08:54:27 +0000389template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaPlt;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000390template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::DynStrTab;
George Rimar0f5ac9f2015-10-20 17:21:35 +0000391template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::ShStrTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000392template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::StrTab;
Rui Ueyamad888d102015-10-09 19:34:55 +0000393template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::DynSymTab;
394template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::SymTab;
Rafael Espindolaea7a1e902015-11-06 22:14:44 +0000395template <class ELFT> typename Out<ELFT>::Elf_Phdr *Out<ELFT>::TlsPhdr;
Michael J. Spencer1e225612015-11-11 01:00:24 +0000396template <class ELFT> uint32_t Out<ELFT>::LocalModuleTlsIndexOffset = -1;
Eugene Zelenko6e43b492015-11-04 02:11:57 +0000397
398} // namespace elf2
399} // namespace lld
400
401#endif // LLD_ELF_OUTPUT_SECTIONS_H