Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 1 | //===- OutputSections.h -----------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Linker |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef LLD_ELF_OUTPUT_SECTIONS_H |
| 11 | #define LLD_ELF_OUTPUT_SECTIONS_H |
| 12 | |
| 13 | #include "lld/Core/LLVM.h" |
| 14 | |
| 15 | #include "llvm/MC/StringTableBuilder.h" |
| 16 | #include "llvm/Object/ELF.h" |
| 17 | |
Davide Italiano | 85121bb | 2015-09-25 03:56:11 +0000 | [diff] [blame] | 18 | #include "Config.h" |
| 19 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 20 | #include <type_traits> |
| 21 | |
| 22 | namespace lld { |
| 23 | namespace elf2 { |
| 24 | |
| 25 | class SymbolBody; |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 26 | template <class ELFT> class SymbolTable; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 27 | template <class ELFT> class SymbolTableSection; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 28 | template <class ELFT> class StringTableSection; |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 29 | template <class ELFT> class EHInputSection; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 30 | template <class ELFT> class InputSection; |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 31 | template <class ELFT> class InputSectionBase; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 32 | template <class ELFT> class MergeInputSection; |
Simon Atanasyan | 1d7df40 | 2015-12-20 10:57:34 +0000 | [diff] [blame] | 33 | template <class ELFT> class MipsReginfoInputSection; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 34 | template <class ELFT> class OutputSection; |
| 35 | template <class ELFT> class ObjectFile; |
| 36 | template <class ELFT> class DefinedRegular; |
| 37 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 38 | template <class ELFT> |
Rafael Espindola | 932efcf | 2015-10-19 20:24:44 +0000 | [diff] [blame] | 39 | static inline typename llvm::object::ELFFile<ELFT>::uintX_t |
| 40 | getAddend(const typename llvm::object::ELFFile<ELFT>::Elf_Rel &Rel) { |
| 41 | return 0; |
| 42 | } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 43 | |
| 44 | template <class ELFT> |
Rafael Espindola | 932efcf | 2015-10-19 20:24:44 +0000 | [diff] [blame] | 45 | static inline typename llvm::object::ELFFile<ELFT>::uintX_t |
| 46 | getAddend(const typename llvm::object::ELFFile<ELFT>::Elf_Rela &Rel) { |
| 47 | return Rel.r_addend; |
| 48 | } |
| 49 | |
Rafael Espindola | 932efcf | 2015-10-19 20:24:44 +0000 | [diff] [blame] | 50 | template <class ELFT, bool IsRela> |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 51 | typename llvm::object::ELFFile<ELFT>::uintX_t |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 52 | getLocalRelTarget(const ObjectFile<ELFT> &File, |
George Rimar | 0b8ed1d | 2015-12-21 10:37:33 +0000 | [diff] [blame] | 53 | const llvm::object::Elf_Rel_Impl<ELFT, IsRela> &Rel, |
| 54 | typename llvm::object::ELFFile<ELFT>::uintX_t Addend); |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 55 | |
Rui Ueyama | 89f4ec7 | 2015-12-25 07:01:09 +0000 | [diff] [blame] | 56 | bool canBePreempted(const SymbolBody *Body, bool NeedsGot); |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 57 | |
Rafael Espindola | 7167585 | 2015-09-22 00:16:19 +0000 | [diff] [blame] | 58 | // This represents a section in an output file. |
| 59 | // Different sub classes represent different types of sections. Some contain |
| 60 | // input sections, others are created by the linker. |
| 61 | // The writer creates multiple OutputSections and assign them unique, |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 62 | // non-overlapping file offsets and VAs. |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 63 | template <class ELFT> class OutputSectionBase { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 64 | public: |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 65 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
| 66 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 67 | |
| 68 | OutputSectionBase(StringRef Name, uint32_t sh_type, uintX_t sh_flags); |
| 69 | void setVA(uintX_t VA) { Header.sh_addr = VA; } |
| 70 | uintX_t getVA() const { return Header.sh_addr; } |
| 71 | void setFileOffset(uintX_t Off) { Header.sh_offset = Off; } |
Rafael Espindola | e2c2461 | 2016-01-29 01:24:25 +0000 | [diff] [blame] | 72 | void setSHName(unsigned Val) { Header.sh_name = Val; } |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 73 | void writeHeaderTo(Elf_Shdr *SHdr); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 74 | StringRef getName() { return Name; } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 75 | |
Rui Ueyama | 40845e6 | 2015-12-26 05:51:07 +0000 | [diff] [blame] | 76 | virtual void addSection(InputSectionBase<ELFT> *C) {} |
| 77 | |
Rui Ueyama | 2317d0d | 2015-10-15 20:55:22 +0000 | [diff] [blame] | 78 | unsigned SectionIndex; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 79 | |
| 80 | // Returns the size of the section in the output file. |
Rafael Espindola | 7757224 | 2015-10-02 19:37:55 +0000 | [diff] [blame] | 81 | uintX_t getSize() const { return Header.sh_size; } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 82 | void setSize(uintX_t Val) { Header.sh_size = Val; } |
| 83 | uintX_t getFlags() { return Header.sh_flags; } |
| 84 | uintX_t getFileOff() { return Header.sh_offset; } |
| 85 | uintX_t getAlign() { |
| 86 | // The ELF spec states that a value of 0 means the section has no alignment |
| 87 | // constraits. |
| 88 | return std::max<uintX_t>(Header.sh_addralign, 1); |
| 89 | } |
| 90 | uint32_t getType() { return Header.sh_type; } |
Rafael Espindola | 115f0f3 | 2015-11-03 14:13:40 +0000 | [diff] [blame] | 91 | void updateAlign(uintX_t Align) { |
| 92 | if (Align > Header.sh_addralign) |
| 93 | Header.sh_addralign = Align; |
| 94 | } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 95 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 96 | virtual void finalize() {} |
| 97 | virtual void writeTo(uint8_t *Buf) = 0; |
Rui Ueyama | d4ea7dd | 2015-12-26 07:01:26 +0000 | [diff] [blame] | 98 | virtual ~OutputSectionBase() = default; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 99 | |
| 100 | protected: |
| 101 | StringRef Name; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 102 | Elf_Shdr Header; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 105 | template <class ELFT> class GotSection final : public OutputSectionBase<ELFT> { |
| 106 | typedef OutputSectionBase<ELFT> Base; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 107 | typedef typename Base::uintX_t uintX_t; |
| 108 | |
| 109 | public: |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 110 | GotSection(); |
Igor Kudrin | 15cd9ff | 2015-11-06 07:43:03 +0000 | [diff] [blame] | 111 | void finalize() override; |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 112 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 113 | void addEntry(SymbolBody *Sym); |
Simon Atanasyan | 56ab5f0 | 2016-01-21 05:33:23 +0000 | [diff] [blame] | 114 | void addMipsLocalEntry(); |
George Rimar | 90cd0a8 | 2015-12-01 19:20:26 +0000 | [diff] [blame] | 115 | bool addDynTlsEntry(SymbolBody *Sym); |
Rui Ueyama | 0e53c7d | 2016-02-05 00:10:02 +0000 | [diff] [blame] | 116 | bool addTlsIndex(); |
Simon Atanasyan | 56ab5f0 | 2016-01-21 05:33:23 +0000 | [diff] [blame] | 117 | bool empty() const { return MipsLocalEntries == 0 && Entries.empty(); } |
Simon Atanasyan | 56ab5f0 | 2016-01-21 05:33:23 +0000 | [diff] [blame] | 118 | uintX_t getMipsLocalFullAddr(const SymbolBody &B); |
| 119 | uintX_t getMipsLocalPageAddr(uintX_t Addr); |
George Rimar | 90cd0a8 | 2015-12-01 19:20:26 +0000 | [diff] [blame] | 120 | uintX_t getGlobalDynAddr(const SymbolBody &B) const; |
George Rimar | 9db204a | 2015-12-02 09:58:20 +0000 | [diff] [blame] | 121 | uintX_t getNumEntries() const { return Entries.size(); } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 122 | |
Igor Kudrin | 304860a | 2015-11-12 04:39:49 +0000 | [diff] [blame] | 123 | // Returns the symbol which corresponds to the first entry of the global part |
| 124 | // of GOT on MIPS platform. It is required to fill up MIPS-specific dynamic |
| 125 | // table properties. |
| 126 | // Returns nullptr if the global part is empty. |
| 127 | const SymbolBody *getMipsFirstGlobalEntry() const; |
| 128 | |
| 129 | // Returns the number of entries in the local part of GOT including |
| 130 | // the number of reserved entries. This method is MIPS-specific. |
| 131 | unsigned getMipsLocalEntriesNum() const; |
| 132 | |
Rui Ueyama | 0e53c7d | 2016-02-05 00:10:02 +0000 | [diff] [blame] | 133 | uintX_t getTlsIndexVA() { return Base::getVA() + TlsIndexOff; } |
George Rimar | b17f739 | 2015-12-01 18:24:07 +0000 | [diff] [blame] | 134 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 135 | private: |
| 136 | std::vector<const SymbolBody *> Entries; |
Rui Ueyama | 0e53c7d | 2016-02-05 00:10:02 +0000 | [diff] [blame] | 137 | uint32_t TlsIndexOff = -1; |
Simon Atanasyan | 56ab5f0 | 2016-01-21 05:33:23 +0000 | [diff] [blame] | 138 | uint32_t MipsLocalEntries = 0; |
| 139 | llvm::DenseMap<uintX_t, size_t> MipsLocalGotPos; |
| 140 | |
| 141 | uintX_t getMipsLocalEntryAddr(uintX_t EntryValue); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 144 | template <class ELFT> |
| 145 | class GotPltSection final : public OutputSectionBase<ELFT> { |
| 146 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
| 147 | |
| 148 | public: |
| 149 | GotPltSection(); |
| 150 | void finalize() override; |
| 151 | void writeTo(uint8_t *Buf) override; |
| 152 | void addEntry(SymbolBody *Sym); |
| 153 | bool empty() const; |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 154 | |
| 155 | private: |
| 156 | std::vector<const SymbolBody *> Entries; |
| 157 | }; |
| 158 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 159 | template <class ELFT> class PltSection final : public OutputSectionBase<ELFT> { |
| 160 | typedef OutputSectionBase<ELFT> Base; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 161 | typedef typename Base::uintX_t uintX_t; |
| 162 | |
| 163 | public: |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 164 | PltSection(); |
Hal Finkel | 6c2a3b8 | 2015-10-08 21:51:31 +0000 | [diff] [blame] | 165 | void finalize() override; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 166 | void writeTo(uint8_t *Buf) override; |
| 167 | void addEntry(SymbolBody *Sym); |
| 168 | bool empty() const { return Entries.empty(); } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 169 | |
| 170 | private: |
George Rimar | 77b7779 | 2015-11-25 22:15:01 +0000 | [diff] [blame] | 171 | std::vector<std::pair<const SymbolBody *, unsigned>> Entries; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | template <class ELFT> struct DynamicReloc { |
Rafael Espindola | de9857e | 2016-02-04 21:33:05 +0000 | [diff] [blame] | 175 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
| 176 | uint32_t Type; |
| 177 | |
| 178 | // Where the relocation is. |
| 179 | enum OffsetKind { |
| 180 | Off_Got, // The got entry of Sym. |
| 181 | Off_GotPlt, // The got.plt entry of Sym. |
| 182 | Off_Bss, // The bss entry of Sym (copy reloc). |
| 183 | Off_Sec, // The final position of the given input section and offset. |
| 184 | Off_LTlsIndex, // The local tls index. |
| 185 | Off_GTlsIndex, // The global tls index of Sym. |
| 186 | Off_GTlsOffset // The global tls offset of Sym. |
| 187 | } OKind; |
| 188 | |
| 189 | SymbolBody *Sym = nullptr; |
| 190 | InputSectionBase<ELFT> *OffsetSec = nullptr; |
| 191 | uintX_t OffsetInSec = 0; |
| 192 | bool UseSymVA = false; |
| 193 | InputSectionBase<ELFT> *TargetSec = nullptr; |
| 194 | uintX_t OffsetInTargetSec = 0; |
| 195 | uintX_t Addend = 0; |
| 196 | |
| 197 | DynamicReloc(uint32_t Type, OffsetKind OKind, SymbolBody *Sym) |
| 198 | : Type(Type), OKind(OKind), Sym(Sym) {} |
| 199 | |
| 200 | DynamicReloc(uint32_t Type, OffsetKind OKind, bool UseSymVA, SymbolBody *Sym) |
| 201 | : Type(Type), OKind(OKind), Sym(Sym), UseSymVA(UseSymVA) {} |
| 202 | |
| 203 | DynamicReloc(uint32_t Type, InputSectionBase<ELFT> *OffsetSec, |
| 204 | uintX_t OffsetInSec, bool UseSymVA, SymbolBody *Sym, |
| 205 | uintX_t Addend) |
| 206 | : Type(Type), OKind(Off_Sec), Sym(Sym), OffsetSec(OffsetSec), |
| 207 | OffsetInSec(OffsetInSec), UseSymVA(UseSymVA), Addend(Addend) {} |
| 208 | |
| 209 | DynamicReloc(uint32_t Type, InputSectionBase<ELFT> *OffsetSec, |
| 210 | uintX_t OffsetInSec, InputSectionBase<ELFT> *TargetSec, |
| 211 | uintX_t OffsetInTargetSec, uintX_t Addend) |
| 212 | : Type(Type), OKind(Off_Sec), OffsetSec(OffsetSec), |
| 213 | OffsetInSec(OffsetInSec), TargetSec(TargetSec), |
| 214 | OffsetInTargetSec(OffsetInTargetSec), Addend(Addend) {} |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | template <class ELFT> |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 218 | class SymbolTableSection final : public OutputSectionBase<ELFT> { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 219 | public: |
| 220 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr; |
| 221 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym; |
| 222 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym_Range Elf_Sym_Range; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 223 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 224 | SymbolTableSection(SymbolTable<ELFT> &Table, |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 225 | StringTableSection<ELFT> &StrTabSec); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 226 | |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 227 | void finalize() override; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 228 | void writeTo(uint8_t *Buf) override; |
Igor Kudrin | ab665fc | 2015-10-20 21:47:58 +0000 | [diff] [blame] | 229 | void addSymbol(SymbolBody *Body); |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 230 | StringTableSection<ELFT> &getStrTabSec() const { return StrTabSec; } |
Rafael Espindola | 0e92f24 | 2016-01-27 16:41:24 +0000 | [diff] [blame] | 231 | unsigned getNumSymbols() const { return NumLocals + Symbols.size() + 1; } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 232 | |
Rafael Espindola | e2c2461 | 2016-01-29 01:24:25 +0000 | [diff] [blame] | 233 | ArrayRef<std::pair<SymbolBody *, unsigned>> getSymbols() const { |
| 234 | return Symbols; |
| 235 | } |
| 236 | |
| 237 | unsigned NumLocals = 0; |
| 238 | StringTableSection<ELFT> &StrTabSec; |
Igor Kudrin | ab665fc | 2015-10-20 21:47:58 +0000 | [diff] [blame] | 239 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 240 | private: |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 241 | void writeLocalSymbols(uint8_t *&Buf); |
Igor Kudrin | ea6a835 | 2015-10-19 08:01:51 +0000 | [diff] [blame] | 242 | void writeGlobalSymbols(uint8_t *Buf); |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 243 | |
Igor Kudrin | 853b88d | 2015-10-20 20:52:14 +0000 | [diff] [blame] | 244 | static uint8_t getSymbolBinding(SymbolBody *Body); |
| 245 | |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 246 | SymbolTable<ELFT> &Table; |
Rafael Espindola | e2c2461 | 2016-01-29 01:24:25 +0000 | [diff] [blame] | 247 | std::vector<std::pair<SymbolBody *, unsigned>> Symbols; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 248 | }; |
| 249 | |
| 250 | template <class ELFT> |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 251 | class RelocationSection final : public OutputSectionBase<ELFT> { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 252 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel; |
| 253 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela; |
Rafael Espindola | 3c83e2b | 2015-10-05 21:09:37 +0000 | [diff] [blame] | 254 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 255 | |
| 256 | public: |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 257 | RelocationSection(StringRef Name, bool IsRela); |
Rafael Espindola | d30eb7d | 2016-02-05 15:03:10 +0000 | [diff] [blame^] | 258 | void addReloc(const DynamicReloc<ELFT> &Reloc); |
George Rimar | 77b7779 | 2015-11-25 22:15:01 +0000 | [diff] [blame] | 259 | unsigned getRelocOffset(); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 260 | void finalize() override; |
| 261 | void writeTo(uint8_t *Buf) override; |
| 262 | bool hasRelocs() const { return !Relocs.empty(); } |
| 263 | bool isRela() const { return IsRela; } |
| 264 | |
George Rimar | a07ff66 | 2015-12-21 10:12:06 +0000 | [diff] [blame] | 265 | bool Static = false; |
| 266 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 267 | private: |
| 268 | std::vector<DynamicReloc<ELFT>> Relocs; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 269 | const bool IsRela; |
| 270 | }; |
| 271 | |
| 272 | template <class ELFT> |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 273 | class OutputSection final : public OutputSectionBase<ELFT> { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 274 | public: |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 275 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr; |
| 276 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym; |
| 277 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel; |
| 278 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 279 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 280 | OutputSection(StringRef Name, uint32_t sh_type, uintX_t sh_flags); |
Rui Ueyama | 40845e6 | 2015-12-26 05:51:07 +0000 | [diff] [blame] | 281 | void addSection(InputSectionBase<ELFT> *C) override; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 282 | void writeTo(uint8_t *Buf) override; |
| 283 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 284 | private: |
Rafael Espindola | 7167585 | 2015-09-22 00:16:19 +0000 | [diff] [blame] | 285 | std::vector<InputSection<ELFT> *> Sections; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 286 | }; |
| 287 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 288 | template <class ELFT> |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 289 | class MergeOutputSection final : public OutputSectionBase<ELFT> { |
| 290 | typedef typename OutputSectionBase<ELFT>::uintX_t uintX_t; |
| 291 | |
Rafael Espindola | f82ed2a | 2015-10-24 22:51:01 +0000 | [diff] [blame] | 292 | bool shouldTailMerge() const; |
| 293 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 294 | public: |
| 295 | MergeOutputSection(StringRef Name, uint32_t sh_type, uintX_t sh_flags); |
Rui Ueyama | 40845e6 | 2015-12-26 05:51:07 +0000 | [diff] [blame] | 296 | void addSection(InputSectionBase<ELFT> *S) override; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 297 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | f82ed2a | 2015-10-24 22:51:01 +0000 | [diff] [blame] | 298 | unsigned getOffset(StringRef Val); |
| 299 | void finalize() override; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 300 | |
| 301 | private: |
Rafael Espindola | f82ed2a | 2015-10-24 22:51:01 +0000 | [diff] [blame] | 302 | llvm::StringTableBuilder Builder{llvm::StringTableBuilder::RAW}; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 303 | }; |
| 304 | |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 305 | // FDE or CIE |
| 306 | template <class ELFT> struct EHRegion { |
| 307 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
| 308 | EHRegion(EHInputSection<ELFT> *S, unsigned Index); |
| 309 | StringRef data() const; |
| 310 | EHInputSection<ELFT> *S; |
| 311 | unsigned Index; |
| 312 | }; |
| 313 | |
| 314 | template <class ELFT> struct Cie : public EHRegion<ELFT> { |
| 315 | Cie(EHInputSection<ELFT> *S, unsigned Index); |
| 316 | std::vector<EHRegion<ELFT>> Fdes; |
George Rimar | f6bc65a | 2016-01-15 13:34:52 +0000 | [diff] [blame] | 317 | uint8_t FdeEncoding; |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 318 | }; |
| 319 | |
| 320 | template <class ELFT> |
| 321 | class EHOutputSection final : public OutputSectionBase<ELFT> { |
| 322 | public: |
| 323 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
| 324 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr; |
| 325 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel; |
| 326 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela; |
| 327 | EHOutputSection(StringRef Name, uint32_t sh_type, uintX_t sh_flags); |
| 328 | void writeTo(uint8_t *Buf) override; |
| 329 | |
| 330 | template <bool IsRela> |
| 331 | void addSectionAux( |
| 332 | EHInputSection<ELFT> *S, |
| 333 | llvm::iterator_range<const llvm::object::Elf_Rel_Impl<ELFT, IsRela> *> |
| 334 | Rels); |
| 335 | |
Rui Ueyama | 40845e6 | 2015-12-26 05:51:07 +0000 | [diff] [blame] | 336 | void addSection(InputSectionBase<ELFT> *S) override; |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 337 | |
| 338 | private: |
George Rimar | f6bc65a | 2016-01-15 13:34:52 +0000 | [diff] [blame] | 339 | uint8_t getFdeEncoding(ArrayRef<uint8_t> D); |
George Rimar | 003be4f | 2015-12-17 09:23:40 +0000 | [diff] [blame] | 340 | uintX_t readEntryLength(ArrayRef<uint8_t> D); |
| 341 | |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 342 | std::vector<EHInputSection<ELFT> *> Sections; |
| 343 | std::vector<Cie<ELFT>> Cies; |
| 344 | |
| 345 | // Maps CIE content + personality to a index in Cies. |
| 346 | llvm::DenseMap<std::pair<StringRef, StringRef>, unsigned> CieMap; |
| 347 | }; |
| 348 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 349 | template <class ELFT> |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 350 | class InterpSection final : public OutputSectionBase<ELFT> { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 351 | public: |
| 352 | InterpSection(); |
Eugene Zelenko | 6e43b49 | 2015-11-04 02:11:57 +0000 | [diff] [blame] | 353 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 354 | }; |
| 355 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 356 | template <class ELFT> |
| 357 | class StringTableSection final : public OutputSectionBase<ELFT> { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 358 | public: |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 359 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
George Rimar | 0f5ac9f | 2015-10-20 17:21:35 +0000 | [diff] [blame] | 360 | StringTableSection(StringRef Name, bool Dynamic); |
Rafael Espindola | e2c2461 | 2016-01-29 01:24:25 +0000 | [diff] [blame] | 361 | unsigned addString(StringRef S, bool HashIt = true); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 362 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | e2c2461 | 2016-01-29 01:24:25 +0000 | [diff] [blame] | 363 | unsigned getSize() const { return Size; } |
Rui Ueyama | 76c0063 | 2016-01-07 02:35:32 +0000 | [diff] [blame] | 364 | void finalize() override { this->Header.sh_size = getSize(); } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 365 | bool isDynamic() const { return Dynamic; } |
| 366 | |
| 367 | private: |
| 368 | const bool Dynamic; |
Rafael Espindola | e2c2461 | 2016-01-29 01:24:25 +0000 | [diff] [blame] | 369 | llvm::DenseMap<StringRef, unsigned> StringMap; |
Rui Ueyama | 76c0063 | 2016-01-07 02:35:32 +0000 | [diff] [blame] | 370 | std::vector<StringRef> Strings; |
Rafael Espindola | e2c2461 | 2016-01-29 01:24:25 +0000 | [diff] [blame] | 371 | unsigned Size = 1; // ELF string tables start with a NUL byte, so 1. |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 372 | }; |
| 373 | |
| 374 | template <class ELFT> |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 375 | class HashTableSection final : public OutputSectionBase<ELFT> { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 376 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Word Elf_Word; |
| 377 | |
| 378 | public: |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 379 | HashTableSection(); |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 380 | void finalize() override; |
| 381 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 382 | }; |
| 383 | |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 384 | // Outputs GNU Hash section. For detailed explanation see: |
| 385 | // https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections |
| 386 | template <class ELFT> |
| 387 | class GnuHashTableSection final : public OutputSectionBase<ELFT> { |
| 388 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Off Elf_Off; |
| 389 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Word Elf_Word; |
| 390 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
| 391 | |
| 392 | public: |
| 393 | GnuHashTableSection(); |
| 394 | void finalize() override; |
| 395 | void writeTo(uint8_t *Buf) override; |
| 396 | |
Igor Kudrin | f1d6029 | 2015-10-28 07:05:56 +0000 | [diff] [blame] | 397 | // Adds symbols to the hash table. |
| 398 | // Sorts the input to satisfy GNU hash section requirements. |
Rafael Espindola | e2c2461 | 2016-01-29 01:24:25 +0000 | [diff] [blame] | 399 | void addSymbols(std::vector<std::pair<SymbolBody *, unsigned>> &Symbols); |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 400 | |
| 401 | private: |
Igor Kudrin | f1d6029 | 2015-10-28 07:05:56 +0000 | [diff] [blame] | 402 | static unsigned calcNBuckets(unsigned NumHashed); |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 403 | static unsigned calcMaskWords(unsigned NumHashed); |
| 404 | |
| 405 | void writeHeader(uint8_t *&Buf); |
| 406 | void writeBloomFilter(uint8_t *&Buf); |
| 407 | void writeHashTable(uint8_t *Buf); |
| 408 | |
Igor Kudrin | f1d6029 | 2015-10-28 07:05:56 +0000 | [diff] [blame] | 409 | struct HashedSymbolData { |
| 410 | SymbolBody *Body; |
Rafael Espindola | e2c2461 | 2016-01-29 01:24:25 +0000 | [diff] [blame] | 411 | unsigned STName; |
Igor Kudrin | f1d6029 | 2015-10-28 07:05:56 +0000 | [diff] [blame] | 412 | uint32_t Hash; |
| 413 | }; |
| 414 | |
| 415 | std::vector<HashedSymbolData> HashedSymbols; |
| 416 | |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 417 | unsigned MaskWords; |
| 418 | unsigned NBuckets; |
| 419 | unsigned Shift2; |
| 420 | }; |
| 421 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 422 | template <class ELFT> |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 423 | class DynamicSection final : public OutputSectionBase<ELFT> { |
| 424 | typedef OutputSectionBase<ELFT> Base; |
| 425 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Dyn Elf_Dyn; |
Rui Ueyama | 2dfd74f | 2015-09-30 21:57:53 +0000 | [diff] [blame] | 426 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel; |
| 427 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 428 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr; |
Rui Ueyama | 2dfd74f | 2015-09-30 21:57:53 +0000 | [diff] [blame] | 429 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym; |
Rafael Espindola | de06936 | 2016-01-25 21:32:04 +0000 | [diff] [blame] | 430 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
| 431 | |
Rui Ueyama | 909cc68 | 2016-02-02 03:11:27 +0000 | [diff] [blame] | 432 | // The .dynamic section contains information for the dynamic linker. |
| 433 | // The section consists of fixed size entries, which consist of |
| 434 | // type and value fields. Value are one of plain integers, symbol |
| 435 | // addresses, or section addresses. This struct represents the entry. |
Rafael Espindola | de06936 | 2016-01-25 21:32:04 +0000 | [diff] [blame] | 436 | struct Entry { |
| 437 | int32_t Tag; |
| 438 | union { |
| 439 | OutputSectionBase<ELFT> *OutSec; |
| 440 | uint64_t Val; |
| 441 | const SymbolBody *Sym; |
| 442 | }; |
| 443 | enum KindT { SecAddr, SymAddr, PlainInt } Kind; |
| 444 | Entry(int32_t Tag, OutputSectionBase<ELFT> *OutSec) |
| 445 | : Tag(Tag), OutSec(OutSec), Kind(SecAddr) {} |
| 446 | Entry(int32_t Tag, uint64_t Val) : Tag(Tag), Val(Val), Kind(PlainInt) {} |
| 447 | Entry(int32_t Tag, const SymbolBody *Sym) |
| 448 | : Tag(Tag), Sym(Sym), Kind(SymAddr) {} |
| 449 | }; |
Rui Ueyama | 909cc68 | 2016-02-02 03:11:27 +0000 | [diff] [blame] | 450 | |
| 451 | // finalize() fills this vector with the section contents. finalize() |
| 452 | // cannot directly create final section contents because when the |
| 453 | // function is called, symbol or section addresses are not fixed yet. |
Rafael Espindola | de06936 | 2016-01-25 21:32:04 +0000 | [diff] [blame] | 454 | std::vector<Entry> Entries; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 455 | |
| 456 | public: |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 457 | DynamicSection(SymbolTable<ELFT> &SymTab); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 458 | void finalize() override; |
| 459 | void writeTo(uint8_t *Buf) override; |
| 460 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 461 | OutputSectionBase<ELFT> *PreInitArraySec = nullptr; |
| 462 | OutputSectionBase<ELFT> *InitArraySec = nullptr; |
| 463 | OutputSectionBase<ELFT> *FiniArraySec = nullptr; |
Rafael Espindola | 7757224 | 2015-10-02 19:37:55 +0000 | [diff] [blame] | 464 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 465 | private: |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 466 | SymbolTable<ELFT> &SymTab; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 467 | }; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 468 | |
Simon Atanasyan | 1d7df40 | 2015-12-20 10:57:34 +0000 | [diff] [blame] | 469 | template <class ELFT> |
| 470 | class MipsReginfoOutputSection final : public OutputSectionBase<ELFT> { |
| 471 | typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo; |
| 472 | |
| 473 | public: |
| 474 | MipsReginfoOutputSection(); |
| 475 | void writeTo(uint8_t *Buf) override; |
Rui Ueyama | 40845e6 | 2015-12-26 05:51:07 +0000 | [diff] [blame] | 476 | void addSection(InputSectionBase<ELFT> *S) override; |
Simon Atanasyan | 1d7df40 | 2015-12-20 10:57:34 +0000 | [diff] [blame] | 477 | |
| 478 | private: |
Rui Ueyama | 70eed36 | 2016-01-06 22:42:43 +0000 | [diff] [blame] | 479 | uint32_t GprMask = 0; |
Simon Atanasyan | 1d7df40 | 2015-12-20 10:57:34 +0000 | [diff] [blame] | 480 | }; |
| 481 | |
George Rimar | f6bc65a | 2016-01-15 13:34:52 +0000 | [diff] [blame] | 482 | // --eh-frame-hdr option tells linker to construct a header for all the |
| 483 | // .eh_frame sections. This header is placed to a section named .eh_frame_hdr |
| 484 | // and also to a PT_GNU_EH_FRAME segment. |
| 485 | // At runtime the unwinder then can find all the PT_GNU_EH_FRAME segments by |
| 486 | // calling dl_iterate_phdr. |
| 487 | // This section contains a lookup table for quick binary search of FDEs. |
| 488 | // Detailed info about internals can be found in Ian Lance Taylor's blog: |
| 489 | // http://www.airs.com/blog/archives/460 (".eh_frame") |
| 490 | // http://www.airs.com/blog/archives/462 (".eh_frame_hdr") |
| 491 | template <class ELFT> |
| 492 | class EhFrameHeader final : public OutputSectionBase<ELFT> { |
| 493 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
| 494 | |
| 495 | public: |
| 496 | EhFrameHeader(); |
| 497 | void writeTo(uint8_t *Buf) override; |
| 498 | |
| 499 | void addFde(uint8_t Enc, size_t Off, uint8_t *PCRel); |
| 500 | void assignEhFrame(EHOutputSection<ELFT> *Sec); |
| 501 | void reserveFde(); |
| 502 | |
| 503 | bool Live = false; |
| 504 | |
| 505 | private: |
| 506 | struct FdeData { |
| 507 | uint8_t Enc; |
| 508 | size_t Off; |
| 509 | uint8_t *PCRel; |
| 510 | }; |
| 511 | |
| 512 | uintX_t getFdePc(uintX_t EhVA, const FdeData &F); |
| 513 | |
| 514 | EHOutputSection<ELFT> *Sec = nullptr; |
| 515 | std::vector<FdeData> FdeList; |
| 516 | }; |
| 517 | |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 518 | // All output sections that are hadnled by the linker specially are |
| 519 | // globally accessible. Writer initializes them, so don't use them |
| 520 | // until Writer is initialized. |
| 521 | template <class ELFT> struct Out { |
Michael J. Spencer | d77f0d2 | 2015-11-03 22:39:09 +0000 | [diff] [blame] | 522 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
Rafael Espindola | ea7a1e90 | 2015-11-06 22:14:44 +0000 | [diff] [blame] | 523 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Phdr Elf_Phdr; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 524 | static DynamicSection<ELFT> *Dynamic; |
George Rimar | f6bc65a | 2016-01-15 13:34:52 +0000 | [diff] [blame] | 525 | static EhFrameHeader<ELFT> *EhFrameHdr; |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 526 | static GnuHashTableSection<ELFT> *GnuHashTab; |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 527 | static GotPltSection<ELFT> *GotPlt; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 528 | static GotSection<ELFT> *Got; |
| 529 | static HashTableSection<ELFT> *HashTab; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 530 | static InterpSection<ELFT> *Interp; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 531 | static OutputSection<ELFT> *Bss; |
Igor Kudrin | 304860a | 2015-11-12 04:39:49 +0000 | [diff] [blame] | 532 | static OutputSection<ELFT> *MipsRldMap; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 533 | static OutputSectionBase<ELFT> *Opd; |
Hal Finkel | daedc12 | 2015-10-12 23:16:53 +0000 | [diff] [blame] | 534 | static uint8_t *OpdBuf; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 535 | static PltSection<ELFT> *Plt; |
| 536 | static RelocationSection<ELFT> *RelaDyn; |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 537 | static RelocationSection<ELFT> *RelaPlt; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 538 | static StringTableSection<ELFT> *DynStrTab; |
George Rimar | 0f5ac9f | 2015-10-20 17:21:35 +0000 | [diff] [blame] | 539 | static StringTableSection<ELFT> *ShStrTab; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 540 | static StringTableSection<ELFT> *StrTab; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 541 | static SymbolTableSection<ELFT> *DynSymTab; |
| 542 | static SymbolTableSection<ELFT> *SymTab; |
Rafael Espindola | ea7a1e90 | 2015-11-06 22:14:44 +0000 | [diff] [blame] | 543 | static Elf_Phdr *TlsPhdr; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 544 | }; |
Rui Ueyama | d888d10 | 2015-10-09 19:34:55 +0000 | [diff] [blame] | 545 | |
| 546 | template <class ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic; |
George Rimar | f6bc65a | 2016-01-15 13:34:52 +0000 | [diff] [blame] | 547 | template <class ELFT> EhFrameHeader<ELFT> *Out<ELFT>::EhFrameHdr; |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 548 | template <class ELFT> GnuHashTableSection<ELFT> *Out<ELFT>::GnuHashTab; |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 549 | template <class ELFT> GotPltSection<ELFT> *Out<ELFT>::GotPlt; |
Rui Ueyama | d888d10 | 2015-10-09 19:34:55 +0000 | [diff] [blame] | 550 | template <class ELFT> GotSection<ELFT> *Out<ELFT>::Got; |
| 551 | template <class ELFT> HashTableSection<ELFT> *Out<ELFT>::HashTab; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 552 | template <class ELFT> InterpSection<ELFT> *Out<ELFT>::Interp; |
Rafael Espindola | d7a267b | 2015-11-03 22:01:20 +0000 | [diff] [blame] | 553 | template <class ELFT> OutputSection<ELFT> *Out<ELFT>::Bss; |
Igor Kudrin | 304860a | 2015-11-12 04:39:49 +0000 | [diff] [blame] | 554 | template <class ELFT> OutputSection<ELFT> *Out<ELFT>::MipsRldMap; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 555 | template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::Opd; |
Hal Finkel | daedc12 | 2015-10-12 23:16:53 +0000 | [diff] [blame] | 556 | template <class ELFT> uint8_t *Out<ELFT>::OpdBuf; |
Rui Ueyama | d888d10 | 2015-10-09 19:34:55 +0000 | [diff] [blame] | 557 | template <class ELFT> PltSection<ELFT> *Out<ELFT>::Plt; |
| 558 | template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaDyn; |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 559 | template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaPlt; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 560 | template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::DynStrTab; |
George Rimar | 0f5ac9f | 2015-10-20 17:21:35 +0000 | [diff] [blame] | 561 | template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::ShStrTab; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 562 | template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::StrTab; |
Rui Ueyama | d888d10 | 2015-10-09 19:34:55 +0000 | [diff] [blame] | 563 | template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::DynSymTab; |
| 564 | template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::SymTab; |
Rafael Espindola | ea7a1e90 | 2015-11-06 22:14:44 +0000 | [diff] [blame] | 565 | template <class ELFT> typename Out<ELFT>::Elf_Phdr *Out<ELFT>::TlsPhdr; |
Eugene Zelenko | 6e43b49 | 2015-11-04 02:11:57 +0000 | [diff] [blame] | 566 | |
| 567 | } // namespace elf2 |
| 568 | } // namespace lld |
| 569 | |
| 570 | #endif // LLD_ELF_OUTPUT_SECTIONS_H |