blob: 1a74023927cfcb38667842694c99817095418130 [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
Simon Atanasyan002e2442016-06-23 15:26:31 +0000137 // Returns offset of TLS part of the MIPS GOT table. This part goes
138 // after 'local' and 'global' entries.
139 uintX_t getMipsTlsOffset();
140
Rui Ueyama0e53c7d2016-02-05 00:10:02 +0000141 uintX_t getTlsIndexVA() { return Base::getVA() + TlsIndexOff; }
Rafael Espindola74031ba2016-04-07 15:20:56 +0000142 uint32_t getTlsIndexOff() { return TlsIndexOff; }
George Rimarb17f7392015-12-01 18:24:07 +0000143
Rui Ueyama022d8e82016-05-24 03:36:07 +0000144 // Flag to force GOT to be in output if we have relocations
145 // that relies on its address.
146 bool HasGotOffRel = false;
147
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000148private:
149 std::vector<const SymbolBody *> Entries;
Rui Ueyama0e53c7d2016-02-05 00:10:02 +0000150 uint32_t TlsIndexOff = -1;
Simon Atanasyan41325112016-06-19 21:39:37 +0000151 uint32_t MipsPageEntries = 0;
Simon Atanasyand2980d32016-03-29 14:07:22 +0000152 // Output sections referenced by MIPS GOT relocations.
153 llvm::SmallPtrSet<const OutputSectionBase<ELFT> *, 10> MipsOutSections;
Simon Atanasyan56ab5f02016-01-21 05:33:23 +0000154 llvm::DenseMap<uintX_t, size_t> MipsLocalGotPos;
Simon Atanasyan41325112016-06-19 21:39:37 +0000155
156 // MIPS ABI requires to create unique GOT entry for each Symbol/Addend
157 // pairs. The `MipsGotMap` maps (S,A) pair to the GOT index in the `MipsLocal`
158 // or `MipsGlobal` vectors. In general it does not have a sence to take in
159 // account addend for preemptible symbols because the corresponding
160 // GOT entries should have one-to-one mapping with dynamic symbols table.
161 // But we use the same container's types for both kind of GOT entries
162 // to handle them uniformly.
163 typedef std::pair<const SymbolBody*, uintX_t> MipsGotEntry;
164 typedef std::vector<MipsGotEntry> MipsGotEntries;
165 llvm::DenseMap<MipsGotEntry, size_t> MipsGotMap;
166 MipsGotEntries MipsLocal;
167 MipsGotEntries MipsGlobal;
168
169 // Write MIPS-specific parts of the GOT.
170 void writeMipsGot(uint8_t *&Buf);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000171};
172
George Rimar648a2c32015-10-20 08:54:27 +0000173template <class ELFT>
174class GotPltSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000175 typedef typename ELFT::uint uintX_t;
George Rimar648a2c32015-10-20 08:54:27 +0000176
177public:
178 GotPltSection();
179 void finalize() override;
180 void writeTo(uint8_t *Buf) override;
Rafael Espindola67d72c02016-03-11 12:06:30 +0000181 void addEntry(SymbolBody &Sym);
George Rimar648a2c32015-10-20 08:54:27 +0000182 bool empty() const;
George Rimar648a2c32015-10-20 08:54:27 +0000183
184private:
185 std::vector<const SymbolBody *> Entries;
186};
187
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000188template <class ELFT> class PltSection final : public OutputSectionBase<ELFT> {
189 typedef OutputSectionBase<ELFT> Base;
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000190 typedef typename ELFT::uint uintX_t;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000191
192public:
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000193 PltSection();
Hal Finkel6c2a3b82015-10-08 21:51:31 +0000194 void finalize() override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000195 void writeTo(uint8_t *Buf) override;
Rafael Espindola67d72c02016-03-11 12:06:30 +0000196 void addEntry(SymbolBody &Sym);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000197 bool empty() const { return Entries.empty(); }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000198
199private:
George Rimar77b77792015-11-25 22:15:01 +0000200 std::vector<std::pair<const SymbolBody *, unsigned>> Entries;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000201};
202
Rui Ueyama809d8e22016-06-23 04:33:42 +0000203template <class ELFT> class DynamicReloc {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000204 typedef typename ELFT::uint uintX_t;
Rui Ueyama809d8e22016-06-23 04:33:42 +0000205
206public:
207 DynamicReloc(uint32_t Type, const InputSectionBase<ELFT> *InputSec,
208 uintX_t OffsetInSec, bool UseSymVA, SymbolBody *Sym,
209 uintX_t Addend)
210 : Type(Type), Sym(Sym), InputSec(InputSec), OffsetInSec(OffsetInSec),
211 UseSymVA(UseSymVA), Addend(Addend) {}
212
213 DynamicReloc(uint32_t Type, const OutputSectionBase<ELFT> *OutputSec,
214 uintX_t OffsetInSec, bool UseSymVA, SymbolBody *Sym,
215 uintX_t Addend)
216 : Type(Type), Sym(Sym), OutputSec(OutputSec), OffsetInSec(OffsetInSec),
217 UseSymVA(UseSymVA), Addend(Addend) {}
218
219 uintX_t getOffset() const;
220 uintX_t getAddend() const;
221 uint32_t getSymIndex() const;
Simon Atanasyan002e2442016-06-23 15:26:31 +0000222 const OutputSectionBase<ELFT> *getOutputSec() const { return OutputSec; }
Rui Ueyama809d8e22016-06-23 04:33:42 +0000223
Rafael Espindolade9857e2016-02-04 21:33:05 +0000224 uint32_t Type;
225
Rui Ueyama809d8e22016-06-23 04:33:42 +0000226private:
Rafael Espindolaac568f92016-04-11 13:47:35 +0000227 SymbolBody *Sym;
Rui Ueyama809d8e22016-06-23 04:33:42 +0000228 const InputSectionBase<ELFT> *InputSec = nullptr;
229 const OutputSectionBase<ELFT> *OutputSec = nullptr;
Rafael Espindolaac568f92016-04-11 13:47:35 +0000230 uintX_t OffsetInSec;
231 bool UseSymVA;
232 uintX_t Addend;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000233};
234
235template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000236class SymbolTableSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000237public:
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000238 typedef typename ELFT::Shdr Elf_Shdr;
239 typedef typename ELFT::Sym Elf_Sym;
240 typedef typename ELFT::SymRange Elf_Sym_Range;
241 typedef typename ELFT::uint uintX_t;
Rui Ueyamaace4f902016-05-24 04:25:47 +0000242 SymbolTableSection(StringTableSection<ELFT> &StrTabSec);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000243
Rui Ueyama0db335f2015-10-07 16:58:54 +0000244 void finalize() override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000245 void writeTo(uint8_t *Buf) override;
Igor Kudrinab665fc2015-10-20 21:47:58 +0000246 void addSymbol(SymbolBody *Body);
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000247 StringTableSection<ELFT> &getStrTabSec() const { return StrTabSec; }
Rafael Espindola0e92f242016-01-27 16:41:24 +0000248 unsigned getNumSymbols() const { return NumLocals + Symbols.size() + 1; }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000249
Rui Ueyamac2e863a2016-02-17 05:06:40 +0000250 ArrayRef<std::pair<SymbolBody *, size_t>> getSymbols() const {
Rafael Espindolae2c24612016-01-29 01:24:25 +0000251 return Symbols;
252 }
253
254 unsigned NumLocals = 0;
255 StringTableSection<ELFT> &StrTabSec;
Igor Kudrinab665fc2015-10-20 21:47:58 +0000256
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000257private:
Rui Ueyama8ddfa812015-09-30 00:32:10 +0000258 void writeLocalSymbols(uint8_t *&Buf);
Igor Kudrinea6a8352015-10-19 08:01:51 +0000259 void writeGlobalSymbols(uint8_t *Buf);
Rui Ueyama8ddfa812015-09-30 00:32:10 +0000260
Rui Ueyama874e7ae2016-02-17 04:56:44 +0000261 const OutputSectionBase<ELFT> *getOutputSection(SymbolBody *Sym);
Igor Kudrin853b88d2015-10-20 20:52:14 +0000262
Rui Ueyamac2e863a2016-02-17 05:06:40 +0000263 // A vector of symbols and their string table offsets.
264 std::vector<std::pair<SymbolBody *, size_t>> Symbols;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000265};
266
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000267// For more information about .gnu.version and .gnu.version_r see:
268// https://www.akkadia.org/drepper/symbol-versioning
269
George Rimard3566302016-06-20 11:55:12 +0000270// The .gnu.version_d section which has a section type of SHT_GNU_verdef shall
271// contain symbol version definitions. The number of entries in this section
272// shall be contained in the DT_VERDEFNUM entry of the .dynamic section.
273// The section shall contain an array of Elf_Verdef structures, optionally
274// followed by an array of Elf_Verdaux structures.
275template <class ELFT>
276class VersionDefinitionSection final : public OutputSectionBase<ELFT> {
277 typedef typename ELFT::Verdef Elf_Verdef;
278 typedef typename ELFT::Verdaux Elf_Verdaux;
279
280 unsigned FileDefNameOff;
281
282public:
283 VersionDefinitionSection();
284 void finalize() override;
285 void writeTo(uint8_t *Buf) override;
286};
287
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000288// The .gnu.version section specifies the required version of each symbol in the
289// dynamic symbol table. It contains one Elf_Versym for each dynamic symbol
290// table entry. An Elf_Versym is just a 16-bit integer that refers to a version
George Rimard3566302016-06-20 11:55:12 +0000291// identifier defined in the either .gnu.version_r or .gnu.version_d section.
292// The values 0 and 1 are reserved. All other values are used for versions in
293// the own object or in any of the dependencies.
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000294template <class ELFT>
295class VersionTableSection final : public OutputSectionBase<ELFT> {
296 typedef typename ELFT::Versym Elf_Versym;
297
298public:
299 VersionTableSection();
300 void finalize() override;
301 void writeTo(uint8_t *Buf) override;
302};
303
304// The .gnu.version_r section defines the version identifiers used by
305// .gnu.version. It contains a linked list of Elf_Verneed data structures. Each
306// Elf_Verneed specifies the version requirements for a single DSO, and contains
307// a reference to a linked list of Elf_Vernaux data structures which define the
308// mapping from version identifiers to version names.
309template <class ELFT>
310class VersionNeedSection final : public OutputSectionBase<ELFT> {
311 typedef typename ELFT::Verneed Elf_Verneed;
312 typedef typename ELFT::Vernaux Elf_Vernaux;
313
314 // A vector of shared files that need Elf_Verneed data structures and the
315 // string table offsets of their sonames.
316 std::vector<std::pair<SharedFile<ELFT> *, size_t>> Needed;
317
George Rimard3566302016-06-20 11:55:12 +0000318 // The next available version identifier.
319 unsigned NextIndex;
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000320
321public:
322 VersionNeedSection();
323 void addSymbol(SharedSymbol<ELFT> *SS);
324 void finalize() override;
325 void writeTo(uint8_t *Buf) override;
326 size_t getNeedNum() const { return Needed.size(); }
327};
328
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000329template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000330class RelocationSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000331 typedef typename ELFT::Rel Elf_Rel;
332 typedef typename ELFT::Rela Elf_Rela;
333 typedef typename ELFT::uint uintX_t;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000334
335public:
George Rimarc191acf2016-05-10 15:47:57 +0000336 RelocationSection(StringRef Name, bool Sort);
Rafael Espindolad30eb7d2016-02-05 15:03:10 +0000337 void addReloc(const DynamicReloc<ELFT> &Reloc);
George Rimar77b77792015-11-25 22:15:01 +0000338 unsigned getRelocOffset();
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000339 void finalize() override;
340 void writeTo(uint8_t *Buf) override;
341 bool hasRelocs() const { return !Relocs.empty(); }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000342
George Rimara07ff662015-12-21 10:12:06 +0000343 bool Static = false;
344
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000345private:
George Rimarc191acf2016-05-10 15:47:57 +0000346 bool Sort;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000347 std::vector<DynamicReloc<ELFT>> Relocs;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000348};
349
350template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000351class OutputSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000352public:
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000353 typedef typename ELFT::Shdr Elf_Shdr;
354 typedef typename ELFT::Sym Elf_Sym;
355 typedef typename ELFT::Rel Elf_Rel;
356 typedef typename ELFT::Rela Elf_Rela;
357 typedef typename ELFT::uint uintX_t;
George Rimar9bec24a2016-02-18 14:20:08 +0000358 OutputSection(StringRef Name, uint32_t Type, uintX_t Flags);
Rui Ueyama40845e62015-12-26 05:51:07 +0000359 void addSection(InputSectionBase<ELFT> *C) override;
Rui Ueyama5af83682016-02-11 23:41:38 +0000360 void sortInitFini();
361 void sortCtorsDtors();
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000362 void writeTo(uint8_t *Buf) override;
George Rimar58941ee2016-02-25 08:23:37 +0000363 void finalize() override;
Rui Ueyama809d8e22016-06-23 04:33:42 +0000364 void assignOffsets() override;
Rafael Espindola71675852015-09-22 00:16:19 +0000365 std::vector<InputSection<ELFT> *> Sections;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000366};
367
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000368template <class ELFT>
Rafael Espindolac159c962015-10-19 21:00:02 +0000369class MergeOutputSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000370 typedef typename ELFT::uint uintX_t;
Rafael Espindolac159c962015-10-19 21:00:02 +0000371
372public:
Rafael Espindola7efa5be2016-02-19 14:17:40 +0000373 MergeOutputSection(StringRef Name, uint32_t Type, uintX_t Flags,
374 uintX_t Alignment);
Rui Ueyama40845e62015-12-26 05:51:07 +0000375 void addSection(InputSectionBase<ELFT> *S) override;
Rafael Espindolac159c962015-10-19 21:00:02 +0000376 void writeTo(uint8_t *Buf) override;
Rafael Espindolaf82ed2a2015-10-24 22:51:01 +0000377 unsigned getOffset(StringRef Val);
378 void finalize() override;
Rui Ueyama406b4692016-05-27 14:39:13 +0000379 void finalizePieces() override;
Peter Collingbournee29e1422016-05-05 04:10:12 +0000380 bool shouldTailMerge() const;
Rafael Espindolac159c962015-10-19 21:00:02 +0000381
382private:
Rafael Espindola7efa5be2016-02-19 14:17:40 +0000383 llvm::StringTableBuilder Builder;
Rui Ueyama406b4692016-05-27 14:39:13 +0000384 std::vector<MergeInputSection<ELFT> *> Sections;
Rafael Espindolac159c962015-10-19 21:00:02 +0000385};
386
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000387struct CieRecord {
388 SectionPiece *Piece = nullptr;
389 std::vector<SectionPiece *> FdePieces;
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000390};
391
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000392// Output section for .eh_frame.
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000393template <class ELFT>
Rui Ueyama1e479c22016-05-23 15:07:59 +0000394class EhOutputSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000395 typedef typename ELFT::uint uintX_t;
396 typedef typename ELFT::Shdr Elf_Shdr;
397 typedef typename ELFT::Rel Elf_Rel;
398 typedef typename ELFT::Rela Elf_Rela;
Rui Ueyamaf86cb902016-05-23 15:12:41 +0000399
400public:
401 EhOutputSection();
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000402 void writeTo(uint8_t *Buf) override;
Rafael Espindola56004c52016-04-07 14:22:09 +0000403 void finalize() override;
Rui Ueyama3b31e672016-05-23 16:24:16 +0000404 bool empty() const { return Sections.empty(); }
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000405
Rui Ueyama40845e62015-12-26 05:51:07 +0000406 void addSection(InputSectionBase<ELFT> *S) override;
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000407
Rui Ueyamade9777a2016-05-23 16:30:41 +0000408 size_t NumFdes = 0;
409
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000410private:
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000411 template <class RelTy>
Rui Ueyama0b9a9032016-05-24 04:19:20 +0000412 void addSectionAux(EhInputSection<ELFT> *S, llvm::ArrayRef<RelTy> Rels);
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000413
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000414 template <class RelTy>
Rui Ueyama0b9a9032016-05-24 04:19:20 +0000415 CieRecord *addCie(SectionPiece &Piece, EhInputSection<ELFT> *Sec,
Rui Ueyama19ccffe2016-05-24 15:40:46 +0000416 ArrayRef<RelTy> &Rels);
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000417
418 template <class RelTy>
Rui Ueyama0b9a9032016-05-24 04:19:20 +0000419 bool isFdeLive(SectionPiece &Piece, EhInputSection<ELFT> *Sec,
Rui Ueyama19ccffe2016-05-24 15:40:46 +0000420 ArrayRef<RelTy> &Rels);
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000421
Rui Ueyamae75e9332016-05-23 03:00:33 +0000422 uintX_t getFdePc(uint8_t *Buf, size_t Off, uint8_t Enc);
423
Rui Ueyama0b9a9032016-05-24 04:19:20 +0000424 std::vector<EhInputSection<ELFT> *> Sections;
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000425 std::vector<CieRecord *> Cies;
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000426
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000427 // CIE records are uniquified by their contents and personality functions.
428 llvm::DenseMap<std::pair<ArrayRef<uint8_t>, SymbolBody *>, CieRecord> CieMap;
429
Rafael Espindola56004c52016-04-07 14:22:09 +0000430 bool Finalized = false;
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000431};
432
Rafael Espindolac159c962015-10-19 21:00:02 +0000433template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000434class InterpSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000435public:
436 InterpSection();
Eugene Zelenko6e43b492015-11-04 02:11:57 +0000437 void writeTo(uint8_t *Buf) override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000438};
439
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000440template <class ELFT>
441class StringTableSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000442public:
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000443 typedef typename ELFT::uint uintX_t;
George Rimar0f5ac9f2015-10-20 17:21:35 +0000444 StringTableSection(StringRef Name, bool Dynamic);
Rafael Espindolae2c24612016-01-29 01:24:25 +0000445 unsigned addString(StringRef S, bool HashIt = true);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000446 void writeTo(uint8_t *Buf) override;
Rafael Espindolae2c24612016-01-29 01:24:25 +0000447 unsigned getSize() const { return Size; }
Rui Ueyama76c00632016-01-07 02:35:32 +0000448 void finalize() override { this->Header.sh_size = getSize(); }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000449 bool isDynamic() const { return Dynamic; }
450
451private:
452 const bool Dynamic;
Rafael Espindolae2c24612016-01-29 01:24:25 +0000453 llvm::DenseMap<StringRef, unsigned> StringMap;
Rui Ueyama76c00632016-01-07 02:35:32 +0000454 std::vector<StringRef> Strings;
Rafael Espindolae2c24612016-01-29 01:24:25 +0000455 unsigned Size = 1; // ELF string tables start with a NUL byte, so 1.
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000456};
457
458template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000459class HashTableSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000460 typedef typename ELFT::Word Elf_Word;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000461
462public:
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000463 HashTableSection();
Rui Ueyama0db335f2015-10-07 16:58:54 +0000464 void finalize() override;
465 void writeTo(uint8_t *Buf) override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000466};
467
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000468// Outputs GNU Hash section. For detailed explanation see:
469// https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections
470template <class ELFT>
471class GnuHashTableSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000472 typedef typename ELFT::Off Elf_Off;
473 typedef typename ELFT::Word Elf_Word;
474 typedef typename ELFT::uint uintX_t;
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000475
476public:
477 GnuHashTableSection();
478 void finalize() override;
479 void writeTo(uint8_t *Buf) override;
480
Igor Kudrinf1d60292015-10-28 07:05:56 +0000481 // Adds symbols to the hash table.
482 // Sorts the input to satisfy GNU hash section requirements.
Rui Ueyamac2e863a2016-02-17 05:06:40 +0000483 void addSymbols(std::vector<std::pair<SymbolBody *, size_t>> &Symbols);
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000484
485private:
Igor Kudrinf1d60292015-10-28 07:05:56 +0000486 static unsigned calcNBuckets(unsigned NumHashed);
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000487 static unsigned calcMaskWords(unsigned NumHashed);
488
489 void writeHeader(uint8_t *&Buf);
490 void writeBloomFilter(uint8_t *&Buf);
491 void writeHashTable(uint8_t *Buf);
492
Rui Ueyama861c7312016-02-17 05:40:03 +0000493 struct SymbolData {
Igor Kudrinf1d60292015-10-28 07:05:56 +0000494 SymbolBody *Body;
Rui Ueyamac2e863a2016-02-17 05:06:40 +0000495 size_t STName;
Igor Kudrinf1d60292015-10-28 07:05:56 +0000496 uint32_t Hash;
497 };
498
Rui Ueyama861c7312016-02-17 05:40:03 +0000499 std::vector<SymbolData> Symbols;
Igor Kudrinf1d60292015-10-28 07:05:56 +0000500
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000501 unsigned MaskWords;
502 unsigned NBuckets;
503 unsigned Shift2;
504};
505
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000506template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000507class DynamicSection final : public OutputSectionBase<ELFT> {
508 typedef OutputSectionBase<ELFT> Base;
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000509 typedef typename ELFT::Dyn Elf_Dyn;
510 typedef typename ELFT::Rel Elf_Rel;
511 typedef typename ELFT::Rela Elf_Rela;
512 typedef typename ELFT::Shdr Elf_Shdr;
513 typedef typename ELFT::Sym Elf_Sym;
514 typedef typename ELFT::uint uintX_t;
Rafael Espindolade069362016-01-25 21:32:04 +0000515
Rui Ueyama909cc682016-02-02 03:11:27 +0000516 // The .dynamic section contains information for the dynamic linker.
517 // The section consists of fixed size entries, which consist of
518 // type and value fields. Value are one of plain integers, symbol
519 // addresses, or section addresses. This struct represents the entry.
Rafael Espindolade069362016-01-25 21:32:04 +0000520 struct Entry {
521 int32_t Tag;
522 union {
523 OutputSectionBase<ELFT> *OutSec;
524 uint64_t Val;
525 const SymbolBody *Sym;
526 };
527 enum KindT { SecAddr, SymAddr, PlainInt } Kind;
528 Entry(int32_t Tag, OutputSectionBase<ELFT> *OutSec)
529 : Tag(Tag), OutSec(OutSec), Kind(SecAddr) {}
530 Entry(int32_t Tag, uint64_t Val) : Tag(Tag), Val(Val), Kind(PlainInt) {}
531 Entry(int32_t Tag, const SymbolBody *Sym)
532 : Tag(Tag), Sym(Sym), Kind(SymAddr) {}
533 };
Rui Ueyama909cc682016-02-02 03:11:27 +0000534
535 // finalize() fills this vector with the section contents. finalize()
536 // cannot directly create final section contents because when the
537 // function is called, symbol or section addresses are not fixed yet.
Rafael Espindolade069362016-01-25 21:32:04 +0000538 std::vector<Entry> Entries;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000539
540public:
Rui Ueyamaace4f902016-05-24 04:25:47 +0000541 explicit DynamicSection();
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000542 void finalize() override;
543 void writeTo(uint8_t *Buf) override;
544
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000545 OutputSectionBase<ELFT> *PreInitArraySec = nullptr;
546 OutputSectionBase<ELFT> *InitArraySec = nullptr;
547 OutputSectionBase<ELFT> *FiniArraySec = nullptr;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000548};
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000549
Simon Atanasyan1d7df402015-12-20 10:57:34 +0000550template <class ELFT>
551class MipsReginfoOutputSection final : public OutputSectionBase<ELFT> {
552 typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
553
554public:
555 MipsReginfoOutputSection();
556 void writeTo(uint8_t *Buf) override;
Rui Ueyama40845e62015-12-26 05:51:07 +0000557 void addSection(InputSectionBase<ELFT> *S) override;
Simon Atanasyan1d7df402015-12-20 10:57:34 +0000558
559private:
Rui Ueyama70eed362016-01-06 22:42:43 +0000560 uint32_t GprMask = 0;
Simon Atanasyan1d7df402015-12-20 10:57:34 +0000561};
562
Simon Atanasyanadd74f32016-05-04 10:07:38 +0000563template <class ELFT>
564class MipsOptionsOutputSection final : public OutputSectionBase<ELFT> {
565 typedef llvm::object::Elf_Mips_Options<ELFT> Elf_Mips_Options;
566 typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
567
568public:
569 MipsOptionsOutputSection();
570 void writeTo(uint8_t *Buf) override;
571 void addSection(InputSectionBase<ELFT> *S) override;
572
573private:
574 uint32_t GprMask = 0;
575};
576
George Rimarf6bc65a2016-01-15 13:34:52 +0000577// --eh-frame-hdr option tells linker to construct a header for all the
578// .eh_frame sections. This header is placed to a section named .eh_frame_hdr
579// and also to a PT_GNU_EH_FRAME segment.
580// At runtime the unwinder then can find all the PT_GNU_EH_FRAME segments by
581// calling dl_iterate_phdr.
582// This section contains a lookup table for quick binary search of FDEs.
583// Detailed info about internals can be found in Ian Lance Taylor's blog:
584// http://www.airs.com/blog/archives/460 (".eh_frame")
585// http://www.airs.com/blog/archives/462 (".eh_frame_hdr")
586template <class ELFT>
587class EhFrameHeader final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000588 typedef typename ELFT::uint uintX_t;
George Rimarf6bc65a2016-01-15 13:34:52 +0000589
590public:
591 EhFrameHeader();
Rui Ueyamade9777a2016-05-23 16:30:41 +0000592 void finalize() override;
George Rimarf6bc65a2016-01-15 13:34:52 +0000593 void writeTo(uint8_t *Buf) override;
Rui Ueyamae75e9332016-05-23 03:00:33 +0000594 void addFde(uint32_t Pc, uint32_t FdeVA);
George Rimarf6bc65a2016-01-15 13:34:52 +0000595
George Rimarf6bc65a2016-01-15 13:34:52 +0000596private:
597 struct FdeData {
Rui Ueyamae75e9332016-05-23 03:00:33 +0000598 uint32_t Pc;
599 uint32_t FdeVA;
George Rimarf6bc65a2016-01-15 13:34:52 +0000600 };
601
Rui Ueyamae75e9332016-05-23 03:00:33 +0000602 std::vector<FdeData> Fdes;
George Rimarf6bc65a2016-01-15 13:34:52 +0000603};
604
Rui Ueyama3a41be22016-04-07 22:49:21 +0000605template <class ELFT> class BuildIdSection : public OutputSectionBase<ELFT> {
Rui Ueyama634ddf02016-03-11 20:51:53 +0000606public:
Rui Ueyama634ddf02016-03-11 20:51:53 +0000607 void writeTo(uint8_t *Buf) override;
Rui Ueyamadd368fc2016-05-02 23:35:59 +0000608 virtual void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) = 0;
Rui Ueyama3a41be22016-04-07 22:49:21 +0000609
610protected:
611 BuildIdSection(size_t HashSize);
612 size_t HashSize;
613 uint8_t *HashBuf = nullptr;
614};
615
616template <class ELFT> class BuildIdFnv1 final : public BuildIdSection<ELFT> {
617public:
618 BuildIdFnv1() : BuildIdSection<ELFT>(8) {}
Rui Ueyamadd368fc2016-05-02 23:35:59 +0000619 void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
Rui Ueyama3a41be22016-04-07 22:49:21 +0000620};
621
622template <class ELFT> class BuildIdMd5 final : public BuildIdSection<ELFT> {
623public:
624 BuildIdMd5() : BuildIdSection<ELFT>(16) {}
Rui Ueyamadd368fc2016-05-02 23:35:59 +0000625 void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
Rui Ueyama634ddf02016-03-11 20:51:53 +0000626};
627
Rui Ueyamad86ec302016-04-07 23:51:56 +0000628template <class ELFT> class BuildIdSha1 final : public BuildIdSection<ELFT> {
629public:
630 BuildIdSha1() : BuildIdSection<ELFT>(20) {}
Rui Ueyamadd368fc2016-05-02 23:35:59 +0000631 void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
Rui Ueyamad86ec302016-04-07 23:51:56 +0000632};
633
Rui Ueyama9194db72016-05-13 21:55:56 +0000634template <class ELFT>
635class BuildIdHexstring final : public BuildIdSection<ELFT> {
636public:
637 BuildIdHexstring();
638 void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
639};
640
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000641// All output sections that are hadnled by the linker specially are
642// globally accessible. Writer initializes them, so don't use them
643// until Writer is initialized.
644template <class ELFT> struct Out {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000645 typedef typename ELFT::uint uintX_t;
646 typedef typename ELFT::Phdr Elf_Phdr;
Rui Ueyama634ddf02016-03-11 20:51:53 +0000647 static BuildIdSection<ELFT> *BuildId;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000648 static DynamicSection<ELFT> *Dynamic;
George Rimarf6bc65a2016-01-15 13:34:52 +0000649 static EhFrameHeader<ELFT> *EhFrameHdr;
Rui Ueyama3b31e672016-05-23 16:24:16 +0000650 static EhOutputSection<ELFT> *EhFrame;
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000651 static GnuHashTableSection<ELFT> *GnuHashTab;
George Rimar648a2c32015-10-20 08:54:27 +0000652 static GotPltSection<ELFT> *GotPlt;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000653 static GotSection<ELFT> *Got;
654 static HashTableSection<ELFT> *HashTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000655 static InterpSection<ELFT> *Interp;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000656 static OutputSection<ELFT> *Bss;
Igor Kudrin304860a2015-11-12 04:39:49 +0000657 static OutputSection<ELFT> *MipsRldMap;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000658 static OutputSectionBase<ELFT> *Opd;
Hal Finkeldaedc122015-10-12 23:16:53 +0000659 static uint8_t *OpdBuf;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000660 static PltSection<ELFT> *Plt;
661 static RelocationSection<ELFT> *RelaDyn;
George Rimar648a2c32015-10-20 08:54:27 +0000662 static RelocationSection<ELFT> *RelaPlt;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000663 static StringTableSection<ELFT> *DynStrTab;
George Rimar0f5ac9f2015-10-20 17:21:35 +0000664 static StringTableSection<ELFT> *ShStrTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000665 static StringTableSection<ELFT> *StrTab;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000666 static SymbolTableSection<ELFT> *DynSymTab;
667 static SymbolTableSection<ELFT> *SymTab;
George Rimard3566302016-06-20 11:55:12 +0000668 static VersionDefinitionSection<ELFT> *VerDef;
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000669 static VersionTableSection<ELFT> *VerSym;
670 static VersionNeedSection<ELFT> *VerNeed;
Rafael Espindolaea7a1e902015-11-06 22:14:44 +0000671 static Elf_Phdr *TlsPhdr;
Rafael Espindola4fc60442016-02-10 22:43:13 +0000672 static OutputSectionBase<ELFT> *ElfHeader;
673 static OutputSectionBase<ELFT> *ProgramHeaders;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000674};
Rui Ueyamad888d102015-10-09 19:34:55 +0000675
Rui Ueyama634ddf02016-03-11 20:51:53 +0000676template <class ELFT> BuildIdSection<ELFT> *Out<ELFT>::BuildId;
Rui Ueyamad888d102015-10-09 19:34:55 +0000677template <class ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic;
George Rimarf6bc65a2016-01-15 13:34:52 +0000678template <class ELFT> EhFrameHeader<ELFT> *Out<ELFT>::EhFrameHdr;
Rui Ueyama3b31e672016-05-23 16:24:16 +0000679template <class ELFT> EhOutputSection<ELFT> *Out<ELFT>::EhFrame;
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000680template <class ELFT> GnuHashTableSection<ELFT> *Out<ELFT>::GnuHashTab;
George Rimar648a2c32015-10-20 08:54:27 +0000681template <class ELFT> GotPltSection<ELFT> *Out<ELFT>::GotPlt;
Rui Ueyamad888d102015-10-09 19:34:55 +0000682template <class ELFT> GotSection<ELFT> *Out<ELFT>::Got;
683template <class ELFT> HashTableSection<ELFT> *Out<ELFT>::HashTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000684template <class ELFT> InterpSection<ELFT> *Out<ELFT>::Interp;
Rafael Espindolad7a267b2015-11-03 22:01:20 +0000685template <class ELFT> OutputSection<ELFT> *Out<ELFT>::Bss;
Igor Kudrin304860a2015-11-12 04:39:49 +0000686template <class ELFT> OutputSection<ELFT> *Out<ELFT>::MipsRldMap;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000687template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::Opd;
Hal Finkeldaedc122015-10-12 23:16:53 +0000688template <class ELFT> uint8_t *Out<ELFT>::OpdBuf;
Rui Ueyamad888d102015-10-09 19:34:55 +0000689template <class ELFT> PltSection<ELFT> *Out<ELFT>::Plt;
690template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaDyn;
George Rimar648a2c32015-10-20 08:54:27 +0000691template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaPlt;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000692template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::DynStrTab;
George Rimar0f5ac9f2015-10-20 17:21:35 +0000693template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::ShStrTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000694template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::StrTab;
Rui Ueyamad888d102015-10-09 19:34:55 +0000695template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::DynSymTab;
696template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::SymTab;
George Rimard3566302016-06-20 11:55:12 +0000697template <class ELFT> VersionDefinitionSection<ELFT> *Out<ELFT>::VerDef;
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000698template <class ELFT> VersionTableSection<ELFT> *Out<ELFT>::VerSym;
699template <class ELFT> VersionNeedSection<ELFT> *Out<ELFT>::VerNeed;
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000700template <class ELFT> typename ELFT::Phdr *Out<ELFT>::TlsPhdr;
Rafael Espindola4fc60442016-02-10 22:43:13 +0000701template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::ElfHeader;
702template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::ProgramHeaders;
Eugene Zelenko6e43b492015-11-04 02:11:57 +0000703
Rafael Espindolae0df00b2016-02-28 00:25:54 +0000704} // namespace elf
Eugene Zelenko6e43b492015-11-04 02:11:57 +0000705} // namespace lld
706
707#endif // LLD_ELF_OUTPUT_SECTIONS_H