1 //===- SyntheticSection.h ---------------------------------------*- C++ -*-===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Synthetic sections represent chunks of linker-created data. If you
11 // need to create a chunk of data that to be included in some section
12 // in the result, you probably want to create that as a synthetic section.
14 // Synthetic sections are designed as input sections as opposed to
15 // output sections because we want to allow them to be manipulated
16 // using linker scripts just like other input sections from regular
19 //===----------------------------------------------------------------------===//
21 #ifndef LLD_ELF_SYNTHETIC_SECTION_H
22 #define LLD_ELF_SYNTHETIC_SECTION_H
26 #include "InputSection.h"
27 #include "llvm/ADT/MapVector.h"
28 #include "llvm/MC/StringTableBuilder.h"
35 class SyntheticSection : public InputSection {
37 SyntheticSection(uint64_t Flags, uint32_t Type, uint32_t Alignment,
39 : InputSection(nullptr, Flags, Type, Alignment, {}, Name,
40 InputSectionBase::Synthetic) {
44 virtual ~SyntheticSection() = default;
45 virtual void writeTo(uint8_t *Buf) = 0;
46 virtual size_t getSize() const = 0;
47 virtual void finalizeContents() {}
48 // If the section has the SHF_ALLOC flag and the size may be changed if
49 // thunks are added, update the section size.
50 virtual bool updateAllocSize() { return false; }
51 // If any additional finalization of contents are needed post thunk creation.
52 virtual void postThunkContents() {}
53 virtual bool empty() const { return false; }
54 uint64_t getVA() const;
56 static bool classof(const SectionBase *D) {
57 return D->kind() == InputSectionBase::Synthetic;
62 EhSectionPiece *Cie = nullptr;
63 std::vector<EhSectionPiece *> Fdes;
66 // Section for .eh_frame.
67 class EhFrameSection final : public SyntheticSection {
70 void writeTo(uint8_t *Buf) override;
71 void finalizeContents() override;
72 bool empty() const override { return Sections.empty(); }
73 size_t getSize() const override { return Size; }
75 template <class ELFT> void addSection(InputSectionBase *S);
77 std::vector<EhInputSection *> Sections;
85 std::vector<FdeData> getFdeData() const;
90 template <class ELFT, class RelTy>
91 void addSectionAux(EhInputSection *S, llvm::ArrayRef<RelTy> Rels);
93 template <class ELFT, class RelTy>
94 CieRecord *addCie(EhSectionPiece &Piece, ArrayRef<RelTy> Rels);
96 template <class ELFT, class RelTy>
97 bool isFdeLive(EhSectionPiece &Piece, ArrayRef<RelTy> Rels);
99 uint64_t getFdePc(uint8_t *Buf, size_t Off, uint8_t Enc) const;
101 std::vector<CieRecord *> CieRecords;
103 // CIE records are uniquified by their contents and personality functions.
104 llvm::DenseMap<std::pair<ArrayRef<uint8_t>, Symbol *>, CieRecord *> CieMap;
107 class GotSection : public SyntheticSection {
110 size_t getSize() const override { return Size; }
111 void finalizeContents() override;
112 bool empty() const override;
113 void writeTo(uint8_t *Buf) override;
115 void addEntry(Symbol &Sym);
116 bool addDynTlsEntry(Symbol &Sym);
118 uint64_t getGlobalDynAddr(const Symbol &B) const;
119 uint64_t getGlobalDynOffset(const Symbol &B) const;
121 uint64_t getTlsIndexVA() { return this->getVA() + TlsIndexOff; }
122 uint32_t getTlsIndexOff() const { return TlsIndexOff; }
124 // Flag to force GOT to be in output if we have relocations
125 // that relies on its address.
126 bool HasGotOffRel = false;
129 size_t NumEntries = 0;
130 uint32_t TlsIndexOff = -1;
134 // .note.gnu.build-id section.
135 class BuildIdSection : public SyntheticSection {
136 // First 16 bytes are a header.
137 static const unsigned HeaderSize = 16;
141 void writeTo(uint8_t *Buf) override;
142 size_t getSize() const override { return HeaderSize + HashSize; }
143 void writeBuildId(llvm::ArrayRef<uint8_t> Buf);
146 void computeHash(llvm::ArrayRef<uint8_t> Buf,
147 std::function<void(uint8_t *, ArrayRef<uint8_t>)> Hash);
153 // BssSection is used to reserve space for copy relocations and common symbols.
154 // We create three instances of this class for .bss, .bss.rel.ro and "COMMON",
155 // that are used for writable symbols, read-only symbols and common symbols,
157 class BssSection final : public SyntheticSection {
159 BssSection(StringRef Name, uint64_t Size, uint32_t Alignment);
160 void writeTo(uint8_t *) override {}
161 bool empty() const override { return getSize() == 0; }
162 size_t getSize() const override { return Size; }
164 static bool classof(const SectionBase *S) { return S->Bss; }
168 class MipsGotSection final : public SyntheticSection {
171 void writeTo(uint8_t *Buf) override;
172 size_t getSize() const override { return Size; }
173 bool updateAllocSize() override;
174 void finalizeContents() override;
175 bool empty() const override;
176 void addEntry(Symbol &Sym, int64_t Addend, RelExpr Expr);
177 bool addDynTlsEntry(Symbol &Sym);
179 uint64_t getPageEntryOffset(const Symbol &B, int64_t Addend) const;
180 uint64_t getSymEntryOffset(const Symbol &B, int64_t Addend) const;
181 uint64_t getGlobalDynOffset(const Symbol &B) const;
183 // Returns the symbol which corresponds to the first entry of the global part
184 // of GOT on MIPS platform. It is required to fill up MIPS-specific dynamic
186 // Returns nullptr if the global part is empty.
187 const Symbol *getFirstGlobalEntry() const;
189 // Returns the number of entries in the local part of GOT including
190 // the number of reserved entries.
191 unsigned getLocalEntriesNum() const;
193 // Returns offset of TLS part of the MIPS GOT table. This part goes
194 // after 'local' and 'global' entries.
195 uint64_t getTlsOffset() const;
197 uint32_t getTlsIndexOff() const { return TlsIndexOff; }
199 uint64_t getGp() const;
202 // MIPS GOT consists of three parts: local, global and tls. Each part
203 // contains different types of entries. Here is a layout of GOT:
204 // - Header entries |
205 // - Page entries | Local part
206 // - Local entries (16-bit access) |
207 // - Local entries (32-bit access) |
208 // - Normal global entries || Global part
209 // - Reloc-only global entries ||
210 // - TLS entries ||| TLS part
213 // Two entries hold predefined value 0x0 and 0x80000000.
215 // These entries created by R_MIPS_GOT_PAGE relocation and R_MIPS_GOT16
216 // relocation against local symbols. They are initialized by higher 16-bit
217 // of the corresponding symbol's value. So each 64kb of address space
218 // requires a single GOT entry.
219 // Local entries (16-bit access):
220 // These entries created by GOT relocations against global non-preemptible
221 // symbols so dynamic linker is not necessary to resolve the symbol's
222 // values. "16-bit access" means that corresponding relocations address
223 // GOT using 16-bit index. Each unique Symbol-Addend pair has its own
225 // Local entries (32-bit access):
226 // These entries are the same as above but created by relocations which
227 // address GOT using 32-bit index (R_MIPS_GOT_HI16/LO16 etc).
228 // Normal global entries:
229 // These entries created by GOT relocations against preemptible global
230 // symbols. They need to be initialized by dynamic linker and they ordered
231 // exactly as the corresponding entries in the dynamic symbols table.
232 // Reloc-only global entries:
233 // These entries created for symbols that are referenced by dynamic
234 // relocations R_MIPS_REL32. These entries are not accessed with gp-relative
235 // addressing, but MIPS ABI requires that these entries be present in GOT.
237 // Entries created by TLS relocations.
239 // Number of "Header" entries.
240 static const unsigned HeaderEntriesNum = 2;
241 // Number of allocated "Page" entries.
242 uint32_t PageEntriesNum = 0;
243 // Map output sections referenced by MIPS GOT relocations
244 // to the first index of "Page" entries allocated for this section.
245 llvm::SmallMapVector<const OutputSection *, size_t, 16> PageIndexMap;
247 typedef std::pair<const Symbol *, uint64_t> GotEntry;
248 typedef std::vector<GotEntry> GotEntries;
249 // Map from Symbol-Addend pair to the GOT index.
250 llvm::DenseMap<GotEntry, size_t> EntryIndexMap;
251 // Local entries (16-bit access).
252 GotEntries LocalEntries;
253 // Local entries (32-bit access).
254 GotEntries LocalEntries32;
256 // Normal and reloc-only global entries.
257 GotEntries GlobalEntries;
260 std::vector<const Symbol *> TlsEntries;
262 uint32_t TlsIndexOff = -1;
266 class GotPltSection final : public SyntheticSection {
269 void addEntry(Symbol &Sym);
270 size_t getSize() const override;
271 void writeTo(uint8_t *Buf) override;
272 bool empty() const override { return Entries.empty(); }
275 std::vector<const Symbol *> Entries;
278 // The IgotPltSection is a Got associated with the PltSection for GNU Ifunc
279 // Symbols that will be relocated by Target->IRelativeRel.
280 // On most Targets the IgotPltSection will immediately follow the GotPltSection
281 // on ARM the IgotPltSection will immediately follow the GotSection.
282 class IgotPltSection final : public SyntheticSection {
285 void addEntry(Symbol &Sym);
286 size_t getSize() const override;
287 void writeTo(uint8_t *Buf) override;
288 bool empty() const override { return Entries.empty(); }
291 std::vector<const Symbol *> Entries;
294 class StringTableSection final : public SyntheticSection {
296 StringTableSection(StringRef Name, bool Dynamic);
297 unsigned addString(StringRef S, bool HashIt = true);
298 void writeTo(uint8_t *Buf) override;
299 size_t getSize() const override { return Size; }
300 bool isDynamic() const { return Dynamic; }
307 llvm::DenseMap<StringRef, unsigned> StringMap;
308 std::vector<StringRef> Strings;
313 DynamicReloc(uint32_t Type, const InputSectionBase *InputSec,
314 uint64_t OffsetInSec, bool UseSymVA, Symbol *Sym, int64_t Addend)
315 : Type(Type), Sym(Sym), InputSec(InputSec), OffsetInSec(OffsetInSec),
316 UseSymVA(UseSymVA), Addend(Addend) {}
318 uint64_t getOffset() const;
319 int64_t getAddend() const;
320 uint32_t getSymIndex() const;
321 const InputSectionBase *getInputSec() const { return InputSec; }
327 const InputSectionBase *InputSec = nullptr;
328 uint64_t OffsetInSec;
333 template <class ELFT> class DynamicSection final : public SyntheticSection {
334 typedef typename ELFT::Dyn Elf_Dyn;
335 typedef typename ELFT::Rel Elf_Rel;
336 typedef typename ELFT::Rela Elf_Rela;
337 typedef typename ELFT::Shdr Elf_Shdr;
338 typedef typename ELFT::Sym Elf_Sym;
340 // finalizeContents() fills this vector with the section contents.
341 std::vector<std::pair<int32_t, std::function<uint64_t()>>> Entries;
345 void finalizeContents() override;
346 void writeTo(uint8_t *Buf) override;
347 size_t getSize() const override { return Size; }
350 void add(int32_t Tag, std::function<uint64_t()> Fn);
351 void addInt(int32_t Tag, uint64_t Val);
352 void addInSec(int32_t Tag, InputSection *Sec);
353 void addOutSec(int32_t Tag, OutputSection *Sec);
354 void addSize(int32_t Tag, OutputSection *Sec);
355 void addSym(int32_t Tag, Symbol *Sym);
360 class RelocationBaseSection : public SyntheticSection {
362 RelocationBaseSection(StringRef Name, uint32_t Type, int32_t DynamicTag,
363 int32_t SizeDynamicTag);
364 void addReloc(const DynamicReloc &Reloc);
365 bool empty() const override { return Relocs.empty(); }
366 size_t getSize() const override { return Relocs.size() * this->Entsize; }
367 size_t getRelativeRelocCount() const { return NumRelativeRelocs; }
368 void finalizeContents() override;
369 int32_t DynamicTag, SizeDynamicTag;
372 std::vector<DynamicReloc> Relocs;
373 size_t NumRelativeRelocs = 0;
376 template <class ELFT>
377 class RelocationSection final : public RelocationBaseSection {
378 typedef typename ELFT::Rel Elf_Rel;
379 typedef typename ELFT::Rela Elf_Rela;
382 RelocationSection(StringRef Name, bool Sort);
383 unsigned getRelocOffset();
384 void writeTo(uint8_t *Buf) override;
390 template <class ELFT>
391 class AndroidPackedRelocationSection final : public RelocationBaseSection {
392 typedef typename ELFT::Rel Elf_Rel;
393 typedef typename ELFT::Rela Elf_Rela;
396 AndroidPackedRelocationSection(StringRef Name);
398 bool updateAllocSize() override;
399 size_t getSize() const override { return RelocData.size(); }
400 void writeTo(uint8_t *Buf) override {
401 memcpy(Buf, RelocData.data(), RelocData.size());
405 SmallVector<char, 0> RelocData;
408 struct SymbolTableEntry {
413 class SymbolTableBaseSection : public SyntheticSection {
415 SymbolTableBaseSection(StringTableSection &StrTabSec);
416 void finalizeContents() override;
417 void postThunkContents() override;
418 size_t getSize() const override { return getNumSymbols() * Entsize; }
419 void addSymbol(Symbol *Sym);
420 unsigned getNumSymbols() const { return Symbols.size() + 1; }
421 size_t getSymbolIndex(Symbol *Sym);
422 ArrayRef<SymbolTableEntry> getSymbols() const { return Symbols; }
425 // A vector of symbols and their string table offsets.
426 std::vector<SymbolTableEntry> Symbols;
428 StringTableSection &StrTabSec;
430 llvm::once_flag OnceFlag;
431 llvm::DenseMap<Symbol *, size_t> SymbolIndexMap;
432 llvm::DenseMap<OutputSection *, size_t> SectionIndexMap;
435 template <class ELFT>
436 class SymbolTableSection final : public SymbolTableBaseSection {
437 typedef typename ELFT::Sym Elf_Sym;
440 SymbolTableSection(StringTableSection &StrTabSec);
441 void writeTo(uint8_t *Buf) override;
444 // Outputs GNU Hash section. For detailed explanation see:
445 // https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections
446 class GnuHashTableSection final : public SyntheticSection {
448 GnuHashTableSection();
449 void finalizeContents() override;
450 void writeTo(uint8_t *Buf) override;
451 size_t getSize() const override { return Size; }
453 // Adds symbols to the hash table.
454 // Sorts the input to satisfy GNU hash section requirements.
455 void addSymbols(std::vector<SymbolTableEntry> &Symbols);
458 size_t getShift2() const { return Config->Is64 ? 6 : 5; }
460 void writeBloomFilter(uint8_t *Buf);
461 void writeHashTable(uint8_t *Buf);
470 std::vector<Entry> Symbols;
476 class HashTableSection final : public SyntheticSection {
479 void finalizeContents() override;
480 void writeTo(uint8_t *Buf) override;
481 size_t getSize() const override { return Size; }
487 // The PltSection is used for both the Plt and Iplt. The former always has a
488 // header as its first entry that is used at run-time to resolve lazy binding.
489 // The latter is used for GNU Ifunc symbols, that will be subject to a
490 // Target->IRelativeRel.
491 class PltSection : public SyntheticSection {
493 PltSection(size_t HeaderSize);
494 void writeTo(uint8_t *Buf) override;
495 size_t getSize() const override;
496 bool empty() const override { return Entries.empty(); }
499 template <class ELFT> void addEntry(Symbol &Sym);
502 unsigned getPltRelocOff() const;
503 std::vector<std::pair<const Symbol *, unsigned>> Entries;
504 // Iplt always has HeaderSize of 0, the Plt HeaderSize is always non-zero
508 // GdbIndexChunk is created for each .debug_info section and contains
509 // information to create a part of .gdb_index for a given input section.
510 struct GdbIndexChunk {
511 struct AddressEntry {
512 InputSection *Section;
514 uint64_t HighAddress;
523 struct NameTypeEntry {
524 llvm::CachedHashStringRef Name;
528 InputSection *DebugInfoSec;
529 std::vector<AddressEntry> AddressAreas;
530 std::vector<CuEntry> CompilationUnits;
531 std::vector<NameTypeEntry> NamesAndTypes;
534 // The symbol type for the .gdb_index section.
538 size_t CuVectorIndex;
541 class GdbIndexSection final : public SyntheticSection {
543 GdbIndexSection(std::vector<GdbIndexChunk> &&Chunks);
544 void writeTo(uint8_t *Buf) override;
545 size_t getSize() const override;
546 bool empty() const override;
550 std::vector<std::vector<uint32_t>> createCuVectors();
551 std::vector<GdbSymbol *> createGdbSymtab();
553 // A symbol table for this .gdb_index section.
554 std::vector<GdbSymbol *> GdbSymtab;
556 // CU vector is a part of constant pool area of section.
557 std::vector<std::vector<uint32_t>> CuVectors;
559 // Symbol table contents.
560 llvm::DenseMap<llvm::CachedHashStringRef, GdbSymbol *> Symbols;
562 // Each chunk contains information gathered from a debug sections of single
563 // object and used to build different areas of gdb index.
564 std::vector<GdbIndexChunk> Chunks;
566 static constexpr uint32_t CuListOffset = 24;
567 uint32_t CuTypesOffset;
568 uint32_t SymtabOffset;
569 uint32_t ConstantPoolOffset;
570 uint32_t StringPoolOffset;
571 uint32_t StringPoolSize;
573 std::vector<size_t> CuVectorOffsets;
576 template <class ELFT> GdbIndexSection *createGdbIndex();
578 // --eh-frame-hdr option tells linker to construct a header for all the
579 // .eh_frame sections. This header is placed to a section named .eh_frame_hdr
580 // and also to a PT_GNU_EH_FRAME segment.
581 // At runtime the unwinder then can find all the PT_GNU_EH_FRAME segments by
582 // calling dl_iterate_phdr.
583 // This section contains a lookup table for quick binary search of FDEs.
584 // Detailed info about internals can be found in Ian Lance Taylor's blog:
585 // http://www.airs.com/blog/archives/460 (".eh_frame")
586 // http://www.airs.com/blog/archives/462 (".eh_frame_hdr")
587 class EhFrameHeader final : public SyntheticSection {
590 void writeTo(uint8_t *Buf) override;
591 size_t getSize() const override;
592 bool empty() const override;
595 // For more information about .gnu.version and .gnu.version_r see:
596 // https://www.akkadia.org/drepper/symbol-versioning
598 // The .gnu.version_d section which has a section type of SHT_GNU_verdef shall
599 // contain symbol version definitions. The number of entries in this section
600 // shall be contained in the DT_VERDEFNUM entry of the .dynamic section.
601 // The section shall contain an array of Elf_Verdef structures, optionally
602 // followed by an array of Elf_Verdaux structures.
603 template <class ELFT>
604 class VersionDefinitionSection final : public SyntheticSection {
605 typedef typename ELFT::Verdef Elf_Verdef;
606 typedef typename ELFT::Verdaux Elf_Verdaux;
609 VersionDefinitionSection();
610 void finalizeContents() override;
611 size_t getSize() const override;
612 void writeTo(uint8_t *Buf) override;
615 void writeOne(uint8_t *Buf, uint32_t Index, StringRef Name, size_t NameOff);
617 unsigned FileDefNameOff;
620 // The .gnu.version section specifies the required version of each symbol in the
621 // dynamic symbol table. It contains one Elf_Versym for each dynamic symbol
622 // table entry. An Elf_Versym is just a 16-bit integer that refers to a version
623 // identifier defined in the either .gnu.version_r or .gnu.version_d section.
624 // The values 0 and 1 are reserved. All other values are used for versions in
625 // the own object or in any of the dependencies.
626 template <class ELFT>
627 class VersionTableSection final : public SyntheticSection {
628 typedef typename ELFT::Versym Elf_Versym;
631 VersionTableSection();
632 void finalizeContents() override;
633 size_t getSize() const override;
634 void writeTo(uint8_t *Buf) override;
635 bool empty() const override;
638 // The .gnu.version_r section defines the version identifiers used by
639 // .gnu.version. It contains a linked list of Elf_Verneed data structures. Each
640 // Elf_Verneed specifies the version requirements for a single DSO, and contains
641 // a reference to a linked list of Elf_Vernaux data structures which define the
642 // mapping from version identifiers to version names.
643 template <class ELFT> class VersionNeedSection final : public SyntheticSection {
644 typedef typename ELFT::Verneed Elf_Verneed;
645 typedef typename ELFT::Vernaux Elf_Vernaux;
647 // A vector of shared files that need Elf_Verneed data structures and the
648 // string table offsets of their sonames.
649 std::vector<std::pair<SharedFile<ELFT> *, size_t>> Needed;
651 // The next available version identifier.
655 VersionNeedSection();
656 void addSymbol(SharedSymbol *SS);
657 void finalizeContents() override;
658 void writeTo(uint8_t *Buf) override;
659 size_t getSize() const override;
660 size_t getNeedNum() const { return Needed.size(); }
661 bool empty() const override;
664 // MergeSyntheticSection is a class that allows us to put mergeable sections
665 // with different attributes in a single output sections. To do that
666 // we put them into MergeSyntheticSection synthetic input sections which are
667 // attached to regular output sections.
668 class MergeSyntheticSection : public SyntheticSection {
670 void addSection(MergeInputSection *MS);
673 MergeSyntheticSection(StringRef Name, uint32_t Type, uint64_t Flags,
675 : SyntheticSection(Flags, Type, Alignment, Name) {}
677 std::vector<MergeInputSection *> Sections;
680 class MergeTailSection final : public MergeSyntheticSection {
682 MergeTailSection(StringRef Name, uint32_t Type, uint64_t Flags,
685 size_t getSize() const override;
686 void writeTo(uint8_t *Buf) override;
687 void finalizeContents() override;
690 llvm::StringTableBuilder Builder;
693 class MergeNoTailSection final : public MergeSyntheticSection {
695 MergeNoTailSection(StringRef Name, uint32_t Type, uint64_t Flags,
697 : MergeSyntheticSection(Name, Type, Flags, Alignment) {}
699 size_t getSize() const override { return Size; }
700 void writeTo(uint8_t *Buf) override;
701 void finalizeContents() override;
704 // We use the most significant bits of a hash as a shard ID.
705 // The reason why we don't want to use the least significant bits is
706 // because DenseMap also uses lower bits to determine a bucket ID.
707 // If we use lower bits, it significantly increases the probability of
709 size_t getShardId(uint32_t Hash) {
710 return Hash >> (32 - llvm::countTrailingZeros(NumShards));
716 // String table contents
717 constexpr static size_t NumShards = 32;
718 std::vector<llvm::StringTableBuilder> Shards;
719 size_t ShardOffsets[NumShards];
722 // .MIPS.abiflags section.
723 template <class ELFT>
724 class MipsAbiFlagsSection final : public SyntheticSection {
725 typedef llvm::object::Elf_Mips_ABIFlags<ELFT> Elf_Mips_ABIFlags;
728 static MipsAbiFlagsSection *create();
730 MipsAbiFlagsSection(Elf_Mips_ABIFlags Flags);
731 size_t getSize() const override { return sizeof(Elf_Mips_ABIFlags); }
732 void writeTo(uint8_t *Buf) override;
735 Elf_Mips_ABIFlags Flags;
738 // .MIPS.options section.
739 template <class ELFT> class MipsOptionsSection final : public SyntheticSection {
740 typedef llvm::object::Elf_Mips_Options<ELFT> Elf_Mips_Options;
741 typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
744 static MipsOptionsSection *create();
746 MipsOptionsSection(Elf_Mips_RegInfo Reginfo);
747 void writeTo(uint8_t *Buf) override;
749 size_t getSize() const override {
750 return sizeof(Elf_Mips_Options) + sizeof(Elf_Mips_RegInfo);
754 Elf_Mips_RegInfo Reginfo;
757 // MIPS .reginfo section.
758 template <class ELFT> class MipsReginfoSection final : public SyntheticSection {
759 typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
762 static MipsReginfoSection *create();
764 MipsReginfoSection(Elf_Mips_RegInfo Reginfo);
765 size_t getSize() const override { return sizeof(Elf_Mips_RegInfo); }
766 void writeTo(uint8_t *Buf) override;
769 Elf_Mips_RegInfo Reginfo;
772 // This is a MIPS specific section to hold a space within the data segment
773 // of executable file which is pointed to by the DT_MIPS_RLD_MAP entry.
774 // See "Dynamic section" in Chapter 5 in the following document:
775 // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
776 class MipsRldMapSection : public SyntheticSection {
779 size_t getSize() const override { return Config->Wordsize; }
780 void writeTo(uint8_t *Buf) override {}
783 class ARMExidxSentinelSection : public SyntheticSection {
785 ARMExidxSentinelSection();
786 size_t getSize() const override { return 8; }
787 void writeTo(uint8_t *Buf) override;
788 bool empty() const override;
790 InputSection *Highest = 0;
793 // A container for one or more linker generated thunks. Instances of these
794 // thunks including ARM interworking and Mips LA25 PI to non-PI thunks.
795 class ThunkSection : public SyntheticSection {
797 // ThunkSection in OS, with desired OutSecOff of Off
798 ThunkSection(OutputSection *OS, uint64_t Off);
800 // Add a newly created Thunk to this container:
801 // Thunk is given offset from start of this InputSection
802 // Thunk defines a symbol in this InputSection that can be used as target
804 void addThunk(Thunk *T);
805 size_t getSize() const override { return Size; }
806 void writeTo(uint8_t *Buf) override;
807 InputSection *getTargetInputSection() const;
810 std::vector<const Thunk *> Thunks;
814 InputSection *createInterpSection();
815 MergeInputSection *createCommentSection();
816 void decompressSections();
817 void mergeSections();
819 Symbol *addSyntheticLocal(StringRef Name, uint8_t Type, uint64_t Value,
820 uint64_t Size, InputSectionBase &Section);
822 // Linker generated sections which can be used as inputs.
824 static InputSection *ARMAttributes;
825 static BssSection *Bss;
826 static BssSection *BssRelRo;
827 static BuildIdSection *BuildId;
828 static EhFrameHeader *EhFrameHdr;
829 static EhFrameSection *EhFrame;
830 static SyntheticSection *Dynamic;
831 static StringTableSection *DynStrTab;
832 static SymbolTableBaseSection *DynSymTab;
833 static GnuHashTableSection *GnuHashTab;
834 static HashTableSection *HashTab;
835 static InputSection *Interp;
836 static GdbIndexSection *GdbIndex;
837 static GotSection *Got;
838 static GotPltSection *GotPlt;
839 static IgotPltSection *IgotPlt;
840 static MipsGotSection *MipsGot;
841 static MipsRldMapSection *MipsRldMap;
842 static PltSection *Plt;
843 static PltSection *Iplt;
844 static RelocationBaseSection *RelaDyn;
845 static RelocationBaseSection *RelaPlt;
846 static RelocationBaseSection *RelaIplt;
847 static StringTableSection *ShStrTab;
848 static StringTableSection *StrTab;
849 static SymbolTableBaseSection *SymTab;
852 template <class ELFT> struct In {
853 static VersionDefinitionSection<ELFT> *VerDef;
854 static VersionTableSection<ELFT> *VerSym;
855 static VersionNeedSection<ELFT> *VerNeed;
858 template <class ELFT> VersionDefinitionSection<ELFT> *In<ELFT>::VerDef;
859 template <class ELFT> VersionTableSection<ELFT> *In<ELFT>::VerSym;
860 template <class ELFT> VersionNeedSection<ELFT> *In<ELFT>::VerNeed;