]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/SyntheticSections.h
Merge ^/head r311546 through r311683.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / ELF / SyntheticSections.h
1 //===- SyntheticSection.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_SYNTHETIC_SECTION_H
11 #define LLD_ELF_SYNTHETIC_SECTION_H
12
13 #include "GdbIndex.h"
14 #include "InputSection.h"
15 #include "llvm/ADT/MapVector.h"
16 #include "llvm/MC/StringTableBuilder.h"
17
18 namespace lld {
19 namespace elf {
20
21 template <class ELFT> class SyntheticSection : public InputSection<ELFT> {
22   typedef typename ELFT::uint uintX_t;
23
24 public:
25   SyntheticSection(uintX_t Flags, uint32_t Type, uintX_t Addralign,
26                    StringRef Name)
27       : InputSection<ELFT>(Flags, Type, Addralign, ArrayRef<uint8_t>(), Name,
28                            InputSectionData::Synthetic) {
29     this->Live = true;
30   }
31
32   virtual ~SyntheticSection() = default;
33   virtual void writeTo(uint8_t *Buf) = 0;
34   virtual size_t getSize() const = 0;
35   virtual void finalize() {}
36   virtual bool empty() const { return false; }
37
38   uintX_t getVA() const {
39     return this->OutSec ? this->OutSec->Addr + this->OutSecOff : 0;
40   }
41
42   static bool classof(const InputSectionData *D) {
43     return D->kind() == InputSectionData::Synthetic;
44   }
45 };
46
47 template <class ELFT> class GotSection final : public SyntheticSection<ELFT> {
48   typedef typename ELFT::uint uintX_t;
49
50 public:
51   GotSection();
52   void writeTo(uint8_t *Buf) override;
53   size_t getSize() const override { return Size; }
54   void finalize() override;
55   bool empty() const override;
56
57   void addEntry(SymbolBody &Sym);
58   bool addDynTlsEntry(SymbolBody &Sym);
59   bool addTlsIndex();
60   uintX_t getGlobalDynAddr(const SymbolBody &B) const;
61   uintX_t getGlobalDynOffset(const SymbolBody &B) const;
62
63   uintX_t getTlsIndexVA() { return this->getVA() + TlsIndexOff; }
64   uint32_t getTlsIndexOff() const { return TlsIndexOff; }
65
66   // Flag to force GOT to be in output if we have relocations
67   // that relies on its address.
68   bool HasGotOffRel = false;
69
70 private:
71   size_t NumEntries = 0;
72   uint32_t TlsIndexOff = -1;
73   uintX_t Size = 0;
74 };
75
76 // .note.gnu.build-id section.
77 template <class ELFT> class BuildIdSection : public SyntheticSection<ELFT> {
78   // First 16 bytes are a header.
79   static const unsigned HeaderSize = 16;
80
81 public:
82   BuildIdSection();
83   void writeTo(uint8_t *Buf) override;
84   size_t getSize() const override { return HeaderSize + HashSize; }
85   void writeBuildId(llvm::ArrayRef<uint8_t> Buf);
86
87 private:
88   void computeHash(llvm::ArrayRef<uint8_t> Buf,
89                    std::function<void(uint8_t *, ArrayRef<uint8_t>)> Hash);
90
91   size_t HashSize;
92   uint8_t *HashBuf;
93 };
94
95 template <class ELFT>
96 class MipsGotSection final : public SyntheticSection<ELFT> {
97   typedef typename ELFT::uint uintX_t;
98
99 public:
100   MipsGotSection();
101   void writeTo(uint8_t *Buf) override;
102   size_t getSize() const override { return Size; }
103   void finalize() override;
104   bool empty() const override;
105   void addEntry(SymbolBody &Sym, uintX_t Addend, RelExpr Expr);
106   bool addDynTlsEntry(SymbolBody &Sym);
107   bool addTlsIndex();
108   uintX_t getPageEntryOffset(const SymbolBody &B, uintX_t Addend) const;
109   uintX_t getBodyEntryOffset(const SymbolBody &B, uintX_t Addend) const;
110   uintX_t getGlobalDynOffset(const SymbolBody &B) const;
111
112   // 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 *getFirstGlobalEntry() const;
117
118   // Returns the number of entries in the local part of GOT including
119   // the number of reserved entries.
120   unsigned getLocalEntriesNum() const;
121
122   // Returns offset of TLS part of the MIPS GOT table. This part goes
123   // after 'local' and 'global' entries.
124   uintX_t getTlsOffset() const;
125
126   uint32_t getTlsIndexOff() const { return TlsIndexOff; }
127
128   uintX_t getGp() const;
129
130 private:
131   // MIPS GOT consists of three parts: local, global and tls. Each part
132   // contains different types of entries. Here is a layout of GOT:
133   // - Header entries                |
134   // - Page entries                  |   Local part
135   // - Local entries (16-bit access) |
136   // - Local entries (32-bit access) |
137   // - Normal global entries         ||  Global part
138   // - Reloc-only global entries     ||
139   // - TLS entries                   ||| TLS part
140   //
141   // Header:
142   //   Two entries hold predefined value 0x0 and 0x80000000.
143   // Page entries:
144   //   These entries created by R_MIPS_GOT_PAGE relocation and R_MIPS_GOT16
145   //   relocation against local symbols. They are initialized by higher 16-bit
146   //   of the corresponding symbol's value. So each 64kb of address space
147   //   requires a single GOT entry.
148   // Local entries (16-bit access):
149   //   These entries created by GOT relocations against global non-preemptible
150   //   symbols so dynamic linker is not necessary to resolve the symbol's
151   //   values. "16-bit access" means that corresponding relocations address
152   //   GOT using 16-bit index. Each unique Symbol-Addend pair has its own
153   //   GOT entry.
154   // Local entries (32-bit access):
155   //   These entries are the same as above but created by relocations which
156   //   address GOT using 32-bit index (R_MIPS_GOT_HI16/LO16 etc).
157   // Normal global entries:
158   //   These entries created by GOT relocations against preemptible global
159   //   symbols. They need to be initialized by dynamic linker and they ordered
160   //   exactly as the corresponding entries in the dynamic symbols table.
161   // Reloc-only global entries:
162   //   These entries created for symbols that are referenced by dynamic
163   //   relocations R_MIPS_REL32. These entries are not accessed with gp-relative
164   //   addressing, but MIPS ABI requires that these entries be present in GOT.
165   // TLS entries:
166   //   Entries created by TLS relocations.
167
168   // Number of "Header" entries.
169   static const unsigned HeaderEntriesNum = 2;
170   // Number of allocated "Page" entries.
171   uint32_t PageEntriesNum = 0;
172   // Map output sections referenced by MIPS GOT relocations
173   // to the first index of "Page" entries allocated for this section.
174   llvm::SmallMapVector<const OutputSectionBase *, size_t, 16> PageIndexMap;
175
176   typedef std::pair<const SymbolBody *, uintX_t> GotEntry;
177   typedef std::vector<GotEntry> GotEntries;
178   // Map from Symbol-Addend pair to the GOT index.
179   llvm::DenseMap<GotEntry, size_t> EntryIndexMap;
180   // Local entries (16-bit access).
181   GotEntries LocalEntries;
182   // Local entries (32-bit access).
183   GotEntries LocalEntries32;
184
185   // Normal and reloc-only global entries.
186   GotEntries GlobalEntries;
187
188   // TLS entries.
189   std::vector<const SymbolBody *> TlsEntries;
190
191   uint32_t TlsIndexOff = -1;
192   uintX_t Size = 0;
193 };
194
195 template <class ELFT>
196 class GotPltSection final : public SyntheticSection<ELFT> {
197   typedef typename ELFT::uint uintX_t;
198
199 public:
200   GotPltSection();
201   void addEntry(SymbolBody &Sym);
202   size_t getSize() const override;
203   void writeTo(uint8_t *Buf) override;
204   bool empty() const override { return Entries.empty(); }
205
206 private:
207   std::vector<const SymbolBody *> Entries;
208 };
209
210 // The IgotPltSection is a Got associated with the IpltSection for GNU Ifunc
211 // Symbols that will be relocated by Target->IRelativeRel.
212 // On most Targets the IgotPltSection will immediately follow the GotPltSection
213 // on ARM the IgotPltSection will immediately follow the GotSection.
214 template <class ELFT>
215 class IgotPltSection final : public SyntheticSection<ELFT> {
216   typedef typename ELFT::uint uintX_t;
217
218 public:
219   IgotPltSection();
220   void addEntry(SymbolBody &Sym);
221   size_t getSize() const override;
222   void writeTo(uint8_t *Buf) override;
223   bool empty() const override { return Entries.empty(); }
224
225 private:
226   std::vector<const SymbolBody *> Entries;
227 };
228
229 template <class ELFT>
230 class StringTableSection final : public SyntheticSection<ELFT> {
231 public:
232   typedef typename ELFT::uint uintX_t;
233   StringTableSection(StringRef Name, bool Dynamic);
234   unsigned addString(StringRef S, bool HashIt = true);
235   void writeTo(uint8_t *Buf) override;
236   size_t getSize() const override { return Size; }
237   bool isDynamic() const { return Dynamic; }
238
239 private:
240   const bool Dynamic;
241
242   // ELF string tables start with a NUL byte, so 1.
243   uintX_t Size = 1;
244
245   llvm::DenseMap<StringRef, unsigned> StringMap;
246   std::vector<StringRef> Strings;
247 };
248
249 template <class ELFT> class DynamicReloc {
250   typedef typename ELFT::uint uintX_t;
251
252 public:
253   DynamicReloc(uint32_t Type, const InputSectionBase<ELFT> *InputSec,
254                uintX_t OffsetInSec, bool UseSymVA, SymbolBody *Sym,
255                uintX_t Addend)
256       : Type(Type), Sym(Sym), InputSec(InputSec), OffsetInSec(OffsetInSec),
257         UseSymVA(UseSymVA), Addend(Addend) {}
258
259   DynamicReloc(uint32_t Type, const OutputSectionBase *OutputSec,
260                uintX_t OffsetInSec, bool UseSymVA, SymbolBody *Sym,
261                uintX_t Addend)
262       : Type(Type), Sym(Sym), OutputSec(OutputSec), OffsetInSec(OffsetInSec),
263         UseSymVA(UseSymVA), Addend(Addend) {}
264
265   uintX_t getOffset() const;
266   uintX_t getAddend() const;
267   uint32_t getSymIndex() const;
268   const OutputSectionBase *getOutputSec() const { return OutputSec; }
269   const InputSectionBase<ELFT> *getInputSec() const { return InputSec; }
270
271   uint32_t Type;
272
273 private:
274   SymbolBody *Sym;
275   const InputSectionBase<ELFT> *InputSec = nullptr;
276   const OutputSectionBase *OutputSec = nullptr;
277   uintX_t OffsetInSec;
278   bool UseSymVA;
279   uintX_t Addend;
280 };
281
282 template <class ELFT>
283 class DynamicSection final : public SyntheticSection<ELFT> {
284   typedef typename ELFT::Dyn Elf_Dyn;
285   typedef typename ELFT::Rel Elf_Rel;
286   typedef typename ELFT::Rela Elf_Rela;
287   typedef typename ELFT::Shdr Elf_Shdr;
288   typedef typename ELFT::Sym Elf_Sym;
289   typedef typename ELFT::uint uintX_t;
290
291   // The .dynamic section contains information for the dynamic linker.
292   // The section consists of fixed size entries, which consist of
293   // type and value fields. Value are one of plain integers, symbol
294   // addresses, or section addresses. This struct represents the entry.
295   struct Entry {
296     int32_t Tag;
297     union {
298       OutputSectionBase *OutSec;
299       InputSection<ELFT> *InSec;
300       uint64_t Val;
301       const SymbolBody *Sym;
302     };
303     enum KindT { SecAddr, SecSize, SymAddr, PlainInt, InSecAddr } Kind;
304     Entry(int32_t Tag, OutputSectionBase *OutSec, KindT Kind = SecAddr)
305         : Tag(Tag), OutSec(OutSec), Kind(Kind) {}
306     Entry(int32_t Tag, InputSection<ELFT> *Sec)
307         : Tag(Tag), InSec(Sec), Kind(InSecAddr) {}
308     Entry(int32_t Tag, uint64_t Val) : Tag(Tag), Val(Val), Kind(PlainInt) {}
309     Entry(int32_t Tag, const SymbolBody *Sym)
310         : Tag(Tag), Sym(Sym), Kind(SymAddr) {}
311   };
312
313   // finalize() fills this vector with the section contents. finalize()
314   // cannot directly create final section contents because when the
315   // function is called, symbol or section addresses are not fixed yet.
316   std::vector<Entry> Entries;
317
318 public:
319   DynamicSection();
320   void finalize() override;
321   void writeTo(uint8_t *Buf) override;
322   size_t getSize() const override { return Size; }
323
324 private:
325   void addEntries();
326   void add(Entry E) { Entries.push_back(E); }
327   uintX_t Size = 0;
328 };
329
330 template <class ELFT>
331 class RelocationSection final : public SyntheticSection<ELFT> {
332   typedef typename ELFT::Rel Elf_Rel;
333   typedef typename ELFT::Rela Elf_Rela;
334   typedef typename ELFT::uint uintX_t;
335
336 public:
337   RelocationSection(StringRef Name, bool Sort);
338   void addReloc(const DynamicReloc<ELFT> &Reloc);
339   unsigned getRelocOffset();
340   void finalize() override;
341   void writeTo(uint8_t *Buf) override;
342   bool empty() const override { return Relocs.empty(); }
343   size_t getSize() const override { return Relocs.size() * this->Entsize; }
344   size_t getRelativeRelocCount() const { return NumRelativeRelocs; }
345
346 private:
347   bool Sort;
348   size_t NumRelativeRelocs = 0;
349   std::vector<DynamicReloc<ELFT>> Relocs;
350 };
351
352 struct SymbolTableEntry {
353   SymbolBody *Symbol;
354   size_t StrTabOffset;
355 };
356
357 template <class ELFT>
358 class SymbolTableSection final : public SyntheticSection<ELFT> {
359 public:
360   typedef typename ELFT::Shdr Elf_Shdr;
361   typedef typename ELFT::Sym Elf_Sym;
362   typedef typename ELFT::SymRange Elf_Sym_Range;
363   typedef typename ELFT::uint uintX_t;
364   SymbolTableSection(StringTableSection<ELFT> &StrTabSec);
365
366   void finalize() override;
367   void writeTo(uint8_t *Buf) override;
368   size_t getSize() const override { return getNumSymbols() * sizeof(Elf_Sym); }
369   void addSymbol(SymbolBody *Body);
370   StringTableSection<ELFT> &getStrTabSec() const { return StrTabSec; }
371   unsigned getNumSymbols() const { return NumLocals + Symbols.size() + 1; }
372
373   ArrayRef<SymbolTableEntry> getSymbols() const { return Symbols; }
374
375   unsigned NumLocals = 0;
376   StringTableSection<ELFT> &StrTabSec;
377
378 private:
379   void writeLocalSymbols(uint8_t *&Buf);
380   void writeGlobalSymbols(uint8_t *Buf);
381
382   const OutputSectionBase *getOutputSection(SymbolBody *Sym);
383
384   // A vector of symbols and their string table offsets.
385   std::vector<SymbolTableEntry> Symbols;
386 };
387
388 // Outputs GNU Hash section. For detailed explanation see:
389 // https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections
390 template <class ELFT>
391 class GnuHashTableSection final : public SyntheticSection<ELFT> {
392   typedef typename ELFT::Off Elf_Off;
393   typedef typename ELFT::Word Elf_Word;
394   typedef typename ELFT::uint uintX_t;
395
396 public:
397   GnuHashTableSection();
398   void finalize() override;
399   void writeTo(uint8_t *Buf) override;
400   size_t getSize() const override { return this->Size; }
401
402   // Adds symbols to the hash table.
403   // Sorts the input to satisfy GNU hash section requirements.
404   void addSymbols(std::vector<SymbolTableEntry> &Symbols);
405
406 private:
407   static unsigned calcNBuckets(unsigned NumHashed);
408   static unsigned calcMaskWords(unsigned NumHashed);
409
410   void writeHeader(uint8_t *&Buf);
411   void writeBloomFilter(uint8_t *&Buf);
412   void writeHashTable(uint8_t *Buf);
413
414   struct SymbolData {
415     SymbolBody *Body;
416     size_t STName;
417     uint32_t Hash;
418   };
419
420   std::vector<SymbolData> Symbols;
421
422   unsigned MaskWords;
423   unsigned NBuckets;
424   unsigned Shift2;
425   uintX_t Size = 0;
426 };
427
428 template <class ELFT>
429 class HashTableSection final : public SyntheticSection<ELFT> {
430   typedef typename ELFT::Word Elf_Word;
431
432 public:
433   HashTableSection();
434   void finalize() override;
435   void writeTo(uint8_t *Buf) override;
436   size_t getSize() const override { return this->Size; }
437
438 private:
439   size_t Size = 0;
440 };
441
442 template <class ELFT> class PltSection final : public SyntheticSection<ELFT> {
443 public:
444   PltSection();
445   void writeTo(uint8_t *Buf) override;
446   size_t getSize() const override;
447   void addEntry(SymbolBody &Sym);
448   bool empty() const override { return Entries.empty(); }
449
450 private:
451   std::vector<std::pair<const SymbolBody *, unsigned>> Entries;
452 };
453
454 // The IpltSection is a variant of Plt for recording entries for GNU Ifunc
455 // symbols that will be subject to a Target->IRelativeRel
456 // The IpltSection immediately follows the Plt section in the Output Section
457 template <class ELFT> class IpltSection final : public SyntheticSection<ELFT> {
458 public:
459   IpltSection();
460   void writeTo(uint8_t *Buf) override;
461   size_t getSize() const override;
462   void addEntry(SymbolBody &Sym);
463   bool empty() const override { return Entries.empty(); }
464
465 private:
466   std::vector<std::pair<const SymbolBody *, unsigned>> Entries;
467 };
468
469 template <class ELFT>
470 class GdbIndexSection final : public SyntheticSection<ELFT> {
471   typedef typename ELFT::uint uintX_t;
472
473   const unsigned OffsetTypeSize = 4;
474   const unsigned CuListOffset = 6 * OffsetTypeSize;
475   const unsigned CompilationUnitSize = 16;
476   const unsigned AddressEntrySize = 16 + OffsetTypeSize;
477   const unsigned SymTabEntrySize = 2 * OffsetTypeSize;
478
479 public:
480   GdbIndexSection();
481   void finalize() override;
482   void writeTo(uint8_t *Buf) override;
483   size_t getSize() const override;
484   bool empty() const override;
485
486   // Pairs of [CU Offset, CU length].
487   std::vector<std::pair<uintX_t, uintX_t>> CompilationUnits;
488
489   llvm::StringTableBuilder StringPool;
490
491   GdbHashTab SymbolTable;
492
493   // The CU vector portion of the constant pool.
494   std::vector<std::vector<std::pair<uint32_t, uint8_t>>> CuVectors;
495
496   std::vector<AddressEntry<ELFT>> AddressArea;
497
498 private:
499   void parseDebugSections();
500   void readDwarf(InputSection<ELFT> *I);
501
502   uint32_t CuTypesOffset;
503   uint32_t SymTabOffset;
504   uint32_t ConstantPoolOffset;
505   uint32_t StringPoolOffset;
506
507   size_t CuVectorsSize = 0;
508   std::vector<size_t> CuVectorsOffset;
509
510   bool Finalized = false;
511 };
512
513 // --eh-frame-hdr option tells linker to construct a header for all the
514 // .eh_frame sections. This header is placed to a section named .eh_frame_hdr
515 // and also to a PT_GNU_EH_FRAME segment.
516 // At runtime the unwinder then can find all the PT_GNU_EH_FRAME segments by
517 // calling dl_iterate_phdr.
518 // This section contains a lookup table for quick binary search of FDEs.
519 // Detailed info about internals can be found in Ian Lance Taylor's blog:
520 // http://www.airs.com/blog/archives/460 (".eh_frame")
521 // http://www.airs.com/blog/archives/462 (".eh_frame_hdr")
522 template <class ELFT>
523 class EhFrameHeader final : public SyntheticSection<ELFT> {
524   typedef typename ELFT::uint uintX_t;
525
526 public:
527   EhFrameHeader();
528   void writeTo(uint8_t *Buf) override;
529   size_t getSize() const override;
530   void addFde(uint32_t Pc, uint32_t FdeVA);
531   bool empty() const override;
532
533 private:
534   struct FdeData {
535     uint32_t Pc;
536     uint32_t FdeVA;
537   };
538
539   std::vector<FdeData> Fdes;
540 };
541
542 // For more information about .gnu.version and .gnu.version_r see:
543 // https://www.akkadia.org/drepper/symbol-versioning
544
545 // The .gnu.version_d section which has a section type of SHT_GNU_verdef shall
546 // contain symbol version definitions. The number of entries in this section
547 // shall be contained in the DT_VERDEFNUM entry of the .dynamic section.
548 // The section shall contain an array of Elf_Verdef structures, optionally
549 // followed by an array of Elf_Verdaux structures.
550 template <class ELFT>
551 class VersionDefinitionSection final : public SyntheticSection<ELFT> {
552   typedef typename ELFT::Verdef Elf_Verdef;
553   typedef typename ELFT::Verdaux Elf_Verdaux;
554
555 public:
556   VersionDefinitionSection();
557   void finalize() override;
558   size_t getSize() const override;
559   void writeTo(uint8_t *Buf) override;
560
561 private:
562   void writeOne(uint8_t *Buf, uint32_t Index, StringRef Name, size_t NameOff);
563
564   unsigned FileDefNameOff;
565 };
566
567 // The .gnu.version section specifies the required version of each symbol in the
568 // dynamic symbol table. It contains one Elf_Versym for each dynamic symbol
569 // table entry. An Elf_Versym is just a 16-bit integer that refers to a version
570 // identifier defined in the either .gnu.version_r or .gnu.version_d section.
571 // The values 0 and 1 are reserved. All other values are used for versions in
572 // the own object or in any of the dependencies.
573 template <class ELFT>
574 class VersionTableSection final : public SyntheticSection<ELFT> {
575   typedef typename ELFT::Versym Elf_Versym;
576
577 public:
578   VersionTableSection();
579   void finalize() override;
580   size_t getSize() const override;
581   void writeTo(uint8_t *Buf) override;
582   bool empty() const override;
583 };
584
585 // The .gnu.version_r section defines the version identifiers used by
586 // .gnu.version. It contains a linked list of Elf_Verneed data structures. Each
587 // Elf_Verneed specifies the version requirements for a single DSO, and contains
588 // a reference to a linked list of Elf_Vernaux data structures which define the
589 // mapping from version identifiers to version names.
590 template <class ELFT>
591 class VersionNeedSection final : public SyntheticSection<ELFT> {
592   typedef typename ELFT::Verneed Elf_Verneed;
593   typedef typename ELFT::Vernaux Elf_Vernaux;
594
595   // A vector of shared files that need Elf_Verneed data structures and the
596   // string table offsets of their sonames.
597   std::vector<std::pair<SharedFile<ELFT> *, size_t>> Needed;
598
599   // The next available version identifier.
600   unsigned NextIndex;
601
602 public:
603   VersionNeedSection();
604   void addSymbol(SharedSymbol<ELFT> *SS);
605   void finalize() override;
606   void writeTo(uint8_t *Buf) override;
607   size_t getSize() const override;
608   size_t getNeedNum() const { return Needed.size(); }
609   bool empty() const override;
610 };
611
612 // .MIPS.abiflags section.
613 template <class ELFT>
614 class MipsAbiFlagsSection final : public SyntheticSection<ELFT> {
615   typedef llvm::object::Elf_Mips_ABIFlags<ELFT> Elf_Mips_ABIFlags;
616
617 public:
618   static MipsAbiFlagsSection *create();
619
620   MipsAbiFlagsSection(Elf_Mips_ABIFlags Flags);
621   size_t getSize() const override { return sizeof(Elf_Mips_ABIFlags); }
622   void writeTo(uint8_t *Buf) override;
623
624 private:
625   Elf_Mips_ABIFlags Flags;
626 };
627
628 // .MIPS.options section.
629 template <class ELFT>
630 class MipsOptionsSection final : public SyntheticSection<ELFT> {
631   typedef llvm::object::Elf_Mips_Options<ELFT> Elf_Mips_Options;
632   typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
633
634 public:
635   static MipsOptionsSection *create();
636
637   MipsOptionsSection(Elf_Mips_RegInfo Reginfo);
638   void writeTo(uint8_t *Buf) override;
639
640   size_t getSize() const override {
641     return sizeof(Elf_Mips_Options) + sizeof(Elf_Mips_RegInfo);
642   }
643
644 private:
645   Elf_Mips_RegInfo Reginfo;
646 };
647
648 // MIPS .reginfo section.
649 template <class ELFT>
650 class MipsReginfoSection final : public SyntheticSection<ELFT> {
651   typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
652
653 public:
654   static MipsReginfoSection *create();
655
656   MipsReginfoSection(Elf_Mips_RegInfo Reginfo);
657   size_t getSize() const override { return sizeof(Elf_Mips_RegInfo); }
658   void writeTo(uint8_t *Buf) override;
659
660 private:
661   Elf_Mips_RegInfo Reginfo;
662 };
663
664 // This is a MIPS specific section to hold a space within the data segment
665 // of executable file which is pointed to by the DT_MIPS_RLD_MAP entry.
666 // See "Dynamic section" in Chapter 5 in the following document:
667 // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
668 template <class ELFT> class MipsRldMapSection : public SyntheticSection<ELFT> {
669 public:
670   MipsRldMapSection();
671   size_t getSize() const override { return sizeof(typename ELFT::uint); }
672   void writeTo(uint8_t *Buf) override;
673 };
674
675 template <class ELFT> class ARMExidxSentinelSection : public SyntheticSection<ELFT> {
676 public:
677   ARMExidxSentinelSection();
678   size_t getSize() const override { return 8; }
679   void writeTo(uint8_t *Buf) override;
680 };
681
682 template <class ELFT> InputSection<ELFT> *createCommonSection();
683 template <class ELFT> InputSection<ELFT> *createInterpSection();
684 template <class ELFT> MergeInputSection<ELFT> *createCommentSection();
685
686 // Linker generated sections which can be used as inputs.
687 template <class ELFT> struct In {
688   static InputSection<ELFT> *ARMAttributes;
689   static BuildIdSection<ELFT> *BuildId;
690   static InputSection<ELFT> *Common;
691   static DynamicSection<ELFT> *Dynamic;
692   static StringTableSection<ELFT> *DynStrTab;
693   static SymbolTableSection<ELFT> *DynSymTab;
694   static EhFrameHeader<ELFT> *EhFrameHdr;
695   static GnuHashTableSection<ELFT> *GnuHashTab;
696   static GdbIndexSection<ELFT> *GdbIndex;
697   static GotSection<ELFT> *Got;
698   static MipsGotSection<ELFT> *MipsGot;
699   static GotPltSection<ELFT> *GotPlt;
700   static IgotPltSection<ELFT> *IgotPlt;
701   static HashTableSection<ELFT> *HashTab;
702   static InputSection<ELFT> *Interp;
703   static MipsRldMapSection<ELFT> *MipsRldMap;
704   static PltSection<ELFT> *Plt;
705   static IpltSection<ELFT> *Iplt;
706   static RelocationSection<ELFT> *RelaDyn;
707   static RelocationSection<ELFT> *RelaPlt;
708   static RelocationSection<ELFT> *RelaIplt;
709   static StringTableSection<ELFT> *ShStrTab;
710   static StringTableSection<ELFT> *StrTab;
711   static SymbolTableSection<ELFT> *SymTab;
712   static VersionDefinitionSection<ELFT> *VerDef;
713   static VersionTableSection<ELFT> *VerSym;
714   static VersionNeedSection<ELFT> *VerNeed;
715 };
716
717 template <class ELFT> InputSection<ELFT> *In<ELFT>::ARMAttributes;
718 template <class ELFT> BuildIdSection<ELFT> *In<ELFT>::BuildId;
719 template <class ELFT> InputSection<ELFT> *In<ELFT>::Common;
720 template <class ELFT> DynamicSection<ELFT> *In<ELFT>::Dynamic;
721 template <class ELFT> StringTableSection<ELFT> *In<ELFT>::DynStrTab;
722 template <class ELFT> SymbolTableSection<ELFT> *In<ELFT>::DynSymTab;
723 template <class ELFT> EhFrameHeader<ELFT> *In<ELFT>::EhFrameHdr;
724 template <class ELFT> GdbIndexSection<ELFT> *In<ELFT>::GdbIndex;
725 template <class ELFT> GnuHashTableSection<ELFT> *In<ELFT>::GnuHashTab;
726 template <class ELFT> GotSection<ELFT> *In<ELFT>::Got;
727 template <class ELFT> MipsGotSection<ELFT> *In<ELFT>::MipsGot;
728 template <class ELFT> GotPltSection<ELFT> *In<ELFT>::GotPlt;
729 template <class ELFT> IgotPltSection<ELFT> *In<ELFT>::IgotPlt;
730 template <class ELFT> HashTableSection<ELFT> *In<ELFT>::HashTab;
731 template <class ELFT> InputSection<ELFT> *In<ELFT>::Interp;
732 template <class ELFT> MipsRldMapSection<ELFT> *In<ELFT>::MipsRldMap;
733 template <class ELFT> PltSection<ELFT> *In<ELFT>::Plt;
734 template <class ELFT> IpltSection<ELFT> *In<ELFT>::Iplt;
735 template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaDyn;
736 template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaPlt;
737 template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaIplt;
738 template <class ELFT> StringTableSection<ELFT> *In<ELFT>::ShStrTab;
739 template <class ELFT> StringTableSection<ELFT> *In<ELFT>::StrTab;
740 template <class ELFT> SymbolTableSection<ELFT> *In<ELFT>::SymTab;
741 template <class ELFT> VersionDefinitionSection<ELFT> *In<ELFT>::VerDef;
742 template <class ELFT> VersionTableSection<ELFT> *In<ELFT>::VerSym;
743 template <class ELFT> VersionNeedSection<ELFT> *In<ELFT>::VerNeed;
744 } // namespace elf
745 } // namespace lld
746
747 #endif