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