]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/SyntheticSections.h
Merge ^/head r313644 through r313895.
[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 addGlobal(SymbolBody *Body);
370   void addLocal(SymbolBody *Body);
371   StringTableSection<ELFT> &getStrTabSec() const { return StrTabSec; }
372   unsigned getNumSymbols() const { return Symbols.size() + 1; }
373   size_t getSymbolIndex(SymbolBody *Body);
374
375   ArrayRef<SymbolTableEntry> getSymbols() const { return Symbols; }
376
377   static const OutputSectionBase *getOutputSection(SymbolBody *Sym);
378
379 private:
380   void writeLocalSymbols(uint8_t *&Buf);
381   void writeGlobalSymbols(uint8_t *Buf);
382
383   // A vector of symbols and their string table offsets.
384   std::vector<SymbolTableEntry> Symbols;
385
386   StringTableSection<ELFT> &StrTabSec;
387
388   unsigned NumLocals = 0;
389 };
390
391 // Outputs GNU Hash section. For detailed explanation see:
392 // https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections
393 template <class ELFT>
394 class GnuHashTableSection final : public SyntheticSection<ELFT> {
395   typedef typename ELFT::Off Elf_Off;
396   typedef typename ELFT::Word Elf_Word;
397   typedef typename ELFT::uint uintX_t;
398
399 public:
400   GnuHashTableSection();
401   void finalize() override;
402   void writeTo(uint8_t *Buf) override;
403   size_t getSize() const override { return this->Size; }
404
405   // Adds symbols to the hash table.
406   // Sorts the input to satisfy GNU hash section requirements.
407   void addSymbols(std::vector<SymbolTableEntry> &Symbols);
408
409 private:
410   static unsigned calcNBuckets(unsigned NumHashed);
411   static unsigned calcMaskWords(unsigned NumHashed);
412
413   void writeHeader(uint8_t *&Buf);
414   void writeBloomFilter(uint8_t *&Buf);
415   void writeHashTable(uint8_t *Buf);
416
417   struct SymbolData {
418     SymbolBody *Body;
419     size_t STName;
420     uint32_t Hash;
421   };
422
423   std::vector<SymbolData> Symbols;
424
425   unsigned MaskWords;
426   unsigned NBuckets;
427   unsigned Shift2;
428   uintX_t Size = 0;
429 };
430
431 template <class ELFT>
432 class HashTableSection final : public SyntheticSection<ELFT> {
433   typedef typename ELFT::Word Elf_Word;
434
435 public:
436   HashTableSection();
437   void finalize() override;
438   void writeTo(uint8_t *Buf) override;
439   size_t getSize() const override { return this->Size; }
440
441 private:
442   size_t Size = 0;
443 };
444
445 template <class ELFT> class PltSection final : public SyntheticSection<ELFT> {
446 public:
447   PltSection();
448   void writeTo(uint8_t *Buf) override;
449   size_t getSize() const override;
450   void addEntry(SymbolBody &Sym);
451   bool empty() const override { return Entries.empty(); }
452
453 private:
454   std::vector<std::pair<const SymbolBody *, unsigned>> Entries;
455 };
456
457 // The IpltSection is a variant of Plt for recording entries for GNU Ifunc
458 // symbols that will be subject to a Target->IRelativeRel
459 // The IpltSection immediately follows the Plt section in the Output Section
460 template <class ELFT> class IpltSection final : public SyntheticSection<ELFT> {
461 public:
462   IpltSection();
463   void writeTo(uint8_t *Buf) override;
464   size_t getSize() const override;
465   void addEntry(SymbolBody &Sym);
466   bool empty() const override { return Entries.empty(); }
467
468 private:
469   std::vector<std::pair<const SymbolBody *, unsigned>> Entries;
470 };
471
472 template <class ELFT>
473 class GdbIndexSection final : public SyntheticSection<ELFT> {
474   typedef typename ELFT::uint uintX_t;
475
476   const unsigned OffsetTypeSize = 4;
477   const unsigned CuListOffset = 6 * OffsetTypeSize;
478   const unsigned CompilationUnitSize = 16;
479   const unsigned AddressEntrySize = 16 + OffsetTypeSize;
480   const unsigned SymTabEntrySize = 2 * OffsetTypeSize;
481
482 public:
483   GdbIndexSection();
484   void finalize() override;
485   void writeTo(uint8_t *Buf) override;
486   size_t getSize() const override;
487   bool empty() const override;
488
489   // Pairs of [CU Offset, CU length].
490   std::vector<std::pair<uintX_t, uintX_t>> CompilationUnits;
491
492   llvm::StringTableBuilder StringPool;
493
494   GdbHashTab SymbolTable;
495
496   // The CU vector portion of the constant pool.
497   std::vector<std::vector<std::pair<uint32_t, uint8_t>>> CuVectors;
498
499   std::vector<AddressEntry<ELFT>> AddressArea;
500
501 private:
502   void parseDebugSections();
503   void readDwarf(InputSection<ELFT> *I);
504
505   uint32_t CuTypesOffset;
506   uint32_t SymTabOffset;
507   uint32_t ConstantPoolOffset;
508   uint32_t StringPoolOffset;
509
510   size_t CuVectorsSize = 0;
511   std::vector<size_t> CuVectorsOffset;
512
513   bool Finalized = false;
514 };
515
516 // --eh-frame-hdr option tells linker to construct a header for all the
517 // .eh_frame sections. This header is placed to a section named .eh_frame_hdr
518 // and also to a PT_GNU_EH_FRAME segment.
519 // At runtime the unwinder then can find all the PT_GNU_EH_FRAME segments by
520 // calling dl_iterate_phdr.
521 // This section contains a lookup table for quick binary search of FDEs.
522 // Detailed info about internals can be found in Ian Lance Taylor's blog:
523 // http://www.airs.com/blog/archives/460 (".eh_frame")
524 // http://www.airs.com/blog/archives/462 (".eh_frame_hdr")
525 template <class ELFT>
526 class EhFrameHeader final : public SyntheticSection<ELFT> {
527   typedef typename ELFT::uint uintX_t;
528
529 public:
530   EhFrameHeader();
531   void writeTo(uint8_t *Buf) override;
532   size_t getSize() const override;
533   void addFde(uint32_t Pc, uint32_t FdeVA);
534   bool empty() const override;
535
536 private:
537   struct FdeData {
538     uint32_t Pc;
539     uint32_t FdeVA;
540   };
541
542   std::vector<FdeData> Fdes;
543 };
544
545 // For more information about .gnu.version and .gnu.version_r see:
546 // https://www.akkadia.org/drepper/symbol-versioning
547
548 // The .gnu.version_d section which has a section type of SHT_GNU_verdef shall
549 // contain symbol version definitions. The number of entries in this section
550 // shall be contained in the DT_VERDEFNUM entry of the .dynamic section.
551 // The section shall contain an array of Elf_Verdef structures, optionally
552 // followed by an array of Elf_Verdaux structures.
553 template <class ELFT>
554 class VersionDefinitionSection final : public SyntheticSection<ELFT> {
555   typedef typename ELFT::Verdef Elf_Verdef;
556   typedef typename ELFT::Verdaux Elf_Verdaux;
557
558 public:
559   VersionDefinitionSection();
560   void finalize() override;
561   size_t getSize() const override;
562   void writeTo(uint8_t *Buf) override;
563
564 private:
565   void writeOne(uint8_t *Buf, uint32_t Index, StringRef Name, size_t NameOff);
566
567   unsigned FileDefNameOff;
568 };
569
570 // The .gnu.version section specifies the required version of each symbol in the
571 // dynamic symbol table. It contains one Elf_Versym for each dynamic symbol
572 // table entry. An Elf_Versym is just a 16-bit integer that refers to a version
573 // identifier defined in the either .gnu.version_r or .gnu.version_d section.
574 // The values 0 and 1 are reserved. All other values are used for versions in
575 // the own object or in any of the dependencies.
576 template <class ELFT>
577 class VersionTableSection final : public SyntheticSection<ELFT> {
578   typedef typename ELFT::Versym Elf_Versym;
579
580 public:
581   VersionTableSection();
582   void finalize() override;
583   size_t getSize() const override;
584   void writeTo(uint8_t *Buf) override;
585   bool empty() const override;
586 };
587
588 // The .gnu.version_r section defines the version identifiers used by
589 // .gnu.version. It contains a linked list of Elf_Verneed data structures. Each
590 // Elf_Verneed specifies the version requirements for a single DSO, and contains
591 // a reference to a linked list of Elf_Vernaux data structures which define the
592 // mapping from version identifiers to version names.
593 template <class ELFT>
594 class VersionNeedSection final : public SyntheticSection<ELFT> {
595   typedef typename ELFT::Verneed Elf_Verneed;
596   typedef typename ELFT::Vernaux Elf_Vernaux;
597
598   // A vector of shared files that need Elf_Verneed data structures and the
599   // string table offsets of their sonames.
600   std::vector<std::pair<SharedFile<ELFT> *, size_t>> Needed;
601
602   // The next available version identifier.
603   unsigned NextIndex;
604
605 public:
606   VersionNeedSection();
607   void addSymbol(SharedSymbol<ELFT> *SS);
608   void finalize() override;
609   void writeTo(uint8_t *Buf) override;
610   size_t getSize() const override;
611   size_t getNeedNum() const { return Needed.size(); }
612   bool empty() const override;
613 };
614
615 // .MIPS.abiflags section.
616 template <class ELFT>
617 class MipsAbiFlagsSection final : public SyntheticSection<ELFT> {
618   typedef llvm::object::Elf_Mips_ABIFlags<ELFT> Elf_Mips_ABIFlags;
619
620 public:
621   static MipsAbiFlagsSection *create();
622
623   MipsAbiFlagsSection(Elf_Mips_ABIFlags Flags);
624   size_t getSize() const override { return sizeof(Elf_Mips_ABIFlags); }
625   void writeTo(uint8_t *Buf) override;
626
627 private:
628   Elf_Mips_ABIFlags Flags;
629 };
630
631 // .MIPS.options section.
632 template <class ELFT>
633 class MipsOptionsSection final : public SyntheticSection<ELFT> {
634   typedef llvm::object::Elf_Mips_Options<ELFT> Elf_Mips_Options;
635   typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
636
637 public:
638   static MipsOptionsSection *create();
639
640   MipsOptionsSection(Elf_Mips_RegInfo Reginfo);
641   void writeTo(uint8_t *Buf) override;
642
643   size_t getSize() const override {
644     return sizeof(Elf_Mips_Options) + sizeof(Elf_Mips_RegInfo);
645   }
646
647 private:
648   Elf_Mips_RegInfo Reginfo;
649 };
650
651 // MIPS .reginfo section.
652 template <class ELFT>
653 class MipsReginfoSection final : public SyntheticSection<ELFT> {
654   typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
655
656 public:
657   static MipsReginfoSection *create();
658
659   MipsReginfoSection(Elf_Mips_RegInfo Reginfo);
660   size_t getSize() const override { return sizeof(Elf_Mips_RegInfo); }
661   void writeTo(uint8_t *Buf) override;
662
663 private:
664   Elf_Mips_RegInfo Reginfo;
665 };
666
667 // This is a MIPS specific section to hold a space within the data segment
668 // of executable file which is pointed to by the DT_MIPS_RLD_MAP entry.
669 // See "Dynamic section" in Chapter 5 in the following document:
670 // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
671 template <class ELFT> class MipsRldMapSection : public SyntheticSection<ELFT> {
672 public:
673   MipsRldMapSection();
674   size_t getSize() const override { return sizeof(typename ELFT::uint); }
675   void writeTo(uint8_t *Buf) override;
676 };
677
678 template <class ELFT> class ARMExidxSentinelSection : public SyntheticSection<ELFT> {
679 public:
680   ARMExidxSentinelSection();
681   size_t getSize() const override { return 8; }
682   void writeTo(uint8_t *Buf) override;
683 };
684
685 template <class ELFT> InputSection<ELFT> *createCommonSection();
686 template <class ELFT> InputSection<ELFT> *createInterpSection();
687 template <class ELFT> MergeInputSection<ELFT> *createCommentSection();
688
689 // Linker generated sections which can be used as inputs.
690 template <class ELFT> struct In {
691   static InputSection<ELFT> *ARMAttributes;
692   static BuildIdSection<ELFT> *BuildId;
693   static InputSection<ELFT> *Common;
694   static DynamicSection<ELFT> *Dynamic;
695   static StringTableSection<ELFT> *DynStrTab;
696   static SymbolTableSection<ELFT> *DynSymTab;
697   static EhFrameHeader<ELFT> *EhFrameHdr;
698   static GnuHashTableSection<ELFT> *GnuHashTab;
699   static GdbIndexSection<ELFT> *GdbIndex;
700   static GotSection<ELFT> *Got;
701   static MipsGotSection<ELFT> *MipsGot;
702   static GotPltSection<ELFT> *GotPlt;
703   static IgotPltSection<ELFT> *IgotPlt;
704   static HashTableSection<ELFT> *HashTab;
705   static InputSection<ELFT> *Interp;
706   static MipsRldMapSection<ELFT> *MipsRldMap;
707   static PltSection<ELFT> *Plt;
708   static IpltSection<ELFT> *Iplt;
709   static RelocationSection<ELFT> *RelaDyn;
710   static RelocationSection<ELFT> *RelaPlt;
711   static RelocationSection<ELFT> *RelaIplt;
712   static StringTableSection<ELFT> *ShStrTab;
713   static StringTableSection<ELFT> *StrTab;
714   static SymbolTableSection<ELFT> *SymTab;
715   static VersionDefinitionSection<ELFT> *VerDef;
716   static VersionTableSection<ELFT> *VerSym;
717   static VersionNeedSection<ELFT> *VerNeed;
718 };
719
720 template <class ELFT> InputSection<ELFT> *In<ELFT>::ARMAttributes;
721 template <class ELFT> BuildIdSection<ELFT> *In<ELFT>::BuildId;
722 template <class ELFT> InputSection<ELFT> *In<ELFT>::Common;
723 template <class ELFT> DynamicSection<ELFT> *In<ELFT>::Dynamic;
724 template <class ELFT> StringTableSection<ELFT> *In<ELFT>::DynStrTab;
725 template <class ELFT> SymbolTableSection<ELFT> *In<ELFT>::DynSymTab;
726 template <class ELFT> EhFrameHeader<ELFT> *In<ELFT>::EhFrameHdr;
727 template <class ELFT> GdbIndexSection<ELFT> *In<ELFT>::GdbIndex;
728 template <class ELFT> GnuHashTableSection<ELFT> *In<ELFT>::GnuHashTab;
729 template <class ELFT> GotSection<ELFT> *In<ELFT>::Got;
730 template <class ELFT> MipsGotSection<ELFT> *In<ELFT>::MipsGot;
731 template <class ELFT> GotPltSection<ELFT> *In<ELFT>::GotPlt;
732 template <class ELFT> IgotPltSection<ELFT> *In<ELFT>::IgotPlt;
733 template <class ELFT> HashTableSection<ELFT> *In<ELFT>::HashTab;
734 template <class ELFT> InputSection<ELFT> *In<ELFT>::Interp;
735 template <class ELFT> MipsRldMapSection<ELFT> *In<ELFT>::MipsRldMap;
736 template <class ELFT> PltSection<ELFT> *In<ELFT>::Plt;
737 template <class ELFT> IpltSection<ELFT> *In<ELFT>::Iplt;
738 template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaDyn;
739 template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaPlt;
740 template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaIplt;
741 template <class ELFT> StringTableSection<ELFT> *In<ELFT>::ShStrTab;
742 template <class ELFT> StringTableSection<ELFT> *In<ELFT>::StrTab;
743 template <class ELFT> SymbolTableSection<ELFT> *In<ELFT>::SymTab;
744 template <class ELFT> VersionDefinitionSection<ELFT> *In<ELFT>::VerDef;
745 template <class ELFT> VersionTableSection<ELFT> *In<ELFT>::VerSym;
746 template <class ELFT> VersionNeedSection<ELFT> *In<ELFT>::VerNeed;
747 } // namespace elf
748 } // namespace lld
749
750 #endif