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