blob: 09b7bbe79dc7af55dc04bbf012390e616a735765 [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
Davide Italiano85121bb2015-09-25 03:56:11 +000013#include "Config.h"
Simon Atanasyan41325112016-06-19 21:39:37 +000014#include "Relocations.h"
Davide Italiano85121bb2015-09-25 03:56:11 +000015
Rui Ueyamaa0752a52016-03-13 20:28:29 +000016#include "lld/Core/LLVM.h"
Simon Atanasyand2980d32016-03-29 14:07:22 +000017#include "llvm/ADT/SmallPtrSet.h"
Rui Ueyamaa0752a52016-03-13 20:28:29 +000018#include "llvm/MC/StringTableBuilder.h"
19#include "llvm/Object/ELF.h"
Rui Ueyama3a41be22016-04-07 22:49:21 +000020#include "llvm/Support/MD5.h"
Rui Ueyamad86ec302016-04-07 23:51:56 +000021#include "llvm/Support/SHA1.h"
Rafael Espindola5805c4f2015-09-21 21:38:08 +000022
23namespace lld {
Rafael Espindolae0df00b2016-02-28 00:25:54 +000024namespace elf {
Rafael Espindola5805c4f2015-09-21 21:38:08 +000025
26class SymbolBody;
Rui Ueyamaf8b285c2016-05-22 23:16:14 +000027struct SectionPiece;
George Rimard3566302016-06-20 11:55:12 +000028struct Version;
Rui Ueyama3ce825e2015-10-09 21:07:25 +000029template <class ELFT> class SymbolTable;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000030template <class ELFT> class SymbolTableSection;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +000031template <class ELFT> class StringTableSection;
Rui Ueyama0b9a9032016-05-24 04:19:20 +000032template <class ELFT> class EhInputSection;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000033template <class ELFT> class InputSection;
Rafael Espindola0c6a4f12015-11-11 19:54:14 +000034template <class ELFT> class InputSectionBase;
Rafael Espindolac159c962015-10-19 21:00:02 +000035template <class ELFT> class MergeInputSection;
Simon Atanasyan1d7df402015-12-20 10:57:34 +000036template <class ELFT> class MipsReginfoInputSection;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000037template <class ELFT> class OutputSection;
38template <class ELFT> class ObjectFile;
Peter Collingbourne21a12fc2016-04-27 20:22:31 +000039template <class ELFT> class SharedFile;
40template <class ELFT> class SharedSymbol;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000041template <class ELFT> class DefinedRegular;
42
Rafael Espindola5805c4f2015-09-21 21:38:08 +000043template <class ELFT>
Rui Ueyama9328b2c2016-03-14 23:16:09 +000044static inline typename ELFT::uint getAddend(const typename ELFT::Rel &Rel) {
Rafael Espindola932efcf2015-10-19 20:24:44 +000045 return 0;
46}
Rafael Espindola5805c4f2015-09-21 21:38:08 +000047
48template <class ELFT>
Rui Ueyama9328b2c2016-03-14 23:16:09 +000049static inline typename ELFT::uint getAddend(const typename ELFT::Rela &Rel) {
Rafael Espindola932efcf2015-10-19 20:24:44 +000050 return Rel.r_addend;
51}
52
George Rimar12737b72016-02-25 08:40:26 +000053bool isValidCIdentifier(StringRef S);
54
Rafael Espindola71675852015-09-22 00:16:19 +000055// This represents a section in an output file.
56// Different sub classes represent different types of sections. Some contain
57// input sections, others are created by the linker.
58// The writer creates multiple OutputSections and assign them unique,
Rafael Espindola5805c4f2015-09-21 21:38:08 +000059// non-overlapping file offsets and VAs.
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +000060template <class ELFT> class OutputSectionBase {
Rafael Espindola5805c4f2015-09-21 21:38:08 +000061public:
Rui Ueyama9328b2c2016-03-14 23:16:09 +000062 typedef typename ELFT::uint uintX_t;
63 typedef typename ELFT::Shdr Elf_Shdr;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000064
George Rimar9bec24a2016-02-18 14:20:08 +000065 OutputSectionBase(StringRef Name, uint32_t Type, uintX_t Flags);
Rafael Espindola5805c4f2015-09-21 21:38:08 +000066 void setVA(uintX_t VA) { Header.sh_addr = VA; }
67 uintX_t getVA() const { return Header.sh_addr; }
68 void setFileOffset(uintX_t Off) { Header.sh_offset = Off; }
Rafael Espindolae2c24612016-01-29 01:24:25 +000069 void setSHName(unsigned Val) { Header.sh_name = Val; }
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +000070 void writeHeaderTo(Elf_Shdr *SHdr);
Rafael Espindola5805c4f2015-09-21 21:38:08 +000071 StringRef getName() { return Name; }
Rafael Espindola5805c4f2015-09-21 21:38:08 +000072
Rui Ueyama40845e62015-12-26 05:51:07 +000073 virtual void addSection(InputSectionBase<ELFT> *C) {}
74
Rui Ueyama2317d0d2015-10-15 20:55:22 +000075 unsigned SectionIndex;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000076
77 // Returns the size of the section in the output file.
Rafael Espindola77572242015-10-02 19:37:55 +000078 uintX_t getSize() const { return Header.sh_size; }
Rafael Espindola5805c4f2015-09-21 21:38:08 +000079 void setSize(uintX_t Val) { Header.sh_size = Val; }
Rafael Espindola571452c2016-04-11 13:44:05 +000080 uintX_t getFlags() const { return Header.sh_flags; }
81 uintX_t getFileOff() const { return Header.sh_offset; }
Rui Ueyama424b4082016-06-17 01:18:46 +000082 uintX_t getAlignment() const {
Rafael Espindola5805c4f2015-09-21 21:38:08 +000083 // The ELF spec states that a value of 0 means the section has no alignment
84 // constraits.
85 return std::max<uintX_t>(Header.sh_addralign, 1);
86 }
Rafael Espindola571452c2016-04-11 13:44:05 +000087 uint32_t getType() const { return Header.sh_type; }
Rui Ueyama424b4082016-06-17 01:18:46 +000088 void updateAlignment(uintX_t Alignment) {
89 if (Alignment > Header.sh_addralign)
90 Header.sh_addralign = Alignment;
Rafael Espindola115f0f32015-11-03 14:13:40 +000091 }
Rafael Espindola5805c4f2015-09-21 21:38:08 +000092
Rui Ueyama47091902016-03-30 19:41:51 +000093 // If true, this section will be page aligned on disk.
94 // Typically the first section of each PT_LOAD segment has this flag.
95 bool PageAlign = false;
96
Rafael Espindola5805c4f2015-09-21 21:38:08 +000097 virtual void finalize() {}
Rui Ueyama406b4692016-05-27 14:39:13 +000098 virtual void finalizePieces() {}
Rui Ueyama809d8e22016-06-23 04:33:42 +000099 virtual void assignOffsets() {}
Rafael Espindola4fc60442016-02-10 22:43:13 +0000100 virtual void writeTo(uint8_t *Buf) {}
Rui Ueyamad4ea7dd2015-12-26 07:01:26 +0000101 virtual ~OutputSectionBase() = default;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000102
103protected:
104 StringRef Name;
Sean Silva580c1b62016-04-20 04:26:16 +0000105 Elf_Shdr Header;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000106};
107
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000108template <class ELFT> class GotSection final : public OutputSectionBase<ELFT> {
109 typedef OutputSectionBase<ELFT> Base;
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000110 typedef typename ELFT::uint uintX_t;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000111
112public:
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000113 GotSection();
Igor Kudrin15cd9ff2015-11-06 07:43:03 +0000114 void finalize() override;
Rafael Espindolaa6627382015-10-06 23:56:53 +0000115 void writeTo(uint8_t *Buf) override;
Rafael Espindola67d72c02016-03-11 12:06:30 +0000116 void addEntry(SymbolBody &Sym);
Simon Atanasyan41325112016-06-19 21:39:37 +0000117 void addMipsEntry(SymbolBody &Sym, uintX_t Addend, RelExpr Expr);
Rafael Espindola67d72c02016-03-11 12:06:30 +0000118 bool addDynTlsEntry(SymbolBody &Sym);
Rui Ueyama0e53c7d2016-02-05 00:10:02 +0000119 bool addTlsIndex();
Simon Atanasyan41325112016-06-19 21:39:37 +0000120 bool empty() const { return MipsPageEntries == 0 && Entries.empty(); }
Rafael Espindola58cd5db2016-04-19 22:46:03 +0000121 uintX_t getMipsLocalPageOffset(uintX_t Addr);
Simon Atanasyan41325112016-06-19 21:39:37 +0000122 uintX_t getMipsGotOffset(const SymbolBody &B, uintX_t Addend) const;
George Rimar90cd0a82015-12-01 19:20:26 +0000123 uintX_t getGlobalDynAddr(const SymbolBody &B) const;
Rafael Espindola74031ba2016-04-07 15:20:56 +0000124 uintX_t getGlobalDynOffset(const SymbolBody &B) const;
George Rimar9db204a2015-12-02 09:58:20 +0000125 uintX_t getNumEntries() const { return Entries.size(); }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000126
Igor Kudrin304860a2015-11-12 04:39:49 +0000127 // Returns the symbol which corresponds to the first entry of the global part
128 // of GOT on MIPS platform. It is required to fill up MIPS-specific dynamic
129 // table properties.
130 // Returns nullptr if the global part is empty.
131 const SymbolBody *getMipsFirstGlobalEntry() const;
132
133 // Returns the number of entries in the local part of GOT including
134 // the number of reserved entries. This method is MIPS-specific.
135 unsigned getMipsLocalEntriesNum() const;
136
Rui Ueyama0e53c7d2016-02-05 00:10:02 +0000137 uintX_t getTlsIndexVA() { return Base::getVA() + TlsIndexOff; }
Rafael Espindola74031ba2016-04-07 15:20:56 +0000138 uint32_t getTlsIndexOff() { return TlsIndexOff; }
George Rimarb17f7392015-12-01 18:24:07 +0000139
Rui Ueyama022d8e82016-05-24 03:36:07 +0000140 // Flag to force GOT to be in output if we have relocations
141 // that relies on its address.
142 bool HasGotOffRel = false;
143
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000144private:
145 std::vector<const SymbolBody *> Entries;
Rui Ueyama0e53c7d2016-02-05 00:10:02 +0000146 uint32_t TlsIndexOff = -1;
Simon Atanasyan41325112016-06-19 21:39:37 +0000147 uint32_t MipsPageEntries = 0;
Simon Atanasyand2980d32016-03-29 14:07:22 +0000148 // Output sections referenced by MIPS GOT relocations.
149 llvm::SmallPtrSet<const OutputSectionBase<ELFT> *, 10> MipsOutSections;
Simon Atanasyan56ab5f02016-01-21 05:33:23 +0000150 llvm::DenseMap<uintX_t, size_t> MipsLocalGotPos;
Simon Atanasyan41325112016-06-19 21:39:37 +0000151
152 // MIPS ABI requires to create unique GOT entry for each Symbol/Addend
153 // pairs. The `MipsGotMap` maps (S,A) pair to the GOT index in the `MipsLocal`
154 // or `MipsGlobal` vectors. In general it does not have a sence to take in
155 // account addend for preemptible symbols because the corresponding
156 // GOT entries should have one-to-one mapping with dynamic symbols table.
157 // But we use the same container's types for both kind of GOT entries
158 // to handle them uniformly.
159 typedef std::pair<const SymbolBody*, uintX_t> MipsGotEntry;
160 typedef std::vector<MipsGotEntry> MipsGotEntries;
161 llvm::DenseMap<MipsGotEntry, size_t> MipsGotMap;
162 MipsGotEntries MipsLocal;
163 MipsGotEntries MipsGlobal;
164
165 // Write MIPS-specific parts of the GOT.
166 void writeMipsGot(uint8_t *&Buf);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000167};
168
George Rimar648a2c32015-10-20 08:54:27 +0000169template <class ELFT>
170class GotPltSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000171 typedef typename ELFT::uint uintX_t;
George Rimar648a2c32015-10-20 08:54:27 +0000172
173public:
174 GotPltSection();
175 void finalize() override;
176 void writeTo(uint8_t *Buf) override;
Rafael Espindola67d72c02016-03-11 12:06:30 +0000177 void addEntry(SymbolBody &Sym);
George Rimar648a2c32015-10-20 08:54:27 +0000178 bool empty() const;
George Rimar648a2c32015-10-20 08:54:27 +0000179
180private:
181 std::vector<const SymbolBody *> Entries;
182};
183
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000184template <class ELFT> class PltSection final : public OutputSectionBase<ELFT> {
185 typedef OutputSectionBase<ELFT> Base;
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000186 typedef typename ELFT::uint uintX_t;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000187
188public:
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000189 PltSection();
Hal Finkel6c2a3b82015-10-08 21:51:31 +0000190 void finalize() override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000191 void writeTo(uint8_t *Buf) override;
Rafael Espindola67d72c02016-03-11 12:06:30 +0000192 void addEntry(SymbolBody &Sym);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000193 bool empty() const { return Entries.empty(); }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000194
195private:
George Rimar77b77792015-11-25 22:15:01 +0000196 std::vector<std::pair<const SymbolBody *, unsigned>> Entries;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000197};
198
Rui Ueyama809d8e22016-06-23 04:33:42 +0000199template <class ELFT> class DynamicReloc {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000200 typedef typename ELFT::uint uintX_t;
Rui Ueyama809d8e22016-06-23 04:33:42 +0000201
202public:
203 DynamicReloc(uint32_t Type, const InputSectionBase<ELFT> *InputSec,
204 uintX_t OffsetInSec, bool UseSymVA, SymbolBody *Sym,
205 uintX_t Addend)
206 : Type(Type), Sym(Sym), InputSec(InputSec), OffsetInSec(OffsetInSec),
207 UseSymVA(UseSymVA), Addend(Addend) {}
208
209 DynamicReloc(uint32_t Type, const OutputSectionBase<ELFT> *OutputSec,
210 uintX_t OffsetInSec, bool UseSymVA, SymbolBody *Sym,
211 uintX_t Addend)
212 : Type(Type), Sym(Sym), OutputSec(OutputSec), OffsetInSec(OffsetInSec),
213 UseSymVA(UseSymVA), Addend(Addend) {}
214
215 uintX_t getOffset() const;
216 uintX_t getAddend() const;
217 uint32_t getSymIndex() const;
218
Rafael Espindolade9857e2016-02-04 21:33:05 +0000219 uint32_t Type;
220
Rui Ueyama809d8e22016-06-23 04:33:42 +0000221private:
Rafael Espindolaac568f92016-04-11 13:47:35 +0000222 SymbolBody *Sym;
Rui Ueyama809d8e22016-06-23 04:33:42 +0000223 const InputSectionBase<ELFT> *InputSec = nullptr;
224 const OutputSectionBase<ELFT> *OutputSec = nullptr;
Rafael Espindolaac568f92016-04-11 13:47:35 +0000225 uintX_t OffsetInSec;
226 bool UseSymVA;
227 uintX_t Addend;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000228};
229
230template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000231class SymbolTableSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000232public:
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000233 typedef typename ELFT::Shdr Elf_Shdr;
234 typedef typename ELFT::Sym Elf_Sym;
235 typedef typename ELFT::SymRange Elf_Sym_Range;
236 typedef typename ELFT::uint uintX_t;
Rui Ueyamaace4f902016-05-24 04:25:47 +0000237 SymbolTableSection(StringTableSection<ELFT> &StrTabSec);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000238
Rui Ueyama0db335f2015-10-07 16:58:54 +0000239 void finalize() override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000240 void writeTo(uint8_t *Buf) override;
Igor Kudrinab665fc2015-10-20 21:47:58 +0000241 void addSymbol(SymbolBody *Body);
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000242 StringTableSection<ELFT> &getStrTabSec() const { return StrTabSec; }
Rafael Espindola0e92f242016-01-27 16:41:24 +0000243 unsigned getNumSymbols() const { return NumLocals + Symbols.size() + 1; }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000244
Rui Ueyamac2e863a2016-02-17 05:06:40 +0000245 ArrayRef<std::pair<SymbolBody *, size_t>> getSymbols() const {
Rafael Espindolae2c24612016-01-29 01:24:25 +0000246 return Symbols;
247 }
248
249 unsigned NumLocals = 0;
250 StringTableSection<ELFT> &StrTabSec;
Igor Kudrinab665fc2015-10-20 21:47:58 +0000251
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000252private:
Rui Ueyama8ddfa812015-09-30 00:32:10 +0000253 void writeLocalSymbols(uint8_t *&Buf);
Igor Kudrinea6a8352015-10-19 08:01:51 +0000254 void writeGlobalSymbols(uint8_t *Buf);
Rui Ueyama8ddfa812015-09-30 00:32:10 +0000255
Rui Ueyama874e7ae2016-02-17 04:56:44 +0000256 const OutputSectionBase<ELFT> *getOutputSection(SymbolBody *Sym);
Igor Kudrin853b88d2015-10-20 20:52:14 +0000257
Rui Ueyamac2e863a2016-02-17 05:06:40 +0000258 // A vector of symbols and their string table offsets.
259 std::vector<std::pair<SymbolBody *, size_t>> Symbols;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000260};
261
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000262// For more information about .gnu.version and .gnu.version_r see:
263// https://www.akkadia.org/drepper/symbol-versioning
264
George Rimard3566302016-06-20 11:55:12 +0000265// The .gnu.version_d section which has a section type of SHT_GNU_verdef shall
266// contain symbol version definitions. The number of entries in this section
267// shall be contained in the DT_VERDEFNUM entry of the .dynamic section.
268// The section shall contain an array of Elf_Verdef structures, optionally
269// followed by an array of Elf_Verdaux structures.
270template <class ELFT>
271class VersionDefinitionSection final : public OutputSectionBase<ELFT> {
272 typedef typename ELFT::Verdef Elf_Verdef;
273 typedef typename ELFT::Verdaux Elf_Verdaux;
274
275 unsigned FileDefNameOff;
276
277public:
278 VersionDefinitionSection();
279 void finalize() override;
280 void writeTo(uint8_t *Buf) override;
281};
282
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000283// The .gnu.version section specifies the required version of each symbol in the
284// dynamic symbol table. It contains one Elf_Versym for each dynamic symbol
285// table entry. An Elf_Versym is just a 16-bit integer that refers to a version
George Rimard3566302016-06-20 11:55:12 +0000286// identifier defined in the either .gnu.version_r or .gnu.version_d section.
287// The values 0 and 1 are reserved. All other values are used for versions in
288// the own object or in any of the dependencies.
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000289template <class ELFT>
290class VersionTableSection final : public OutputSectionBase<ELFT> {
291 typedef typename ELFT::Versym Elf_Versym;
292
293public:
294 VersionTableSection();
295 void finalize() override;
296 void writeTo(uint8_t *Buf) override;
297};
298
299// The .gnu.version_r section defines the version identifiers used by
300// .gnu.version. It contains a linked list of Elf_Verneed data structures. Each
301// Elf_Verneed specifies the version requirements for a single DSO, and contains
302// a reference to a linked list of Elf_Vernaux data structures which define the
303// mapping from version identifiers to version names.
304template <class ELFT>
305class VersionNeedSection final : public OutputSectionBase<ELFT> {
306 typedef typename ELFT::Verneed Elf_Verneed;
307 typedef typename ELFT::Vernaux Elf_Vernaux;
308
309 // A vector of shared files that need Elf_Verneed data structures and the
310 // string table offsets of their sonames.
311 std::vector<std::pair<SharedFile<ELFT> *, size_t>> Needed;
312
George Rimard3566302016-06-20 11:55:12 +0000313 // The next available version identifier.
314 unsigned NextIndex;
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000315
316public:
317 VersionNeedSection();
318 void addSymbol(SharedSymbol<ELFT> *SS);
319 void finalize() override;
320 void writeTo(uint8_t *Buf) override;
321 size_t getNeedNum() const { return Needed.size(); }
322};
323
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000324template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000325class RelocationSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000326 typedef typename ELFT::Rel Elf_Rel;
327 typedef typename ELFT::Rela Elf_Rela;
328 typedef typename ELFT::uint uintX_t;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000329
330public:
George Rimarc191acf2016-05-10 15:47:57 +0000331 RelocationSection(StringRef Name, bool Sort);
Rafael Espindolad30eb7d2016-02-05 15:03:10 +0000332 void addReloc(const DynamicReloc<ELFT> &Reloc);
George Rimar77b77792015-11-25 22:15:01 +0000333 unsigned getRelocOffset();
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000334 void finalize() override;
335 void writeTo(uint8_t *Buf) override;
336 bool hasRelocs() const { return !Relocs.empty(); }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000337
George Rimara07ff662015-12-21 10:12:06 +0000338 bool Static = false;
339
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000340private:
George Rimarc191acf2016-05-10 15:47:57 +0000341 bool Sort;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000342 std::vector<DynamicReloc<ELFT>> Relocs;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000343};
344
345template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000346class OutputSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000347public:
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000348 typedef typename ELFT::Shdr Elf_Shdr;
349 typedef typename ELFT::Sym Elf_Sym;
350 typedef typename ELFT::Rel Elf_Rel;
351 typedef typename ELFT::Rela Elf_Rela;
352 typedef typename ELFT::uint uintX_t;
George Rimar9bec24a2016-02-18 14:20:08 +0000353 OutputSection(StringRef Name, uint32_t Type, uintX_t Flags);
Rui Ueyama40845e62015-12-26 05:51:07 +0000354 void addSection(InputSectionBase<ELFT> *C) override;
Rui Ueyama5af83682016-02-11 23:41:38 +0000355 void sortInitFini();
356 void sortCtorsDtors();
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000357 void writeTo(uint8_t *Buf) override;
George Rimar58941ee2016-02-25 08:23:37 +0000358 void finalize() override;
Rui Ueyama809d8e22016-06-23 04:33:42 +0000359 void assignOffsets() override;
Rafael Espindola71675852015-09-22 00:16:19 +0000360 std::vector<InputSection<ELFT> *> Sections;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000361};
362
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000363template <class ELFT>
Rafael Espindolac159c962015-10-19 21:00:02 +0000364class MergeOutputSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000365 typedef typename ELFT::uint uintX_t;
Rafael Espindolac159c962015-10-19 21:00:02 +0000366
367public:
Rafael Espindola7efa5be2016-02-19 14:17:40 +0000368 MergeOutputSection(StringRef Name, uint32_t Type, uintX_t Flags,
369 uintX_t Alignment);
Rui Ueyama40845e62015-12-26 05:51:07 +0000370 void addSection(InputSectionBase<ELFT> *S) override;
Rafael Espindolac159c962015-10-19 21:00:02 +0000371 void writeTo(uint8_t *Buf) override;
Rafael Espindolaf82ed2a2015-10-24 22:51:01 +0000372 unsigned getOffset(StringRef Val);
373 void finalize() override;
Rui Ueyama406b4692016-05-27 14:39:13 +0000374 void finalizePieces() override;
Peter Collingbournee29e1422016-05-05 04:10:12 +0000375 bool shouldTailMerge() const;
Rafael Espindolac159c962015-10-19 21:00:02 +0000376
377private:
Rafael Espindola7efa5be2016-02-19 14:17:40 +0000378 llvm::StringTableBuilder Builder;
Rui Ueyama406b4692016-05-27 14:39:13 +0000379 std::vector<MergeInputSection<ELFT> *> Sections;
Rafael Espindolac159c962015-10-19 21:00:02 +0000380};
381
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000382struct CieRecord {
383 SectionPiece *Piece = nullptr;
384 std::vector<SectionPiece *> FdePieces;
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000385};
386
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000387// Output section for .eh_frame.
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000388template <class ELFT>
Rui Ueyama1e479c22016-05-23 15:07:59 +0000389class EhOutputSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000390 typedef typename ELFT::uint uintX_t;
391 typedef typename ELFT::Shdr Elf_Shdr;
392 typedef typename ELFT::Rel Elf_Rel;
393 typedef typename ELFT::Rela Elf_Rela;
Rui Ueyamaf86cb902016-05-23 15:12:41 +0000394
395public:
396 EhOutputSection();
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000397 void writeTo(uint8_t *Buf) override;
Rafael Espindola56004c52016-04-07 14:22:09 +0000398 void finalize() override;
Rui Ueyama3b31e672016-05-23 16:24:16 +0000399 bool empty() const { return Sections.empty(); }
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000400
Rui Ueyama40845e62015-12-26 05:51:07 +0000401 void addSection(InputSectionBase<ELFT> *S) override;
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000402
Rui Ueyamade9777a2016-05-23 16:30:41 +0000403 size_t NumFdes = 0;
404
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000405private:
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000406 template <class RelTy>
Rui Ueyama0b9a9032016-05-24 04:19:20 +0000407 void addSectionAux(EhInputSection<ELFT> *S, llvm::ArrayRef<RelTy> Rels);
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000408
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000409 template <class RelTy>
Rui Ueyama0b9a9032016-05-24 04:19:20 +0000410 CieRecord *addCie(SectionPiece &Piece, EhInputSection<ELFT> *Sec,
Rui Ueyama19ccffe2016-05-24 15:40:46 +0000411 ArrayRef<RelTy> &Rels);
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000412
413 template <class RelTy>
Rui Ueyama0b9a9032016-05-24 04:19:20 +0000414 bool isFdeLive(SectionPiece &Piece, EhInputSection<ELFT> *Sec,
Rui Ueyama19ccffe2016-05-24 15:40:46 +0000415 ArrayRef<RelTy> &Rels);
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000416
Rui Ueyamae75e9332016-05-23 03:00:33 +0000417 uintX_t getFdePc(uint8_t *Buf, size_t Off, uint8_t Enc);
418
Rui Ueyama0b9a9032016-05-24 04:19:20 +0000419 std::vector<EhInputSection<ELFT> *> Sections;
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000420 std::vector<CieRecord *> Cies;
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000421
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000422 // CIE records are uniquified by their contents and personality functions.
423 llvm::DenseMap<std::pair<ArrayRef<uint8_t>, SymbolBody *>, CieRecord> CieMap;
424
Rafael Espindola56004c52016-04-07 14:22:09 +0000425 bool Finalized = false;
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000426};
427
Rafael Espindolac159c962015-10-19 21:00:02 +0000428template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000429class InterpSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000430public:
431 InterpSection();
Eugene Zelenko6e43b492015-11-04 02:11:57 +0000432 void writeTo(uint8_t *Buf) override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000433};
434
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000435template <class ELFT>
436class StringTableSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000437public:
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000438 typedef typename ELFT::uint uintX_t;
George Rimar0f5ac9f2015-10-20 17:21:35 +0000439 StringTableSection(StringRef Name, bool Dynamic);
Rafael Espindolae2c24612016-01-29 01:24:25 +0000440 unsigned addString(StringRef S, bool HashIt = true);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000441 void writeTo(uint8_t *Buf) override;
Rafael Espindolae2c24612016-01-29 01:24:25 +0000442 unsigned getSize() const { return Size; }
Rui Ueyama76c00632016-01-07 02:35:32 +0000443 void finalize() override { this->Header.sh_size = getSize(); }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000444 bool isDynamic() const { return Dynamic; }
445
446private:
447 const bool Dynamic;
Rafael Espindolae2c24612016-01-29 01:24:25 +0000448 llvm::DenseMap<StringRef, unsigned> StringMap;
Rui Ueyama76c00632016-01-07 02:35:32 +0000449 std::vector<StringRef> Strings;
Rafael Espindolae2c24612016-01-29 01:24:25 +0000450 unsigned Size = 1; // ELF string tables start with a NUL byte, so 1.
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000451};
452
453template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000454class HashTableSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000455 typedef typename ELFT::Word Elf_Word;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000456
457public:
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000458 HashTableSection();
Rui Ueyama0db335f2015-10-07 16:58:54 +0000459 void finalize() override;
460 void writeTo(uint8_t *Buf) override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000461};
462
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000463// Outputs GNU Hash section. For detailed explanation see:
464// https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections
465template <class ELFT>
466class GnuHashTableSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000467 typedef typename ELFT::Off Elf_Off;
468 typedef typename ELFT::Word Elf_Word;
469 typedef typename ELFT::uint uintX_t;
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000470
471public:
472 GnuHashTableSection();
473 void finalize() override;
474 void writeTo(uint8_t *Buf) override;
475
Igor Kudrinf1d60292015-10-28 07:05:56 +0000476 // Adds symbols to the hash table.
477 // Sorts the input to satisfy GNU hash section requirements.
Rui Ueyamac2e863a2016-02-17 05:06:40 +0000478 void addSymbols(std::vector<std::pair<SymbolBody *, size_t>> &Symbols);
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000479
480private:
Igor Kudrinf1d60292015-10-28 07:05:56 +0000481 static unsigned calcNBuckets(unsigned NumHashed);
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000482 static unsigned calcMaskWords(unsigned NumHashed);
483
484 void writeHeader(uint8_t *&Buf);
485 void writeBloomFilter(uint8_t *&Buf);
486 void writeHashTable(uint8_t *Buf);
487
Rui Ueyama861c7312016-02-17 05:40:03 +0000488 struct SymbolData {
Igor Kudrinf1d60292015-10-28 07:05:56 +0000489 SymbolBody *Body;
Rui Ueyamac2e863a2016-02-17 05:06:40 +0000490 size_t STName;
Igor Kudrinf1d60292015-10-28 07:05:56 +0000491 uint32_t Hash;
492 };
493
Rui Ueyama861c7312016-02-17 05:40:03 +0000494 std::vector<SymbolData> Symbols;
Igor Kudrinf1d60292015-10-28 07:05:56 +0000495
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000496 unsigned MaskWords;
497 unsigned NBuckets;
498 unsigned Shift2;
499};
500
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000501template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000502class DynamicSection final : public OutputSectionBase<ELFT> {
503 typedef OutputSectionBase<ELFT> Base;
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000504 typedef typename ELFT::Dyn Elf_Dyn;
505 typedef typename ELFT::Rel Elf_Rel;
506 typedef typename ELFT::Rela Elf_Rela;
507 typedef typename ELFT::Shdr Elf_Shdr;
508 typedef typename ELFT::Sym Elf_Sym;
509 typedef typename ELFT::uint uintX_t;
Rafael Espindolade069362016-01-25 21:32:04 +0000510
Rui Ueyama909cc682016-02-02 03:11:27 +0000511 // The .dynamic section contains information for the dynamic linker.
512 // The section consists of fixed size entries, which consist of
513 // type and value fields. Value are one of plain integers, symbol
514 // addresses, or section addresses. This struct represents the entry.
Rafael Espindolade069362016-01-25 21:32:04 +0000515 struct Entry {
516 int32_t Tag;
517 union {
518 OutputSectionBase<ELFT> *OutSec;
519 uint64_t Val;
520 const SymbolBody *Sym;
521 };
522 enum KindT { SecAddr, SymAddr, PlainInt } Kind;
523 Entry(int32_t Tag, OutputSectionBase<ELFT> *OutSec)
524 : Tag(Tag), OutSec(OutSec), Kind(SecAddr) {}
525 Entry(int32_t Tag, uint64_t Val) : Tag(Tag), Val(Val), Kind(PlainInt) {}
526 Entry(int32_t Tag, const SymbolBody *Sym)
527 : Tag(Tag), Sym(Sym), Kind(SymAddr) {}
528 };
Rui Ueyama909cc682016-02-02 03:11:27 +0000529
530 // finalize() fills this vector with the section contents. finalize()
531 // cannot directly create final section contents because when the
532 // function is called, symbol or section addresses are not fixed yet.
Rafael Espindolade069362016-01-25 21:32:04 +0000533 std::vector<Entry> Entries;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000534
535public:
Rui Ueyamaace4f902016-05-24 04:25:47 +0000536 explicit DynamicSection();
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000537 void finalize() override;
538 void writeTo(uint8_t *Buf) override;
539
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000540 OutputSectionBase<ELFT> *PreInitArraySec = nullptr;
541 OutputSectionBase<ELFT> *InitArraySec = nullptr;
542 OutputSectionBase<ELFT> *FiniArraySec = nullptr;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000543};
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000544
Simon Atanasyan1d7df402015-12-20 10:57:34 +0000545template <class ELFT>
546class MipsReginfoOutputSection final : public OutputSectionBase<ELFT> {
547 typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
548
549public:
550 MipsReginfoOutputSection();
551 void writeTo(uint8_t *Buf) override;
Rui Ueyama40845e62015-12-26 05:51:07 +0000552 void addSection(InputSectionBase<ELFT> *S) override;
Simon Atanasyan1d7df402015-12-20 10:57:34 +0000553
554private:
Rui Ueyama70eed362016-01-06 22:42:43 +0000555 uint32_t GprMask = 0;
Simon Atanasyan1d7df402015-12-20 10:57:34 +0000556};
557
Simon Atanasyanadd74f32016-05-04 10:07:38 +0000558template <class ELFT>
559class MipsOptionsOutputSection final : public OutputSectionBase<ELFT> {
560 typedef llvm::object::Elf_Mips_Options<ELFT> Elf_Mips_Options;
561 typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
562
563public:
564 MipsOptionsOutputSection();
565 void writeTo(uint8_t *Buf) override;
566 void addSection(InputSectionBase<ELFT> *S) override;
567
568private:
569 uint32_t GprMask = 0;
570};
571
George Rimarf6bc65a2016-01-15 13:34:52 +0000572// --eh-frame-hdr option tells linker to construct a header for all the
573// .eh_frame sections. This header is placed to a section named .eh_frame_hdr
574// and also to a PT_GNU_EH_FRAME segment.
575// At runtime the unwinder then can find all the PT_GNU_EH_FRAME segments by
576// calling dl_iterate_phdr.
577// This section contains a lookup table for quick binary search of FDEs.
578// Detailed info about internals can be found in Ian Lance Taylor's blog:
579// http://www.airs.com/blog/archives/460 (".eh_frame")
580// http://www.airs.com/blog/archives/462 (".eh_frame_hdr")
581template <class ELFT>
582class EhFrameHeader final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000583 typedef typename ELFT::uint uintX_t;
George Rimarf6bc65a2016-01-15 13:34:52 +0000584
585public:
586 EhFrameHeader();
Rui Ueyamade9777a2016-05-23 16:30:41 +0000587 void finalize() override;
George Rimarf6bc65a2016-01-15 13:34:52 +0000588 void writeTo(uint8_t *Buf) override;
Rui Ueyamae75e9332016-05-23 03:00:33 +0000589 void addFde(uint32_t Pc, uint32_t FdeVA);
George Rimarf6bc65a2016-01-15 13:34:52 +0000590
George Rimarf6bc65a2016-01-15 13:34:52 +0000591private:
592 struct FdeData {
Rui Ueyamae75e9332016-05-23 03:00:33 +0000593 uint32_t Pc;
594 uint32_t FdeVA;
George Rimarf6bc65a2016-01-15 13:34:52 +0000595 };
596
Rui Ueyamae75e9332016-05-23 03:00:33 +0000597 std::vector<FdeData> Fdes;
George Rimarf6bc65a2016-01-15 13:34:52 +0000598};
599
Rui Ueyama3a41be22016-04-07 22:49:21 +0000600template <class ELFT> class BuildIdSection : public OutputSectionBase<ELFT> {
Rui Ueyama634ddf02016-03-11 20:51:53 +0000601public:
Rui Ueyama634ddf02016-03-11 20:51:53 +0000602 void writeTo(uint8_t *Buf) override;
Rui Ueyamadd368fc2016-05-02 23:35:59 +0000603 virtual void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) = 0;
Rui Ueyama3a41be22016-04-07 22:49:21 +0000604
605protected:
606 BuildIdSection(size_t HashSize);
607 size_t HashSize;
608 uint8_t *HashBuf = nullptr;
609};
610
611template <class ELFT> class BuildIdFnv1 final : public BuildIdSection<ELFT> {
612public:
613 BuildIdFnv1() : BuildIdSection<ELFT>(8) {}
Rui Ueyamadd368fc2016-05-02 23:35:59 +0000614 void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
Rui Ueyama3a41be22016-04-07 22:49:21 +0000615};
616
617template <class ELFT> class BuildIdMd5 final : public BuildIdSection<ELFT> {
618public:
619 BuildIdMd5() : BuildIdSection<ELFT>(16) {}
Rui Ueyamadd368fc2016-05-02 23:35:59 +0000620 void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
Rui Ueyama634ddf02016-03-11 20:51:53 +0000621};
622
Rui Ueyamad86ec302016-04-07 23:51:56 +0000623template <class ELFT> class BuildIdSha1 final : public BuildIdSection<ELFT> {
624public:
625 BuildIdSha1() : BuildIdSection<ELFT>(20) {}
Rui Ueyamadd368fc2016-05-02 23:35:59 +0000626 void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
Rui Ueyamad86ec302016-04-07 23:51:56 +0000627};
628
Rui Ueyama9194db72016-05-13 21:55:56 +0000629template <class ELFT>
630class BuildIdHexstring final : public BuildIdSection<ELFT> {
631public:
632 BuildIdHexstring();
633 void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
634};
635
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000636// All output sections that are hadnled by the linker specially are
637// globally accessible. Writer initializes them, so don't use them
638// until Writer is initialized.
639template <class ELFT> struct Out {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000640 typedef typename ELFT::uint uintX_t;
641 typedef typename ELFT::Phdr Elf_Phdr;
Rui Ueyama634ddf02016-03-11 20:51:53 +0000642 static BuildIdSection<ELFT> *BuildId;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000643 static DynamicSection<ELFT> *Dynamic;
George Rimarf6bc65a2016-01-15 13:34:52 +0000644 static EhFrameHeader<ELFT> *EhFrameHdr;
Rui Ueyama3b31e672016-05-23 16:24:16 +0000645 static EhOutputSection<ELFT> *EhFrame;
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000646 static GnuHashTableSection<ELFT> *GnuHashTab;
George Rimar648a2c32015-10-20 08:54:27 +0000647 static GotPltSection<ELFT> *GotPlt;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000648 static GotSection<ELFT> *Got;
649 static HashTableSection<ELFT> *HashTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000650 static InterpSection<ELFT> *Interp;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000651 static OutputSection<ELFT> *Bss;
Igor Kudrin304860a2015-11-12 04:39:49 +0000652 static OutputSection<ELFT> *MipsRldMap;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000653 static OutputSectionBase<ELFT> *Opd;
Hal Finkeldaedc122015-10-12 23:16:53 +0000654 static uint8_t *OpdBuf;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000655 static PltSection<ELFT> *Plt;
656 static RelocationSection<ELFT> *RelaDyn;
George Rimar648a2c32015-10-20 08:54:27 +0000657 static RelocationSection<ELFT> *RelaPlt;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000658 static StringTableSection<ELFT> *DynStrTab;
George Rimar0f5ac9f2015-10-20 17:21:35 +0000659 static StringTableSection<ELFT> *ShStrTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000660 static StringTableSection<ELFT> *StrTab;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000661 static SymbolTableSection<ELFT> *DynSymTab;
662 static SymbolTableSection<ELFT> *SymTab;
George Rimard3566302016-06-20 11:55:12 +0000663 static VersionDefinitionSection<ELFT> *VerDef;
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000664 static VersionTableSection<ELFT> *VerSym;
665 static VersionNeedSection<ELFT> *VerNeed;
Rafael Espindolaea7a1e902015-11-06 22:14:44 +0000666 static Elf_Phdr *TlsPhdr;
Rafael Espindola4fc60442016-02-10 22:43:13 +0000667 static OutputSectionBase<ELFT> *ElfHeader;
668 static OutputSectionBase<ELFT> *ProgramHeaders;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000669};
Rui Ueyamad888d102015-10-09 19:34:55 +0000670
Rui Ueyama634ddf02016-03-11 20:51:53 +0000671template <class ELFT> BuildIdSection<ELFT> *Out<ELFT>::BuildId;
Rui Ueyamad888d102015-10-09 19:34:55 +0000672template <class ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic;
George Rimarf6bc65a2016-01-15 13:34:52 +0000673template <class ELFT> EhFrameHeader<ELFT> *Out<ELFT>::EhFrameHdr;
Rui Ueyama3b31e672016-05-23 16:24:16 +0000674template <class ELFT> EhOutputSection<ELFT> *Out<ELFT>::EhFrame;
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000675template <class ELFT> GnuHashTableSection<ELFT> *Out<ELFT>::GnuHashTab;
George Rimar648a2c32015-10-20 08:54:27 +0000676template <class ELFT> GotPltSection<ELFT> *Out<ELFT>::GotPlt;
Rui Ueyamad888d102015-10-09 19:34:55 +0000677template <class ELFT> GotSection<ELFT> *Out<ELFT>::Got;
678template <class ELFT> HashTableSection<ELFT> *Out<ELFT>::HashTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000679template <class ELFT> InterpSection<ELFT> *Out<ELFT>::Interp;
Rafael Espindolad7a267b2015-11-03 22:01:20 +0000680template <class ELFT> OutputSection<ELFT> *Out<ELFT>::Bss;
Igor Kudrin304860a2015-11-12 04:39:49 +0000681template <class ELFT> OutputSection<ELFT> *Out<ELFT>::MipsRldMap;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000682template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::Opd;
Hal Finkeldaedc122015-10-12 23:16:53 +0000683template <class ELFT> uint8_t *Out<ELFT>::OpdBuf;
Rui Ueyamad888d102015-10-09 19:34:55 +0000684template <class ELFT> PltSection<ELFT> *Out<ELFT>::Plt;
685template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaDyn;
George Rimar648a2c32015-10-20 08:54:27 +0000686template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaPlt;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000687template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::DynStrTab;
George Rimar0f5ac9f2015-10-20 17:21:35 +0000688template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::ShStrTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000689template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::StrTab;
Rui Ueyamad888d102015-10-09 19:34:55 +0000690template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::DynSymTab;
691template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::SymTab;
George Rimard3566302016-06-20 11:55:12 +0000692template <class ELFT> VersionDefinitionSection<ELFT> *Out<ELFT>::VerDef;
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000693template <class ELFT> VersionTableSection<ELFT> *Out<ELFT>::VerSym;
694template <class ELFT> VersionNeedSection<ELFT> *Out<ELFT>::VerNeed;
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000695template <class ELFT> typename ELFT::Phdr *Out<ELFT>::TlsPhdr;
Rafael Espindola4fc60442016-02-10 22:43:13 +0000696template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::ElfHeader;
697template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::ProgramHeaders;
Eugene Zelenko6e43b492015-11-04 02:11:57 +0000698
Rafael Espindolae0df00b2016-02-28 00:25:54 +0000699} // namespace elf
Eugene Zelenko6e43b492015-11-04 02:11:57 +0000700} // namespace lld
701
702#endif // LLD_ELF_OUTPUT_SECTIONS_H