blob: 81fa9e5227d9ae0dc584dcca9350c7667c069418 [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;
Rafael Espindola2deeb602016-07-21 20:18:30 +000027struct EhSectionPiece;
Rui Ueyama3ce825e2015-10-09 21:07:25 +000028template <class ELFT> class SymbolTable;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000029template <class ELFT> class SymbolTableSection;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +000030template <class ELFT> class StringTableSection;
Rui Ueyama0b9a9032016-05-24 04:19:20 +000031template <class ELFT> class EhInputSection;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000032template <class ELFT> class InputSection;
Rafael Espindola0c6a4f12015-11-11 19:54:14 +000033template <class ELFT> class InputSectionBase;
Rafael Espindolac159c962015-10-19 21:00:02 +000034template <class ELFT> class MergeInputSection;
Simon Atanasyan1d7df402015-12-20 10:57:34 +000035template <class ELFT> class MipsReginfoInputSection;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000036template <class ELFT> class OutputSection;
37template <class ELFT> class ObjectFile;
Peter Collingbourne21a12fc2016-04-27 20:22:31 +000038template <class ELFT> class SharedFile;
39template <class ELFT> class SharedSymbol;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000040template <class ELFT> class DefinedRegular;
41
Rafael Espindola71675852015-09-22 00:16:19 +000042// This represents a section in an output file.
43// Different sub classes represent different types of sections. Some contain
44// input sections, others are created by the linker.
45// The writer creates multiple OutputSections and assign them unique,
Rafael Espindola5805c4f2015-09-21 21:38:08 +000046// non-overlapping file offsets and VAs.
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +000047template <class ELFT> class OutputSectionBase {
Rafael Espindola5805c4f2015-09-21 21:38:08 +000048public:
Rui Ueyama9328b2c2016-03-14 23:16:09 +000049 typedef typename ELFT::uint uintX_t;
50 typedef typename ELFT::Shdr Elf_Shdr;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000051
George Rimar9bec24a2016-02-18 14:20:08 +000052 OutputSectionBase(StringRef Name, uint32_t Type, uintX_t Flags);
Rafael Espindola5805c4f2015-09-21 21:38:08 +000053 void setVA(uintX_t VA) { Header.sh_addr = VA; }
54 uintX_t getVA() const { return Header.sh_addr; }
55 void setFileOffset(uintX_t Off) { Header.sh_offset = Off; }
Rafael Espindolae2c24612016-01-29 01:24:25 +000056 void setSHName(unsigned Val) { Header.sh_name = Val; }
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +000057 void writeHeaderTo(Elf_Shdr *SHdr);
Rafael Espindola5805c4f2015-09-21 21:38:08 +000058 StringRef getName() { return Name; }
Rafael Espindola5805c4f2015-09-21 21:38:08 +000059
Rui Ueyama40845e62015-12-26 05:51:07 +000060 virtual void addSection(InputSectionBase<ELFT> *C) {}
61
Rui Ueyama2317d0d2015-10-15 20:55:22 +000062 unsigned SectionIndex;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000063
64 // Returns the size of the section in the output file.
Rafael Espindola77572242015-10-02 19:37:55 +000065 uintX_t getSize() const { return Header.sh_size; }
Rafael Espindola5805c4f2015-09-21 21:38:08 +000066 void setSize(uintX_t Val) { Header.sh_size = Val; }
Rafael Espindola571452c2016-04-11 13:44:05 +000067 uintX_t getFlags() const { return Header.sh_flags; }
Rafael Espindola0b113672016-07-27 14:10:56 +000068 uint32_t getPhdrFlags() const;
Rafael Espindola571452c2016-04-11 13:44:05 +000069 uintX_t getFileOff() const { return Header.sh_offset; }
Rui Ueyama3b04d832016-07-14 05:46:24 +000070 uintX_t getAlignment() const { return Header.sh_addralign; }
Rafael Espindola571452c2016-04-11 13:44:05 +000071 uint32_t getType() const { return Header.sh_type; }
Rui Ueyama3b04d832016-07-14 05:46:24 +000072
Rui Ueyama424b4082016-06-17 01:18:46 +000073 void updateAlignment(uintX_t Alignment) {
74 if (Alignment > Header.sh_addralign)
75 Header.sh_addralign = Alignment;
Rafael Espindola115f0f32015-11-03 14:13:40 +000076 }
Rafael Espindola5805c4f2015-09-21 21:38:08 +000077
Rui Ueyama47091902016-03-30 19:41:51 +000078 // If true, this section will be page aligned on disk.
79 // Typically the first section of each PT_LOAD segment has this flag.
80 bool PageAlign = false;
81
Rafael Espindola5805c4f2015-09-21 21:38:08 +000082 virtual void finalize() {}
Rui Ueyama406b4692016-05-27 14:39:13 +000083 virtual void finalizePieces() {}
Rui Ueyama809d8e22016-06-23 04:33:42 +000084 virtual void assignOffsets() {}
Rafael Espindola4fc60442016-02-10 22:43:13 +000085 virtual void writeTo(uint8_t *Buf) {}
Rui Ueyamad4ea7dd2015-12-26 07:01:26 +000086 virtual ~OutputSectionBase() = default;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000087
88protected:
89 StringRef Name;
Sean Silva580c1b62016-04-20 04:26:16 +000090 Elf_Shdr Header;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000091};
92
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +000093template <class ELFT> class GotSection final : public OutputSectionBase<ELFT> {
94 typedef OutputSectionBase<ELFT> Base;
Rui Ueyama9328b2c2016-03-14 23:16:09 +000095 typedef typename ELFT::uint uintX_t;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000096
97public:
Rui Ueyama15ef5e12015-10-07 19:18:16 +000098 GotSection();
Igor Kudrin15cd9ff2015-11-06 07:43:03 +000099 void finalize() override;
Rafael Espindolaa6627382015-10-06 23:56:53 +0000100 void writeTo(uint8_t *Buf) override;
Rafael Espindola67d72c02016-03-11 12:06:30 +0000101 void addEntry(SymbolBody &Sym);
Simon Atanasyan41325112016-06-19 21:39:37 +0000102 void addMipsEntry(SymbolBody &Sym, uintX_t Addend, RelExpr Expr);
Rafael Espindola67d72c02016-03-11 12:06:30 +0000103 bool addDynTlsEntry(SymbolBody &Sym);
Rui Ueyama0e53c7d2016-02-05 00:10:02 +0000104 bool addTlsIndex();
Simon Atanasyan41325112016-06-19 21:39:37 +0000105 bool empty() const { return MipsPageEntries == 0 && Entries.empty(); }
Rafael Espindola58cd5db2016-04-19 22:46:03 +0000106 uintX_t getMipsLocalPageOffset(uintX_t Addr);
Simon Atanasyan41325112016-06-19 21:39:37 +0000107 uintX_t getMipsGotOffset(const SymbolBody &B, uintX_t Addend) const;
George Rimar90cd0a82015-12-01 19:20:26 +0000108 uintX_t getGlobalDynAddr(const SymbolBody &B) const;
Rafael Espindola74031ba2016-04-07 15:20:56 +0000109 uintX_t getGlobalDynOffset(const SymbolBody &B) const;
George Rimar9db204a2015-12-02 09:58:20 +0000110 uintX_t getNumEntries() const { return Entries.size(); }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000111
Igor Kudrin304860a2015-11-12 04:39:49 +0000112 // Returns the symbol which corresponds to the first entry of the global part
113 // of GOT on MIPS platform. It is required to fill up MIPS-specific dynamic
114 // table properties.
115 // Returns nullptr if the global part is empty.
116 const SymbolBody *getMipsFirstGlobalEntry() const;
117
118 // Returns the number of entries in the local part of GOT including
119 // the number of reserved entries. This method is MIPS-specific.
120 unsigned getMipsLocalEntriesNum() const;
121
Simon Atanasyan002e2442016-06-23 15:26:31 +0000122 // Returns offset of TLS part of the MIPS GOT table. This part goes
123 // after 'local' and 'global' entries.
124 uintX_t getMipsTlsOffset();
125
Rui Ueyama0e53c7d2016-02-05 00:10:02 +0000126 uintX_t getTlsIndexVA() { return Base::getVA() + TlsIndexOff; }
Rafael Espindola74031ba2016-04-07 15:20:56 +0000127 uint32_t getTlsIndexOff() { return TlsIndexOff; }
George Rimarb17f7392015-12-01 18:24:07 +0000128
Rui Ueyama022d8e82016-05-24 03:36:07 +0000129 // Flag to force GOT to be in output if we have relocations
130 // that relies on its address.
131 bool HasGotOffRel = false;
132
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000133private:
134 std::vector<const SymbolBody *> Entries;
Rui Ueyama0e53c7d2016-02-05 00:10:02 +0000135 uint32_t TlsIndexOff = -1;
Simon Atanasyan41325112016-06-19 21:39:37 +0000136 uint32_t MipsPageEntries = 0;
Simon Atanasyand2980d32016-03-29 14:07:22 +0000137 // Output sections referenced by MIPS GOT relocations.
138 llvm::SmallPtrSet<const OutputSectionBase<ELFT> *, 10> MipsOutSections;
Simon Atanasyan56ab5f02016-01-21 05:33:23 +0000139 llvm::DenseMap<uintX_t, size_t> MipsLocalGotPos;
Simon Atanasyan41325112016-06-19 21:39:37 +0000140
141 // MIPS ABI requires to create unique GOT entry for each Symbol/Addend
142 // pairs. The `MipsGotMap` maps (S,A) pair to the GOT index in the `MipsLocal`
143 // or `MipsGlobal` vectors. In general it does not have a sence to take in
144 // account addend for preemptible symbols because the corresponding
145 // GOT entries should have one-to-one mapping with dynamic symbols table.
146 // But we use the same container's types for both kind of GOT entries
147 // to handle them uniformly.
148 typedef std::pair<const SymbolBody*, uintX_t> MipsGotEntry;
149 typedef std::vector<MipsGotEntry> MipsGotEntries;
150 llvm::DenseMap<MipsGotEntry, size_t> MipsGotMap;
151 MipsGotEntries MipsLocal;
152 MipsGotEntries MipsGlobal;
153
154 // Write MIPS-specific parts of the GOT.
155 void writeMipsGot(uint8_t *&Buf);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000156};
157
George Rimar648a2c32015-10-20 08:54:27 +0000158template <class ELFT>
159class GotPltSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000160 typedef typename ELFT::uint uintX_t;
George Rimar648a2c32015-10-20 08:54:27 +0000161
162public:
163 GotPltSection();
164 void finalize() override;
165 void writeTo(uint8_t *Buf) override;
Rafael Espindola67d72c02016-03-11 12:06:30 +0000166 void addEntry(SymbolBody &Sym);
George Rimar648a2c32015-10-20 08:54:27 +0000167 bool empty() const;
George Rimar648a2c32015-10-20 08:54:27 +0000168
169private:
170 std::vector<const SymbolBody *> Entries;
171};
172
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000173template <class ELFT> class PltSection final : public OutputSectionBase<ELFT> {
174 typedef OutputSectionBase<ELFT> Base;
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000175 typedef typename ELFT::uint uintX_t;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000176
177public:
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000178 PltSection();
Hal Finkel6c2a3b82015-10-08 21:51:31 +0000179 void finalize() override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000180 void writeTo(uint8_t *Buf) override;
Rafael Espindola67d72c02016-03-11 12:06:30 +0000181 void addEntry(SymbolBody &Sym);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000182 bool empty() const { return Entries.empty(); }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000183
184private:
George Rimar77b77792015-11-25 22:15:01 +0000185 std::vector<std::pair<const SymbolBody *, unsigned>> Entries;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000186};
187
Rui Ueyama809d8e22016-06-23 04:33:42 +0000188template <class ELFT> class DynamicReloc {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000189 typedef typename ELFT::uint uintX_t;
Rui Ueyama809d8e22016-06-23 04:33:42 +0000190
191public:
192 DynamicReloc(uint32_t Type, const InputSectionBase<ELFT> *InputSec,
193 uintX_t OffsetInSec, bool UseSymVA, SymbolBody *Sym,
194 uintX_t Addend)
195 : Type(Type), Sym(Sym), InputSec(InputSec), OffsetInSec(OffsetInSec),
196 UseSymVA(UseSymVA), Addend(Addend) {}
197
198 DynamicReloc(uint32_t Type, const OutputSectionBase<ELFT> *OutputSec,
199 uintX_t OffsetInSec, bool UseSymVA, SymbolBody *Sym,
200 uintX_t Addend)
201 : Type(Type), Sym(Sym), OutputSec(OutputSec), OffsetInSec(OffsetInSec),
202 UseSymVA(UseSymVA), Addend(Addend) {}
203
204 uintX_t getOffset() const;
205 uintX_t getAddend() const;
206 uint32_t getSymIndex() const;
Simon Atanasyan002e2442016-06-23 15:26:31 +0000207 const OutputSectionBase<ELFT> *getOutputSec() const { return OutputSec; }
Rui Ueyama809d8e22016-06-23 04:33:42 +0000208
Rafael Espindolade9857e2016-02-04 21:33:05 +0000209 uint32_t Type;
210
Rui Ueyama809d8e22016-06-23 04:33:42 +0000211private:
Rafael Espindolaac568f92016-04-11 13:47:35 +0000212 SymbolBody *Sym;
Rui Ueyama809d8e22016-06-23 04:33:42 +0000213 const InputSectionBase<ELFT> *InputSec = nullptr;
214 const OutputSectionBase<ELFT> *OutputSec = nullptr;
Rafael Espindolaac568f92016-04-11 13:47:35 +0000215 uintX_t OffsetInSec;
216 bool UseSymVA;
217 uintX_t Addend;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000218};
219
220template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000221class SymbolTableSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000222public:
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000223 typedef typename ELFT::Shdr Elf_Shdr;
224 typedef typename ELFT::Sym Elf_Sym;
225 typedef typename ELFT::SymRange Elf_Sym_Range;
226 typedef typename ELFT::uint uintX_t;
Rui Ueyamaace4f902016-05-24 04:25:47 +0000227 SymbolTableSection(StringTableSection<ELFT> &StrTabSec);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000228
Rui Ueyama0db335f2015-10-07 16:58:54 +0000229 void finalize() override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000230 void writeTo(uint8_t *Buf) override;
Igor Kudrinab665fc2015-10-20 21:47:58 +0000231 void addSymbol(SymbolBody *Body);
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000232 StringTableSection<ELFT> &getStrTabSec() const { return StrTabSec; }
Rafael Espindola0e92f242016-01-27 16:41:24 +0000233 unsigned getNumSymbols() const { return NumLocals + Symbols.size() + 1; }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000234
Rui Ueyamac2e863a2016-02-17 05:06:40 +0000235 ArrayRef<std::pair<SymbolBody *, size_t>> getSymbols() const {
Rafael Espindolae2c24612016-01-29 01:24:25 +0000236 return Symbols;
237 }
238
239 unsigned NumLocals = 0;
240 StringTableSection<ELFT> &StrTabSec;
Igor Kudrinab665fc2015-10-20 21:47:58 +0000241
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000242private:
Rui Ueyama8ddfa812015-09-30 00:32:10 +0000243 void writeLocalSymbols(uint8_t *&Buf);
Igor Kudrinea6a8352015-10-19 08:01:51 +0000244 void writeGlobalSymbols(uint8_t *Buf);
Rui Ueyama8ddfa812015-09-30 00:32:10 +0000245
Rui Ueyama874e7ae2016-02-17 04:56:44 +0000246 const OutputSectionBase<ELFT> *getOutputSection(SymbolBody *Sym);
Igor Kudrin853b88d2015-10-20 20:52:14 +0000247
Rui Ueyamac2e863a2016-02-17 05:06:40 +0000248 // A vector of symbols and their string table offsets.
249 std::vector<std::pair<SymbolBody *, size_t>> Symbols;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000250};
251
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000252// For more information about .gnu.version and .gnu.version_r see:
253// https://www.akkadia.org/drepper/symbol-versioning
254
George Rimard3566302016-06-20 11:55:12 +0000255// The .gnu.version_d section which has a section type of SHT_GNU_verdef shall
256// contain symbol version definitions. The number of entries in this section
257// shall be contained in the DT_VERDEFNUM entry of the .dynamic section.
258// The section shall contain an array of Elf_Verdef structures, optionally
259// followed by an array of Elf_Verdaux structures.
260template <class ELFT>
261class VersionDefinitionSection final : public OutputSectionBase<ELFT> {
262 typedef typename ELFT::Verdef Elf_Verdef;
263 typedef typename ELFT::Verdaux Elf_Verdaux;
264
George Rimard3566302016-06-20 11:55:12 +0000265public:
266 VersionDefinitionSection();
267 void finalize() override;
268 void writeTo(uint8_t *Buf) override;
Rui Ueyama9f619642016-07-16 02:29:45 +0000269
270private:
271 void writeOne(uint8_t *Buf, uint32_t Index, StringRef Name, size_t NameOff);
272
273 unsigned FileDefNameOff;
George Rimard3566302016-06-20 11:55:12 +0000274};
275
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000276// The .gnu.version section specifies the required version of each symbol in the
277// dynamic symbol table. It contains one Elf_Versym for each dynamic symbol
278// table entry. An Elf_Versym is just a 16-bit integer that refers to a version
George Rimard3566302016-06-20 11:55:12 +0000279// identifier defined in the either .gnu.version_r or .gnu.version_d section.
280// The values 0 and 1 are reserved. All other values are used for versions in
281// the own object or in any of the dependencies.
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000282template <class ELFT>
283class VersionTableSection final : public OutputSectionBase<ELFT> {
284 typedef typename ELFT::Versym Elf_Versym;
285
286public:
287 VersionTableSection();
288 void finalize() override;
289 void writeTo(uint8_t *Buf) override;
290};
291
292// The .gnu.version_r section defines the version identifiers used by
293// .gnu.version. It contains a linked list of Elf_Verneed data structures. Each
294// Elf_Verneed specifies the version requirements for a single DSO, and contains
295// a reference to a linked list of Elf_Vernaux data structures which define the
296// mapping from version identifiers to version names.
297template <class ELFT>
298class VersionNeedSection final : public OutputSectionBase<ELFT> {
299 typedef typename ELFT::Verneed Elf_Verneed;
300 typedef typename ELFT::Vernaux Elf_Vernaux;
301
302 // A vector of shared files that need Elf_Verneed data structures and the
303 // string table offsets of their sonames.
304 std::vector<std::pair<SharedFile<ELFT> *, size_t>> Needed;
305
George Rimard3566302016-06-20 11:55:12 +0000306 // The next available version identifier.
307 unsigned NextIndex;
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000308
309public:
310 VersionNeedSection();
311 void addSymbol(SharedSymbol<ELFT> *SS);
312 void finalize() override;
313 void writeTo(uint8_t *Buf) override;
314 size_t getNeedNum() const { return Needed.size(); }
315};
316
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000317template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000318class RelocationSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000319 typedef typename ELFT::Rel Elf_Rel;
320 typedef typename ELFT::Rela Elf_Rela;
321 typedef typename ELFT::uint uintX_t;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000322
323public:
George Rimarc191acf2016-05-10 15:47:57 +0000324 RelocationSection(StringRef Name, bool Sort);
Rafael Espindolad30eb7d2016-02-05 15:03:10 +0000325 void addReloc(const DynamicReloc<ELFT> &Reloc);
George Rimar77b77792015-11-25 22:15:01 +0000326 unsigned getRelocOffset();
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000327 void finalize() override;
328 void writeTo(uint8_t *Buf) override;
329 bool hasRelocs() const { return !Relocs.empty(); }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000330
331private:
George Rimarc191acf2016-05-10 15:47:57 +0000332 bool Sort;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000333 std::vector<DynamicReloc<ELFT>> Relocs;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000334};
335
336template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000337class OutputSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000338public:
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000339 typedef typename ELFT::Shdr Elf_Shdr;
340 typedef typename ELFT::Sym Elf_Sym;
341 typedef typename ELFT::Rel Elf_Rel;
342 typedef typename ELFT::Rela Elf_Rela;
343 typedef typename ELFT::uint uintX_t;
George Rimar9bec24a2016-02-18 14:20:08 +0000344 OutputSection(StringRef Name, uint32_t Type, uintX_t Flags);
Rui Ueyama40845e62015-12-26 05:51:07 +0000345 void addSection(InputSectionBase<ELFT> *C) override;
Rui Ueyama5af83682016-02-11 23:41:38 +0000346 void sortInitFini();
347 void sortCtorsDtors();
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000348 void writeTo(uint8_t *Buf) override;
George Rimar58941ee2016-02-25 08:23:37 +0000349 void finalize() override;
Rui Ueyama809d8e22016-06-23 04:33:42 +0000350 void assignOffsets() override;
Rafael Espindola71675852015-09-22 00:16:19 +0000351 std::vector<InputSection<ELFT> *> Sections;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000352};
353
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000354template <class ELFT>
Rafael Espindolac159c962015-10-19 21:00:02 +0000355class MergeOutputSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000356 typedef typename ELFT::uint uintX_t;
Rafael Espindolac159c962015-10-19 21:00:02 +0000357
358public:
Rafael Espindola7efa5be2016-02-19 14:17:40 +0000359 MergeOutputSection(StringRef Name, uint32_t Type, uintX_t Flags,
360 uintX_t Alignment);
Rui Ueyama40845e62015-12-26 05:51:07 +0000361 void addSection(InputSectionBase<ELFT> *S) override;
Rafael Espindolac159c962015-10-19 21:00:02 +0000362 void writeTo(uint8_t *Buf) override;
Rafael Espindolaf82ed2a2015-10-24 22:51:01 +0000363 unsigned getOffset(StringRef Val);
364 void finalize() override;
Rui Ueyama406b4692016-05-27 14:39:13 +0000365 void finalizePieces() override;
Peter Collingbournee29e1422016-05-05 04:10:12 +0000366 bool shouldTailMerge() const;
Rafael Espindolac159c962015-10-19 21:00:02 +0000367
368private:
Rafael Espindola7efa5be2016-02-19 14:17:40 +0000369 llvm::StringTableBuilder Builder;
Rui Ueyama406b4692016-05-27 14:39:13 +0000370 std::vector<MergeInputSection<ELFT> *> Sections;
Rafael Espindolac159c962015-10-19 21:00:02 +0000371};
372
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000373struct CieRecord {
Rafael Espindola2deeb602016-07-21 20:18:30 +0000374 EhSectionPiece *Piece = nullptr;
375 std::vector<EhSectionPiece *> FdePieces;
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000376};
377
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000378// Output section for .eh_frame.
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000379template <class ELFT>
Rui Ueyama1e479c22016-05-23 15:07:59 +0000380class EhOutputSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000381 typedef typename ELFT::uint uintX_t;
382 typedef typename ELFT::Shdr Elf_Shdr;
383 typedef typename ELFT::Rel Elf_Rel;
384 typedef typename ELFT::Rela Elf_Rela;
Rui Ueyamaf86cb902016-05-23 15:12:41 +0000385
386public:
387 EhOutputSection();
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000388 void writeTo(uint8_t *Buf) override;
Rafael Espindola56004c52016-04-07 14:22:09 +0000389 void finalize() override;
Rui Ueyama3b31e672016-05-23 16:24:16 +0000390 bool empty() const { return Sections.empty(); }
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000391
Rui Ueyama40845e62015-12-26 05:51:07 +0000392 void addSection(InputSectionBase<ELFT> *S) override;
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000393
Rui Ueyamade9777a2016-05-23 16:30:41 +0000394 size_t NumFdes = 0;
395
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000396private:
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000397 template <class RelTy>
Rui Ueyama0b9a9032016-05-24 04:19:20 +0000398 void addSectionAux(EhInputSection<ELFT> *S, llvm::ArrayRef<RelTy> Rels);
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000399
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000400 template <class RelTy>
Rafael Espindola2deeb602016-07-21 20:18:30 +0000401 CieRecord *addCie(EhSectionPiece &Piece, EhInputSection<ELFT> *Sec,
402 ArrayRef<RelTy> Rels);
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000403
404 template <class RelTy>
Rafael Espindola2deeb602016-07-21 20:18:30 +0000405 bool isFdeLive(EhSectionPiece &Piece, EhInputSection<ELFT> *Sec,
406 ArrayRef<RelTy> Rels);
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000407
Rui Ueyamae75e9332016-05-23 03:00:33 +0000408 uintX_t getFdePc(uint8_t *Buf, size_t Off, uint8_t Enc);
409
Rui Ueyama0b9a9032016-05-24 04:19:20 +0000410 std::vector<EhInputSection<ELFT> *> Sections;
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000411 std::vector<CieRecord *> Cies;
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000412
Rui Ueyamaf8b285c2016-05-22 23:16:14 +0000413 // CIE records are uniquified by their contents and personality functions.
414 llvm::DenseMap<std::pair<ArrayRef<uint8_t>, SymbolBody *>, CieRecord> CieMap;
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000415};
416
Rafael Espindolac159c962015-10-19 21:00:02 +0000417template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000418class InterpSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000419public:
420 InterpSection();
Eugene Zelenko6e43b492015-11-04 02:11:57 +0000421 void writeTo(uint8_t *Buf) override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000422};
423
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000424template <class ELFT>
425class StringTableSection final : public OutputSectionBase<ELFT> {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000426public:
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000427 typedef typename ELFT::uint uintX_t;
George Rimar0f5ac9f2015-10-20 17:21:35 +0000428 StringTableSection(StringRef Name, bool Dynamic);
Rafael Espindolae2c24612016-01-29 01:24:25 +0000429 unsigned addString(StringRef S, bool HashIt = true);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000430 void writeTo(uint8_t *Buf) override;
Rafael Espindolae2c24612016-01-29 01:24:25 +0000431 unsigned getSize() const { return Size; }
Rui Ueyama76c00632016-01-07 02:35:32 +0000432 void finalize() override { this->Header.sh_size = getSize(); }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000433 bool isDynamic() const { return Dynamic; }
434
435private:
436 const bool Dynamic;
Rafael Espindolae2c24612016-01-29 01:24:25 +0000437 llvm::DenseMap<StringRef, unsigned> StringMap;
Rui Ueyama76c00632016-01-07 02:35:32 +0000438 std::vector<StringRef> Strings;
Rafael Espindolae2c24612016-01-29 01:24:25 +0000439 unsigned Size = 1; // ELF string tables start with a NUL byte, so 1.
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000440};
441
442template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000443class HashTableSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000444 typedef typename ELFT::Word Elf_Word;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000445
446public:
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000447 HashTableSection();
Rui Ueyama0db335f2015-10-07 16:58:54 +0000448 void finalize() override;
449 void writeTo(uint8_t *Buf) override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000450};
451
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000452// Outputs GNU Hash section. For detailed explanation see:
453// https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections
454template <class ELFT>
455class GnuHashTableSection final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000456 typedef typename ELFT::Off Elf_Off;
457 typedef typename ELFT::Word Elf_Word;
458 typedef typename ELFT::uint uintX_t;
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000459
460public:
461 GnuHashTableSection();
462 void finalize() override;
463 void writeTo(uint8_t *Buf) override;
464
Igor Kudrinf1d60292015-10-28 07:05:56 +0000465 // Adds symbols to the hash table.
466 // Sorts the input to satisfy GNU hash section requirements.
Rui Ueyamac2e863a2016-02-17 05:06:40 +0000467 void addSymbols(std::vector<std::pair<SymbolBody *, size_t>> &Symbols);
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000468
469private:
Igor Kudrinf1d60292015-10-28 07:05:56 +0000470 static unsigned calcNBuckets(unsigned NumHashed);
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000471 static unsigned calcMaskWords(unsigned NumHashed);
472
473 void writeHeader(uint8_t *&Buf);
474 void writeBloomFilter(uint8_t *&Buf);
475 void writeHashTable(uint8_t *Buf);
476
Rui Ueyama861c7312016-02-17 05:40:03 +0000477 struct SymbolData {
Igor Kudrinf1d60292015-10-28 07:05:56 +0000478 SymbolBody *Body;
Rui Ueyamac2e863a2016-02-17 05:06:40 +0000479 size_t STName;
Igor Kudrinf1d60292015-10-28 07:05:56 +0000480 uint32_t Hash;
481 };
482
Rui Ueyama861c7312016-02-17 05:40:03 +0000483 std::vector<SymbolData> Symbols;
Igor Kudrinf1d60292015-10-28 07:05:56 +0000484
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000485 unsigned MaskWords;
486 unsigned NBuckets;
487 unsigned Shift2;
488};
489
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000490template <class ELFT>
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000491class DynamicSection final : public OutputSectionBase<ELFT> {
492 typedef OutputSectionBase<ELFT> Base;
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000493 typedef typename ELFT::Dyn Elf_Dyn;
494 typedef typename ELFT::Rel Elf_Rel;
495 typedef typename ELFT::Rela Elf_Rela;
496 typedef typename ELFT::Shdr Elf_Shdr;
497 typedef typename ELFT::Sym Elf_Sym;
498 typedef typename ELFT::uint uintX_t;
Rafael Espindolade069362016-01-25 21:32:04 +0000499
Rui Ueyama909cc682016-02-02 03:11:27 +0000500 // The .dynamic section contains information for the dynamic linker.
501 // The section consists of fixed size entries, which consist of
502 // type and value fields. Value are one of plain integers, symbol
503 // addresses, or section addresses. This struct represents the entry.
Rafael Espindolade069362016-01-25 21:32:04 +0000504 struct Entry {
505 int32_t Tag;
506 union {
507 OutputSectionBase<ELFT> *OutSec;
508 uint64_t Val;
509 const SymbolBody *Sym;
510 };
511 enum KindT { SecAddr, SymAddr, PlainInt } Kind;
512 Entry(int32_t Tag, OutputSectionBase<ELFT> *OutSec)
513 : Tag(Tag), OutSec(OutSec), Kind(SecAddr) {}
514 Entry(int32_t Tag, uint64_t Val) : Tag(Tag), Val(Val), Kind(PlainInt) {}
515 Entry(int32_t Tag, const SymbolBody *Sym)
516 : Tag(Tag), Sym(Sym), Kind(SymAddr) {}
517 };
Rui Ueyama909cc682016-02-02 03:11:27 +0000518
519 // finalize() fills this vector with the section contents. finalize()
520 // cannot directly create final section contents because when the
521 // function is called, symbol or section addresses are not fixed yet.
Rafael Espindolade069362016-01-25 21:32:04 +0000522 std::vector<Entry> Entries;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000523
524public:
Rui Ueyamaace4f902016-05-24 04:25:47 +0000525 explicit DynamicSection();
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000526 void finalize() override;
527 void writeTo(uint8_t *Buf) override;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000528};
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000529
Simon Atanasyan1d7df402015-12-20 10:57:34 +0000530template <class ELFT>
531class MipsReginfoOutputSection final : public OutputSectionBase<ELFT> {
532 typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
533
534public:
535 MipsReginfoOutputSection();
536 void writeTo(uint8_t *Buf) override;
Rui Ueyama40845e62015-12-26 05:51:07 +0000537 void addSection(InputSectionBase<ELFT> *S) override;
Simon Atanasyan1d7df402015-12-20 10:57:34 +0000538
539private:
Rui Ueyama70eed362016-01-06 22:42:43 +0000540 uint32_t GprMask = 0;
Simon Atanasyan1d7df402015-12-20 10:57:34 +0000541};
542
Simon Atanasyanadd74f32016-05-04 10:07:38 +0000543template <class ELFT>
544class MipsOptionsOutputSection final : public OutputSectionBase<ELFT> {
545 typedef llvm::object::Elf_Mips_Options<ELFT> Elf_Mips_Options;
546 typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
547
548public:
549 MipsOptionsOutputSection();
550 void writeTo(uint8_t *Buf) override;
551 void addSection(InputSectionBase<ELFT> *S) override;
552
553private:
554 uint32_t GprMask = 0;
555};
556
George Rimarf6bc65a2016-01-15 13:34:52 +0000557// --eh-frame-hdr option tells linker to construct a header for all the
558// .eh_frame sections. This header is placed to a section named .eh_frame_hdr
559// and also to a PT_GNU_EH_FRAME segment.
560// At runtime the unwinder then can find all the PT_GNU_EH_FRAME segments by
561// calling dl_iterate_phdr.
562// This section contains a lookup table for quick binary search of FDEs.
563// Detailed info about internals can be found in Ian Lance Taylor's blog:
564// http://www.airs.com/blog/archives/460 (".eh_frame")
565// http://www.airs.com/blog/archives/462 (".eh_frame_hdr")
566template <class ELFT>
567class EhFrameHeader final : public OutputSectionBase<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000568 typedef typename ELFT::uint uintX_t;
George Rimarf6bc65a2016-01-15 13:34:52 +0000569
570public:
571 EhFrameHeader();
Rui Ueyamade9777a2016-05-23 16:30:41 +0000572 void finalize() override;
George Rimarf6bc65a2016-01-15 13:34:52 +0000573 void writeTo(uint8_t *Buf) override;
Rui Ueyamae75e9332016-05-23 03:00:33 +0000574 void addFde(uint32_t Pc, uint32_t FdeVA);
George Rimarf6bc65a2016-01-15 13:34:52 +0000575
George Rimarf6bc65a2016-01-15 13:34:52 +0000576private:
577 struct FdeData {
Rui Ueyamae75e9332016-05-23 03:00:33 +0000578 uint32_t Pc;
579 uint32_t FdeVA;
George Rimarf6bc65a2016-01-15 13:34:52 +0000580 };
581
Rui Ueyamae75e9332016-05-23 03:00:33 +0000582 std::vector<FdeData> Fdes;
George Rimarf6bc65a2016-01-15 13:34:52 +0000583};
584
Rui Ueyama3a41be22016-04-07 22:49:21 +0000585template <class ELFT> class BuildIdSection : public OutputSectionBase<ELFT> {
Rui Ueyama634ddf02016-03-11 20:51:53 +0000586public:
Rui Ueyama634ddf02016-03-11 20:51:53 +0000587 void writeTo(uint8_t *Buf) override;
Rui Ueyamadd368fc2016-05-02 23:35:59 +0000588 virtual void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) = 0;
Rui Ueyama3a41be22016-04-07 22:49:21 +0000589
590protected:
591 BuildIdSection(size_t HashSize);
592 size_t HashSize;
593 uint8_t *HashBuf = nullptr;
594};
595
596template <class ELFT> class BuildIdFnv1 final : public BuildIdSection<ELFT> {
597public:
598 BuildIdFnv1() : BuildIdSection<ELFT>(8) {}
Rui Ueyamadd368fc2016-05-02 23:35:59 +0000599 void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
Rui Ueyama3a41be22016-04-07 22:49:21 +0000600};
601
602template <class ELFT> class BuildIdMd5 final : public BuildIdSection<ELFT> {
603public:
604 BuildIdMd5() : BuildIdSection<ELFT>(16) {}
Rui Ueyamadd368fc2016-05-02 23:35:59 +0000605 void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
Rui Ueyama634ddf02016-03-11 20:51:53 +0000606};
607
Rui Ueyamad86ec302016-04-07 23:51:56 +0000608template <class ELFT> class BuildIdSha1 final : public BuildIdSection<ELFT> {
609public:
610 BuildIdSha1() : BuildIdSection<ELFT>(20) {}
Rui Ueyamadd368fc2016-05-02 23:35:59 +0000611 void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
Rui Ueyamad86ec302016-04-07 23:51:56 +0000612};
613
Rui Ueyama9194db72016-05-13 21:55:56 +0000614template <class ELFT>
615class BuildIdHexstring final : public BuildIdSection<ELFT> {
616public:
617 BuildIdHexstring();
618 void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
619};
620
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000621// All output sections that are hadnled by the linker specially are
622// globally accessible. Writer initializes them, so don't use them
623// until Writer is initialized.
624template <class ELFT> struct Out {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000625 typedef typename ELFT::uint uintX_t;
626 typedef typename ELFT::Phdr Elf_Phdr;
Rui Ueyama634ddf02016-03-11 20:51:53 +0000627 static BuildIdSection<ELFT> *BuildId;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000628 static DynamicSection<ELFT> *Dynamic;
George Rimarf6bc65a2016-01-15 13:34:52 +0000629 static EhFrameHeader<ELFT> *EhFrameHdr;
Rui Ueyama3b31e672016-05-23 16:24:16 +0000630 static EhOutputSection<ELFT> *EhFrame;
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000631 static GnuHashTableSection<ELFT> *GnuHashTab;
George Rimar648a2c32015-10-20 08:54:27 +0000632 static GotPltSection<ELFT> *GotPlt;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000633 static GotSection<ELFT> *Got;
634 static HashTableSection<ELFT> *HashTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000635 static InterpSection<ELFT> *Interp;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000636 static OutputSection<ELFT> *Bss;
Igor Kudrin304860a2015-11-12 04:39:49 +0000637 static OutputSection<ELFT> *MipsRldMap;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000638 static OutputSectionBase<ELFT> *Opd;
Hal Finkeldaedc122015-10-12 23:16:53 +0000639 static uint8_t *OpdBuf;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000640 static PltSection<ELFT> *Plt;
641 static RelocationSection<ELFT> *RelaDyn;
George Rimar648a2c32015-10-20 08:54:27 +0000642 static RelocationSection<ELFT> *RelaPlt;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000643 static StringTableSection<ELFT> *DynStrTab;
George Rimar0f5ac9f2015-10-20 17:21:35 +0000644 static StringTableSection<ELFT> *ShStrTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000645 static StringTableSection<ELFT> *StrTab;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000646 static SymbolTableSection<ELFT> *DynSymTab;
647 static SymbolTableSection<ELFT> *SymTab;
George Rimard3566302016-06-20 11:55:12 +0000648 static VersionDefinitionSection<ELFT> *VerDef;
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000649 static VersionTableSection<ELFT> *VerSym;
650 static VersionNeedSection<ELFT> *VerNeed;
Rafael Espindolaea7a1e902015-11-06 22:14:44 +0000651 static Elf_Phdr *TlsPhdr;
Rafael Espindola4fc60442016-02-10 22:43:13 +0000652 static OutputSectionBase<ELFT> *ElfHeader;
653 static OutputSectionBase<ELFT> *ProgramHeaders;
Rui Ueyamaa8f6fea2016-08-09 04:25:20 +0000654
655 static OutputSectionBase<ELFT> *PreinitArray;
656 static OutputSectionBase<ELFT> *InitArray;
657 static OutputSectionBase<ELFT> *FiniArray;
Rui Ueyama15ef5e12015-10-07 19:18:16 +0000658};
Rui Ueyamad888d102015-10-09 19:34:55 +0000659
George Rimar6892afa2016-07-12 09:49:43 +0000660template <bool Is64Bits> struct SectionKey {
661 typedef typename std::conditional<Is64Bits, uint64_t, uint32_t>::type uintX_t;
662 StringRef Name;
663 uint32_t Type;
664 uintX_t Flags;
665 uintX_t Alignment;
666};
667
668// This class knows how to create an output section for a given
669// input section. Output section type is determined by various
670// factors, including input section's sh_flags, sh_type and
671// linker scripts.
672template <class ELFT> class OutputSectionFactory {
673 typedef typename ELFT::Shdr Elf_Shdr;
674 typedef typename ELFT::uint uintX_t;
675 typedef typename elf::SectionKey<ELFT::Is64Bits> Key;
676
677public:
678 std::pair<OutputSectionBase<ELFT> *, bool> create(InputSectionBase<ELFT> *C,
679 StringRef OutsecName);
680
George Rimar6892afa2016-07-12 09:49:43 +0000681private:
682 Key createKey(InputSectionBase<ELFT> *C, StringRef OutsecName);
683
684 llvm::SmallDenseMap<Key, OutputSectionBase<ELFT> *> Map;
Rui Ueyamaa7f78842016-07-20 17:19:03 +0000685 std::vector<std::unique_ptr<OutputSectionBase<ELFT>>> OwningSections;
George Rimar6892afa2016-07-12 09:49:43 +0000686};
687
Rui Ueyama634ddf02016-03-11 20:51:53 +0000688template <class ELFT> BuildIdSection<ELFT> *Out<ELFT>::BuildId;
Rui Ueyamad888d102015-10-09 19:34:55 +0000689template <class ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic;
George Rimarf6bc65a2016-01-15 13:34:52 +0000690template <class ELFT> EhFrameHeader<ELFT> *Out<ELFT>::EhFrameHdr;
Rui Ueyama3b31e672016-05-23 16:24:16 +0000691template <class ELFT> EhOutputSection<ELFT> *Out<ELFT>::EhFrame;
Igor Kudrin1b0d7062015-10-22 08:21:35 +0000692template <class ELFT> GnuHashTableSection<ELFT> *Out<ELFT>::GnuHashTab;
George Rimar648a2c32015-10-20 08:54:27 +0000693template <class ELFT> GotPltSection<ELFT> *Out<ELFT>::GotPlt;
Rui Ueyamad888d102015-10-09 19:34:55 +0000694template <class ELFT> GotSection<ELFT> *Out<ELFT>::Got;
695template <class ELFT> HashTableSection<ELFT> *Out<ELFT>::HashTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000696template <class ELFT> InterpSection<ELFT> *Out<ELFT>::Interp;
Rafael Espindolad7a267b2015-11-03 22:01:20 +0000697template <class ELFT> OutputSection<ELFT> *Out<ELFT>::Bss;
Igor Kudrin304860a2015-11-12 04:39:49 +0000698template <class ELFT> OutputSection<ELFT> *Out<ELFT>::MipsRldMap;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000699template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::Opd;
Hal Finkeldaedc122015-10-12 23:16:53 +0000700template <class ELFT> uint8_t *Out<ELFT>::OpdBuf;
Rui Ueyamad888d102015-10-09 19:34:55 +0000701template <class ELFT> PltSection<ELFT> *Out<ELFT>::Plt;
702template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaDyn;
George Rimar648a2c32015-10-20 08:54:27 +0000703template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaPlt;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000704template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::DynStrTab;
George Rimar0f5ac9f2015-10-20 17:21:35 +0000705template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::ShStrTab;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000706template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::StrTab;
Rui Ueyamad888d102015-10-09 19:34:55 +0000707template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::DynSymTab;
708template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::SymTab;
George Rimard3566302016-06-20 11:55:12 +0000709template <class ELFT> VersionDefinitionSection<ELFT> *Out<ELFT>::VerDef;
Peter Collingbourne21a12fc2016-04-27 20:22:31 +0000710template <class ELFT> VersionTableSection<ELFT> *Out<ELFT>::VerSym;
711template <class ELFT> VersionNeedSection<ELFT> *Out<ELFT>::VerNeed;
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000712template <class ELFT> typename ELFT::Phdr *Out<ELFT>::TlsPhdr;
Rafael Espindola4fc60442016-02-10 22:43:13 +0000713template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::ElfHeader;
714template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::ProgramHeaders;
Rui Ueyamaa8f6fea2016-08-09 04:25:20 +0000715template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::PreinitArray;
716template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::InitArray;
717template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::FiniArray;
Eugene Zelenko6e43b492015-11-04 02:11:57 +0000718
Rafael Espindolae0df00b2016-02-28 00:25:54 +0000719} // namespace elf
Eugene Zelenko6e43b492015-11-04 02:11:57 +0000720} // namespace lld
721
George Rimar6892afa2016-07-12 09:49:43 +0000722namespace llvm {
723template <bool Is64Bits> struct DenseMapInfo<lld::elf::SectionKey<Is64Bits>> {
724 typedef typename lld::elf::SectionKey<Is64Bits> Key;
725
726 static Key getEmptyKey();
727 static Key getTombstoneKey();
728 static unsigned getHashValue(const Key &Val);
729 static bool isEqual(const Key &LHS, const Key &RHS);
730};
731}
732
733#endif