xref: /freebsd/contrib/llvm-project/lld/ELF/SyntheticSections.h (revision a1f13cbcbb26465d8b54c18a294896add63d6536)
1 //===- SyntheticSection.h ---------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Synthetic sections represent chunks of linker-created data. If you
10 // need to create a chunk of data that to be included in some section
11 // in the result, you probably want to create that as a synthetic section.
12 //
13 // Synthetic sections are designed as input sections as opposed to
14 // output sections because we want to allow them to be manipulated
15 // using linker scripts just like other input sections from regular
16 // files.
17 //
18 //===----------------------------------------------------------------------===//
19 
20 #ifndef LLD_ELF_SYNTHETIC_SECTIONS_H
21 #define LLD_ELF_SYNTHETIC_SECTIONS_H
22 
23 #include "DWARF.h"
24 #include "EhFrame.h"
25 #include "InputSection.h"
26 #include "llvm/ADT/DenseSet.h"
27 #include "llvm/ADT/MapVector.h"
28 #include "llvm/MC/StringTableBuilder.h"
29 #include "llvm/Support/Endian.h"
30 #include <functional>
31 
32 namespace lld {
33 namespace elf {
34 class Defined;
35 struct PhdrEntry;
36 class SymbolTableBaseSection;
37 
38 class SyntheticSection : public InputSection {
39 public:
40   SyntheticSection(uint64_t flags, uint32_t type, uint32_t alignment,
41                    StringRef name)
42       : InputSection(nullptr, flags, type, alignment, {}, name,
43                      InputSectionBase::Synthetic) {}
44 
45   virtual ~SyntheticSection() = default;
46   virtual void writeTo(uint8_t *buf) = 0;
47   virtual size_t getSize() const = 0;
48   virtual void finalizeContents() {}
49   // If the section has the SHF_ALLOC flag and the size may be changed if
50   // thunks are added, update the section size.
51   virtual bool updateAllocSize() { return false; }
52   virtual bool isNeeded() const { return true; }
53 
54   static bool classof(const SectionBase *d) {
55     return d->kind() == InputSectionBase::Synthetic;
56   }
57 };
58 
59 struct CieRecord {
60   EhSectionPiece *cie = nullptr;
61   SmallVector<EhSectionPiece *, 0> fdes;
62 };
63 
64 // Section for .eh_frame.
65 class EhFrameSection final : public SyntheticSection {
66 public:
67   EhFrameSection();
68   void writeTo(uint8_t *buf) override;
69   void finalizeContents() override;
70   bool isNeeded() const override { return !sections.empty(); }
71   size_t getSize() const override { return size; }
72 
73   static bool classof(const SectionBase *d) {
74     return SyntheticSection::classof(d) && d->name == ".eh_frame";
75   }
76 
77   void addSection(EhInputSection *sec);
78 
79   SmallVector<EhInputSection *, 0> sections;
80   size_t numFdes = 0;
81 
82   struct FdeData {
83     uint32_t pcRel;
84     uint32_t fdeVARel;
85   };
86 
87   SmallVector<FdeData, 0> getFdeData() const;
88   ArrayRef<CieRecord *> getCieRecords() const { return cieRecords; }
89   template <class ELFT>
90   void iterateFDEWithLSDA(llvm::function_ref<void(InputSection &)> fn);
91 
92 private:
93   // This is used only when parsing EhInputSection. We keep it here to avoid
94   // allocating one for each EhInputSection.
95   llvm::DenseMap<size_t, CieRecord *> offsetToCie;
96 
97   uint64_t size = 0;
98 
99   template <class ELFT, class RelTy>
100   void addRecords(EhInputSection *s, llvm::ArrayRef<RelTy> rels);
101   template <class ELFT> void addSectionAux(EhInputSection *s);
102   template <class ELFT, class RelTy>
103   void iterateFDEWithLSDAAux(EhInputSection &sec, ArrayRef<RelTy> rels,
104                              llvm::DenseSet<size_t> &ciesWithLSDA,
105                              llvm::function_ref<void(InputSection &)> fn);
106 
107   template <class ELFT, class RelTy>
108   CieRecord *addCie(EhSectionPiece &piece, ArrayRef<RelTy> rels);
109 
110   template <class ELFT, class RelTy>
111   Defined *isFdeLive(EhSectionPiece &piece, ArrayRef<RelTy> rels);
112 
113   uint64_t getFdePc(uint8_t *buf, size_t off, uint8_t enc) const;
114 
115   SmallVector<CieRecord *, 0> cieRecords;
116 
117   // CIE records are uniquified by their contents and personality functions.
118   llvm::DenseMap<std::pair<ArrayRef<uint8_t>, Symbol *>, CieRecord *> cieMap;
119 };
120 
121 class GotSection : public SyntheticSection {
122 public:
123   GotSection();
124   size_t getSize() const override { return size; }
125   void finalizeContents() override;
126   bool isNeeded() const override;
127   void writeTo(uint8_t *buf) override;
128 
129   void addEntry(Symbol &sym);
130   bool addTlsDescEntry(Symbol &sym);
131   bool addDynTlsEntry(Symbol &sym);
132   bool addTlsIndex();
133   uint32_t getTlsDescOffset(const Symbol &sym) const;
134   uint64_t getTlsDescAddr(const Symbol &sym) const;
135   uint64_t getGlobalDynAddr(const Symbol &b) const;
136   uint64_t getGlobalDynOffset(const Symbol &b) const;
137 
138   uint64_t getTlsIndexVA() { return this->getVA() + tlsIndexOff; }
139   uint32_t getTlsIndexOff() const { return tlsIndexOff; }
140 
141   // Flag to force GOT to be in output if we have relocations
142   // that relies on its address.
143   bool hasGotOffRel = false;
144 
145 protected:
146   size_t numEntries = 0;
147   uint32_t tlsIndexOff = -1;
148   uint64_t size = 0;
149 };
150 
151 // .note.GNU-stack section.
152 class GnuStackSection : public SyntheticSection {
153 public:
154   GnuStackSection()
155       : SyntheticSection(0, llvm::ELF::SHT_PROGBITS, 1, ".note.GNU-stack") {}
156   void writeTo(uint8_t *buf) override {}
157   size_t getSize() const override { return 0; }
158 };
159 
160 class GnuPropertySection : public SyntheticSection {
161 public:
162   GnuPropertySection();
163   void writeTo(uint8_t *buf) override;
164   size_t getSize() const override;
165 };
166 
167 // .note.gnu.build-id section.
168 class BuildIdSection : public SyntheticSection {
169   // First 16 bytes are a header.
170   static const unsigned headerSize = 16;
171 
172 public:
173   const size_t hashSize;
174   BuildIdSection();
175   void writeTo(uint8_t *buf) override;
176   size_t getSize() const override { return headerSize + hashSize; }
177   void writeBuildId(llvm::ArrayRef<uint8_t> buf);
178 
179 private:
180   uint8_t *hashBuf;
181 };
182 
183 // BssSection is used to reserve space for copy relocations and common symbols.
184 // We create three instances of this class for .bss, .bss.rel.ro and "COMMON",
185 // that are used for writable symbols, read-only symbols and common symbols,
186 // respectively.
187 class BssSection final : public SyntheticSection {
188 public:
189   BssSection(StringRef name, uint64_t size, uint32_t alignment);
190   void writeTo(uint8_t *) override {
191     llvm_unreachable("unexpected writeTo() call for SHT_NOBITS section");
192   }
193   bool isNeeded() const override { return size != 0; }
194   size_t getSize() const override { return size; }
195 
196   static bool classof(const SectionBase *s) { return s->bss; }
197   uint64_t size;
198 };
199 
200 class MipsGotSection final : public SyntheticSection {
201 public:
202   MipsGotSection();
203   void writeTo(uint8_t *buf) override;
204   size_t getSize() const override { return size; }
205   bool updateAllocSize() override;
206   void finalizeContents() override;
207   bool isNeeded() const override;
208 
209   // Join separate GOTs built for each input file to generate
210   // primary and optional multiple secondary GOTs.
211   void build();
212 
213   void addEntry(InputFile &file, Symbol &sym, int64_t addend, RelExpr expr);
214   void addDynTlsEntry(InputFile &file, Symbol &sym);
215   void addTlsIndex(InputFile &file);
216 
217   uint64_t getPageEntryOffset(const InputFile *f, const Symbol &s,
218                               int64_t addend) const;
219   uint64_t getSymEntryOffset(const InputFile *f, const Symbol &s,
220                              int64_t addend) const;
221   uint64_t getGlobalDynOffset(const InputFile *f, const Symbol &s) const;
222   uint64_t getTlsIndexOffset(const InputFile *f) const;
223 
224   // Returns the symbol which corresponds to the first entry of the global part
225   // of GOT on MIPS platform. It is required to fill up MIPS-specific dynamic
226   // table properties.
227   // Returns nullptr if the global part is empty.
228   const Symbol *getFirstGlobalEntry() const;
229 
230   // Returns the number of entries in the local part of GOT including
231   // the number of reserved entries.
232   unsigned getLocalEntriesNum() const;
233 
234   // Return _gp value for primary GOT (nullptr) or particular input file.
235   uint64_t getGp(const InputFile *f = nullptr) const;
236 
237 private:
238   // MIPS GOT consists of three parts: local, global and tls. Each part
239   // contains different types of entries. Here is a layout of GOT:
240   // - Header entries                |
241   // - Page entries                  |   Local part
242   // - Local entries (16-bit access) |
243   // - Local entries (32-bit access) |
244   // - Normal global entries         ||  Global part
245   // - Reloc-only global entries     ||
246   // - TLS entries                   ||| TLS part
247   //
248   // Header:
249   //   Two entries hold predefined value 0x0 and 0x80000000.
250   // Page entries:
251   //   These entries created by R_MIPS_GOT_PAGE relocation and R_MIPS_GOT16
252   //   relocation against local symbols. They are initialized by higher 16-bit
253   //   of the corresponding symbol's value. So each 64kb of address space
254   //   requires a single GOT entry.
255   // Local entries (16-bit access):
256   //   These entries created by GOT relocations against global non-preemptible
257   //   symbols so dynamic linker is not necessary to resolve the symbol's
258   //   values. "16-bit access" means that corresponding relocations address
259   //   GOT using 16-bit index. Each unique Symbol-Addend pair has its own
260   //   GOT entry.
261   // Local entries (32-bit access):
262   //   These entries are the same as above but created by relocations which
263   //   address GOT using 32-bit index (R_MIPS_GOT_HI16/LO16 etc).
264   // Normal global entries:
265   //   These entries created by GOT relocations against preemptible global
266   //   symbols. They need to be initialized by dynamic linker and they ordered
267   //   exactly as the corresponding entries in the dynamic symbols table.
268   // Reloc-only global entries:
269   //   These entries created for symbols that are referenced by dynamic
270   //   relocations R_MIPS_REL32. These entries are not accessed with gp-relative
271   //   addressing, but MIPS ABI requires that these entries be present in GOT.
272   // TLS entries:
273   //   Entries created by TLS relocations.
274   //
275   // If the sum of local, global and tls entries is less than 64K only single
276   // got is enough. Otherwise, multi-got is created. Series of primary and
277   // multiple secondary GOTs have the following layout:
278   // - Primary GOT
279   //     Header
280   //     Local entries
281   //     Global entries
282   //     Relocation only entries
283   //     TLS entries
284   //
285   // - Secondary GOT
286   //     Local entries
287   //     Global entries
288   //     TLS entries
289   // ...
290   //
291   // All GOT entries required by relocations from a single input file entirely
292   // belong to either primary or one of secondary GOTs. To reference GOT entries
293   // each GOT has its own _gp value points to the "middle" of the GOT.
294   // In the code this value loaded to the register which is used for GOT access.
295   //
296   // MIPS 32 function's prologue:
297   //   lui     v0,0x0
298   //   0: R_MIPS_HI16  _gp_disp
299   //   addiu   v0,v0,0
300   //   4: R_MIPS_LO16  _gp_disp
301   //
302   // MIPS 64:
303   //   lui     at,0x0
304   //   14: R_MIPS_GPREL16  main
305   //
306   // Dynamic linker does not know anything about secondary GOTs and cannot
307   // use a regular MIPS mechanism for GOT entries initialization. So we have
308   // to use an approach accepted by other architectures and create dynamic
309   // relocations R_MIPS_REL32 to initialize global entries (and local in case
310   // of PIC code) in secondary GOTs. But ironically MIPS dynamic linker
311   // requires GOT entries and correspondingly ordered dynamic symbol table
312   // entries to deal with dynamic relocations. To handle this problem
313   // relocation-only section in the primary GOT contains entries for all
314   // symbols referenced in global parts of secondary GOTs. Although the sum
315   // of local and normal global entries of the primary got should be less
316   // than 64K, the size of the primary got (including relocation-only entries
317   // can be greater than 64K, because parts of the primary got that overflow
318   // the 64K limit are used only by the dynamic linker at dynamic link-time
319   // and not by 16-bit gp-relative addressing at run-time.
320   //
321   // For complete multi-GOT description see the following link
322   // https://dmz-portal.mips.com/wiki/MIPS_Multi_GOT
323 
324   // Number of "Header" entries.
325   static const unsigned headerEntriesNum = 2;
326 
327   uint64_t size = 0;
328 
329   // Symbol and addend.
330   using GotEntry = std::pair<Symbol *, int64_t>;
331 
332   struct FileGot {
333     InputFile *file = nullptr;
334     size_t startIndex = 0;
335 
336     struct PageBlock {
337       size_t firstIndex;
338       size_t count;
339       PageBlock() : firstIndex(0), count(0) {}
340     };
341 
342     // Map output sections referenced by MIPS GOT relocations
343     // to the description (index/count) "page" entries allocated
344     // for this section.
345     llvm::SmallMapVector<const OutputSection *, PageBlock, 16> pagesMap;
346     // Maps from Symbol+Addend pair or just Symbol to the GOT entry index.
347     llvm::MapVector<GotEntry, size_t> local16;
348     llvm::MapVector<GotEntry, size_t> local32;
349     llvm::MapVector<Symbol *, size_t> global;
350     llvm::MapVector<Symbol *, size_t> relocs;
351     llvm::MapVector<Symbol *, size_t> tls;
352     // Set of symbols referenced by dynamic TLS relocations.
353     llvm::MapVector<Symbol *, size_t> dynTlsSymbols;
354 
355     // Total number of all entries.
356     size_t getEntriesNum() const;
357     // Number of "page" entries.
358     size_t getPageEntriesNum() const;
359     // Number of entries require 16-bit index to access.
360     size_t getIndexedEntriesNum() const;
361   };
362 
363   // Container of GOT created for each input file.
364   // After building a final series of GOTs this container
365   // holds primary and secondary GOT's.
366   std::vector<FileGot> gots;
367 
368   // Return (and create if necessary) `FileGot`.
369   FileGot &getGot(InputFile &f);
370 
371   // Try to merge two GOTs. In case of success the `Dst` contains
372   // result of merging and the function returns true. In case of
373   // overflow the `Dst` is unchanged and the function returns false.
374   bool tryMergeGots(FileGot & dst, FileGot & src, bool isPrimary);
375 };
376 
377 class GotPltSection final : public SyntheticSection {
378 public:
379   GotPltSection();
380   void addEntry(Symbol &sym);
381   size_t getSize() const override;
382   void writeTo(uint8_t *buf) override;
383   bool isNeeded() const override;
384 
385   // Flag to force GotPlt to be in output if we have relocations
386   // that relies on its address.
387   bool hasGotPltOffRel = false;
388 
389 private:
390   SmallVector<const Symbol *, 0> entries;
391 };
392 
393 // The IgotPltSection is a Got associated with the PltSection for GNU Ifunc
394 // Symbols that will be relocated by Target->IRelativeRel.
395 // On most Targets the IgotPltSection will immediately follow the GotPltSection
396 // on ARM the IgotPltSection will immediately follow the GotSection.
397 class IgotPltSection final : public SyntheticSection {
398 public:
399   IgotPltSection();
400   void addEntry(Symbol &sym);
401   size_t getSize() const override;
402   void writeTo(uint8_t *buf) override;
403   bool isNeeded() const override { return !entries.empty(); }
404 
405 private:
406   SmallVector<const Symbol *, 0> entries;
407 };
408 
409 class StringTableSection final : public SyntheticSection {
410 public:
411   StringTableSection(StringRef name, bool dynamic);
412   unsigned addString(StringRef s, bool hashIt = true);
413   void writeTo(uint8_t *buf) override;
414   size_t getSize() const override { return size; }
415   bool isDynamic() const { return dynamic; }
416 
417 private:
418   const bool dynamic;
419 
420   uint64_t size = 0;
421 
422   llvm::DenseMap<llvm::CachedHashStringRef, unsigned> stringMap;
423   SmallVector<StringRef, 0> strings;
424 };
425 
426 class DynamicReloc {
427 public:
428   enum Kind {
429     /// The resulting dynamic relocation does not reference a symbol (#sym must
430     /// be nullptr) and uses #addend as the result of computeAddend().
431     AddendOnly,
432     /// The resulting dynamic relocation will not reference a symbol: #sym is
433     /// only used to compute the addend with InputSection::getRelocTargetVA().
434     /// Useful for various relative and TLS relocations (e.g. R_X86_64_TPOFF64).
435     AddendOnlyWithTargetVA,
436     /// The resulting dynamic relocation references symbol #sym from the dynamic
437     /// symbol table and uses #addend as the value of computeAddend().
438     AgainstSymbol,
439     /// The resulting dynamic relocation references symbol #sym from the dynamic
440     /// symbol table and uses InputSection::getRelocTargetVA() + #addend for the
441     /// final addend. It can be used for relocations that write the symbol VA as
442     // the addend (e.g. R_MIPS_TLS_TPREL64) but still reference the symbol.
443     AgainstSymbolWithTargetVA,
444     /// This is used by the MIPS multi-GOT implementation. It relocates
445     /// addresses of 64kb pages that lie inside the output section.
446     MipsMultiGotPage,
447   };
448   /// This constructor records a relocation against a symbol.
449   DynamicReloc(RelType type, const InputSectionBase *inputSec,
450                uint64_t offsetInSec, Kind kind, Symbol &sym, int64_t addend,
451                RelExpr expr)
452       : sym(&sym), inputSec(inputSec), offsetInSec(offsetInSec), type(type),
453         addend(addend), kind(kind), expr(expr) {}
454   /// This constructor records a relative relocation with no symbol.
455   DynamicReloc(RelType type, const InputSectionBase *inputSec,
456                uint64_t offsetInSec, int64_t addend = 0)
457       : sym(nullptr), inputSec(inputSec), offsetInSec(offsetInSec), type(type),
458         addend(addend), kind(AddendOnly), expr(R_ADDEND) {}
459   /// This constructor records dynamic relocation settings used by the MIPS
460   /// multi-GOT implementation.
461   DynamicReloc(RelType type, const InputSectionBase *inputSec,
462                uint64_t offsetInSec, const OutputSection *outputSec,
463                int64_t addend)
464       : sym(nullptr), outputSec(outputSec), inputSec(inputSec),
465         offsetInSec(offsetInSec), type(type), addend(addend),
466         kind(MipsMultiGotPage), expr(R_ADDEND) {}
467 
468   uint64_t getOffset() const;
469   uint32_t getSymIndex(SymbolTableBaseSection *symTab) const;
470   bool needsDynSymIndex() const {
471     return kind == AgainstSymbol || kind == AgainstSymbolWithTargetVA;
472   }
473 
474   /// Computes the addend of the dynamic relocation. Note that this is not the
475   /// same as the #addend member variable as it may also include the symbol
476   /// address/the address of the corresponding GOT entry/etc.
477   int64_t computeAddend() const;
478 
479   void computeRaw(SymbolTableBaseSection *symtab);
480 
481   Symbol *sym;
482   const OutputSection *outputSec = nullptr;
483   const InputSectionBase *inputSec;
484   uint64_t offsetInSec;
485   uint64_t r_offset;
486   RelType type;
487   uint32_t r_sym;
488   // Initially input addend, then the output addend after
489   // RelocationSection<ELFT>::writeTo.
490   int64_t addend;
491 
492 private:
493   Kind kind;
494   // The kind of expression used to calculate the added (required e.g. for
495   // relative GOT relocations).
496   RelExpr expr;
497 };
498 
499 template <class ELFT> class DynamicSection final : public SyntheticSection {
500   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
501 
502 public:
503   DynamicSection();
504   void finalizeContents() override;
505   void writeTo(uint8_t *buf) override;
506   size_t getSize() const override { return size; }
507 
508 private:
509   std::vector<std::pair<int32_t, uint64_t>> computeContents();
510   uint64_t size = 0;
511 };
512 
513 class RelocationBaseSection : public SyntheticSection {
514 public:
515   RelocationBaseSection(StringRef name, uint32_t type, int32_t dynamicTag,
516                         int32_t sizeDynamicTag, bool combreloc);
517   /// Add a dynamic relocation without writing an addend to the output section.
518   /// This overload can be used if the addends are written directly instead of
519   /// using relocations on the input section (e.g. MipsGotSection::writeTo()).
520   void addReloc(const DynamicReloc &reloc) { relocs.push_back(reloc); }
521   /// Add a dynamic relocation against \p sym with an optional addend.
522   void addSymbolReloc(RelType dynType, InputSectionBase &isec,
523                       uint64_t offsetInSec, Symbol &sym, int64_t addend = 0,
524                       llvm::Optional<RelType> addendRelType = llvm::None);
525   /// Add a relative dynamic relocation that uses the target address of \p sym
526   /// (i.e. InputSection::getRelocTargetVA()) + \p addend as the addend.
527   void addRelativeReloc(RelType dynType, InputSectionBase &isec,
528                         uint64_t offsetInSec, Symbol &sym, int64_t addend,
529                         RelType addendRelType, RelExpr expr);
530   /// Add a dynamic relocation using the target address of \p sym as the addend
531   /// if \p sym is non-preemptible. Otherwise add a relocation against \p sym.
532   void addAddendOnlyRelocIfNonPreemptible(RelType dynType,
533                                           InputSectionBase &isec,
534                                           uint64_t offsetInSec, Symbol &sym,
535                                           RelType addendRelType);
536   void addReloc(DynamicReloc::Kind kind, RelType dynType,
537                 InputSectionBase &inputSec, uint64_t offsetInSec, Symbol &sym,
538                 int64_t addend, RelExpr expr, RelType addendRelType);
539   bool isNeeded() const override { return !relocs.empty(); }
540   size_t getSize() const override { return relocs.size() * this->entsize; }
541   size_t getRelativeRelocCount() const { return numRelativeRelocs; }
542   void partitionRels();
543   void finalizeContents() override;
544   static bool classof(const SectionBase *d) {
545     return SyntheticSection::classof(d) &&
546            (d->type == llvm::ELF::SHT_RELA || d->type == llvm::ELF::SHT_REL ||
547             d->type == llvm::ELF::SHT_RELR);
548   }
549   int32_t dynamicTag, sizeDynamicTag;
550   SmallVector<DynamicReloc, 0> relocs;
551 
552 protected:
553   void computeRels();
554   size_t numRelativeRelocs = 0; // used by -z combreloc
555   bool combreloc;
556 };
557 
558 template <class ELFT>
559 class RelocationSection final : public RelocationBaseSection {
560   using Elf_Rel = typename ELFT::Rel;
561   using Elf_Rela = typename ELFT::Rela;
562 
563 public:
564   RelocationSection(StringRef name, bool combreloc);
565   void writeTo(uint8_t *buf) override;
566 };
567 
568 template <class ELFT>
569 class AndroidPackedRelocationSection final : public RelocationBaseSection {
570   using Elf_Rel = typename ELFT::Rel;
571   using Elf_Rela = typename ELFT::Rela;
572 
573 public:
574   AndroidPackedRelocationSection(StringRef name);
575 
576   bool updateAllocSize() override;
577   size_t getSize() const override { return relocData.size(); }
578   void writeTo(uint8_t *buf) override {
579     memcpy(buf, relocData.data(), relocData.size());
580   }
581 
582 private:
583   SmallVector<char, 0> relocData;
584 };
585 
586 struct RelativeReloc {
587   uint64_t getOffset() const { return inputSec->getVA(offsetInSec); }
588 
589   const InputSectionBase *inputSec;
590   uint64_t offsetInSec;
591 };
592 
593 class RelrBaseSection : public SyntheticSection {
594 public:
595   RelrBaseSection();
596   bool isNeeded() const override { return !relocs.empty(); }
597   SmallVector<RelativeReloc, 0> relocs;
598 };
599 
600 // RelrSection is used to encode offsets for relative relocations.
601 // Proposal for adding SHT_RELR sections to generic-abi is here:
602 //   https://groups.google.com/forum/#!topic/generic-abi/bX460iggiKg
603 // For more details, see the comment in RelrSection::updateAllocSize().
604 template <class ELFT> class RelrSection final : public RelrBaseSection {
605   using Elf_Relr = typename ELFT::Relr;
606 
607 public:
608   RelrSection();
609 
610   bool updateAllocSize() override;
611   size_t getSize() const override { return relrRelocs.size() * this->entsize; }
612   void writeTo(uint8_t *buf) override {
613     memcpy(buf, relrRelocs.data(), getSize());
614   }
615 
616 private:
617   SmallVector<Elf_Relr, 0> relrRelocs;
618 };
619 
620 struct SymbolTableEntry {
621   Symbol *sym;
622   size_t strTabOffset;
623 };
624 
625 class SymbolTableBaseSection : public SyntheticSection {
626 public:
627   SymbolTableBaseSection(StringTableSection &strTabSec);
628   void finalizeContents() override;
629   size_t getSize() const override { return getNumSymbols() * entsize; }
630   void addSymbol(Symbol *sym);
631   unsigned getNumSymbols() const { return symbols.size() + 1; }
632   size_t getSymbolIndex(Symbol *sym);
633   ArrayRef<SymbolTableEntry> getSymbols() const { return symbols; }
634 
635 protected:
636   void sortSymTabSymbols();
637 
638   // A vector of symbols and their string table offsets.
639   SmallVector<SymbolTableEntry, 0> symbols;
640 
641   StringTableSection &strTabSec;
642 
643   llvm::once_flag onceFlag;
644   llvm::DenseMap<Symbol *, size_t> symbolIndexMap;
645   llvm::DenseMap<OutputSection *, size_t> sectionIndexMap;
646 };
647 
648 template <class ELFT>
649 class SymbolTableSection final : public SymbolTableBaseSection {
650   using Elf_Sym = typename ELFT::Sym;
651 
652 public:
653   SymbolTableSection(StringTableSection &strTabSec);
654   void writeTo(uint8_t *buf) override;
655 };
656 
657 class SymtabShndxSection final : public SyntheticSection {
658 public:
659   SymtabShndxSection();
660 
661   void writeTo(uint8_t *buf) override;
662   size_t getSize() const override;
663   bool isNeeded() const override;
664   void finalizeContents() override;
665 };
666 
667 // Outputs GNU Hash section. For detailed explanation see:
668 // https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections
669 class GnuHashTableSection final : public SyntheticSection {
670 public:
671   GnuHashTableSection();
672   void finalizeContents() override;
673   void writeTo(uint8_t *buf) override;
674   size_t getSize() const override { return size; }
675 
676   // Adds symbols to the hash table.
677   // Sorts the input to satisfy GNU hash section requirements.
678   void addSymbols(llvm::SmallVectorImpl<SymbolTableEntry> &symbols);
679 
680 private:
681   // See the comment in writeBloomFilter.
682   enum { Shift2 = 26 };
683 
684   struct Entry {
685     Symbol *sym;
686     size_t strTabOffset;
687     uint32_t hash;
688     uint32_t bucketIdx;
689   };
690 
691   SmallVector<Entry, 0> symbols;
692   size_t maskWords;
693   size_t nBuckets = 0;
694   size_t size = 0;
695 };
696 
697 class HashTableSection final : public SyntheticSection {
698 public:
699   HashTableSection();
700   void finalizeContents() override;
701   void writeTo(uint8_t *buf) override;
702   size_t getSize() const override { return size; }
703 
704 private:
705   size_t size = 0;
706 };
707 
708 // Used for PLT entries. It usually has a PLT header for lazy binding. Each PLT
709 // entry is associated with a JUMP_SLOT relocation, which may be resolved lazily
710 // at runtime.
711 //
712 // On PowerPC, this section contains lazy symbol resolvers. A branch instruction
713 // jumps to a PLT call stub, which will then jump to the target (BIND_NOW) or a
714 // lazy symbol resolver.
715 //
716 // On x86 when IBT is enabled, this section (.plt.sec) contains PLT call stubs.
717 // A call instruction jumps to a .plt.sec entry, which will then jump to the
718 // target (BIND_NOW) or a .plt entry.
719 class PltSection : public SyntheticSection {
720 public:
721   PltSection();
722   void writeTo(uint8_t *buf) override;
723   size_t getSize() const override;
724   bool isNeeded() const override;
725   void addSymbols();
726   void addEntry(Symbol &sym);
727   size_t getNumEntries() const { return entries.size(); }
728 
729   size_t headerSize;
730 
731   SmallVector<const Symbol *, 0> entries;
732 };
733 
734 // Used for non-preemptible ifuncs. It does not have a header. Each entry is
735 // associated with an IRELATIVE relocation, which will be resolved eagerly at
736 // runtime. PltSection can only contain entries associated with JUMP_SLOT
737 // relocations, so IPLT entries are in a separate section.
738 class IpltSection final : public SyntheticSection {
739   SmallVector<const Symbol *, 0> entries;
740 
741 public:
742   IpltSection();
743   void writeTo(uint8_t *buf) override;
744   size_t getSize() const override;
745   bool isNeeded() const override { return !entries.empty(); }
746   void addSymbols();
747   void addEntry(Symbol &sym);
748 };
749 
750 class PPC32GlinkSection : public PltSection {
751 public:
752   PPC32GlinkSection();
753   void writeTo(uint8_t *buf) override;
754   size_t getSize() const override;
755 
756   SmallVector<const Symbol *, 0> canonical_plts;
757   static constexpr size_t footerSize = 64;
758 };
759 
760 // This is x86-only.
761 class IBTPltSection : public SyntheticSection {
762 public:
763   IBTPltSection();
764   void writeTo(uint8_t *Buf) override;
765   bool isNeeded() const override;
766   size_t getSize() const override;
767 };
768 
769 class GdbIndexSection final : public SyntheticSection {
770 public:
771   struct AddressEntry {
772     InputSection *section;
773     uint64_t lowAddress;
774     uint64_t highAddress;
775     uint32_t cuIndex;
776   };
777 
778   struct CuEntry {
779     uint64_t cuOffset;
780     uint64_t cuLength;
781   };
782 
783   struct NameAttrEntry {
784     llvm::CachedHashStringRef name;
785     uint32_t cuIndexAndAttrs;
786   };
787 
788   struct GdbChunk {
789     InputSection *sec;
790     SmallVector<AddressEntry, 0> addressAreas;
791     SmallVector<CuEntry, 0> compilationUnits;
792   };
793 
794   struct GdbSymbol {
795     llvm::CachedHashStringRef name;
796     SmallVector<uint32_t, 0> cuVector;
797     uint32_t nameOff;
798     uint32_t cuVectorOff;
799   };
800 
801   GdbIndexSection();
802   template <typename ELFT> static GdbIndexSection *create();
803   void writeTo(uint8_t *buf) override;
804   size_t getSize() const override { return size; }
805   bool isNeeded() const override;
806 
807 private:
808   struct GdbIndexHeader {
809     llvm::support::ulittle32_t version;
810     llvm::support::ulittle32_t cuListOff;
811     llvm::support::ulittle32_t cuTypesOff;
812     llvm::support::ulittle32_t addressAreaOff;
813     llvm::support::ulittle32_t symtabOff;
814     llvm::support::ulittle32_t constantPoolOff;
815   };
816 
817   void initOutputSize();
818   size_t computeSymtabSize() const;
819 
820   // Each chunk contains information gathered from debug sections of a
821   // single object file.
822   SmallVector<GdbChunk, 0> chunks;
823 
824   // A symbol table for this .gdb_index section.
825   SmallVector<GdbSymbol, 0> symbols;
826 
827   size_t size;
828 };
829 
830 // --eh-frame-hdr option tells linker to construct a header for all the
831 // .eh_frame sections. This header is placed to a section named .eh_frame_hdr
832 // and also to a PT_GNU_EH_FRAME segment.
833 // At runtime the unwinder then can find all the PT_GNU_EH_FRAME segments by
834 // calling dl_iterate_phdr.
835 // This section contains a lookup table for quick binary search of FDEs.
836 // Detailed info about internals can be found in Ian Lance Taylor's blog:
837 // http://www.airs.com/blog/archives/460 (".eh_frame")
838 // http://www.airs.com/blog/archives/462 (".eh_frame_hdr")
839 class EhFrameHeader final : public SyntheticSection {
840 public:
841   EhFrameHeader();
842   void write();
843   void writeTo(uint8_t *buf) override;
844   size_t getSize() const override;
845   bool isNeeded() const override;
846 };
847 
848 // For more information about .gnu.version and .gnu.version_r see:
849 // https://www.akkadia.org/drepper/symbol-versioning
850 
851 // The .gnu.version_d section which has a section type of SHT_GNU_verdef shall
852 // contain symbol version definitions. The number of entries in this section
853 // shall be contained in the DT_VERDEFNUM entry of the .dynamic section.
854 // The section shall contain an array of Elf_Verdef structures, optionally
855 // followed by an array of Elf_Verdaux structures.
856 class VersionDefinitionSection final : public SyntheticSection {
857 public:
858   VersionDefinitionSection();
859   void finalizeContents() override;
860   size_t getSize() const override;
861   void writeTo(uint8_t *buf) override;
862 
863 private:
864   enum { EntrySize = 28 };
865   void writeOne(uint8_t *buf, uint32_t index, StringRef name, size_t nameOff);
866   StringRef getFileDefName();
867 
868   unsigned fileDefNameOff;
869   SmallVector<unsigned, 0> verDefNameOffs;
870 };
871 
872 // The .gnu.version section specifies the required version of each symbol in the
873 // dynamic symbol table. It contains one Elf_Versym for each dynamic symbol
874 // table entry. An Elf_Versym is just a 16-bit integer that refers to a version
875 // identifier defined in the either .gnu.version_r or .gnu.version_d section.
876 // The values 0 and 1 are reserved. All other values are used for versions in
877 // the own object or in any of the dependencies.
878 class VersionTableSection final : public SyntheticSection {
879 public:
880   VersionTableSection();
881   void finalizeContents() override;
882   size_t getSize() const override;
883   void writeTo(uint8_t *buf) override;
884   bool isNeeded() const override;
885 };
886 
887 // The .gnu.version_r section defines the version identifiers used by
888 // .gnu.version. It contains a linked list of Elf_Verneed data structures. Each
889 // Elf_Verneed specifies the version requirements for a single DSO, and contains
890 // a reference to a linked list of Elf_Vernaux data structures which define the
891 // mapping from version identifiers to version names.
892 template <class ELFT>
893 class VersionNeedSection final : public SyntheticSection {
894   using Elf_Verneed = typename ELFT::Verneed;
895   using Elf_Vernaux = typename ELFT::Vernaux;
896 
897   struct Vernaux {
898     uint64_t hash;
899     uint32_t verneedIndex;
900     uint64_t nameStrTab;
901   };
902 
903   struct Verneed {
904     uint64_t nameStrTab;
905     std::vector<Vernaux> vernauxs;
906   };
907 
908   SmallVector<Verneed, 0> verneeds;
909 
910 public:
911   VersionNeedSection();
912   void finalizeContents() override;
913   void writeTo(uint8_t *buf) override;
914   size_t getSize() const override;
915   bool isNeeded() const override;
916 };
917 
918 // MergeSyntheticSection is a class that allows us to put mergeable sections
919 // with different attributes in a single output sections. To do that
920 // we put them into MergeSyntheticSection synthetic input sections which are
921 // attached to regular output sections.
922 class MergeSyntheticSection : public SyntheticSection {
923 public:
924   void addSection(MergeInputSection *ms);
925   SmallVector<MergeInputSection *, 0> sections;
926 
927 protected:
928   MergeSyntheticSection(StringRef name, uint32_t type, uint64_t flags,
929                         uint32_t alignment)
930       : SyntheticSection(flags, type, alignment, name) {}
931 };
932 
933 class MergeTailSection final : public MergeSyntheticSection {
934 public:
935   MergeTailSection(StringRef name, uint32_t type, uint64_t flags,
936                    uint32_t alignment);
937 
938   size_t getSize() const override;
939   void writeTo(uint8_t *buf) override;
940   void finalizeContents() override;
941 
942 private:
943   llvm::StringTableBuilder builder;
944 };
945 
946 class MergeNoTailSection final : public MergeSyntheticSection {
947 public:
948   MergeNoTailSection(StringRef name, uint32_t type, uint64_t flags,
949                      uint32_t alignment)
950       : MergeSyntheticSection(name, type, flags, alignment) {}
951 
952   size_t getSize() const override { return size; }
953   void writeTo(uint8_t *buf) override;
954   void finalizeContents() override;
955 
956 private:
957   // We use the most significant bits of a hash as a shard ID.
958   // The reason why we don't want to use the least significant bits is
959   // because DenseMap also uses lower bits to determine a bucket ID.
960   // If we use lower bits, it significantly increases the probability of
961   // hash collisons.
962   size_t getShardId(uint32_t hash) {
963     assert((hash >> 31) == 0);
964     return hash >> (31 - llvm::countTrailingZeros(numShards));
965   }
966 
967   // Section size
968   size_t size;
969 
970   // String table contents
971   constexpr static size_t numShards = 32;
972   SmallVector<llvm::StringTableBuilder, 0> shards;
973   size_t shardOffsets[numShards];
974 };
975 
976 // .MIPS.abiflags section.
977 template <class ELFT>
978 class MipsAbiFlagsSection final : public SyntheticSection {
979   using Elf_Mips_ABIFlags = llvm::object::Elf_Mips_ABIFlags<ELFT>;
980 
981 public:
982   static std::unique_ptr<MipsAbiFlagsSection> create();
983 
984   MipsAbiFlagsSection(Elf_Mips_ABIFlags flags);
985   size_t getSize() const override { return sizeof(Elf_Mips_ABIFlags); }
986   void writeTo(uint8_t *buf) override;
987 
988 private:
989   Elf_Mips_ABIFlags flags;
990 };
991 
992 // .MIPS.options section.
993 template <class ELFT> class MipsOptionsSection final : public SyntheticSection {
994   using Elf_Mips_Options = llvm::object::Elf_Mips_Options<ELFT>;
995   using Elf_Mips_RegInfo = llvm::object::Elf_Mips_RegInfo<ELFT>;
996 
997 public:
998   static std::unique_ptr<MipsOptionsSection<ELFT>> create();
999 
1000   MipsOptionsSection(Elf_Mips_RegInfo reginfo);
1001   void writeTo(uint8_t *buf) override;
1002 
1003   size_t getSize() const override {
1004     return sizeof(Elf_Mips_Options) + sizeof(Elf_Mips_RegInfo);
1005   }
1006 
1007 private:
1008   Elf_Mips_RegInfo reginfo;
1009 };
1010 
1011 // MIPS .reginfo section.
1012 template <class ELFT> class MipsReginfoSection final : public SyntheticSection {
1013   using Elf_Mips_RegInfo = llvm::object::Elf_Mips_RegInfo<ELFT>;
1014 
1015 public:
1016   static std::unique_ptr<MipsReginfoSection> create();
1017 
1018   MipsReginfoSection(Elf_Mips_RegInfo reginfo);
1019   size_t getSize() const override { return sizeof(Elf_Mips_RegInfo); }
1020   void writeTo(uint8_t *buf) override;
1021 
1022 private:
1023   Elf_Mips_RegInfo reginfo;
1024 };
1025 
1026 // This is a MIPS specific section to hold a space within the data segment
1027 // of executable file which is pointed to by the DT_MIPS_RLD_MAP entry.
1028 // See "Dynamic section" in Chapter 5 in the following document:
1029 // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
1030 class MipsRldMapSection : public SyntheticSection {
1031 public:
1032   MipsRldMapSection();
1033   size_t getSize() const override { return config->wordsize; }
1034   void writeTo(uint8_t *buf) override {}
1035 };
1036 
1037 // Representation of the combined .ARM.Exidx input sections. We process these
1038 // as a SyntheticSection like .eh_frame as we need to merge duplicate entries
1039 // and add terminating sentinel entries.
1040 //
1041 // The .ARM.exidx input sections after SHF_LINK_ORDER processing is done form
1042 // a table that the unwinder can derive (Addresses are encoded as offsets from
1043 // table):
1044 // | Address of function | Unwind instructions for function |
1045 // where the unwind instructions are either a small number of unwind or the
1046 // special EXIDX_CANTUNWIND entry representing no unwinding information.
1047 // When an exception is thrown from an address A, the unwinder searches the
1048 // table for the closest table entry with Address of function <= A. This means
1049 // that for two consecutive table entries:
1050 // | A1 | U1 |
1051 // | A2 | U2 |
1052 // The range of addresses described by U1 is [A1, A2)
1053 //
1054 // There are two cases where we need a linker generated table entry to fixup
1055 // the address ranges in the table
1056 // Case 1:
1057 // - A sentinel entry added with an address higher than all
1058 // executable sections. This was needed to work around libunwind bug pr31091.
1059 // - After address assignment we need to find the highest addressed executable
1060 // section and use the limit of that section so that the unwinder never
1061 // matches it.
1062 // Case 2:
1063 // - InputSections without a .ARM.exidx section (usually from Assembly)
1064 // need a table entry so that they terminate the range of the previously
1065 // function. This is pr40277.
1066 //
1067 // Instead of storing pointers to the .ARM.exidx InputSections from
1068 // InputObjects, we store pointers to the executable sections that need
1069 // .ARM.exidx sections. We can then use the dependentSections of these to
1070 // either find the .ARM.exidx section or know that we need to generate one.
1071 class ARMExidxSyntheticSection : public SyntheticSection {
1072 public:
1073   ARMExidxSyntheticSection();
1074 
1075   // Add an input section to the ARMExidxSyntheticSection. Returns whether the
1076   // section needs to be removed from the main input section list.
1077   bool addSection(InputSection *isec);
1078 
1079   size_t getSize() const override { return size; }
1080   void writeTo(uint8_t *buf) override;
1081   bool isNeeded() const override;
1082   // Sort and remove duplicate entries.
1083   void finalizeContents() override;
1084   InputSection *getLinkOrderDep() const;
1085 
1086   static bool classof(const SectionBase *d);
1087 
1088   // Links to the ARMExidxSections so we can transfer the relocations once the
1089   // layout is known.
1090   SmallVector<InputSection *, 0> exidxSections;
1091 
1092 private:
1093   size_t size = 0;
1094 
1095   // Instead of storing pointers to the .ARM.exidx InputSections from
1096   // InputObjects, we store pointers to the executable sections that need
1097   // .ARM.exidx sections. We can then use the dependentSections of these to
1098   // either find the .ARM.exidx section or know that we need to generate one.
1099   SmallVector<InputSection *, 0> executableSections;
1100 
1101   // The executable InputSection with the highest address to use for the
1102   // sentinel. We store separately from ExecutableSections as merging of
1103   // duplicate entries may mean this InputSection is removed from
1104   // ExecutableSections.
1105   InputSection *sentinel = nullptr;
1106 };
1107 
1108 // A container for one or more linker generated thunks. Instances of these
1109 // thunks including ARM interworking and Mips LA25 PI to non-PI thunks.
1110 class ThunkSection : public SyntheticSection {
1111 public:
1112   // ThunkSection in OS, with desired outSecOff of Off
1113   ThunkSection(OutputSection *os, uint64_t off);
1114 
1115   // Add a newly created Thunk to this container:
1116   // Thunk is given offset from start of this InputSection
1117   // Thunk defines a symbol in this InputSection that can be used as target
1118   // of a relocation
1119   void addThunk(Thunk *t);
1120   size_t getSize() const override;
1121   void writeTo(uint8_t *buf) override;
1122   InputSection *getTargetInputSection() const;
1123   bool assignOffsets();
1124 
1125   // When true, round up reported size of section to 4 KiB. See comment
1126   // in addThunkSection() for more details.
1127   bool roundUpSizeForErrata = false;
1128 
1129 private:
1130   SmallVector<Thunk *, 0> thunks;
1131   size_t size = 0;
1132 };
1133 
1134 // Used to compute outSecOff of .got2 in each object file. This is needed to
1135 // synthesize PLT entries for PPC32 Secure PLT ABI.
1136 class PPC32Got2Section final : public SyntheticSection {
1137 public:
1138   PPC32Got2Section();
1139   size_t getSize() const override { return 0; }
1140   bool isNeeded() const override;
1141   void finalizeContents() override;
1142   void writeTo(uint8_t *buf) override {}
1143 };
1144 
1145 // This section is used to store the addresses of functions that are called
1146 // in range-extending thunks on PowerPC64. When producing position dependent
1147 // code the addresses are link-time constants and the table is written out to
1148 // the binary. When producing position-dependent code the table is allocated and
1149 // filled in by the dynamic linker.
1150 class PPC64LongBranchTargetSection final : public SyntheticSection {
1151 public:
1152   PPC64LongBranchTargetSection();
1153   uint64_t getEntryVA(const Symbol *sym, int64_t addend);
1154   llvm::Optional<uint32_t> addEntry(const Symbol *sym, int64_t addend);
1155   size_t getSize() const override;
1156   void writeTo(uint8_t *buf) override;
1157   bool isNeeded() const override;
1158   void finalizeContents() override { finalized = true; }
1159 
1160 private:
1161   SmallVector<std::pair<const Symbol *, int64_t>, 0> entries;
1162   llvm::DenseMap<std::pair<const Symbol *, int64_t>, uint32_t> entry_index;
1163   bool finalized = false;
1164 };
1165 
1166 template <typename ELFT>
1167 class PartitionElfHeaderSection : public SyntheticSection {
1168 public:
1169   PartitionElfHeaderSection();
1170   size_t getSize() const override;
1171   void writeTo(uint8_t *buf) override;
1172 };
1173 
1174 template <typename ELFT>
1175 class PartitionProgramHeadersSection : public SyntheticSection {
1176 public:
1177   PartitionProgramHeadersSection();
1178   size_t getSize() const override;
1179   void writeTo(uint8_t *buf) override;
1180 };
1181 
1182 class PartitionIndexSection : public SyntheticSection {
1183 public:
1184   PartitionIndexSection();
1185   size_t getSize() const override;
1186   void finalizeContents() override;
1187   void writeTo(uint8_t *buf) override;
1188 };
1189 
1190 InputSection *createInterpSection();
1191 MergeInputSection *createCommentSection();
1192 template <class ELFT> void splitSections();
1193 
1194 template <typename ELFT> void writeEhdr(uint8_t *buf, Partition &part);
1195 template <typename ELFT> void writePhdrs(uint8_t *buf, Partition &part);
1196 
1197 Defined *addSyntheticLocal(StringRef name, uint8_t type, uint64_t value,
1198                            uint64_t size, InputSectionBase &section);
1199 
1200 void addVerneed(Symbol *ss);
1201 
1202 // Linker generated per-partition sections.
1203 struct Partition {
1204   StringRef name;
1205   uint64_t nameStrTab;
1206 
1207   std::unique_ptr<SyntheticSection> elfHeader;
1208   std::unique_ptr<SyntheticSection> programHeaders;
1209   SmallVector<PhdrEntry *, 0> phdrs;
1210 
1211   std::unique_ptr<ARMExidxSyntheticSection> armExidx;
1212   std::unique_ptr<BuildIdSection> buildId;
1213   std::unique_ptr<SyntheticSection> dynamic;
1214   std::unique_ptr<StringTableSection> dynStrTab;
1215   std::unique_ptr<SymbolTableBaseSection> dynSymTab;
1216   std::unique_ptr<EhFrameHeader> ehFrameHdr;
1217   std::unique_ptr<EhFrameSection> ehFrame;
1218   std::unique_ptr<GnuHashTableSection> gnuHashTab;
1219   std::unique_ptr<HashTableSection> hashTab;
1220   std::unique_ptr<RelocationBaseSection> relaDyn;
1221   std::unique_ptr<RelrBaseSection> relrDyn;
1222   std::unique_ptr<VersionDefinitionSection> verDef;
1223   std::unique_ptr<SyntheticSection> verNeed;
1224   std::unique_ptr<VersionTableSection> verSym;
1225 
1226   unsigned getNumber() const { return this - &partitions[0] + 1; }
1227 };
1228 
1229 extern Partition *mainPart;
1230 
1231 inline Partition &SectionBase::getPartition() const {
1232   assert(isLive());
1233   return partitions[partition - 1];
1234 }
1235 
1236 // Linker generated sections which can be used as inputs and are not specific to
1237 // a partition.
1238 struct InStruct {
1239   std::unique_ptr<InputSection> attributes;
1240   std::unique_ptr<BssSection> bss;
1241   std::unique_ptr<BssSection> bssRelRo;
1242   std::unique_ptr<GotSection> got;
1243   std::unique_ptr<GotPltSection> gotPlt;
1244   std::unique_ptr<IgotPltSection> igotPlt;
1245   std::unique_ptr<PPC64LongBranchTargetSection> ppc64LongBranchTarget;
1246   std::unique_ptr<SyntheticSection> mipsAbiFlags;
1247   std::unique_ptr<MipsGotSection> mipsGot;
1248   std::unique_ptr<SyntheticSection> mipsOptions;
1249   std::unique_ptr<SyntheticSection> mipsReginfo;
1250   std::unique_ptr<MipsRldMapSection> mipsRldMap;
1251   std::unique_ptr<SyntheticSection> partEnd;
1252   std::unique_ptr<SyntheticSection> partIndex;
1253   std::unique_ptr<PltSection> plt;
1254   std::unique_ptr<IpltSection> iplt;
1255   std::unique_ptr<PPC32Got2Section> ppc32Got2;
1256   std::unique_ptr<IBTPltSection> ibtPlt;
1257   std::unique_ptr<RelocationBaseSection> relaPlt;
1258   std::unique_ptr<RelocationBaseSection> relaIplt;
1259   std::unique_ptr<StringTableSection> shStrTab;
1260   std::unique_ptr<StringTableSection> strTab;
1261   std::unique_ptr<SymbolTableBaseSection> symTab;
1262   std::unique_ptr<SymtabShndxSection> symTabShndx;
1263 
1264   void reset();
1265 };
1266 
1267 extern InStruct in;
1268 
1269 } // namespace elf
1270 } // namespace lld
1271 
1272 #endif
1273