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 | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 29 | template <class ELFT> class InputSection; |
| 30 | template <class ELFT> class OutputSection; |
| 31 | template <class ELFT> class ObjectFile; |
| 32 | template <class ELFT> class DefinedRegular; |
Rafael Espindola | cd076f0 | 2015-09-25 18:19:03 +0000 | [diff] [blame] | 33 | template <class ELFT> class ELFSymbolBody; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 34 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 35 | template <class ELFT> |
Rafael Espindola | 932efcf | 2015-10-19 20:24:44 +0000 | [diff] [blame^] | 36 | static inline typename llvm::object::ELFFile<ELFT>::uintX_t |
| 37 | getAddend(const typename llvm::object::ELFFile<ELFT>::Elf_Rel &Rel) { |
| 38 | return 0; |
| 39 | } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 40 | |
| 41 | template <class ELFT> |
Rafael Espindola | 932efcf | 2015-10-19 20:24:44 +0000 | [diff] [blame^] | 42 | static inline typename llvm::object::ELFFile<ELFT>::uintX_t |
| 43 | getAddend(const typename llvm::object::ELFFile<ELFT>::Elf_Rela &Rel) { |
| 44 | return Rel.r_addend; |
| 45 | } |
| 46 | |
| 47 | template <class ELFT> |
| 48 | typename llvm::object::ELFFile<ELFT>::uintX_t getSymVA(const SymbolBody &S); |
| 49 | |
| 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, |
Rafael Espindola | 932efcf | 2015-10-19 20:24:44 +0000 | [diff] [blame^] | 53 | const llvm::object::Elf_Rel_Impl<ELFT, IsRela> &Rel); |
Rafael Espindola | cc6ebb8 | 2015-10-14 18:42:16 +0000 | [diff] [blame] | 54 | bool canBePreempted(const SymbolBody *Body, bool NeedsGot); |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 55 | template <class ELFT> bool includeInSymtab(const SymbolBody &B); |
| 56 | |
Rafael Espindola | 05a3dd2 | 2015-09-22 23:38:23 +0000 | [diff] [blame] | 57 | bool includeInDynamicSymtab(const SymbolBody &B); |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 58 | |
| 59 | template <class ELFT> |
| 60 | bool shouldKeepInSymtab( |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 61 | const ObjectFile<ELFT> &File, StringRef Name, |
| 62 | const typename llvm::object::ELFFile<ELFT>::Elf_Sym &Sym); |
Davide Italiano | 85121bb | 2015-09-25 03:56:11 +0000 | [diff] [blame] | 63 | |
Rafael Espindola | 7167585 | 2015-09-22 00:16:19 +0000 | [diff] [blame] | 64 | // This represents a section in an output file. |
| 65 | // Different sub classes represent different types of sections. Some contain |
| 66 | // input sections, others are created by the linker. |
| 67 | // The writer creates multiple OutputSections and assign them unique, |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 68 | // non-overlapping file offsets and VAs. |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 69 | template <class ELFT> class OutputSectionBase { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 70 | public: |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 71 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
| 72 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 73 | |
| 74 | OutputSectionBase(StringRef Name, uint32_t sh_type, uintX_t sh_flags); |
| 75 | void setVA(uintX_t VA) { Header.sh_addr = VA; } |
| 76 | uintX_t getVA() const { return Header.sh_addr; } |
| 77 | void setFileOffset(uintX_t Off) { Header.sh_offset = Off; } |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 78 | void writeHeaderTo(Elf_Shdr *SHdr); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 79 | StringRef getName() { return Name; } |
| 80 | void setNameOffset(uintX_t Offset) { Header.sh_name = Offset; } |
| 81 | |
Rui Ueyama | 2317d0d | 2015-10-15 20:55:22 +0000 | [diff] [blame] | 82 | unsigned SectionIndex; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 83 | |
| 84 | // Returns the size of the section in the output file. |
Rafael Espindola | 7757224 | 2015-10-02 19:37:55 +0000 | [diff] [blame] | 85 | uintX_t getSize() const { return Header.sh_size; } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 86 | void setSize(uintX_t Val) { Header.sh_size = Val; } |
| 87 | uintX_t getFlags() { return Header.sh_flags; } |
| 88 | uintX_t getFileOff() { return Header.sh_offset; } |
| 89 | uintX_t getAlign() { |
| 90 | // The ELF spec states that a value of 0 means the section has no alignment |
| 91 | // constraits. |
| 92 | return std::max<uintX_t>(Header.sh_addralign, 1); |
| 93 | } |
| 94 | uint32_t getType() { return Header.sh_type; } |
| 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; |
| 98 | |
| 99 | protected: |
| 100 | StringRef Name; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 101 | Elf_Shdr Header; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 102 | ~OutputSectionBase() = default; |
| 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(); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 111 | void finalize() override { |
Rui Ueyama | 5f551ae | 2015-10-14 14:02:06 +0000 | [diff] [blame] | 112 | this->Header.sh_size = Entries.size() * sizeof(uintX_t); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 113 | } |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 114 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 115 | void addEntry(SymbolBody *Sym); |
| 116 | bool empty() const { return Entries.empty(); } |
| 117 | uintX_t getEntryAddr(const SymbolBody &B) const; |
| 118 | |
| 119 | private: |
| 120 | std::vector<const SymbolBody *> Entries; |
| 121 | }; |
| 122 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 123 | template <class ELFT> class PltSection final : public OutputSectionBase<ELFT> { |
| 124 | typedef OutputSectionBase<ELFT> Base; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 125 | typedef typename Base::uintX_t uintX_t; |
| 126 | |
| 127 | public: |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 128 | PltSection(); |
Hal Finkel | 6c2a3b8 | 2015-10-08 21:51:31 +0000 | [diff] [blame] | 129 | void finalize() override; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 130 | void writeTo(uint8_t *Buf) override; |
| 131 | void addEntry(SymbolBody *Sym); |
| 132 | bool empty() const { return Entries.empty(); } |
| 133 | uintX_t getEntryAddr(const SymbolBody &B) const; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 134 | |
| 135 | private: |
| 136 | std::vector<const SymbolBody *> Entries; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | template <class ELFT> struct DynamicReloc { |
| 140 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel; |
| 141 | const InputSection<ELFT> &C; |
| 142 | const Elf_Rel &RI; |
| 143 | }; |
| 144 | |
| 145 | template <class ELFT> |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 146 | class SymbolTableSection final : public OutputSectionBase<ELFT> { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 147 | public: |
| 148 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr; |
| 149 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym; |
| 150 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym_Range Elf_Sym_Range; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 151 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 152 | SymbolTableSection(SymbolTable<ELFT> &Table, |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 153 | StringTableSection<ELFT> &StrTabSec); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 154 | |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 155 | void finalize() override; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 156 | void writeTo(uint8_t *Buf) override; |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 157 | void addSymbol(StringRef Name, bool isLocal = false); |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 158 | StringTableSection<ELFT> &getStrTabSec() const { return StrTabSec; } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 159 | unsigned getNumSymbols() const { return NumVisible + 1; } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 160 | |
| 161 | private: |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 162 | void writeLocalSymbols(uint8_t *&Buf); |
Igor Kudrin | ea6a835 | 2015-10-19 08:01:51 +0000 | [diff] [blame] | 163 | void writeGlobalSymbols(uint8_t *Buf); |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 164 | |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 165 | SymbolTable<ELFT> &Table; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 166 | StringTableSection<ELFT> &StrTabSec; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 167 | unsigned NumVisible = 0; |
| 168 | unsigned NumLocals = 0; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | template <class ELFT> |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 172 | class RelocationSection final : public OutputSectionBase<ELFT> { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 173 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel; |
| 174 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela; |
Rafael Espindola | 3c83e2b | 2015-10-05 21:09:37 +0000 | [diff] [blame] | 175 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 176 | |
| 177 | public: |
Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame] | 178 | RelocationSection(bool IsRela); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 179 | void addReloc(const DynamicReloc<ELFT> &Reloc) { Relocs.push_back(Reloc); } |
| 180 | void finalize() override; |
| 181 | void writeTo(uint8_t *Buf) override; |
| 182 | bool hasRelocs() const { return !Relocs.empty(); } |
| 183 | bool isRela() const { return IsRela; } |
| 184 | |
| 185 | private: |
| 186 | std::vector<DynamicReloc<ELFT>> Relocs; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 187 | const bool IsRela; |
| 188 | }; |
| 189 | |
| 190 | template <class ELFT> |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 191 | class OutputSection final : public OutputSectionBase<ELFT> { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 192 | public: |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 193 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr; |
| 194 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym; |
| 195 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel; |
| 196 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 197 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 198 | OutputSection(StringRef Name, uint32_t sh_type, uintX_t sh_flags); |
Rafael Espindola | 7167585 | 2015-09-22 00:16:19 +0000 | [diff] [blame] | 199 | void addSection(InputSection<ELFT> *C); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 200 | void writeTo(uint8_t *Buf) override; |
| 201 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 202 | private: |
Rafael Espindola | 7167585 | 2015-09-22 00:16:19 +0000 | [diff] [blame] | 203 | std::vector<InputSection<ELFT> *> Sections; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 204 | }; |
| 205 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 206 | template <class ELFT> |
| 207 | class InterpSection final : public OutputSectionBase<ELFT> { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 208 | public: |
| 209 | InterpSection(); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 210 | void writeTo(uint8_t *Buf); |
| 211 | }; |
| 212 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 213 | template <class ELFT> |
| 214 | class StringTableSection final : public OutputSectionBase<ELFT> { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 215 | public: |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 216 | typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t; |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 217 | StringTableSection(bool Dynamic); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 218 | void add(StringRef S) { StrTabBuilder.add(S); } |
| 219 | size_t getFileOff(StringRef S) const { return StrTabBuilder.getOffset(S); } |
| 220 | StringRef data() const { return StrTabBuilder.data(); } |
| 221 | void writeTo(uint8_t *Buf) override; |
| 222 | |
| 223 | void finalize() override { |
| 224 | StrTabBuilder.finalize(llvm::StringTableBuilder::ELF); |
| 225 | this->Header.sh_size = StrTabBuilder.data().size(); |
| 226 | } |
| 227 | |
| 228 | bool isDynamic() const { return Dynamic; } |
| 229 | |
| 230 | private: |
| 231 | const bool Dynamic; |
| 232 | llvm::StringTableBuilder StrTabBuilder; |
| 233 | }; |
| 234 | |
| 235 | template <class ELFT> |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 236 | class HashTableSection final : public OutputSectionBase<ELFT> { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 237 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Word Elf_Word; |
| 238 | |
| 239 | public: |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 240 | HashTableSection(); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 241 | void addSymbol(SymbolBody *S); |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 242 | void finalize() override; |
| 243 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 244 | |
| 245 | private: |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 246 | std::vector<uint32_t> Hashes; |
| 247 | }; |
| 248 | |
| 249 | template <class ELFT> |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 250 | class DynamicSection final : public OutputSectionBase<ELFT> { |
| 251 | typedef OutputSectionBase<ELFT> Base; |
| 252 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Dyn Elf_Dyn; |
Rui Ueyama | 2dfd74f | 2015-09-30 21:57:53 +0000 | [diff] [blame] | 253 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel; |
| 254 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 255 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr; |
Rui Ueyama | 2dfd74f | 2015-09-30 21:57:53 +0000 | [diff] [blame] | 256 | typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 257 | |
| 258 | public: |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 259 | DynamicSection(SymbolTable<ELFT> &SymTab); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 260 | void finalize() override; |
| 261 | void writeTo(uint8_t *Buf) override; |
| 262 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 263 | OutputSectionBase<ELFT> *PreInitArraySec = nullptr; |
| 264 | OutputSectionBase<ELFT> *InitArraySec = nullptr; |
| 265 | OutputSectionBase<ELFT> *FiniArraySec = nullptr; |
Rafael Espindola | 7757224 | 2015-10-02 19:37:55 +0000 | [diff] [blame] | 266 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 267 | private: |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 268 | SymbolTable<ELFT> &SymTab; |
Igor Kudrin | b1f2b51 | 2015-10-05 10:29:46 +0000 | [diff] [blame] | 269 | const ELFSymbolBody<ELFT> *InitSym = nullptr; |
| 270 | const ELFSymbolBody<ELFT> *FiniSym = nullptr; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 271 | }; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 272 | |
| 273 | // All output sections that are hadnled by the linker specially are |
| 274 | // globally accessible. Writer initializes them, so don't use them |
| 275 | // until Writer is initialized. |
| 276 | template <class ELFT> struct Out { |
| 277 | static DynamicSection<ELFT> *Dynamic; |
| 278 | static GotSection<ELFT> *Got; |
| 279 | static HashTableSection<ELFT> *HashTab; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 280 | static InterpSection<ELFT> *Interp; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 281 | static OutputSection<ELFT> *Bss; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 282 | static OutputSectionBase<ELFT> *Opd; |
Hal Finkel | daedc12 | 2015-10-12 23:16:53 +0000 | [diff] [blame] | 283 | static uint8_t *OpdBuf; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 284 | static PltSection<ELFT> *Plt; |
| 285 | static RelocationSection<ELFT> *RelaDyn; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 286 | static StringTableSection<ELFT> *DynStrTab; |
| 287 | static StringTableSection<ELFT> *StrTab; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 288 | static SymbolTableSection<ELFT> *DynSymTab; |
| 289 | static SymbolTableSection<ELFT> *SymTab; |
| 290 | }; |
Rui Ueyama | d888d10 | 2015-10-09 19:34:55 +0000 | [diff] [blame] | 291 | |
| 292 | template <class ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic; |
| 293 | template <class ELFT> GotSection<ELFT> *Out<ELFT>::Got; |
| 294 | template <class ELFT> HashTableSection<ELFT> *Out<ELFT>::HashTab; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 295 | template <class ELFT> InterpSection<ELFT> *Out<ELFT>::Interp; |
Rui Ueyama | d888d10 | 2015-10-09 19:34:55 +0000 | [diff] [blame] | 296 | template <class ELFT> OutputSection<ELFT> *Out<ELFT>::Bss; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 297 | template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::Opd; |
Hal Finkel | daedc12 | 2015-10-12 23:16:53 +0000 | [diff] [blame] | 298 | template <class ELFT> uint8_t *Out<ELFT>::OpdBuf; |
Rui Ueyama | d888d10 | 2015-10-09 19:34:55 +0000 | [diff] [blame] | 299 | template <class ELFT> PltSection<ELFT> *Out<ELFT>::Plt; |
| 300 | template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaDyn; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 301 | template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::DynStrTab; |
| 302 | template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::StrTab; |
Rui Ueyama | d888d10 | 2015-10-09 19:34:55 +0000 | [diff] [blame] | 303 | template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::DynSymTab; |
| 304 | template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::SymTab; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | #endif |