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 | |
Davide Italiano | 85121bb | 2015-09-25 03:56:11 +0000 | [diff] [blame] | 13 | #include "Config.h" |
George Rimar | 58fa524 | 2016-10-20 09:19:48 +0000 | [diff] [blame] | 14 | #include "GdbIndex.h" |
Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 15 | #include "Relocations.h" |
Davide Italiano | 85121bb | 2015-09-25 03:56:11 +0000 | [diff] [blame] | 16 | |
Rui Ueyama | a0752a5 | 2016-03-13 20:28:29 +0000 | [diff] [blame] | 17 | #include "lld/Core/LLVM.h" |
Simon Atanasyan | d2980d3 | 2016-03-29 14:07:22 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/SmallPtrSet.h" |
Rui Ueyama | a0752a5 | 2016-03-13 20:28:29 +0000 | [diff] [blame] | 19 | #include "llvm/MC/StringTableBuilder.h" |
| 20 | #include "llvm/Object/ELF.h" |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 21 | |
| 22 | namespace lld { |
Rafael Espindola | e0df00b | 2016-02-28 00:25:54 +0000 | [diff] [blame] | 23 | namespace elf { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 24 | |
| 25 | class SymbolBody; |
Rafael Espindola | 2deeb60 | 2016-07-21 20:18:30 +0000 | [diff] [blame] | 26 | struct EhSectionPiece; |
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; |
Rui Ueyama | 0b9a903 | 2016-05-24 04:19:20 +0000 | [diff] [blame] | 30 | template <class ELFT> class EhInputSection; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 31 | template <class ELFT> class InputSection; |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 32 | template <class ELFT> class InputSectionBase; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 33 | template <class ELFT> class MergeInputSection; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 34 | template <class ELFT> class OutputSection; |
| 35 | template <class ELFT> class ObjectFile; |
Peter Collingbourne | 21a12fc | 2016-04-27 20:22:31 +0000 | [diff] [blame] | 36 | template <class ELFT> class SharedFile; |
| 37 | template <class ELFT> class SharedSymbol; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 38 | template <class ELFT> class DefinedRegular; |
| 39 | |
Rafael Espindola | 7167585 | 2015-09-22 00:16:19 +0000 | [diff] [blame] | 40 | // This represents a section in an output file. |
| 41 | // Different sub classes represent different types of sections. Some contain |
| 42 | // input sections, others are created by the linker. |
| 43 | // The writer creates multiple OutputSections and assign them unique, |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 44 | // non-overlapping file offsets and VAs. |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 45 | class OutputSectionBase { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 46 | public: |
Eugene Leviant | 9d278b6 | 2016-08-10 18:10:41 +0000 | [diff] [blame] | 47 | enum Kind { |
| 48 | Base, |
Eugene Leviant | 9d278b6 | 2016-08-10 18:10:41 +0000 | [diff] [blame] | 49 | Dynamic, |
| 50 | EHFrame, |
| 51 | EHFrameHdr, |
| 52 | GnuHashTable, |
| 53 | Got, |
| 54 | GotPlt, |
| 55 | HashTable, |
Eugene Leviant | 9d278b6 | 2016-08-10 18:10:41 +0000 | [diff] [blame] | 56 | Merge, |
Eugene Leviant | 9d278b6 | 2016-08-10 18:10:41 +0000 | [diff] [blame] | 57 | Plt, |
| 58 | Regular, |
| 59 | Reloc, |
| 60 | StrTable, |
| 61 | SymTable, |
| 62 | VersDef, |
| 63 | VersNeed, |
| 64 | VersTable |
| 65 | }; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 66 | |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 67 | OutputSectionBase(StringRef Name, uint32_t Type, uint64_t Flags); |
| 68 | void setLMAOffset(uint64_t LMAOff) { LMAOffset = LMAOff; } |
| 69 | uint64_t getLMA() const { return Addr + LMAOffset; } |
| 70 | template <typename ELFT> void writeHeaderTo(typename ELFT::Shdr *SHdr); |
Rafael Espindola | 63732f5 | 2016-11-04 13:20:45 +0000 | [diff] [blame] | 71 | StringRef getName() const { return Name; } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 72 | |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 73 | virtual void addSection(InputSectionData *C) {} |
Eugene Leviant | 9d278b6 | 2016-08-10 18:10:41 +0000 | [diff] [blame] | 74 | virtual Kind getKind() const { return Base; } |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 75 | static bool classof(const OutputSectionBase *B) { |
Eugene Leviant | 9d278b6 | 2016-08-10 18:10:41 +0000 | [diff] [blame] | 76 | return B->getKind() == Base; |
| 77 | } |
Rui Ueyama | 40845e6 | 2015-12-26 05:51:07 +0000 | [diff] [blame] | 78 | |
Rui Ueyama | 2317d0d | 2015-10-15 20:55:22 +0000 | [diff] [blame] | 79 | unsigned SectionIndex; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 80 | |
Rafael Espindola | 0b11367 | 2016-07-27 14:10:56 +0000 | [diff] [blame] | 81 | uint32_t getPhdrFlags() const; |
Rui Ueyama | 3b04d83 | 2016-07-14 05:46:24 +0000 | [diff] [blame] | 82 | |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 83 | void updateAlignment(uint64_t Alignment) { |
Rafael Espindola | 04a2e34 | 2016-11-09 01:42:41 +0000 | [diff] [blame] | 84 | if (Alignment > Addralign) |
| 85 | Addralign = Alignment; |
Rafael Espindola | 115f0f3 | 2015-11-03 14:13:40 +0000 | [diff] [blame] | 86 | } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 87 | |
Rui Ueyama | 4709190 | 2016-03-30 19:41:51 +0000 | [diff] [blame] | 88 | // If true, this section will be page aligned on disk. |
| 89 | // Typically the first section of each PT_LOAD segment has this flag. |
| 90 | bool PageAlign = false; |
| 91 | |
Eugene Leviant | 3d9abec | 2016-09-29 09:20:33 +0000 | [diff] [blame] | 92 | // Pointer to the first section in PT_LOAD segment, which this section |
| 93 | // also resides in. This field is used to correctly compute file offset |
| 94 | // of a section. When two sections share the same load segment, difference |
| 95 | // between their file offsets should be equal to difference between their |
| 96 | // virtual addresses. To compute some section offset we use the following |
| 97 | // formula: Off = Off_first + VA - VA_first. |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 98 | OutputSectionBase *FirstInPtLoad = nullptr; |
Eugene Leviant | 3d9abec | 2016-09-29 09:20:33 +0000 | [diff] [blame] | 99 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 100 | virtual void finalize() {} |
Rui Ueyama | 406b469 | 2016-05-27 14:39:13 +0000 | [diff] [blame] | 101 | virtual void finalizePieces() {} |
Rui Ueyama | 809d8e2 | 2016-06-23 04:33:42 +0000 | [diff] [blame] | 102 | virtual void assignOffsets() {} |
Rafael Espindola | 4fc6044 | 2016-02-10 22:43:13 +0000 | [diff] [blame] | 103 | virtual void writeTo(uint8_t *Buf) {} |
Rui Ueyama | d4ea7dd | 2015-12-26 07:01:26 +0000 | [diff] [blame] | 104 | virtual ~OutputSectionBase() = default; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 105 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 106 | StringRef Name; |
Rafael Espindola | 04a2e34 | 2016-11-09 01:42:41 +0000 | [diff] [blame] | 107 | |
| 108 | // The following fields correspond to Elf_Shdr members. |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 109 | uint64_t Size = 0; |
| 110 | uint64_t Entsize = 0; |
| 111 | uint64_t Addralign = 0; |
| 112 | uint64_t Offset = 0; |
| 113 | uint64_t Flags = 0; |
| 114 | uint64_t LMAOffset = 0; |
| 115 | uint64_t Addr = 0; |
Rafael Espindola | 04a2e34 | 2016-11-09 01:42:41 +0000 | [diff] [blame] | 116 | uint32_t ShName = 0; |
| 117 | uint32_t Type = 0; |
| 118 | uint32_t Info = 0; |
| 119 | uint32_t Link = 0; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 120 | }; |
| 121 | |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 122 | template <class ELFT> class GdbIndexSection final : public OutputSectionBase { |
George Rimar | 58fa524 | 2016-10-20 09:19:48 +0000 | [diff] [blame] | 123 | typedef typename ELFT::uint uintX_t; |
| 124 | |
| 125 | const unsigned OffsetTypeSize = 4; |
| 126 | const unsigned CuListOffset = 6 * OffsetTypeSize; |
| 127 | const unsigned CompilationUnitSize = 16; |
| 128 | const unsigned AddressEntrySize = 16 + OffsetTypeSize; |
| 129 | const unsigned SymTabEntrySize = 2 * OffsetTypeSize; |
| 130 | |
| 131 | public: |
| 132 | GdbIndexSection(); |
| 133 | void finalize() override; |
| 134 | void writeTo(uint8_t *Buf) override; |
| 135 | |
| 136 | // Pairs of [CU Offset, CU length]. |
| 137 | std::vector<std::pair<uintX_t, uintX_t>> CompilationUnits; |
| 138 | |
| 139 | private: |
| 140 | void parseDebugSections(); |
| 141 | void readDwarf(InputSection<ELFT> *I); |
| 142 | |
| 143 | uint32_t CuTypesOffset; |
| 144 | }; |
| 145 | |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 146 | template <class ELFT> class GotSection final : public OutputSectionBase { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 147 | typedef typename ELFT::uint uintX_t; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 148 | |
| 149 | public: |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 150 | GotSection(); |
Igor Kudrin | 15cd9ff | 2015-11-06 07:43:03 +0000 | [diff] [blame] | 151 | void finalize() override; |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 152 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | 67d72c0 | 2016-03-11 12:06:30 +0000 | [diff] [blame] | 153 | void addEntry(SymbolBody &Sym); |
Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 154 | void addMipsEntry(SymbolBody &Sym, uintX_t Addend, RelExpr Expr); |
Rafael Espindola | 67d72c0 | 2016-03-11 12:06:30 +0000 | [diff] [blame] | 155 | bool addDynTlsEntry(SymbolBody &Sym); |
Rui Ueyama | 0e53c7d | 2016-02-05 00:10:02 +0000 | [diff] [blame] | 156 | bool addTlsIndex(); |
Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 157 | bool empty() const { return MipsPageEntries == 0 && Entries.empty(); } |
Rafael Espindola | 58cd5db | 2016-04-19 22:46:03 +0000 | [diff] [blame] | 158 | uintX_t getMipsLocalPageOffset(uintX_t Addr); |
Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 159 | uintX_t getMipsGotOffset(const SymbolBody &B, uintX_t Addend) const; |
George Rimar | 90cd0a8 | 2015-12-01 19:20:26 +0000 | [diff] [blame] | 160 | uintX_t getGlobalDynAddr(const SymbolBody &B) const; |
Rafael Espindola | 74031ba | 2016-04-07 15:20:56 +0000 | [diff] [blame] | 161 | uintX_t getGlobalDynOffset(const SymbolBody &B) const; |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 162 | Kind getKind() const override { return Got; } |
| 163 | static bool classof(const OutputSectionBase *B) { |
| 164 | return B->getKind() == Got; |
| 165 | } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 166 | |
Igor Kudrin | 304860a | 2015-11-12 04:39:49 +0000 | [diff] [blame] | 167 | // Returns the symbol which corresponds to the first entry of the global part |
| 168 | // of GOT on MIPS platform. It is required to fill up MIPS-specific dynamic |
| 169 | // table properties. |
| 170 | // Returns nullptr if the global part is empty. |
| 171 | const SymbolBody *getMipsFirstGlobalEntry() const; |
| 172 | |
| 173 | // Returns the number of entries in the local part of GOT including |
| 174 | // the number of reserved entries. This method is MIPS-specific. |
| 175 | unsigned getMipsLocalEntriesNum() const; |
| 176 | |
Simon Atanasyan | 002e244 | 2016-06-23 15:26:31 +0000 | [diff] [blame] | 177 | // Returns offset of TLS part of the MIPS GOT table. This part goes |
| 178 | // after 'local' and 'global' entries. |
Simon Atanasyan | bc94693 | 2016-10-19 17:13:43 +0000 | [diff] [blame] | 179 | uintX_t getMipsTlsOffset() const; |
Simon Atanasyan | 002e244 | 2016-06-23 15:26:31 +0000 | [diff] [blame] | 180 | |
Rafael Espindola | 04a2e34 | 2016-11-09 01:42:41 +0000 | [diff] [blame] | 181 | uintX_t getTlsIndexVA() { return this->Addr + TlsIndexOff; } |
Simon Atanasyan | bc94693 | 2016-10-19 17:13:43 +0000 | [diff] [blame] | 182 | uint32_t getTlsIndexOff() const { return TlsIndexOff; } |
George Rimar | b17f739 | 2015-12-01 18:24:07 +0000 | [diff] [blame] | 183 | |
Rui Ueyama | 022d8e8 | 2016-05-24 03:36:07 +0000 | [diff] [blame] | 184 | // Flag to force GOT to be in output if we have relocations |
| 185 | // that relies on its address. |
| 186 | bool HasGotOffRel = false; |
| 187 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 188 | private: |
| 189 | std::vector<const SymbolBody *> Entries; |
Rui Ueyama | 0e53c7d | 2016-02-05 00:10:02 +0000 | [diff] [blame] | 190 | uint32_t TlsIndexOff = -1; |
Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 191 | uint32_t MipsPageEntries = 0; |
Simon Atanasyan | d2980d3 | 2016-03-29 14:07:22 +0000 | [diff] [blame] | 192 | // Output sections referenced by MIPS GOT relocations. |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 193 | llvm::SmallPtrSet<const OutputSectionBase *, 10> MipsOutSections; |
Simon Atanasyan | 56ab5f0 | 2016-01-21 05:33:23 +0000 | [diff] [blame] | 194 | llvm::DenseMap<uintX_t, size_t> MipsLocalGotPos; |
Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 195 | |
| 196 | // MIPS ABI requires to create unique GOT entry for each Symbol/Addend |
| 197 | // pairs. The `MipsGotMap` maps (S,A) pair to the GOT index in the `MipsLocal` |
| 198 | // or `MipsGlobal` vectors. In general it does not have a sence to take in |
| 199 | // account addend for preemptible symbols because the corresponding |
| 200 | // GOT entries should have one-to-one mapping with dynamic symbols table. |
| 201 | // But we use the same container's types for both kind of GOT entries |
| 202 | // to handle them uniformly. |
George Rimar | a4c7e74 | 2016-10-20 08:36:42 +0000 | [diff] [blame] | 203 | typedef std::pair<const SymbolBody *, uintX_t> MipsGotEntry; |
Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 204 | typedef std::vector<MipsGotEntry> MipsGotEntries; |
| 205 | llvm::DenseMap<MipsGotEntry, size_t> MipsGotMap; |
| 206 | MipsGotEntries MipsLocal; |
Simon Atanasyan | bed04bf | 2016-10-21 07:22:30 +0000 | [diff] [blame] | 207 | MipsGotEntries MipsLocal32; |
Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 208 | MipsGotEntries MipsGlobal; |
| 209 | |
| 210 | // Write MIPS-specific parts of the GOT. |
Simon Atanasyan | 919a58c | 2016-09-08 09:07:19 +0000 | [diff] [blame] | 211 | void writeMipsGot(uint8_t *Buf); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 212 | }; |
| 213 | |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 214 | template <class ELFT> class GotPltSection final : public OutputSectionBase { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 215 | typedef typename ELFT::uint uintX_t; |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 216 | |
| 217 | public: |
| 218 | GotPltSection(); |
| 219 | void finalize() override; |
| 220 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | 67d72c0 | 2016-03-11 12:06:30 +0000 | [diff] [blame] | 221 | void addEntry(SymbolBody &Sym); |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 222 | bool empty() const; |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 223 | Kind getKind() const override { return GotPlt; } |
| 224 | static bool classof(const OutputSectionBase *B) { |
| 225 | return B->getKind() == GotPlt; |
| 226 | } |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 227 | |
| 228 | private: |
| 229 | std::vector<const SymbolBody *> Entries; |
| 230 | }; |
| 231 | |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 232 | template <class ELFT> class PltSection final : public OutputSectionBase { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 233 | typedef typename ELFT::uint uintX_t; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 234 | |
| 235 | public: |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 236 | PltSection(); |
Hal Finkel | 6c2a3b8 | 2015-10-08 21:51:31 +0000 | [diff] [blame] | 237 | void finalize() override; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 238 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | 67d72c0 | 2016-03-11 12:06:30 +0000 | [diff] [blame] | 239 | void addEntry(SymbolBody &Sym); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 240 | bool empty() const { return Entries.empty(); } |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 241 | Kind getKind() const override { return Plt; } |
| 242 | static bool classof(const OutputSectionBase *B) { |
| 243 | return B->getKind() == Plt; |
| 244 | } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 245 | |
| 246 | private: |
George Rimar | 77b7779 | 2015-11-25 22:15:01 +0000 | [diff] [blame] | 247 | std::vector<std::pair<const SymbolBody *, unsigned>> Entries; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 248 | }; |
| 249 | |
Rui Ueyama | 809d8e2 | 2016-06-23 04:33:42 +0000 | [diff] [blame] | 250 | template <class ELFT> class DynamicReloc { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 251 | typedef typename ELFT::uint uintX_t; |
Rui Ueyama | 809d8e2 | 2016-06-23 04:33:42 +0000 | [diff] [blame] | 252 | |
| 253 | public: |
| 254 | DynamicReloc(uint32_t Type, const InputSectionBase<ELFT> *InputSec, |
| 255 | uintX_t OffsetInSec, bool UseSymVA, SymbolBody *Sym, |
| 256 | uintX_t Addend) |
| 257 | : Type(Type), Sym(Sym), InputSec(InputSec), OffsetInSec(OffsetInSec), |
| 258 | UseSymVA(UseSymVA), Addend(Addend) {} |
| 259 | |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 260 | DynamicReloc(uint32_t Type, const OutputSectionBase *OutputSec, |
Rui Ueyama | 809d8e2 | 2016-06-23 04:33:42 +0000 | [diff] [blame] | 261 | uintX_t OffsetInSec, bool UseSymVA, SymbolBody *Sym, |
| 262 | uintX_t Addend) |
| 263 | : Type(Type), Sym(Sym), OutputSec(OutputSec), OffsetInSec(OffsetInSec), |
| 264 | UseSymVA(UseSymVA), Addend(Addend) {} |
| 265 | |
| 266 | uintX_t getOffset() const; |
| 267 | uintX_t getAddend() const; |
| 268 | uint32_t getSymIndex() const; |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 269 | const OutputSectionBase *getOutputSec() const { return OutputSec; } |
Rui Ueyama | 809d8e2 | 2016-06-23 04:33:42 +0000 | [diff] [blame] | 270 | |
Rafael Espindola | de9857e | 2016-02-04 21:33:05 +0000 | [diff] [blame] | 271 | uint32_t Type; |
| 272 | |
Rui Ueyama | 809d8e2 | 2016-06-23 04:33:42 +0000 | [diff] [blame] | 273 | private: |
Rafael Espindola | ac568f9 | 2016-04-11 13:47:35 +0000 | [diff] [blame] | 274 | SymbolBody *Sym; |
Rui Ueyama | 809d8e2 | 2016-06-23 04:33:42 +0000 | [diff] [blame] | 275 | const InputSectionBase<ELFT> *InputSec = nullptr; |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 276 | const OutputSectionBase *OutputSec = nullptr; |
Rafael Espindola | ac568f9 | 2016-04-11 13:47:35 +0000 | [diff] [blame] | 277 | uintX_t OffsetInSec; |
| 278 | bool UseSymVA; |
| 279 | uintX_t Addend; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 280 | }; |
| 281 | |
Michael J. Spencer | f8a8148 | 2016-10-19 23:49:27 +0000 | [diff] [blame] | 282 | struct SymbolTableEntry { |
| 283 | SymbolBody *Symbol; |
Reid Kleckner | 2918d0b | 2016-10-20 00:13:34 +0000 | [diff] [blame] | 284 | size_t StrTabOffset; |
Michael J. Spencer | f8a8148 | 2016-10-19 23:49:27 +0000 | [diff] [blame] | 285 | }; |
| 286 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 287 | template <class ELFT> |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 288 | class SymbolTableSection final : public OutputSectionBase { |
| 289 | typedef OutputSectionBase Base; |
Eugene Leviant | 9d278b6 | 2016-08-10 18:10:41 +0000 | [diff] [blame] | 290 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 291 | public: |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 292 | typedef typename ELFT::Shdr Elf_Shdr; |
| 293 | typedef typename ELFT::Sym Elf_Sym; |
| 294 | typedef typename ELFT::SymRange Elf_Sym_Range; |
| 295 | typedef typename ELFT::uint uintX_t; |
Rui Ueyama | ace4f90 | 2016-05-24 04:25:47 +0000 | [diff] [blame] | 296 | SymbolTableSection(StringTableSection<ELFT> &StrTabSec); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 297 | |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 298 | void finalize() override; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 299 | void writeTo(uint8_t *Buf) override; |
Igor Kudrin | ab665fc | 2015-10-20 21:47:58 +0000 | [diff] [blame] | 300 | void addSymbol(SymbolBody *Body); |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 301 | StringTableSection<ELFT> &getStrTabSec() const { return StrTabSec; } |
Rafael Espindola | 0e92f24 | 2016-01-27 16:41:24 +0000 | [diff] [blame] | 302 | unsigned getNumSymbols() const { return NumLocals + Symbols.size() + 1; } |
Eugene Leviant | 9d278b6 | 2016-08-10 18:10:41 +0000 | [diff] [blame] | 303 | typename Base::Kind getKind() const override { return Base::SymTable; } |
| 304 | static bool classof(const Base *B) { return B->getKind() == Base::SymTable; } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 305 | |
George Rimar | a4c7e74 | 2016-10-20 08:36:42 +0000 | [diff] [blame] | 306 | ArrayRef<SymbolTableEntry> getSymbols() const { return Symbols; } |
Rafael Espindola | e2c2461 | 2016-01-29 01:24:25 +0000 | [diff] [blame] | 307 | |
| 308 | unsigned NumLocals = 0; |
| 309 | StringTableSection<ELFT> &StrTabSec; |
Igor Kudrin | ab665fc | 2015-10-20 21:47:58 +0000 | [diff] [blame] | 310 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 311 | private: |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 312 | void writeLocalSymbols(uint8_t *&Buf); |
Igor Kudrin | ea6a835 | 2015-10-19 08:01:51 +0000 | [diff] [blame] | 313 | void writeGlobalSymbols(uint8_t *Buf); |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 314 | |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 315 | const OutputSectionBase *getOutputSection(SymbolBody *Sym); |
Igor Kudrin | 853b88d | 2015-10-20 20:52:14 +0000 | [diff] [blame] | 316 | |
Rui Ueyama | c2e863a | 2016-02-17 05:06:40 +0000 | [diff] [blame] | 317 | // A vector of symbols and their string table offsets. |
Michael J. Spencer | f8a8148 | 2016-10-19 23:49:27 +0000 | [diff] [blame] | 318 | std::vector<SymbolTableEntry> Symbols; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 319 | }; |
| 320 | |
Peter Collingbourne | 21a12fc | 2016-04-27 20:22:31 +0000 | [diff] [blame] | 321 | // For more information about .gnu.version and .gnu.version_r see: |
| 322 | // https://www.akkadia.org/drepper/symbol-versioning |
| 323 | |
George Rimar | d356630 | 2016-06-20 11:55:12 +0000 | [diff] [blame] | 324 | // The .gnu.version_d section which has a section type of SHT_GNU_verdef shall |
| 325 | // contain symbol version definitions. The number of entries in this section |
| 326 | // shall be contained in the DT_VERDEFNUM entry of the .dynamic section. |
| 327 | // The section shall contain an array of Elf_Verdef structures, optionally |
| 328 | // followed by an array of Elf_Verdaux structures. |
| 329 | template <class ELFT> |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 330 | class VersionDefinitionSection final : public OutputSectionBase { |
George Rimar | d356630 | 2016-06-20 11:55:12 +0000 | [diff] [blame] | 331 | typedef typename ELFT::Verdef Elf_Verdef; |
| 332 | typedef typename ELFT::Verdaux Elf_Verdaux; |
| 333 | |
George Rimar | d356630 | 2016-06-20 11:55:12 +0000 | [diff] [blame] | 334 | public: |
| 335 | VersionDefinitionSection(); |
| 336 | void finalize() override; |
| 337 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 338 | Kind getKind() const override { return VersDef; } |
| 339 | static bool classof(const OutputSectionBase *B) { |
| 340 | return B->getKind() == VersDef; |
| 341 | } |
Rui Ueyama | 9f61964 | 2016-07-16 02:29:45 +0000 | [diff] [blame] | 342 | |
| 343 | private: |
| 344 | void writeOne(uint8_t *Buf, uint32_t Index, StringRef Name, size_t NameOff); |
| 345 | |
| 346 | unsigned FileDefNameOff; |
George Rimar | d356630 | 2016-06-20 11:55:12 +0000 | [diff] [blame] | 347 | }; |
| 348 | |
Peter Collingbourne | 21a12fc | 2016-04-27 20:22:31 +0000 | [diff] [blame] | 349 | // The .gnu.version section specifies the required version of each symbol in the |
| 350 | // dynamic symbol table. It contains one Elf_Versym for each dynamic symbol |
| 351 | // table entry. An Elf_Versym is just a 16-bit integer that refers to a version |
George Rimar | d356630 | 2016-06-20 11:55:12 +0000 | [diff] [blame] | 352 | // identifier defined in the either .gnu.version_r or .gnu.version_d section. |
| 353 | // The values 0 and 1 are reserved. All other values are used for versions in |
| 354 | // the own object or in any of the dependencies. |
Peter Collingbourne | 21a12fc | 2016-04-27 20:22:31 +0000 | [diff] [blame] | 355 | template <class ELFT> |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 356 | class VersionTableSection final : public OutputSectionBase { |
Peter Collingbourne | 21a12fc | 2016-04-27 20:22:31 +0000 | [diff] [blame] | 357 | typedef typename ELFT::Versym Elf_Versym; |
| 358 | |
| 359 | public: |
| 360 | VersionTableSection(); |
| 361 | void finalize() override; |
| 362 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 363 | Kind getKind() const override { return VersTable; } |
| 364 | static bool classof(const OutputSectionBase *B) { |
| 365 | return B->getKind() == VersTable; |
| 366 | } |
Peter Collingbourne | 21a12fc | 2016-04-27 20:22:31 +0000 | [diff] [blame] | 367 | }; |
| 368 | |
| 369 | // The .gnu.version_r section defines the version identifiers used by |
| 370 | // .gnu.version. It contains a linked list of Elf_Verneed data structures. Each |
| 371 | // Elf_Verneed specifies the version requirements for a single DSO, and contains |
| 372 | // a reference to a linked list of Elf_Vernaux data structures which define the |
| 373 | // mapping from version identifiers to version names. |
| 374 | template <class ELFT> |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 375 | class VersionNeedSection final : public OutputSectionBase { |
Peter Collingbourne | 21a12fc | 2016-04-27 20:22:31 +0000 | [diff] [blame] | 376 | typedef typename ELFT::Verneed Elf_Verneed; |
| 377 | typedef typename ELFT::Vernaux Elf_Vernaux; |
| 378 | |
| 379 | // A vector of shared files that need Elf_Verneed data structures and the |
| 380 | // string table offsets of their sonames. |
| 381 | std::vector<std::pair<SharedFile<ELFT> *, size_t>> Needed; |
| 382 | |
George Rimar | d356630 | 2016-06-20 11:55:12 +0000 | [diff] [blame] | 383 | // The next available version identifier. |
| 384 | unsigned NextIndex; |
Peter Collingbourne | 21a12fc | 2016-04-27 20:22:31 +0000 | [diff] [blame] | 385 | |
| 386 | public: |
| 387 | VersionNeedSection(); |
| 388 | void addSymbol(SharedSymbol<ELFT> *SS); |
| 389 | void finalize() override; |
| 390 | void writeTo(uint8_t *Buf) override; |
| 391 | size_t getNeedNum() const { return Needed.size(); } |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 392 | Kind getKind() const override { return VersNeed; } |
| 393 | static bool classof(const OutputSectionBase *B) { |
| 394 | return B->getKind() == VersNeed; |
| 395 | } |
Peter Collingbourne | 21a12fc | 2016-04-27 20:22:31 +0000 | [diff] [blame] | 396 | }; |
| 397 | |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 398 | template <class ELFT> class RelocationSection final : public OutputSectionBase { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 399 | typedef typename ELFT::Rel Elf_Rel; |
| 400 | typedef typename ELFT::Rela Elf_Rela; |
| 401 | typedef typename ELFT::uint uintX_t; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 402 | |
| 403 | public: |
George Rimar | c191acf | 2016-05-10 15:47:57 +0000 | [diff] [blame] | 404 | RelocationSection(StringRef Name, bool Sort); |
Rafael Espindola | d30eb7d | 2016-02-05 15:03:10 +0000 | [diff] [blame] | 405 | void addReloc(const DynamicReloc<ELFT> &Reloc); |
George Rimar | 77b7779 | 2015-11-25 22:15:01 +0000 | [diff] [blame] | 406 | unsigned getRelocOffset(); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 407 | void finalize() override; |
| 408 | void writeTo(uint8_t *Buf) override; |
| 409 | bool hasRelocs() const { return !Relocs.empty(); } |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 410 | Kind getKind() const override { return Reloc; } |
Eugene Leviant | aa49819 | 2016-08-31 08:51:39 +0000 | [diff] [blame] | 411 | size_t getRelativeRelocCount() const { return NumRelativeRelocs; } |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 412 | static bool classof(const OutputSectionBase *B) { |
| 413 | return B->getKind() == Reloc; |
| 414 | } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 415 | |
| 416 | private: |
George Rimar | c191acf | 2016-05-10 15:47:57 +0000 | [diff] [blame] | 417 | bool Sort; |
Eugene Leviant | aa49819 | 2016-08-31 08:51:39 +0000 | [diff] [blame] | 418 | size_t NumRelativeRelocs = 0; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 419 | std::vector<DynamicReloc<ELFT>> Relocs; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 420 | }; |
| 421 | |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 422 | template <class ELFT> class OutputSection final : public OutputSectionBase { |
Eugene Leviant | 9d278b6 | 2016-08-10 18:10:41 +0000 | [diff] [blame] | 423 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 424 | public: |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 425 | typedef typename ELFT::Shdr Elf_Shdr; |
| 426 | typedef typename ELFT::Sym Elf_Sym; |
| 427 | typedef typename ELFT::Rel Elf_Rel; |
| 428 | typedef typename ELFT::Rela Elf_Rela; |
| 429 | typedef typename ELFT::uint uintX_t; |
George Rimar | 9bec24a | 2016-02-18 14:20:08 +0000 | [diff] [blame] | 430 | OutputSection(StringRef Name, uint32_t Type, uintX_t Flags); |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 431 | void addSection(InputSectionData *C) override; |
George Rimar | 1a33c0f | 2016-11-10 09:05:20 +0000 | [diff] [blame^] | 432 | void sort(std::function<unsigned(InputSection<ELFT> *S)> Order); |
Rui Ueyama | 5af8368 | 2016-02-11 23:41:38 +0000 | [diff] [blame] | 433 | void sortInitFini(); |
| 434 | void sortCtorsDtors(); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 435 | void writeTo(uint8_t *Buf) override; |
George Rimar | 58941ee | 2016-02-25 08:23:37 +0000 | [diff] [blame] | 436 | void finalize() override; |
Rui Ueyama | 809d8e2 | 2016-06-23 04:33:42 +0000 | [diff] [blame] | 437 | void assignOffsets() override; |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 438 | Kind getKind() const override { return Regular; } |
| 439 | static bool classof(const OutputSectionBase *B) { |
| 440 | return B->getKind() == Regular; |
| 441 | } |
Rafael Espindola | 7167585 | 2015-09-22 00:16:19 +0000 | [diff] [blame] | 442 | std::vector<InputSection<ELFT> *> Sections; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 443 | }; |
| 444 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 445 | template <class ELFT> |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 446 | class MergeOutputSection final : public OutputSectionBase { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 447 | typedef typename ELFT::uint uintX_t; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 448 | |
| 449 | public: |
Rafael Espindola | 7efa5be | 2016-02-19 14:17:40 +0000 | [diff] [blame] | 450 | MergeOutputSection(StringRef Name, uint32_t Type, uintX_t Flags, |
| 451 | uintX_t Alignment); |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 452 | void addSection(InputSectionData *S) override; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 453 | void writeTo(uint8_t *Buf) override; |
Justin Lebar | ee34a73 | 2016-10-17 22:24:36 +0000 | [diff] [blame] | 454 | unsigned getOffset(llvm::CachedHashStringRef Val); |
Rafael Espindola | f82ed2a | 2015-10-24 22:51:01 +0000 | [diff] [blame] | 455 | void finalize() override; |
Rui Ueyama | 406b469 | 2016-05-27 14:39:13 +0000 | [diff] [blame] | 456 | void finalizePieces() override; |
Peter Collingbourne | e29e142 | 2016-05-05 04:10:12 +0000 | [diff] [blame] | 457 | bool shouldTailMerge() const; |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 458 | Kind getKind() const override { return Merge; } |
| 459 | static bool classof(const OutputSectionBase *B) { |
| 460 | return B->getKind() == Merge; |
| 461 | } |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 462 | |
| 463 | private: |
Rafael Espindola | 7efa5be | 2016-02-19 14:17:40 +0000 | [diff] [blame] | 464 | llvm::StringTableBuilder Builder; |
Rui Ueyama | 406b469 | 2016-05-27 14:39:13 +0000 | [diff] [blame] | 465 | std::vector<MergeInputSection<ELFT> *> Sections; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 466 | }; |
| 467 | |
Rui Ueyama | f8b285c | 2016-05-22 23:16:14 +0000 | [diff] [blame] | 468 | struct CieRecord { |
Rafael Espindola | 2deeb60 | 2016-07-21 20:18:30 +0000 | [diff] [blame] | 469 | EhSectionPiece *Piece = nullptr; |
| 470 | std::vector<EhSectionPiece *> FdePieces; |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 471 | }; |
| 472 | |
Rui Ueyama | f8b285c | 2016-05-22 23:16:14 +0000 | [diff] [blame] | 473 | // Output section for .eh_frame. |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 474 | template <class ELFT> class EhOutputSection final : public OutputSectionBase { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 475 | typedef typename ELFT::uint uintX_t; |
| 476 | typedef typename ELFT::Shdr Elf_Shdr; |
| 477 | typedef typename ELFT::Rel Elf_Rel; |
| 478 | typedef typename ELFT::Rela Elf_Rela; |
Rui Ueyama | f86cb90 | 2016-05-23 15:12:41 +0000 | [diff] [blame] | 479 | |
| 480 | public: |
| 481 | EhOutputSection(); |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 482 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | 56004c5 | 2016-04-07 14:22:09 +0000 | [diff] [blame] | 483 | void finalize() override; |
Rui Ueyama | 3b31e67 | 2016-05-23 16:24:16 +0000 | [diff] [blame] | 484 | bool empty() const { return Sections.empty(); } |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 485 | |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 486 | void addSection(InputSectionData *S) override; |
| 487 | Kind getKind() const override { return EHFrame; } |
| 488 | static bool classof(const OutputSectionBase *B) { |
| 489 | return B->getKind() == EHFrame; |
| 490 | } |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 491 | |
Rui Ueyama | de9777a | 2016-05-23 16:30:41 +0000 | [diff] [blame] | 492 | size_t NumFdes = 0; |
| 493 | |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 494 | private: |
Rui Ueyama | f8b285c | 2016-05-22 23:16:14 +0000 | [diff] [blame] | 495 | template <class RelTy> |
Rui Ueyama | 0b9a903 | 2016-05-24 04:19:20 +0000 | [diff] [blame] | 496 | void addSectionAux(EhInputSection<ELFT> *S, llvm::ArrayRef<RelTy> Rels); |
Rui Ueyama | f8b285c | 2016-05-22 23:16:14 +0000 | [diff] [blame] | 497 | |
Rui Ueyama | f8b285c | 2016-05-22 23:16:14 +0000 | [diff] [blame] | 498 | template <class RelTy> |
Rafael Espindola | 2deeb60 | 2016-07-21 20:18:30 +0000 | [diff] [blame] | 499 | CieRecord *addCie(EhSectionPiece &Piece, EhInputSection<ELFT> *Sec, |
| 500 | ArrayRef<RelTy> Rels); |
Rui Ueyama | f8b285c | 2016-05-22 23:16:14 +0000 | [diff] [blame] | 501 | |
| 502 | template <class RelTy> |
Rafael Espindola | 2deeb60 | 2016-07-21 20:18:30 +0000 | [diff] [blame] | 503 | bool isFdeLive(EhSectionPiece &Piece, EhInputSection<ELFT> *Sec, |
| 504 | ArrayRef<RelTy> Rels); |
Rui Ueyama | f8b285c | 2016-05-22 23:16:14 +0000 | [diff] [blame] | 505 | |
Rui Ueyama | e75e933 | 2016-05-23 03:00:33 +0000 | [diff] [blame] | 506 | uintX_t getFdePc(uint8_t *Buf, size_t Off, uint8_t Enc); |
| 507 | |
Rui Ueyama | 0b9a903 | 2016-05-24 04:19:20 +0000 | [diff] [blame] | 508 | std::vector<EhInputSection<ELFT> *> Sections; |
Rui Ueyama | f8b285c | 2016-05-22 23:16:14 +0000 | [diff] [blame] | 509 | std::vector<CieRecord *> Cies; |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 510 | |
Rui Ueyama | f8b285c | 2016-05-22 23:16:14 +0000 | [diff] [blame] | 511 | // CIE records are uniquified by their contents and personality functions. |
| 512 | llvm::DenseMap<std::pair<ArrayRef<uint8_t>, SymbolBody *>, CieRecord> CieMap; |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 513 | }; |
| 514 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 515 | template <class ELFT> |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 516 | class StringTableSection final : public OutputSectionBase { |
Eugene Leviant | 9d278b6 | 2016-08-10 18:10:41 +0000 | [diff] [blame] | 517 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 518 | public: |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 519 | typedef typename ELFT::uint uintX_t; |
George Rimar | 0f5ac9f | 2015-10-20 17:21:35 +0000 | [diff] [blame] | 520 | StringTableSection(StringRef Name, bool Dynamic); |
Rafael Espindola | e2c2461 | 2016-01-29 01:24:25 +0000 | [diff] [blame] | 521 | unsigned addString(StringRef S, bool HashIt = true); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 522 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 523 | bool isDynamic() const { return Dynamic; } |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 524 | Kind getKind() const override { return StrTable; } |
| 525 | static bool classof(const OutputSectionBase *B) { |
| 526 | return B->getKind() == StrTable; |
| 527 | } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 528 | |
| 529 | private: |
| 530 | const bool Dynamic; |
Rafael Espindola | e2c2461 | 2016-01-29 01:24:25 +0000 | [diff] [blame] | 531 | llvm::DenseMap<StringRef, unsigned> StringMap; |
Rui Ueyama | 76c0063 | 2016-01-07 02:35:32 +0000 | [diff] [blame] | 532 | std::vector<StringRef> Strings; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 533 | }; |
| 534 | |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 535 | template <class ELFT> class HashTableSection final : public OutputSectionBase { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 536 | typedef typename ELFT::Word Elf_Word; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 537 | |
| 538 | public: |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 539 | HashTableSection(); |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 540 | void finalize() override; |
| 541 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 542 | Kind getKind() const override { return HashTable; } |
| 543 | static bool classof(const OutputSectionBase *B) { |
| 544 | return B->getKind() == HashTable; |
| 545 | } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 546 | }; |
| 547 | |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 548 | // Outputs GNU Hash section. For detailed explanation see: |
| 549 | // https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections |
| 550 | template <class ELFT> |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 551 | class GnuHashTableSection final : public OutputSectionBase { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 552 | typedef typename ELFT::Off Elf_Off; |
| 553 | typedef typename ELFT::Word Elf_Word; |
| 554 | typedef typename ELFT::uint uintX_t; |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 555 | |
| 556 | public: |
| 557 | GnuHashTableSection(); |
| 558 | void finalize() override; |
| 559 | void writeTo(uint8_t *Buf) override; |
| 560 | |
Igor Kudrin | f1d6029 | 2015-10-28 07:05:56 +0000 | [diff] [blame] | 561 | // Adds symbols to the hash table. |
| 562 | // Sorts the input to satisfy GNU hash section requirements. |
Michael J. Spencer | f8a8148 | 2016-10-19 23:49:27 +0000 | [diff] [blame] | 563 | void addSymbols(std::vector<SymbolTableEntry> &Symbols); |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 564 | Kind getKind() const override { return GnuHashTable; } |
| 565 | static bool classof(const OutputSectionBase *B) { |
| 566 | return B->getKind() == GnuHashTable; |
Eugene Leviant | 9d278b6 | 2016-08-10 18:10:41 +0000 | [diff] [blame] | 567 | } |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 568 | |
| 569 | private: |
Igor Kudrin | f1d6029 | 2015-10-28 07:05:56 +0000 | [diff] [blame] | 570 | static unsigned calcNBuckets(unsigned NumHashed); |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 571 | static unsigned calcMaskWords(unsigned NumHashed); |
| 572 | |
| 573 | void writeHeader(uint8_t *&Buf); |
| 574 | void writeBloomFilter(uint8_t *&Buf); |
| 575 | void writeHashTable(uint8_t *Buf); |
| 576 | |
Rui Ueyama | 861c731 | 2016-02-17 05:40:03 +0000 | [diff] [blame] | 577 | struct SymbolData { |
Igor Kudrin | f1d6029 | 2015-10-28 07:05:56 +0000 | [diff] [blame] | 578 | SymbolBody *Body; |
Rui Ueyama | c2e863a | 2016-02-17 05:06:40 +0000 | [diff] [blame] | 579 | size_t STName; |
Igor Kudrin | f1d6029 | 2015-10-28 07:05:56 +0000 | [diff] [blame] | 580 | uint32_t Hash; |
| 581 | }; |
| 582 | |
Rui Ueyama | 861c731 | 2016-02-17 05:40:03 +0000 | [diff] [blame] | 583 | std::vector<SymbolData> Symbols; |
Igor Kudrin | f1d6029 | 2015-10-28 07:05:56 +0000 | [diff] [blame] | 584 | |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 585 | unsigned MaskWords; |
| 586 | unsigned NBuckets; |
| 587 | unsigned Shift2; |
| 588 | }; |
| 589 | |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 590 | template <class ELFT> class DynamicSection final : public OutputSectionBase { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 591 | typedef typename ELFT::Dyn Elf_Dyn; |
| 592 | typedef typename ELFT::Rel Elf_Rel; |
| 593 | typedef typename ELFT::Rela Elf_Rela; |
| 594 | typedef typename ELFT::Shdr Elf_Shdr; |
| 595 | typedef typename ELFT::Sym Elf_Sym; |
| 596 | typedef typename ELFT::uint uintX_t; |
Rafael Espindola | de06936 | 2016-01-25 21:32:04 +0000 | [diff] [blame] | 597 | |
Rui Ueyama | 909cc68 | 2016-02-02 03:11:27 +0000 | [diff] [blame] | 598 | // The .dynamic section contains information for the dynamic linker. |
| 599 | // The section consists of fixed size entries, which consist of |
| 600 | // type and value fields. Value are one of plain integers, symbol |
| 601 | // addresses, or section addresses. This struct represents the entry. |
Rafael Espindola | de06936 | 2016-01-25 21:32:04 +0000 | [diff] [blame] | 602 | struct Entry { |
| 603 | int32_t Tag; |
| 604 | union { |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 605 | OutputSectionBase *OutSec; |
Rafael Espindola | de06936 | 2016-01-25 21:32:04 +0000 | [diff] [blame] | 606 | uint64_t Val; |
| 607 | const SymbolBody *Sym; |
| 608 | }; |
George Rimar | 03e0560 | 2016-08-19 15:23:39 +0000 | [diff] [blame] | 609 | enum KindT { SecAddr, SecSize, SymAddr, PlainInt } Kind; |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 610 | Entry(int32_t Tag, OutputSectionBase *OutSec, KindT Kind = SecAddr) |
George Rimar | 03e0560 | 2016-08-19 15:23:39 +0000 | [diff] [blame] | 611 | : Tag(Tag), OutSec(OutSec), Kind(Kind) {} |
Rafael Espindola | de06936 | 2016-01-25 21:32:04 +0000 | [diff] [blame] | 612 | Entry(int32_t Tag, uint64_t Val) : Tag(Tag), Val(Val), Kind(PlainInt) {} |
| 613 | Entry(int32_t Tag, const SymbolBody *Sym) |
| 614 | : Tag(Tag), Sym(Sym), Kind(SymAddr) {} |
| 615 | }; |
Rui Ueyama | 909cc68 | 2016-02-02 03:11:27 +0000 | [diff] [blame] | 616 | |
| 617 | // finalize() fills this vector with the section contents. finalize() |
| 618 | // cannot directly create final section contents because when the |
| 619 | // function is called, symbol or section addresses are not fixed yet. |
Rafael Espindola | de06936 | 2016-01-25 21:32:04 +0000 | [diff] [blame] | 620 | std::vector<Entry> Entries; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 621 | |
| 622 | public: |
Rui Ueyama | a959393 | 2016-11-02 02:18:01 +0000 | [diff] [blame] | 623 | DynamicSection(); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 624 | void finalize() override; |
| 625 | void writeTo(uint8_t *Buf) override; |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 626 | Kind getKind() const override { return Dynamic; } |
| 627 | static bool classof(const OutputSectionBase *B) { |
| 628 | return B->getKind() == Dynamic; |
| 629 | } |
Rui Ueyama | a959393 | 2016-11-02 02:18:01 +0000 | [diff] [blame] | 630 | |
| 631 | private: |
| 632 | void addEntries(); |
| 633 | void Add(Entry E) { Entries.push_back(E); } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 634 | }; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 635 | |
George Rimar | f6bc65a | 2016-01-15 13:34:52 +0000 | [diff] [blame] | 636 | // --eh-frame-hdr option tells linker to construct a header for all the |
| 637 | // .eh_frame sections. This header is placed to a section named .eh_frame_hdr |
| 638 | // and also to a PT_GNU_EH_FRAME segment. |
| 639 | // At runtime the unwinder then can find all the PT_GNU_EH_FRAME segments by |
| 640 | // calling dl_iterate_phdr. |
| 641 | // This section contains a lookup table for quick binary search of FDEs. |
| 642 | // Detailed info about internals can be found in Ian Lance Taylor's blog: |
| 643 | // http://www.airs.com/blog/archives/460 (".eh_frame") |
| 644 | // http://www.airs.com/blog/archives/462 (".eh_frame_hdr") |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 645 | template <class ELFT> class EhFrameHeader final : public OutputSectionBase { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 646 | typedef typename ELFT::uint uintX_t; |
George Rimar | f6bc65a | 2016-01-15 13:34:52 +0000 | [diff] [blame] | 647 | |
| 648 | public: |
| 649 | EhFrameHeader(); |
Rui Ueyama | de9777a | 2016-05-23 16:30:41 +0000 | [diff] [blame] | 650 | void finalize() override; |
George Rimar | f6bc65a | 2016-01-15 13:34:52 +0000 | [diff] [blame] | 651 | void writeTo(uint8_t *Buf) override; |
Rui Ueyama | e75e933 | 2016-05-23 03:00:33 +0000 | [diff] [blame] | 652 | void addFde(uint32_t Pc, uint32_t FdeVA); |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 653 | Kind getKind() const override { return EHFrameHdr; } |
| 654 | static bool classof(const OutputSectionBase *B) { |
| 655 | return B->getKind() == EHFrameHdr; |
Eugene Leviant | 9d278b6 | 2016-08-10 18:10:41 +0000 | [diff] [blame] | 656 | } |
George Rimar | f6bc65a | 2016-01-15 13:34:52 +0000 | [diff] [blame] | 657 | |
George Rimar | f6bc65a | 2016-01-15 13:34:52 +0000 | [diff] [blame] | 658 | private: |
| 659 | struct FdeData { |
Rui Ueyama | e75e933 | 2016-05-23 03:00:33 +0000 | [diff] [blame] | 660 | uint32_t Pc; |
| 661 | uint32_t FdeVA; |
George Rimar | f6bc65a | 2016-01-15 13:34:52 +0000 | [diff] [blame] | 662 | }; |
| 663 | |
Rui Ueyama | e75e933 | 2016-05-23 03:00:33 +0000 | [diff] [blame] | 664 | std::vector<FdeData> Fdes; |
George Rimar | f6bc65a | 2016-01-15 13:34:52 +0000 | [diff] [blame] | 665 | }; |
| 666 | |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 667 | // All output sections that are hadnled by the linker specially are |
| 668 | // globally accessible. Writer initializes them, so don't use them |
| 669 | // until Writer is initialized. |
| 670 | template <class ELFT> struct Out { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 671 | typedef typename ELFT::uint uintX_t; |
| 672 | typedef typename ELFT::Phdr Elf_Phdr; |
Rui Ueyama | cfadbd9 | 2016-11-01 23:12:51 +0000 | [diff] [blame] | 673 | |
| 674 | static uint8_t First; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 675 | static DynamicSection<ELFT> *Dynamic; |
George Rimar | f6bc65a | 2016-01-15 13:34:52 +0000 | [diff] [blame] | 676 | static EhFrameHeader<ELFT> *EhFrameHdr; |
Rui Ueyama | 3b31e67 | 2016-05-23 16:24:16 +0000 | [diff] [blame] | 677 | static EhOutputSection<ELFT> *EhFrame; |
George Rimar | 58fa524 | 2016-10-20 09:19:48 +0000 | [diff] [blame] | 678 | static GdbIndexSection<ELFT> *GdbIndex; |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 679 | static GnuHashTableSection<ELFT> *GnuHashTab; |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 680 | static GotPltSection<ELFT> *GotPlt; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 681 | static GotSection<ELFT> *Got; |
| 682 | static HashTableSection<ELFT> *HashTab; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 683 | static OutputSection<ELFT> *Bss; |
Igor Kudrin | 304860a | 2015-11-12 04:39:49 +0000 | [diff] [blame] | 684 | static OutputSection<ELFT> *MipsRldMap; |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 685 | static OutputSectionBase *Opd; |
Hal Finkel | daedc12 | 2015-10-12 23:16:53 +0000 | [diff] [blame] | 686 | static uint8_t *OpdBuf; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 687 | static PltSection<ELFT> *Plt; |
| 688 | static RelocationSection<ELFT> *RelaDyn; |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 689 | static RelocationSection<ELFT> *RelaPlt; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 690 | static StringTableSection<ELFT> *DynStrTab; |
George Rimar | 0f5ac9f | 2015-10-20 17:21:35 +0000 | [diff] [blame] | 691 | static StringTableSection<ELFT> *ShStrTab; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 692 | static StringTableSection<ELFT> *StrTab; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 693 | static SymbolTableSection<ELFT> *DynSymTab; |
| 694 | static SymbolTableSection<ELFT> *SymTab; |
George Rimar | d356630 | 2016-06-20 11:55:12 +0000 | [diff] [blame] | 695 | static VersionDefinitionSection<ELFT> *VerDef; |
Peter Collingbourne | 21a12fc | 2016-04-27 20:22:31 +0000 | [diff] [blame] | 696 | static VersionTableSection<ELFT> *VerSym; |
| 697 | static VersionNeedSection<ELFT> *VerNeed; |
Rafael Espindola | ea7a1e90 | 2015-11-06 22:14:44 +0000 | [diff] [blame] | 698 | static Elf_Phdr *TlsPhdr; |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 699 | static OutputSectionBase *DebugInfo; |
| 700 | static OutputSectionBase *ElfHeader; |
| 701 | static OutputSectionBase *ProgramHeaders; |
| 702 | static OutputSectionBase *PreinitArray; |
| 703 | static OutputSectionBase *InitArray; |
| 704 | static OutputSectionBase *FiniArray; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 705 | }; |
Rui Ueyama | d888d10 | 2015-10-09 19:34:55 +0000 | [diff] [blame] | 706 | |
George Rimar | 6892afa | 2016-07-12 09:49:43 +0000 | [diff] [blame] | 707 | template <bool Is64Bits> struct SectionKey { |
| 708 | typedef typename std::conditional<Is64Bits, uint64_t, uint32_t>::type uintX_t; |
| 709 | StringRef Name; |
| 710 | uint32_t Type; |
| 711 | uintX_t Flags; |
| 712 | uintX_t Alignment; |
| 713 | }; |
| 714 | |
| 715 | // This class knows how to create an output section for a given |
| 716 | // input section. Output section type is determined by various |
| 717 | // factors, including input section's sh_flags, sh_type and |
| 718 | // linker scripts. |
| 719 | template <class ELFT> class OutputSectionFactory { |
| 720 | typedef typename ELFT::Shdr Elf_Shdr; |
| 721 | typedef typename ELFT::uint uintX_t; |
| 722 | typedef typename elf::SectionKey<ELFT::Is64Bits> Key; |
| 723 | |
| 724 | public: |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 725 | std::pair<OutputSectionBase *, bool> create(InputSectionBase<ELFT> *C, |
| 726 | StringRef OutsecName); |
| 727 | std::pair<OutputSectionBase *, bool> |
Rafael Espindola | 10897f1 | 2016-09-13 14:23:14 +0000 | [diff] [blame] | 728 | create(const SectionKey<ELFT::Is64Bits> &Key, InputSectionBase<ELFT> *C); |
George Rimar | 6892afa | 2016-07-12 09:49:43 +0000 | [diff] [blame] | 729 | |
George Rimar | 6892afa | 2016-07-12 09:49:43 +0000 | [diff] [blame] | 730 | private: |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 731 | llvm::SmallDenseMap<Key, OutputSectionBase *> Map; |
George Rimar | 6892afa | 2016-07-12 09:49:43 +0000 | [diff] [blame] | 732 | }; |
| 733 | |
Rafael Espindola | 0d4b6d5 | 2016-09-22 16:47:21 +0000 | [diff] [blame] | 734 | template <class ELFT> uint64_t getHeaderSize() { |
| 735 | if (Config->OFormatBinary) |
| 736 | return 0; |
Rafael Espindola | 04a2e34 | 2016-11-09 01:42:41 +0000 | [diff] [blame] | 737 | return Out<ELFT>::ElfHeader->Size + Out<ELFT>::ProgramHeaders->Size; |
Rafael Espindola | 0d4b6d5 | 2016-09-22 16:47:21 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Rui Ueyama | cfadbd9 | 2016-11-01 23:12:51 +0000 | [diff] [blame] | 740 | template <class ELFT> uint8_t Out<ELFT>::First; |
Rui Ueyama | d888d10 | 2015-10-09 19:34:55 +0000 | [diff] [blame] | 741 | template <class ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic; |
George Rimar | f6bc65a | 2016-01-15 13:34:52 +0000 | [diff] [blame] | 742 | template <class ELFT> EhFrameHeader<ELFT> *Out<ELFT>::EhFrameHdr; |
Rui Ueyama | 3b31e67 | 2016-05-23 16:24:16 +0000 | [diff] [blame] | 743 | template <class ELFT> EhOutputSection<ELFT> *Out<ELFT>::EhFrame; |
George Rimar | 58fa524 | 2016-10-20 09:19:48 +0000 | [diff] [blame] | 744 | template <class ELFT> GdbIndexSection<ELFT> *Out<ELFT>::GdbIndex; |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 745 | template <class ELFT> GnuHashTableSection<ELFT> *Out<ELFT>::GnuHashTab; |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 746 | template <class ELFT> GotPltSection<ELFT> *Out<ELFT>::GotPlt; |
Rui Ueyama | d888d10 | 2015-10-09 19:34:55 +0000 | [diff] [blame] | 747 | template <class ELFT> GotSection<ELFT> *Out<ELFT>::Got; |
| 748 | template <class ELFT> HashTableSection<ELFT> *Out<ELFT>::HashTab; |
Rafael Espindola | d7a267b | 2015-11-03 22:01:20 +0000 | [diff] [blame] | 749 | template <class ELFT> OutputSection<ELFT> *Out<ELFT>::Bss; |
Igor Kudrin | 304860a | 2015-11-12 04:39:49 +0000 | [diff] [blame] | 750 | template <class ELFT> OutputSection<ELFT> *Out<ELFT>::MipsRldMap; |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 751 | template <class ELFT> OutputSectionBase *Out<ELFT>::Opd; |
Hal Finkel | daedc12 | 2015-10-12 23:16:53 +0000 | [diff] [blame] | 752 | template <class ELFT> uint8_t *Out<ELFT>::OpdBuf; |
Rui Ueyama | d888d10 | 2015-10-09 19:34:55 +0000 | [diff] [blame] | 753 | template <class ELFT> PltSection<ELFT> *Out<ELFT>::Plt; |
| 754 | template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaDyn; |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 755 | template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaPlt; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 756 | template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::DynStrTab; |
George Rimar | 0f5ac9f | 2015-10-20 17:21:35 +0000 | [diff] [blame] | 757 | template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::ShStrTab; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 758 | template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::StrTab; |
Rui Ueyama | d888d10 | 2015-10-09 19:34:55 +0000 | [diff] [blame] | 759 | template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::DynSymTab; |
| 760 | template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::SymTab; |
George Rimar | d356630 | 2016-06-20 11:55:12 +0000 | [diff] [blame] | 761 | template <class ELFT> VersionDefinitionSection<ELFT> *Out<ELFT>::VerDef; |
Peter Collingbourne | 21a12fc | 2016-04-27 20:22:31 +0000 | [diff] [blame] | 762 | template <class ELFT> VersionTableSection<ELFT> *Out<ELFT>::VerSym; |
| 763 | template <class ELFT> VersionNeedSection<ELFT> *Out<ELFT>::VerNeed; |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 764 | template <class ELFT> typename ELFT::Phdr *Out<ELFT>::TlsPhdr; |
Rafael Espindola | e08e78d | 2016-11-09 23:23:45 +0000 | [diff] [blame] | 765 | template <class ELFT> OutputSectionBase *Out<ELFT>::DebugInfo; |
| 766 | template <class ELFT> OutputSectionBase *Out<ELFT>::ElfHeader; |
| 767 | template <class ELFT> OutputSectionBase *Out<ELFT>::ProgramHeaders; |
| 768 | template <class ELFT> OutputSectionBase *Out<ELFT>::PreinitArray; |
| 769 | template <class ELFT> OutputSectionBase *Out<ELFT>::InitArray; |
| 770 | template <class ELFT> OutputSectionBase *Out<ELFT>::FiniArray; |
Rafael Espindola | e0df00b | 2016-02-28 00:25:54 +0000 | [diff] [blame] | 771 | } // namespace elf |
Eugene Zelenko | 6e43b49 | 2015-11-04 02:11:57 +0000 | [diff] [blame] | 772 | } // namespace lld |
| 773 | |
George Rimar | 6892afa | 2016-07-12 09:49:43 +0000 | [diff] [blame] | 774 | namespace llvm { |
| 775 | template <bool Is64Bits> struct DenseMapInfo<lld::elf::SectionKey<Is64Bits>> { |
| 776 | typedef typename lld::elf::SectionKey<Is64Bits> Key; |
| 777 | |
| 778 | static Key getEmptyKey(); |
| 779 | static Key getTombstoneKey(); |
| 780 | static unsigned getHashValue(const Key &Val); |
| 781 | static bool isEqual(const Key &LHS, const Key &RHS); |
| 782 | }; |
| 783 | } |
| 784 | |
| 785 | #endif |