Rui Ueyama | 6dc7fcb | 2016-11-01 20:28:21 +0000 | [diff] [blame] | 1 | //===- SyntheticSections.cpp ----------------------------------------------===// |
| 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 | // This file contains linker-synthesized sections. Currently, |
| 11 | // synthetic sections are created either output sections or input sections, |
| 12 | // but we are rewriting code so that all synthetic sections are created as |
| 13 | // input sections. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
| 17 | #include "SyntheticSections.h" |
| 18 | #include "Config.h" |
| 19 | #include "Error.h" |
| 20 | #include "InputFiles.h" |
Rui Ueyama | e288eef | 2016-11-02 18:58:44 +0000 | [diff] [blame] | 21 | #include "Memory.h" |
Rui Ueyama | 6dc7fcb | 2016-11-01 20:28:21 +0000 | [diff] [blame] | 22 | #include "OutputSections.h" |
| 23 | #include "Strings.h" |
Rui Ueyama | e8a6102 | 2016-11-05 23:05:47 +0000 | [diff] [blame] | 24 | #include "SymbolTable.h" |
Simon Atanasyan | ce02cf0 | 2016-11-09 21:36:56 +0000 | [diff] [blame] | 25 | #include "Target.h" |
Simon Atanasyan | fa03b0f | 2016-11-09 21:37:06 +0000 | [diff] [blame] | 26 | #include "Writer.h" |
Rui Ueyama | 6dc7fcb | 2016-11-01 20:28:21 +0000 | [diff] [blame] | 27 | |
Rui Ueyama | 3da3f06 | 2016-11-10 20:20:37 +0000 | [diff] [blame] | 28 | #include "lld/Config/Version.h" |
George Rimar | 364b59e2 | 2016-11-06 07:42:55 +0000 | [diff] [blame] | 29 | #include "lld/Core/Parallel.h" |
Eugene Leviant | 952eb4d | 2016-11-21 15:52:10 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Dwarf.h" |
Rui Ueyama | 6dc7fcb | 2016-11-01 20:28:21 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Endian.h" |
| 32 | #include "llvm/Support/MD5.h" |
| 33 | #include "llvm/Support/RandomNumberGenerator.h" |
| 34 | #include "llvm/Support/SHA1.h" |
| 35 | #include "llvm/Support/xxhash.h" |
Rui Ueyama | 3da3f06 | 2016-11-10 20:20:37 +0000 | [diff] [blame] | 36 | #include <cstdlib> |
Rui Ueyama | 6dc7fcb | 2016-11-01 20:28:21 +0000 | [diff] [blame] | 37 | |
| 38 | using namespace llvm; |
Eugene Leviant | 952eb4d | 2016-11-21 15:52:10 +0000 | [diff] [blame] | 39 | using namespace llvm::dwarf; |
Rui Ueyama | 6dc7fcb | 2016-11-01 20:28:21 +0000 | [diff] [blame] | 40 | using namespace llvm::ELF; |
| 41 | using namespace llvm::object; |
| 42 | using namespace llvm::support; |
| 43 | using namespace llvm::support::endian; |
| 44 | |
| 45 | using namespace lld; |
| 46 | using namespace lld::elf; |
| 47 | |
Rui Ueyama | e8a6102 | 2016-11-05 23:05:47 +0000 | [diff] [blame] | 48 | template <class ELFT> static std::vector<DefinedCommon *> getCommonSymbols() { |
| 49 | std::vector<DefinedCommon *> V; |
| 50 | for (Symbol *S : Symtab<ELFT>::X->getSymbols()) |
| 51 | if (auto *B = dyn_cast<DefinedCommon>(S->body())) |
| 52 | V.push_back(B); |
| 53 | return V; |
| 54 | } |
| 55 | |
| 56 | // Find all common symbols and allocate space for them. |
Rafael Espindola | 682a5bc | 2016-11-08 14:42:34 +0000 | [diff] [blame] | 57 | template <class ELFT> InputSection<ELFT> *elf::createCommonSection() { |
| 58 | auto *Ret = make<InputSection<ELFT>>(SHF_ALLOC | SHF_WRITE, SHT_NOBITS, 1, |
| 59 | ArrayRef<uint8_t>(), "COMMON"); |
| 60 | Ret->Live = true; |
Rui Ueyama | e8a6102 | 2016-11-05 23:05:47 +0000 | [diff] [blame] | 61 | |
| 62 | // Sort the common symbols by alignment as an heuristic to pack them better. |
| 63 | std::vector<DefinedCommon *> Syms = getCommonSymbols<ELFT>(); |
| 64 | std::stable_sort(Syms.begin(), Syms.end(), |
| 65 | [](const DefinedCommon *A, const DefinedCommon *B) { |
| 66 | return A->Alignment > B->Alignment; |
| 67 | }); |
| 68 | |
| 69 | // Assign offsets to symbols. |
| 70 | size_t Size = 0; |
| 71 | size_t Alignment = 1; |
| 72 | for (DefinedCommon *Sym : Syms) { |
Rui Ueyama | 1c78682 | 2016-11-05 23:14:54 +0000 | [diff] [blame] | 73 | Alignment = std::max<size_t>(Alignment, Sym->Alignment); |
Rui Ueyama | e8a6102 | 2016-11-05 23:05:47 +0000 | [diff] [blame] | 74 | Size = alignTo(Size, Sym->Alignment); |
| 75 | |
| 76 | // Compute symbol offset relative to beginning of input section. |
| 77 | Sym->Offset = Size; |
| 78 | Size += Sym->Size; |
| 79 | } |
Rafael Espindola | 682a5bc | 2016-11-08 14:42:34 +0000 | [diff] [blame] | 80 | Ret->Alignment = Alignment; |
| 81 | Ret->Data = makeArrayRef<uint8_t>(nullptr, Size); |
| 82 | return Ret; |
Rui Ueyama | e8a6102 | 2016-11-05 23:05:47 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Rui Ueyama | 3da3f06 | 2016-11-10 20:20:37 +0000 | [diff] [blame] | 85 | // Returns an LLD version string. |
| 86 | static ArrayRef<uint8_t> getVersion() { |
| 87 | // Check LLD_VERSION first for ease of testing. |
| 88 | // You can get consitent output by using the environment variable. |
| 89 | // This is only for testing. |
| 90 | StringRef S = getenv("LLD_VERSION"); |
| 91 | if (S.empty()) |
| 92 | S = Saver.save(Twine("Linker: ") + getLLDVersion()); |
| 93 | |
| 94 | // +1 to include the terminating '\0'. |
| 95 | return {(const uint8_t *)S.data(), S.size() + 1}; |
Davide Italiano | b69f38f | 2016-11-11 00:05:41 +0000 | [diff] [blame] | 96 | } |
Rui Ueyama | 3da3f06 | 2016-11-10 20:20:37 +0000 | [diff] [blame] | 97 | |
| 98 | // Creates a .comment section containing LLD version info. |
| 99 | // With this feature, you can identify LLD-generated binaries easily |
| 100 | // by "objdump -s -j .comment <file>". |
| 101 | // The returned object is a mergeable string section. |
| 102 | template <class ELFT> MergeInputSection<ELFT> *elf::createCommentSection() { |
| 103 | typename ELFT::Shdr Hdr = {}; |
| 104 | Hdr.sh_flags = SHF_MERGE | SHF_STRINGS; |
| 105 | Hdr.sh_type = SHT_PROGBITS; |
| 106 | Hdr.sh_entsize = 1; |
| 107 | Hdr.sh_addralign = 1; |
| 108 | |
| 109 | auto *Ret = make<MergeInputSection<ELFT>>(/*file=*/nullptr, &Hdr, ".comment"); |
| 110 | Ret->Data = getVersion(); |
| 111 | Ret->splitIntoPieces(); |
| 112 | return Ret; |
| 113 | } |
| 114 | |
Simon Atanasyan | ce02cf0 | 2016-11-09 21:36:56 +0000 | [diff] [blame] | 115 | // Iterate over sections of the specified type. For each section call |
| 116 | // provided function. After that "kill" the section by turning off |
| 117 | // "Live" flag, so that they won't be included in the final output. |
| 118 | template <class ELFT> |
| 119 | static void iterateSectionContents( |
| 120 | uint32_t Type, |
Simon Atanasyan | 93214b7 | 2016-11-09 21:46:42 +0000 | [diff] [blame] | 121 | std::function<void(elf::ObjectFile<ELFT> *, ArrayRef<uint8_t>)> F) { |
Simon Atanasyan | ce02cf0 | 2016-11-09 21:36:56 +0000 | [diff] [blame] | 122 | for (InputSectionBase<ELFT> *Sec : Symtab<ELFT>::X->Sections) { |
| 123 | if (Sec && Sec->Live && Sec->Type == Type) { |
| 124 | Sec->Live = false; |
| 125 | F(Sec->getFile(), Sec->Data); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
Simon Atanasyan | fa03b0f | 2016-11-09 21:37:06 +0000 | [diff] [blame] | 130 | // .MIPS.abiflags section. |
| 131 | template <class ELFT> |
| 132 | MipsAbiFlagsSection<ELFT>::MipsAbiFlagsSection() |
| 133 | : InputSection<ELFT>(SHF_ALLOC, SHT_MIPS_ABIFLAGS, 8, ArrayRef<uint8_t>(), |
| 134 | ".MIPS.abiflags") { |
| 135 | auto Func = [this](ObjectFile<ELFT> *F, ArrayRef<uint8_t> D) { |
| 136 | if (D.size() != sizeof(Elf_Mips_ABIFlags)) { |
| 137 | error(getFilename(F) + ": invalid size of .MIPS.abiflags section"); |
| 138 | return; |
| 139 | } |
| 140 | auto *S = reinterpret_cast<const Elf_Mips_ABIFlags *>(D.data()); |
| 141 | if (S->version != 0) { |
| 142 | error(getFilename(F) + ": unexpected .MIPS.abiflags version " + |
| 143 | Twine(S->version)); |
| 144 | return; |
| 145 | } |
| 146 | // LLD checks ISA compatibility in getMipsEFlags(). Here we just |
| 147 | // select the highest number of ISA/Rev/Ext. |
| 148 | Flags.isa_level = std::max(Flags.isa_level, S->isa_level); |
| 149 | Flags.isa_rev = std::max(Flags.isa_rev, S->isa_rev); |
| 150 | Flags.isa_ext = std::max(Flags.isa_ext, S->isa_ext); |
| 151 | Flags.gpr_size = std::max(Flags.gpr_size, S->gpr_size); |
| 152 | Flags.cpr1_size = std::max(Flags.cpr1_size, S->cpr1_size); |
| 153 | Flags.cpr2_size = std::max(Flags.cpr2_size, S->cpr2_size); |
| 154 | Flags.ases |= S->ases; |
| 155 | Flags.flags1 |= S->flags1; |
| 156 | Flags.flags2 |= S->flags2; |
| 157 | Flags.fp_abi = |
| 158 | elf::getMipsFpAbiFlag(Flags.fp_abi, S->fp_abi, getFilename(F)); |
| 159 | }; |
| 160 | iterateSectionContents<ELFT>(SHT_MIPS_ABIFLAGS, Func); |
| 161 | |
| 162 | this->Data = ArrayRef<uint8_t>((const uint8_t *)&Flags, sizeof(Flags)); |
| 163 | this->Live = true; |
| 164 | } |
| 165 | |
Simon Atanasyan | ce02cf0 | 2016-11-09 21:36:56 +0000 | [diff] [blame] | 166 | // .MIPS.options section. |
| 167 | template <class ELFT> |
| 168 | MipsOptionsSection<ELFT>::MipsOptionsSection() |
| 169 | : InputSection<ELFT>(SHF_ALLOC, SHT_MIPS_OPTIONS, 8, ArrayRef<uint8_t>(), |
| 170 | ".MIPS.options") { |
| 171 | Buf.resize(sizeof(Elf_Mips_Options) + sizeof(Elf_Mips_RegInfo)); |
| 172 | getOptions()->kind = ODK_REGINFO; |
| 173 | getOptions()->size = Buf.size(); |
| 174 | auto Func = [this](ObjectFile<ELFT> *F, ArrayRef<uint8_t> D) { |
| 175 | while (!D.empty()) { |
| 176 | if (D.size() < sizeof(Elf_Mips_Options)) { |
| 177 | error(getFilename(F) + ": invalid size of .MIPS.options section"); |
| 178 | break; |
| 179 | } |
| 180 | auto *O = reinterpret_cast<const Elf_Mips_Options *>(D.data()); |
| 181 | if (O->kind == ODK_REGINFO) { |
| 182 | if (Config->Relocatable && O->getRegInfo().ri_gp_value) |
| 183 | error(getFilename(F) + ": unsupported non-zero ri_gp_value"); |
| 184 | getOptions()->getRegInfo().ri_gprmask |= O->getRegInfo().ri_gprmask; |
| 185 | F->MipsGp0 = O->getRegInfo().ri_gp_value; |
| 186 | break; |
| 187 | } |
| 188 | if (!O->size) |
| 189 | fatal(getFilename(F) + ": zero option descriptor size"); |
| 190 | D = D.slice(O->size); |
| 191 | } |
| 192 | }; |
| 193 | iterateSectionContents<ELFT>(SHT_MIPS_OPTIONS, Func); |
| 194 | |
| 195 | this->Data = ArrayRef<uint8_t>(Buf); |
| 196 | // Section should be alive for N64 ABI only. |
| 197 | this->Live = ELFT::Is64Bits; |
| 198 | } |
| 199 | |
| 200 | template <class ELFT> void MipsOptionsSection<ELFT>::finalize() { |
| 201 | if (!Config->Relocatable) |
| 202 | getOptions()->getRegInfo().ri_gp_value = |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 203 | In<ELFT>::MipsGot->getVA() + MipsGPOffset; |
Simon Atanasyan | ce02cf0 | 2016-11-09 21:36:56 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | // MIPS .reginfo section. |
| 207 | template <class ELFT> |
| 208 | MipsReginfoSection<ELFT>::MipsReginfoSection() |
| 209 | : InputSection<ELFT>(SHF_ALLOC, SHT_MIPS_REGINFO, 4, ArrayRef<uint8_t>(), |
| 210 | ".reginfo") { |
| 211 | auto Func = [this](ObjectFile<ELFT> *F, ArrayRef<uint8_t> D) { |
| 212 | if (D.size() != sizeof(Elf_Mips_RegInfo)) { |
| 213 | error(getFilename(F) + ": invalid size of .reginfo section"); |
| 214 | return; |
| 215 | } |
| 216 | auto *R = reinterpret_cast<const Elf_Mips_RegInfo *>(D.data()); |
| 217 | if (Config->Relocatable && R->ri_gp_value) |
| 218 | error(getFilename(F) + ": unsupported non-zero ri_gp_value"); |
| 219 | Reginfo.ri_gprmask |= R->ri_gprmask; |
| 220 | F->MipsGp0 = R->ri_gp_value; |
| 221 | }; |
| 222 | iterateSectionContents<ELFT>(SHT_MIPS_REGINFO, Func); |
| 223 | |
| 224 | this->Data = ArrayRef<uint8_t>((const uint8_t *)&Reginfo, sizeof(Reginfo)); |
| 225 | // Section should be alive for O32 and N32 ABIs only. |
| 226 | this->Live = !ELFT::Is64Bits; |
| 227 | } |
| 228 | |
| 229 | template <class ELFT> void MipsReginfoSection<ELFT>::finalize() { |
| 230 | if (!Config->Relocatable) |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 231 | Reginfo.ri_gp_value = In<ELFT>::MipsGot->getVA() + MipsGPOffset; |
Simon Atanasyan | ce02cf0 | 2016-11-09 21:36:56 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Rui Ueyama | e288eef | 2016-11-02 18:58:44 +0000 | [diff] [blame] | 234 | static ArrayRef<uint8_t> createInterp() { |
| 235 | // StringSaver guarantees that the returned string ends with '\0'. |
| 236 | StringRef S = Saver.save(Config->DynamicLinker); |
Rui Ueyama | 6294a24 | 2016-11-04 17:41:29 +0000 | [diff] [blame] | 237 | return {(const uint8_t *)S.data(), S.size() + 1}; |
Rui Ueyama | e288eef | 2016-11-02 18:58:44 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Rafael Espindola | c0e47fb | 2016-11-08 14:56:27 +0000 | [diff] [blame] | 240 | template <class ELFT> InputSection<ELFT> *elf::createInterpSection() { |
| 241 | auto *Ret = make<InputSection<ELFT>>(SHF_ALLOC, SHT_PROGBITS, 1, |
| 242 | createInterp(), ".interp"); |
| 243 | Ret->Live = true; |
| 244 | return Ret; |
Rui Ueyama | a9ee8d6 | 2016-11-04 22:25:39 +0000 | [diff] [blame] | 245 | } |
Rui Ueyama | e288eef | 2016-11-02 18:58:44 +0000 | [diff] [blame] | 246 | |
Rui Ueyama | 6dc7fcb | 2016-11-01 20:28:21 +0000 | [diff] [blame] | 247 | template <class ELFT> |
Rui Ueyama | c4030a1 | 2016-11-22 00:54:15 +0000 | [diff] [blame^] | 248 | BuildIdSection<ELFT>::BuildIdSection() |
Rui Ueyama | 6dc7fcb | 2016-11-01 20:28:21 +0000 | [diff] [blame] | 249 | : InputSection<ELFT>(SHF_ALLOC, SHT_NOTE, 1, ArrayRef<uint8_t>(), |
George Rimar | 364b59e2 | 2016-11-06 07:42:55 +0000 | [diff] [blame] | 250 | ".note.gnu.build-id"), |
Rui Ueyama | c4030a1 | 2016-11-22 00:54:15 +0000 | [diff] [blame^] | 251 | HashSize(getHashSize()) { |
Rui Ueyama | a9ee8d6 | 2016-11-04 22:25:39 +0000 | [diff] [blame] | 252 | this->Live = true; |
| 253 | |
Rafael Espindola | 0e876cf | 2016-11-10 15:41:34 +0000 | [diff] [blame] | 254 | Buf.resize(HeaderSize + HashSize); |
Rui Ueyama | 6dc7fcb | 2016-11-01 20:28:21 +0000 | [diff] [blame] | 255 | const endianness E = ELFT::TargetEndianness; |
Rafael Espindola | 1a54112 | 2016-11-08 14:47:16 +0000 | [diff] [blame] | 256 | write32<E>(Buf.data(), 4); // Name size |
| 257 | write32<E>(Buf.data() + 4, HashSize); // Content size |
| 258 | write32<E>(Buf.data() + 8, NT_GNU_BUILD_ID); // Type |
| 259 | memcpy(Buf.data() + 12, "GNU", 4); // Name string |
| 260 | this->Data = ArrayRef<uint8_t>(Buf); |
Rui Ueyama | 6dc7fcb | 2016-11-01 20:28:21 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Rui Ueyama | 35e0075 | 2016-11-10 00:12:28 +0000 | [diff] [blame] | 263 | // Returns the location of the build-id hash value in the output. |
Rui Ueyama | 6dc7fcb | 2016-11-01 20:28:21 +0000 | [diff] [blame] | 264 | template <class ELFT> |
Rui Ueyama | c4030a1 | 2016-11-22 00:54:15 +0000 | [diff] [blame^] | 265 | uint8_t *BuildIdSection<ELFT>::getOutputLoc(uint8_t *Start) { |
Rafael Espindola | 0e876cf | 2016-11-10 15:41:34 +0000 | [diff] [blame] | 266 | return Start + this->OutSec->Offset + this->OutSecOff + HeaderSize; |
Rui Ueyama | 6dc7fcb | 2016-11-01 20:28:21 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Rui Ueyama | c4030a1 | 2016-11-22 00:54:15 +0000 | [diff] [blame^] | 269 | template <class ELFT> size_t BuildIdSection<ELFT>::getHashSize() { |
| 270 | switch (Config->BuildId) { |
| 271 | case BuildIdKind::Fast: |
| 272 | return 8; |
| 273 | case BuildIdKind::Md5: |
| 274 | case BuildIdKind::Uuid: |
| 275 | return 16; |
| 276 | case BuildIdKind::Sha1: |
| 277 | return 20; |
| 278 | case BuildIdKind::Hexstring: |
| 279 | return Config->BuildIdVector.size(); |
| 280 | default: |
| 281 | llvm_unreachable("unknown BuildIdKind"); |
| 282 | } |
| 283 | } |
| 284 | |
Rui Ueyama | 35e0075 | 2016-11-10 00:12:28 +0000 | [diff] [blame] | 285 | // Split one uint8 array into small pieces of uint8 arrays. |
George Rimar | 364b59e2 | 2016-11-06 07:42:55 +0000 | [diff] [blame] | 286 | static std::vector<ArrayRef<uint8_t>> split(ArrayRef<uint8_t> Arr, |
| 287 | size_t ChunkSize) { |
| 288 | std::vector<ArrayRef<uint8_t>> Ret; |
| 289 | while (Arr.size() > ChunkSize) { |
| 290 | Ret.push_back(Arr.take_front(ChunkSize)); |
| 291 | Arr = Arr.drop_front(ChunkSize); |
| 292 | } |
| 293 | if (!Arr.empty()) |
| 294 | Ret.push_back(Arr); |
| 295 | return Ret; |
| 296 | } |
| 297 | |
Rui Ueyama | 35e0075 | 2016-11-10 00:12:28 +0000 | [diff] [blame] | 298 | // Computes a hash value of Data using a given hash function. |
| 299 | // In order to utilize multiple cores, we first split data into 1MB |
| 300 | // chunks, compute a hash for each chunk, and then compute a hash value |
| 301 | // of the hash values. |
George Rimar | 364b59e2 | 2016-11-06 07:42:55 +0000 | [diff] [blame] | 302 | template <class ELFT> |
| 303 | void BuildIdSection<ELFT>::computeHash( |
George Rimar | 828787a | 2016-11-06 08:39:46 +0000 | [diff] [blame] | 304 | llvm::MutableArrayRef<uint8_t> Data, |
Rui Ueyama | 35e0075 | 2016-11-10 00:12:28 +0000 | [diff] [blame] | 305 | std::function<void(ArrayRef<uint8_t> Arr, uint8_t *Dest)> HashFn) { |
George Rimar | 364b59e2 | 2016-11-06 07:42:55 +0000 | [diff] [blame] | 306 | std::vector<ArrayRef<uint8_t>> Chunks = split(Data, 1024 * 1024); |
| 307 | std::vector<uint8_t> HashList(Chunks.size() * HashSize); |
| 308 | |
Rui Ueyama | 35e0075 | 2016-11-10 00:12:28 +0000 | [diff] [blame] | 309 | auto Fn = [&](ArrayRef<uint8_t> &Chunk) { |
| 310 | size_t Idx = &Chunk - Chunks.data(); |
| 311 | HashFn(Chunk, HashList.data() + Idx * HashSize); |
| 312 | }; |
George Rimar | 364b59e2 | 2016-11-06 07:42:55 +0000 | [diff] [blame] | 313 | |
Rui Ueyama | 35e0075 | 2016-11-10 00:12:28 +0000 | [diff] [blame] | 314 | if (Config->Threads) |
| 315 | parallel_for_each(Chunks.begin(), Chunks.end(), Fn); |
| 316 | else |
| 317 | std::for_each(Chunks.begin(), Chunks.end(), Fn); |
| 318 | |
Rui Ueyama | c4030a1 | 2016-11-22 00:54:15 +0000 | [diff] [blame^] | 319 | HashFn(HashList, getOutputLoc(Data.begin())); |
George Rimar | 364b59e2 | 2016-11-06 07:42:55 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Rui Ueyama | 6dc7fcb | 2016-11-01 20:28:21 +0000 | [diff] [blame] | 322 | template <class ELFT> |
Rui Ueyama | c4030a1 | 2016-11-22 00:54:15 +0000 | [diff] [blame^] | 323 | void BuildIdSection<ELFT>::writeBuildId(MutableArrayRef<uint8_t> Buf) { |
| 324 | switch (Config->BuildId) { |
| 325 | case BuildIdKind::Fast: |
| 326 | computeHash(Buf, [](ArrayRef<uint8_t> Arr, uint8_t *Dest) { |
| 327 | write64le(Dest, xxHash64(toStringRef(Arr))); |
| 328 | }); |
| 329 | break; |
| 330 | case BuildIdKind::Md5: |
| 331 | computeHash(Buf, [](ArrayRef<uint8_t> Arr, uint8_t *Dest) { |
| 332 | MD5 Hash; |
| 333 | Hash.update(Arr); |
| 334 | MD5::MD5Result Res; |
| 335 | Hash.final(Res); |
| 336 | memcpy(Dest, Res, 16); |
| 337 | }); |
| 338 | break; |
| 339 | case BuildIdKind::Sha1: |
| 340 | computeHash(Buf, [](ArrayRef<uint8_t> Arr, uint8_t *Dest) { |
| 341 | SHA1 Hash; |
| 342 | Hash.update(Arr); |
| 343 | memcpy(Dest, Hash.final().data(), 20); |
| 344 | }); |
| 345 | break; |
| 346 | case BuildIdKind::Uuid: |
| 347 | if (getRandomBytes(getOutputLoc(Buf.data()), HashSize)) |
| 348 | error("entropy source failure"); |
| 349 | break; |
| 350 | case BuildIdKind::Hexstring: |
| 351 | memcpy(this->getOutputLoc(Buf.data()), Config->BuildIdVector.data(), |
| 352 | Config->BuildIdVector.size()); |
| 353 | break; |
| 354 | default: |
| 355 | llvm_unreachable("unknown BuildIdKind"); |
| 356 | } |
Rui Ueyama | 6dc7fcb | 2016-11-01 20:28:21 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Eugene Leviant | 41ca327 | 2016-11-10 09:48:29 +0000 | [diff] [blame] | 359 | template <class ELFT> |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 360 | GotSection<ELFT>::GotSection() |
| 361 | : SyntheticSection<ELFT>(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS, |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 362 | Target->GotEntrySize, ".got") {} |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 363 | |
| 364 | template <class ELFT> void GotSection<ELFT>::addEntry(SymbolBody &Sym) { |
| 365 | Sym.GotIndex = Entries.size(); |
| 366 | Entries.push_back(&Sym); |
| 367 | } |
| 368 | |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 369 | template <class ELFT> bool GotSection<ELFT>::addDynTlsEntry(SymbolBody &Sym) { |
| 370 | if (Sym.GlobalDynIndex != -1U) |
| 371 | return false; |
| 372 | Sym.GlobalDynIndex = Entries.size(); |
| 373 | // Global Dynamic TLS entries take two GOT slots. |
| 374 | Entries.push_back(nullptr); |
| 375 | Entries.push_back(&Sym); |
| 376 | return true; |
| 377 | } |
| 378 | |
| 379 | // Reserves TLS entries for a TLS module ID and a TLS block offset. |
| 380 | // In total it takes two GOT slots. |
| 381 | template <class ELFT> bool GotSection<ELFT>::addTlsIndex() { |
| 382 | if (TlsIndexOff != uint32_t(-1)) |
| 383 | return false; |
| 384 | TlsIndexOff = Entries.size() * sizeof(uintX_t); |
| 385 | Entries.push_back(nullptr); |
| 386 | Entries.push_back(nullptr); |
| 387 | return true; |
| 388 | } |
| 389 | |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 390 | template <class ELFT> |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 391 | typename GotSection<ELFT>::uintX_t |
| 392 | GotSection<ELFT>::getGlobalDynAddr(const SymbolBody &B) const { |
| 393 | return this->getVA() + B.GlobalDynIndex * sizeof(uintX_t); |
| 394 | } |
| 395 | |
| 396 | template <class ELFT> |
| 397 | typename GotSection<ELFT>::uintX_t |
| 398 | GotSection<ELFT>::getGlobalDynOffset(const SymbolBody &B) const { |
| 399 | return B.GlobalDynIndex * sizeof(uintX_t); |
| 400 | } |
| 401 | |
| 402 | template <class ELFT> void GotSection<ELFT>::finalize() { |
| 403 | Size = Entries.size() * sizeof(uintX_t); |
| 404 | } |
| 405 | |
| 406 | template <class ELFT> void GotSection<ELFT>::writeTo(uint8_t *Buf) { |
| 407 | for (const SymbolBody *B : Entries) { |
| 408 | uint8_t *Entry = Buf; |
| 409 | Buf += sizeof(uintX_t); |
| 410 | if (!B) |
| 411 | continue; |
| 412 | if (B->isPreemptible()) |
| 413 | continue; // The dynamic linker will take care of it. |
| 414 | uintX_t VA = B->getVA<ELFT>(); |
| 415 | write<uintX_t, ELFT::TargetEndianness, sizeof(uintX_t)>(Entry, VA); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | template <class ELFT> |
| 420 | MipsGotSection<ELFT>::MipsGotSection() |
| 421 | : SyntheticSection<ELFT>(SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL, |
| 422 | SHT_PROGBITS, Target->GotEntrySize, ".got") {} |
| 423 | |
| 424 | template <class ELFT> |
| 425 | void MipsGotSection<ELFT>::addEntry(SymbolBody &Sym, uintX_t Addend, |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 426 | RelExpr Expr) { |
| 427 | // For "true" local symbols which can be referenced from the same module |
| 428 | // only compiler creates two instructions for address loading: |
| 429 | // |
| 430 | // lw $8, 0($gp) # R_MIPS_GOT16 |
| 431 | // addi $8, $8, 0 # R_MIPS_LO16 |
| 432 | // |
| 433 | // The first instruction loads high 16 bits of the symbol address while |
| 434 | // the second adds an offset. That allows to reduce number of required |
| 435 | // GOT entries because only one global offset table entry is necessary |
| 436 | // for every 64 KBytes of local data. So for local symbols we need to |
| 437 | // allocate number of GOT entries to hold all required "page" addresses. |
| 438 | // |
| 439 | // All global symbols (hidden and regular) considered by compiler uniformly. |
| 440 | // It always generates a single `lw` instruction and R_MIPS_GOT16 relocation |
| 441 | // to load address of the symbol. So for each such symbol we need to |
| 442 | // allocate dedicated GOT entry to store its address. |
| 443 | // |
| 444 | // If a symbol is preemptible we need help of dynamic linker to get its |
| 445 | // final address. The corresponding GOT entries are allocated in the |
| 446 | // "global" part of GOT. Entries for non preemptible global symbol allocated |
| 447 | // in the "local" part of GOT. |
| 448 | // |
| 449 | // See "Global Offset Table" in Chapter 5: |
| 450 | // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf |
| 451 | if (Expr == R_MIPS_GOT_LOCAL_PAGE) { |
| 452 | // At this point we do not know final symbol value so to reduce number |
| 453 | // of allocated GOT entries do the following trick. Save all output |
| 454 | // sections referenced by GOT relocations. Then later in the `finalize` |
| 455 | // method calculate number of "pages" required to cover all saved output |
| 456 | // section and allocate appropriate number of GOT entries. |
| 457 | auto *OutSec = cast<DefinedRegular<ELFT>>(&Sym)->Section->OutSec; |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 458 | OutSections.insert(OutSec); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 459 | return; |
| 460 | } |
| 461 | if (Sym.isTls()) { |
| 462 | // GOT entries created for MIPS TLS relocations behave like |
| 463 | // almost GOT entries from other ABIs. They go to the end |
| 464 | // of the global offset table. |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 465 | Sym.GotIndex = TlsEntries.size(); |
| 466 | TlsEntries.push_back(&Sym); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 467 | return; |
| 468 | } |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 469 | auto AddEntry = [&](SymbolBody &S, uintX_t A, GotEntries &Items) { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 470 | if (S.isInGot() && !A) |
| 471 | return; |
| 472 | size_t NewIndex = Items.size(); |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 473 | if (!EntryIndexMap.insert({{&S, A}, NewIndex}).second) |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 474 | return; |
| 475 | Items.emplace_back(&S, A); |
| 476 | if (!A) |
| 477 | S.GotIndex = NewIndex; |
| 478 | }; |
| 479 | if (Sym.isPreemptible()) { |
| 480 | // Ignore addends for preemptible symbols. They got single GOT entry anyway. |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 481 | AddEntry(Sym, 0, GlobalEntries); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 482 | Sym.IsInGlobalMipsGot = true; |
| 483 | } else if (Expr == R_MIPS_GOT_OFF32) { |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 484 | AddEntry(Sym, Addend, LocalEntries32); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 485 | Sym.Is32BitMipsGot = true; |
| 486 | } else { |
| 487 | // Hold local GOT entries accessed via a 16-bit index separately. |
| 488 | // That allows to write them in the beginning of the GOT and keep |
| 489 | // their indexes as less as possible to escape relocation's overflow. |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 490 | AddEntry(Sym, Addend, LocalEntries); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 494 | template <class ELFT> bool MipsGotSection<ELFT>::addDynTlsEntry(SymbolBody &Sym) { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 495 | if (Sym.GlobalDynIndex != -1U) |
| 496 | return false; |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 497 | Sym.GlobalDynIndex = TlsEntries.size(); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 498 | // Global Dynamic TLS entries take two GOT slots. |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 499 | TlsEntries.push_back(nullptr); |
| 500 | TlsEntries.push_back(&Sym); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 501 | return true; |
| 502 | } |
| 503 | |
| 504 | // Reserves TLS entries for a TLS module ID and a TLS block offset. |
| 505 | // In total it takes two GOT slots. |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 506 | template <class ELFT> bool MipsGotSection<ELFT>::addTlsIndex() { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 507 | if (TlsIndexOff != uint32_t(-1)) |
| 508 | return false; |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 509 | TlsIndexOff = TlsEntries.size() * sizeof(uintX_t); |
| 510 | TlsEntries.push_back(nullptr); |
| 511 | TlsEntries.push_back(nullptr); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 512 | return true; |
| 513 | } |
| 514 | |
| 515 | template <class ELFT> |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 516 | typename MipsGotSection<ELFT>::uintX_t |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 517 | MipsGotSection<ELFT>::getPageEntryOffset(uintX_t EntryValue) { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 518 | // Initialize the entry by the %hi(EntryValue) expression |
| 519 | // but without right-shifting. |
| 520 | EntryValue = (EntryValue + 0x8000) & ~0xffff; |
| 521 | // Take into account MIPS GOT header. |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 522 | // See comment in the MipsGotSection::writeTo. |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 523 | size_t NewIndex = PageIndexMap.size() + 2; |
| 524 | auto P = PageIndexMap.insert(std::make_pair(EntryValue, NewIndex)); |
| 525 | assert(!P.second || PageIndexMap.size() <= PageEntriesNum); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 526 | return (uintX_t)P.first->second * sizeof(uintX_t) - MipsGPOffset; |
| 527 | } |
| 528 | |
| 529 | template <class ELFT> |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 530 | typename MipsGotSection<ELFT>::uintX_t |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 531 | MipsGotSection<ELFT>::getBodyEntryOffset(const SymbolBody &B, |
| 532 | uintX_t Addend) const { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 533 | // Calculate offset of the GOT entries block: TLS, global, local. |
| 534 | uintX_t GotBlockOff; |
| 535 | if (B.isTls()) |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 536 | GotBlockOff = getTlsOffset(); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 537 | else if (B.IsInGlobalMipsGot) |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 538 | GotBlockOff = getLocalEntriesNum() * sizeof(uintX_t); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 539 | else if (B.Is32BitMipsGot) |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 540 | GotBlockOff = (PageEntriesNum + LocalEntries.size()) * sizeof(uintX_t); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 541 | else |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 542 | GotBlockOff = PageEntriesNum * sizeof(uintX_t); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 543 | // Calculate index of the GOT entry in the block. |
| 544 | uintX_t GotIndex; |
| 545 | if (B.isInGot()) |
| 546 | GotIndex = B.GotIndex; |
| 547 | else { |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 548 | auto It = EntryIndexMap.find({&B, Addend}); |
| 549 | assert(It != EntryIndexMap.end()); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 550 | GotIndex = It->second; |
| 551 | } |
| 552 | return GotBlockOff + GotIndex * sizeof(uintX_t) - MipsGPOffset; |
| 553 | } |
| 554 | |
| 555 | template <class ELFT> |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 556 | typename MipsGotSection<ELFT>::uintX_t |
| 557 | MipsGotSection<ELFT>::getTlsOffset() const { |
| 558 | return (getLocalEntriesNum() + GlobalEntries.size()) * sizeof(uintX_t); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | template <class ELFT> |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 562 | typename MipsGotSection<ELFT>::uintX_t |
| 563 | MipsGotSection<ELFT>::getGlobalDynOffset(const SymbolBody &B) const { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 564 | return B.GlobalDynIndex * sizeof(uintX_t); |
| 565 | } |
| 566 | |
| 567 | template <class ELFT> |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 568 | const SymbolBody *MipsGotSection<ELFT>::getFirstGlobalEntry() const { |
| 569 | return GlobalEntries.empty() ? nullptr : GlobalEntries.front().first; |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | template <class ELFT> |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 573 | unsigned MipsGotSection<ELFT>::getLocalEntriesNum() const { |
| 574 | return PageEntriesNum + LocalEntries.size() + LocalEntries32.size(); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 577 | template <class ELFT> void MipsGotSection<ELFT>::finalize() { |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 578 | size_t EntriesNum = TlsEntries.size(); |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 579 | // Take into account MIPS GOT header. |
| 580 | // See comment in the MipsGotSection::writeTo. |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 581 | PageEntriesNum += 2; |
| 582 | for (const OutputSectionBase *OutSec : OutSections) { |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 583 | // Calculate an upper bound of MIPS GOT entries required to store page |
| 584 | // addresses of local symbols. We assume the worst case - each 64kb |
| 585 | // page of the output section has at least one GOT relocation against it. |
| 586 | // Add 0x8000 to the section's size because the page address stored |
| 587 | // in the GOT entry is calculated as (value + 0x8000) & ~0xffff. |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 588 | PageEntriesNum += (OutSec->Size + 0x8000 + 0xfffe) / 0xffff; |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 589 | } |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 590 | EntriesNum += getLocalEntriesNum() + GlobalEntries.size(); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 591 | Size = EntriesNum * sizeof(uintX_t); |
| 592 | } |
| 593 | |
| 594 | template <class ELFT> |
| 595 | static void writeUint(uint8_t *Buf, typename ELFT::uint Val) { |
| 596 | typedef typename ELFT::uint uintX_t; |
| 597 | write<uintX_t, ELFT::TargetEndianness, sizeof(uintX_t)>(Buf, Val); |
| 598 | } |
| 599 | |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 600 | template <class ELFT> void MipsGotSection<ELFT>::writeTo(uint8_t *Buf) { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 601 | // Set the MSB of the second GOT slot. This is not required by any |
| 602 | // MIPS ABI documentation, though. |
| 603 | // |
| 604 | // There is a comment in glibc saying that "The MSB of got[1] of a |
| 605 | // gnu object is set to identify gnu objects," and in GNU gold it |
| 606 | // says "the second entry will be used by some runtime loaders". |
| 607 | // But how this field is being used is unclear. |
| 608 | // |
| 609 | // We are not really willing to mimic other linkers behaviors |
| 610 | // without understanding why they do that, but because all files |
| 611 | // generated by GNU tools have this special GOT value, and because |
| 612 | // we've been doing this for years, it is probably a safe bet to |
| 613 | // keep doing this for now. We really need to revisit this to see |
| 614 | // if we had to do this. |
| 615 | auto *P = reinterpret_cast<typename ELFT::Off *>(Buf); |
| 616 | P[1] = uintX_t(1) << (ELFT::Is64Bits ? 63 : 31); |
| 617 | // Write 'page address' entries to the local part of the GOT. |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 618 | for (std::pair<uintX_t, size_t> &L : PageIndexMap) { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 619 | uint8_t *Entry = Buf + L.second * sizeof(uintX_t); |
| 620 | writeUint<ELFT>(Entry, L.first); |
| 621 | } |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 622 | Buf += PageEntriesNum * sizeof(uintX_t); |
| 623 | auto AddEntry = [&](const GotEntry &SA) { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 624 | uint8_t *Entry = Buf; |
| 625 | Buf += sizeof(uintX_t); |
| 626 | const SymbolBody *Body = SA.first; |
| 627 | uintX_t VA = Body->template getVA<ELFT>(SA.second); |
| 628 | writeUint<ELFT>(Entry, VA); |
| 629 | }; |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 630 | std::for_each(std::begin(LocalEntries), std::end(LocalEntries), AddEntry); |
| 631 | std::for_each(std::begin(LocalEntries32), std::end(LocalEntries32), AddEntry); |
| 632 | std::for_each(std::begin(GlobalEntries), std::end(GlobalEntries), AddEntry); |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 633 | // Initialize TLS-related GOT entries. If the entry has a corresponding |
| 634 | // dynamic relocations, leave it initialized by zero. Write down adjusted |
| 635 | // TLS symbol's values otherwise. To calculate the adjustments use offsets |
| 636 | // for thread-local storage. |
| 637 | // https://www.linux-mips.org/wiki/NPTL |
| 638 | if (TlsIndexOff != -1U && !Config->Pic) |
| 639 | writeUint<ELFT>(Buf + TlsIndexOff, 1); |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 640 | for (const SymbolBody *B : TlsEntries) { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 641 | if (!B || B->isPreemptible()) |
| 642 | continue; |
| 643 | uintX_t VA = B->getVA<ELFT>(); |
| 644 | if (B->GotIndex != -1U) { |
| 645 | uint8_t *Entry = Buf + B->GotIndex * sizeof(uintX_t); |
| 646 | writeUint<ELFT>(Entry, VA - 0x7000); |
| 647 | } |
| 648 | if (B->GlobalDynIndex != -1U) { |
| 649 | uint8_t *Entry = Buf + B->GlobalDynIndex * sizeof(uintX_t); |
| 650 | writeUint<ELFT>(Entry, 1); |
| 651 | Entry += sizeof(uintX_t); |
| 652 | writeUint<ELFT>(Entry, VA - 0x8000); |
| 653 | } |
| 654 | } |
| 655 | } |
| 656 | |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 657 | template <class ELFT> |
Eugene Leviant | 41ca327 | 2016-11-10 09:48:29 +0000 | [diff] [blame] | 658 | GotPltSection<ELFT>::GotPltSection() |
| 659 | : SyntheticSection<ELFT>(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS, |
George Rimar | d8b2776 | 2016-11-14 10:14:18 +0000 | [diff] [blame] | 660 | Target->GotPltEntrySize, ".got.plt") {} |
Eugene Leviant | 41ca327 | 2016-11-10 09:48:29 +0000 | [diff] [blame] | 661 | |
| 662 | template <class ELFT> void GotPltSection<ELFT>::addEntry(SymbolBody &Sym) { |
| 663 | Sym.GotPltIndex = Target->GotPltHeaderEntriesNum + Entries.size(); |
| 664 | Entries.push_back(&Sym); |
| 665 | } |
| 666 | |
| 667 | template <class ELFT> bool GotPltSection<ELFT>::empty() const { |
| 668 | return Entries.empty(); |
| 669 | } |
| 670 | |
| 671 | template <class ELFT> size_t GotPltSection<ELFT>::getSize() const { |
| 672 | return (Target->GotPltHeaderEntriesNum + Entries.size()) * |
| 673 | Target->GotPltEntrySize; |
| 674 | } |
| 675 | |
| 676 | template <class ELFT> void GotPltSection<ELFT>::writeTo(uint8_t *Buf) { |
| 677 | Target->writeGotPltHeader(Buf); |
| 678 | Buf += Target->GotPltHeaderEntriesNum * Target->GotPltEntrySize; |
| 679 | for (const SymbolBody *B : Entries) { |
| 680 | Target->writeGotPlt(Buf, *B); |
| 681 | Buf += sizeof(uintX_t); |
| 682 | } |
| 683 | } |
| 684 | |
Eugene Leviant | 22eb026 | 2016-11-14 09:16:00 +0000 | [diff] [blame] | 685 | template <class ELFT> |
| 686 | StringTableSection<ELFT>::StringTableSection(StringRef Name, bool Dynamic) |
| 687 | : SyntheticSection<ELFT>(Dynamic ? (uintX_t)SHF_ALLOC : 0, SHT_STRTAB, 1, |
| 688 | Name), |
| 689 | Dynamic(Dynamic) {} |
| 690 | |
| 691 | // Adds a string to the string table. If HashIt is true we hash and check for |
| 692 | // duplicates. It is optional because the name of global symbols are already |
| 693 | // uniqued and hashing them again has a big cost for a small value: uniquing |
| 694 | // them with some other string that happens to be the same. |
| 695 | template <class ELFT> |
| 696 | unsigned StringTableSection<ELFT>::addString(StringRef S, bool HashIt) { |
| 697 | if (HashIt) { |
| 698 | auto R = StringMap.insert(std::make_pair(S, this->Size)); |
| 699 | if (!R.second) |
| 700 | return R.first->second; |
| 701 | } |
| 702 | unsigned Ret = this->Size; |
| 703 | this->Size = this->Size + S.size() + 1; |
| 704 | Strings.push_back(S); |
| 705 | return Ret; |
| 706 | } |
| 707 | |
| 708 | template <class ELFT> void StringTableSection<ELFT>::writeTo(uint8_t *Buf) { |
| 709 | // ELF string tables start with NUL byte, so advance the pointer by one. |
| 710 | ++Buf; |
| 711 | for (StringRef S : Strings) { |
| 712 | memcpy(Buf, S.data(), S.size()); |
| 713 | Buf += S.size() + 1; |
| 714 | } |
| 715 | } |
| 716 | |
Eugene Leviant | e9bab5d | 2016-11-21 16:59:33 +0000 | [diff] [blame] | 717 | // Returns the number of version definition entries. Because the first entry |
| 718 | // is for the version definition itself, it is the number of versioned symbols |
| 719 | // plus one. Note that we don't support multiple versions yet. |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 720 | static unsigned getVerDefNum() { return Config->VersionDefinitions.size() + 1; } |
| 721 | |
| 722 | template <class ELFT> |
| 723 | DynamicSection<ELFT>::DynamicSection() |
| 724 | : SyntheticSection<ELFT>(SHF_ALLOC | SHF_WRITE, SHT_DYNAMIC, |
| 725 | sizeof(uintX_t), ".dynamic") { |
| 726 | this->Entsize = ELFT::Is64Bits ? 16 : 8; |
| 727 | // .dynamic section is not writable on MIPS. |
| 728 | // See "Special Section" in Chapter 4 in the following document: |
| 729 | // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf |
| 730 | if (Config->EMachine == EM_MIPS) |
| 731 | this->Flags = SHF_ALLOC; |
| 732 | |
| 733 | addEntries(); |
| 734 | } |
| 735 | |
| 736 | // There are some dynamic entries that don't depend on other sections. |
| 737 | // Such entries can be set early. |
| 738 | template <class ELFT> void DynamicSection<ELFT>::addEntries() { |
| 739 | // Add strings to .dynstr early so that .dynstr's size will be |
| 740 | // fixed early. |
| 741 | for (StringRef S : Config->AuxiliaryList) |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 742 | add({DT_AUXILIARY, In<ELFT>::DynStrTab->addString(S)}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 743 | if (!Config->RPath.empty()) |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 744 | add({Config->EnableNewDtags ? DT_RUNPATH : DT_RPATH, |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 745 | In<ELFT>::DynStrTab->addString(Config->RPath)}); |
| 746 | for (SharedFile<ELFT> *F : Symtab<ELFT>::X->getSharedFiles()) |
| 747 | if (F->isNeeded()) |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 748 | add({DT_NEEDED, In<ELFT>::DynStrTab->addString(F->getSoName())}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 749 | if (!Config->SoName.empty()) |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 750 | add({DT_SONAME, In<ELFT>::DynStrTab->addString(Config->SoName)}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 751 | |
| 752 | // Set DT_FLAGS and DT_FLAGS_1. |
| 753 | uint32_t DtFlags = 0; |
| 754 | uint32_t DtFlags1 = 0; |
| 755 | if (Config->Bsymbolic) |
| 756 | DtFlags |= DF_SYMBOLIC; |
| 757 | if (Config->ZNodelete) |
| 758 | DtFlags1 |= DF_1_NODELETE; |
| 759 | if (Config->ZNow) { |
| 760 | DtFlags |= DF_BIND_NOW; |
| 761 | DtFlags1 |= DF_1_NOW; |
| 762 | } |
| 763 | if (Config->ZOrigin) { |
| 764 | DtFlags |= DF_ORIGIN; |
| 765 | DtFlags1 |= DF_1_ORIGIN; |
| 766 | } |
| 767 | |
| 768 | if (DtFlags) |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 769 | add({DT_FLAGS, DtFlags}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 770 | if (DtFlags1) |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 771 | add({DT_FLAGS_1, DtFlags1}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 772 | |
| 773 | if (!Config->Entry.empty()) |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 774 | add({DT_DEBUG, (uint64_t)0}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | // Add remaining entries to complete .dynamic contents. |
| 778 | template <class ELFT> void DynamicSection<ELFT>::finalize() { |
| 779 | if (this->Size) |
| 780 | return; // Already finalized. |
| 781 | |
| 782 | this->Link = In<ELFT>::DynStrTab->OutSec->SectionIndex; |
| 783 | |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 784 | if (In<ELFT>::RelaDyn->hasRelocs()) { |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 785 | bool IsRela = Config->Rela; |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 786 | add({IsRela ? DT_RELA : DT_REL, In<ELFT>::RelaDyn}); |
| 787 | add({IsRela ? DT_RELASZ : DT_RELSZ, In<ELFT>::RelaDyn->getSize()}); |
| 788 | add({IsRela ? DT_RELAENT : DT_RELENT, |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 789 | uintX_t(IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel))}); |
| 790 | |
| 791 | // MIPS dynamic loader does not support RELCOUNT tag. |
| 792 | // The problem is in the tight relation between dynamic |
| 793 | // relocations and GOT. So do not emit this tag on MIPS. |
| 794 | if (Config->EMachine != EM_MIPS) { |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 795 | size_t NumRelativeRels = In<ELFT>::RelaDyn->getRelativeRelocCount(); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 796 | if (Config->ZCombreloc && NumRelativeRels) |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 797 | add({IsRela ? DT_RELACOUNT : DT_RELCOUNT, NumRelativeRels}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 798 | } |
| 799 | } |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 800 | if (In<ELFT>::RelaPlt->hasRelocs()) { |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 801 | add({DT_JMPREL, In<ELFT>::RelaPlt}); |
| 802 | add({DT_PLTRELSZ, In<ELFT>::RelaPlt->getSize()}); |
| 803 | add({Config->EMachine == EM_MIPS ? DT_MIPS_PLTGOT : DT_PLTGOT, |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 804 | In<ELFT>::GotPlt}); |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 805 | add({DT_PLTREL, uint64_t(Config->Rela ? DT_RELA : DT_REL)}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 806 | } |
| 807 | |
Eugene Leviant | 9230db9 | 2016-11-17 09:16:34 +0000 | [diff] [blame] | 808 | add({DT_SYMTAB, In<ELFT>::DynSymTab}); |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 809 | add({DT_SYMENT, sizeof(Elf_Sym)}); |
| 810 | add({DT_STRTAB, In<ELFT>::DynStrTab}); |
| 811 | add({DT_STRSZ, In<ELFT>::DynStrTab->getSize()}); |
Eugene Leviant | be809a7 | 2016-11-18 06:44:18 +0000 | [diff] [blame] | 812 | if (In<ELFT>::GnuHashTab) |
| 813 | add({DT_GNU_HASH, In<ELFT>::GnuHashTab}); |
Eugene Leviant | b96e809 | 2016-11-18 09:06:47 +0000 | [diff] [blame] | 814 | if (In<ELFT>::HashTab) |
| 815 | add({DT_HASH, In<ELFT>::HashTab}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 816 | |
| 817 | if (Out<ELFT>::PreinitArray) { |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 818 | add({DT_PREINIT_ARRAY, Out<ELFT>::PreinitArray}); |
| 819 | add({DT_PREINIT_ARRAYSZ, Out<ELFT>::PreinitArray, Entry::SecSize}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 820 | } |
| 821 | if (Out<ELFT>::InitArray) { |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 822 | add({DT_INIT_ARRAY, Out<ELFT>::InitArray}); |
| 823 | add({DT_INIT_ARRAYSZ, Out<ELFT>::InitArray, Entry::SecSize}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 824 | } |
| 825 | if (Out<ELFT>::FiniArray) { |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 826 | add({DT_FINI_ARRAY, Out<ELFT>::FiniArray}); |
| 827 | add({DT_FINI_ARRAYSZ, Out<ELFT>::FiniArray, Entry::SecSize}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | if (SymbolBody *B = Symtab<ELFT>::X->find(Config->Init)) |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 831 | add({DT_INIT, B}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 832 | if (SymbolBody *B = Symtab<ELFT>::X->find(Config->Fini)) |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 833 | add({DT_FINI, B}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 834 | |
Eugene Leviant | e9bab5d | 2016-11-21 16:59:33 +0000 | [diff] [blame] | 835 | bool HasVerNeed = In<ELFT>::VerNeed->getNeedNum() != 0; |
| 836 | if (HasVerNeed || In<ELFT>::VerDef) |
| 837 | add({DT_VERSYM, In<ELFT>::VerSym}); |
| 838 | if (In<ELFT>::VerDef) { |
| 839 | add({DT_VERDEF, In<ELFT>::VerDef}); |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 840 | add({DT_VERDEFNUM, getVerDefNum()}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 841 | } |
| 842 | if (HasVerNeed) { |
Eugene Leviant | e9bab5d | 2016-11-21 16:59:33 +0000 | [diff] [blame] | 843 | add({DT_VERNEED, In<ELFT>::VerNeed}); |
| 844 | add({DT_VERNEEDNUM, In<ELFT>::VerNeed->getNeedNum()}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | if (Config->EMachine == EM_MIPS) { |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 848 | add({DT_MIPS_RLD_VERSION, 1}); |
| 849 | add({DT_MIPS_FLAGS, RHF_NOTPOT}); |
| 850 | add({DT_MIPS_BASE_ADDRESS, Config->ImageBase}); |
Eugene Leviant | 9230db9 | 2016-11-17 09:16:34 +0000 | [diff] [blame] | 851 | add({DT_MIPS_SYMTABNO, In<ELFT>::DynSymTab->getNumSymbols()}); |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 852 | add({DT_MIPS_LOCAL_GOTNO, In<ELFT>::MipsGot->getLocalEntriesNum()}); |
| 853 | if (const SymbolBody *B = In<ELFT>::MipsGot->getFirstGlobalEntry()) |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 854 | add({DT_MIPS_GOTSYM, B->DynsymIndex}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 855 | else |
Eugene Leviant | 9230db9 | 2016-11-17 09:16:34 +0000 | [diff] [blame] | 856 | add({DT_MIPS_GOTSYM, In<ELFT>::DynSymTab->getNumSymbols()}); |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 857 | add({DT_PLTGOT, In<ELFT>::MipsGot}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 858 | if (Out<ELFT>::MipsRldMap) |
Rui Ueyama | 729ac79 | 2016-11-17 04:10:09 +0000 | [diff] [blame] | 859 | add({DT_MIPS_RLD_MAP, Out<ELFT>::MipsRldMap}); |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | this->OutSec->Entsize = this->Entsize; |
| 863 | this->OutSec->Link = this->Link; |
| 864 | |
| 865 | // +1 for DT_NULL |
| 866 | this->Size = (Entries.size() + 1) * this->Entsize; |
| 867 | } |
| 868 | |
| 869 | template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) { |
| 870 | auto *P = reinterpret_cast<Elf_Dyn *>(Buf); |
| 871 | |
| 872 | for (const Entry &E : Entries) { |
| 873 | P->d_tag = E.Tag; |
| 874 | switch (E.Kind) { |
| 875 | case Entry::SecAddr: |
| 876 | P->d_un.d_ptr = E.OutSec->Addr; |
| 877 | break; |
| 878 | case Entry::InSecAddr: |
| 879 | P->d_un.d_ptr = E.InSec->OutSec->Addr + E.InSec->OutSecOff; |
| 880 | break; |
| 881 | case Entry::SecSize: |
| 882 | P->d_un.d_val = E.OutSec->Size; |
| 883 | break; |
| 884 | case Entry::SymAddr: |
| 885 | P->d_un.d_ptr = E.Sym->template getVA<ELFT>(); |
| 886 | break; |
| 887 | case Entry::PlainInt: |
| 888 | P->d_un.d_val = E.Val; |
| 889 | break; |
| 890 | } |
| 891 | ++P; |
| 892 | } |
| 893 | } |
| 894 | |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 895 | template <class ELFT> |
| 896 | typename ELFT::uint DynamicReloc<ELFT>::getOffset() const { |
| 897 | if (OutputSec) |
| 898 | return OutputSec->Addr + OffsetInSec; |
| 899 | return InputSec->OutSec->Addr + InputSec->getOffset(OffsetInSec); |
| 900 | } |
| 901 | |
| 902 | template <class ELFT> |
| 903 | typename ELFT::uint DynamicReloc<ELFT>::getAddend() const { |
| 904 | if (UseSymVA) |
| 905 | return Sym->getVA<ELFT>(Addend); |
| 906 | return Addend; |
| 907 | } |
| 908 | |
| 909 | template <class ELFT> uint32_t DynamicReloc<ELFT>::getSymIndex() const { |
| 910 | if (Sym && !UseSymVA) |
| 911 | return Sym->DynsymIndex; |
| 912 | return 0; |
| 913 | } |
| 914 | |
| 915 | template <class ELFT> |
| 916 | RelocationSection<ELFT>::RelocationSection(StringRef Name, bool Sort) |
| 917 | : SyntheticSection<ELFT>(SHF_ALLOC, Config->Rela ? SHT_RELA : SHT_REL, |
| 918 | sizeof(uintX_t), Name), |
| 919 | Sort(Sort) { |
| 920 | this->Entsize = Config->Rela ? sizeof(Elf_Rela) : sizeof(Elf_Rel); |
| 921 | } |
| 922 | |
| 923 | template <class ELFT> |
| 924 | void RelocationSection<ELFT>::addReloc(const DynamicReloc<ELFT> &Reloc) { |
| 925 | if (Reloc.Type == Target->RelativeRel) |
| 926 | ++NumRelativeRelocs; |
| 927 | Relocs.push_back(Reloc); |
| 928 | } |
| 929 | |
| 930 | template <class ELFT, class RelTy> |
| 931 | static bool compRelocations(const RelTy &A, const RelTy &B) { |
| 932 | bool AIsRel = A.getType(Config->Mips64EL) == Target->RelativeRel; |
| 933 | bool BIsRel = B.getType(Config->Mips64EL) == Target->RelativeRel; |
| 934 | if (AIsRel != BIsRel) |
| 935 | return AIsRel; |
| 936 | |
| 937 | return A.getSymbol(Config->Mips64EL) < B.getSymbol(Config->Mips64EL); |
| 938 | } |
| 939 | |
| 940 | template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) { |
| 941 | uint8_t *BufBegin = Buf; |
| 942 | for (const DynamicReloc<ELFT> &Rel : Relocs) { |
| 943 | auto *P = reinterpret_cast<Elf_Rela *>(Buf); |
| 944 | Buf += Config->Rela ? sizeof(Elf_Rela) : sizeof(Elf_Rel); |
| 945 | |
| 946 | if (Config->Rela) |
| 947 | P->r_addend = Rel.getAddend(); |
| 948 | P->r_offset = Rel.getOffset(); |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 949 | if (Config->EMachine == EM_MIPS && Rel.getInputSec() == In<ELFT>::MipsGot) |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 950 | // Dynamic relocation against MIPS GOT section make deal TLS entries |
| 951 | // allocated in the end of the GOT. We need to adjust the offset to take |
| 952 | // in account 'local' and 'global' GOT entries. |
Simon Atanasyan | b8bfec6 | 2016-11-17 21:49:14 +0000 | [diff] [blame] | 953 | P->r_offset += In<ELFT>::MipsGot->getTlsOffset(); |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 954 | P->setSymbolAndType(Rel.getSymIndex(), Rel.Type, Config->Mips64EL); |
| 955 | } |
| 956 | |
| 957 | if (Sort) { |
| 958 | if (Config->Rela) |
| 959 | std::stable_sort((Elf_Rela *)BufBegin, |
| 960 | (Elf_Rela *)BufBegin + Relocs.size(), |
| 961 | compRelocations<ELFT, Elf_Rela>); |
| 962 | else |
| 963 | std::stable_sort((Elf_Rel *)BufBegin, (Elf_Rel *)BufBegin + Relocs.size(), |
| 964 | compRelocations<ELFT, Elf_Rel>); |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | template <class ELFT> unsigned RelocationSection<ELFT>::getRelocOffset() { |
| 969 | return this->Entsize * Relocs.size(); |
| 970 | } |
| 971 | |
| 972 | template <class ELFT> void RelocationSection<ELFT>::finalize() { |
Eugene Leviant | 9230db9 | 2016-11-17 09:16:34 +0000 | [diff] [blame] | 973 | this->Link = In<ELFT>::DynSymTab ? In<ELFT>::DynSymTab->OutSec->SectionIndex |
| 974 | : In<ELFT>::SymTab->OutSec->SectionIndex; |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 975 | |
| 976 | // Set required output section properties. |
| 977 | this->OutSec->Link = this->Link; |
| 978 | this->OutSec->Entsize = this->Entsize; |
| 979 | } |
| 980 | |
Eugene Leviant | 9230db9 | 2016-11-17 09:16:34 +0000 | [diff] [blame] | 981 | template <class ELFT> |
| 982 | SymbolTableSection<ELFT>::SymbolTableSection( |
| 983 | StringTableSection<ELFT> &StrTabSec) |
| 984 | : SyntheticSection<ELFT>(StrTabSec.isDynamic() ? (uintX_t)SHF_ALLOC : 0, |
| 985 | StrTabSec.isDynamic() ? SHT_DYNSYM : SHT_SYMTAB, |
| 986 | sizeof(uintX_t), |
| 987 | StrTabSec.isDynamic() ? ".dynsym" : ".symtab"), |
| 988 | StrTabSec(StrTabSec) { |
| 989 | this->Entsize = sizeof(Elf_Sym); |
| 990 | } |
| 991 | |
| 992 | // Orders symbols according to their positions in the GOT, |
| 993 | // in compliance with MIPS ABI rules. |
| 994 | // See "Global Offset Table" in Chapter 5 in the following document |
| 995 | // for detailed description: |
| 996 | // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf |
| 997 | static bool sortMipsSymbols(const SymbolBody *L, const SymbolBody *R) { |
| 998 | // Sort entries related to non-local preemptible symbols by GOT indexes. |
| 999 | // All other entries go to the first part of GOT in arbitrary order. |
| 1000 | bool LIsInLocalGot = !L->IsInGlobalMipsGot; |
| 1001 | bool RIsInLocalGot = !R->IsInGlobalMipsGot; |
| 1002 | if (LIsInLocalGot || RIsInLocalGot) |
| 1003 | return !RIsInLocalGot; |
| 1004 | return L->GotIndex < R->GotIndex; |
| 1005 | } |
| 1006 | |
| 1007 | static uint8_t getSymbolBinding(SymbolBody *Body) { |
| 1008 | Symbol *S = Body->symbol(); |
| 1009 | if (Config->Relocatable) |
| 1010 | return S->Binding; |
| 1011 | uint8_t Visibility = S->Visibility; |
| 1012 | if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED) |
| 1013 | return STB_LOCAL; |
| 1014 | if (Config->NoGnuUnique && S->Binding == STB_GNU_UNIQUE) |
| 1015 | return STB_GLOBAL; |
| 1016 | return S->Binding; |
| 1017 | } |
| 1018 | |
| 1019 | template <class ELFT> void SymbolTableSection<ELFT>::finalize() { |
| 1020 | this->OutSec->Link = this->Link = StrTabSec.OutSec->SectionIndex; |
| 1021 | this->OutSec->Info = this->Info = NumLocals + 1; |
| 1022 | this->OutSec->Entsize = this->Entsize; |
| 1023 | |
| 1024 | if (Config->Relocatable) { |
| 1025 | size_t I = NumLocals; |
| 1026 | for (const SymbolTableEntry &S : Symbols) |
| 1027 | S.Symbol->DynsymIndex = ++I; |
| 1028 | return; |
| 1029 | } |
| 1030 | |
| 1031 | if (!StrTabSec.isDynamic()) { |
| 1032 | std::stable_sort(Symbols.begin(), Symbols.end(), |
| 1033 | [](const SymbolTableEntry &L, const SymbolTableEntry &R) { |
| 1034 | return getSymbolBinding(L.Symbol) == STB_LOCAL && |
| 1035 | getSymbolBinding(R.Symbol) != STB_LOCAL; |
| 1036 | }); |
| 1037 | return; |
| 1038 | } |
Eugene Leviant | be809a7 | 2016-11-18 06:44:18 +0000 | [diff] [blame] | 1039 | if (In<ELFT>::GnuHashTab) |
Eugene Leviant | 9230db9 | 2016-11-17 09:16:34 +0000 | [diff] [blame] | 1040 | // NB: It also sorts Symbols to meet the GNU hash table requirements. |
Eugene Leviant | be809a7 | 2016-11-18 06:44:18 +0000 | [diff] [blame] | 1041 | In<ELFT>::GnuHashTab->addSymbols(Symbols); |
Eugene Leviant | 9230db9 | 2016-11-17 09:16:34 +0000 | [diff] [blame] | 1042 | else if (Config->EMachine == EM_MIPS) |
| 1043 | std::stable_sort(Symbols.begin(), Symbols.end(), |
| 1044 | [](const SymbolTableEntry &L, const SymbolTableEntry &R) { |
| 1045 | return sortMipsSymbols(L.Symbol, R.Symbol); |
| 1046 | }); |
| 1047 | size_t I = 0; |
| 1048 | for (const SymbolTableEntry &S : Symbols) |
| 1049 | S.Symbol->DynsymIndex = ++I; |
| 1050 | } |
| 1051 | |
| 1052 | template <class ELFT> void SymbolTableSection<ELFT>::addSymbol(SymbolBody *B) { |
| 1053 | Symbols.push_back({B, StrTabSec.addString(B->getName(), false)}); |
| 1054 | } |
| 1055 | |
| 1056 | template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) { |
| 1057 | Buf += sizeof(Elf_Sym); |
| 1058 | |
| 1059 | // All symbols with STB_LOCAL binding precede the weak and global symbols. |
| 1060 | // .dynsym only contains global symbols. |
| 1061 | if (Config->Discard != DiscardPolicy::All && !StrTabSec.isDynamic()) |
| 1062 | writeLocalSymbols(Buf); |
| 1063 | |
| 1064 | writeGlobalSymbols(Buf); |
| 1065 | } |
| 1066 | |
| 1067 | template <class ELFT> |
| 1068 | void SymbolTableSection<ELFT>::writeLocalSymbols(uint8_t *&Buf) { |
| 1069 | // Iterate over all input object files to copy their local symbols |
| 1070 | // to the output symbol table pointed by Buf. |
| 1071 | for (ObjectFile<ELFT> *File : Symtab<ELFT>::X->getObjectFiles()) { |
| 1072 | for (const std::pair<const DefinedRegular<ELFT> *, size_t> &P : |
| 1073 | File->KeptLocalSyms) { |
| 1074 | const DefinedRegular<ELFT> &Body = *P.first; |
| 1075 | InputSectionBase<ELFT> *Section = Body.Section; |
| 1076 | auto *ESym = reinterpret_cast<Elf_Sym *>(Buf); |
| 1077 | |
| 1078 | if (!Section) { |
| 1079 | ESym->st_shndx = SHN_ABS; |
| 1080 | ESym->st_value = Body.Value; |
| 1081 | } else { |
| 1082 | const OutputSectionBase *OutSec = Section->OutSec; |
| 1083 | ESym->st_shndx = OutSec->SectionIndex; |
| 1084 | ESym->st_value = OutSec->Addr + Section->getOffset(Body); |
| 1085 | } |
| 1086 | ESym->st_name = P.second; |
| 1087 | ESym->st_size = Body.template getSize<ELFT>(); |
| 1088 | ESym->setBindingAndType(STB_LOCAL, Body.Type); |
| 1089 | Buf += sizeof(*ESym); |
| 1090 | } |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | template <class ELFT> |
| 1095 | void SymbolTableSection<ELFT>::writeGlobalSymbols(uint8_t *Buf) { |
| 1096 | // Write the internal symbol table contents to the output symbol table |
| 1097 | // pointed by Buf. |
| 1098 | auto *ESym = reinterpret_cast<Elf_Sym *>(Buf); |
| 1099 | for (const SymbolTableEntry &S : Symbols) { |
| 1100 | SymbolBody *Body = S.Symbol; |
| 1101 | size_t StrOff = S.StrTabOffset; |
| 1102 | |
| 1103 | uint8_t Type = Body->Type; |
| 1104 | uintX_t Size = Body->getSize<ELFT>(); |
| 1105 | |
| 1106 | ESym->setBindingAndType(getSymbolBinding(Body), Type); |
| 1107 | ESym->st_size = Size; |
| 1108 | ESym->st_name = StrOff; |
| 1109 | ESym->setVisibility(Body->symbol()->Visibility); |
| 1110 | ESym->st_value = Body->getVA<ELFT>(); |
| 1111 | |
| 1112 | if (const OutputSectionBase *OutSec = getOutputSection(Body)) |
| 1113 | ESym->st_shndx = OutSec->SectionIndex; |
| 1114 | else if (isa<DefinedRegular<ELFT>>(Body)) |
| 1115 | ESym->st_shndx = SHN_ABS; |
| 1116 | |
| 1117 | if (Config->EMachine == EM_MIPS) { |
| 1118 | // On MIPS we need to mark symbol which has a PLT entry and requires |
| 1119 | // pointer equality by STO_MIPS_PLT flag. That is necessary to help |
| 1120 | // dynamic linker distinguish such symbols and MIPS lazy-binding stubs. |
| 1121 | // https://sourceware.org/ml/binutils/2008-07/txt00000.txt |
| 1122 | if (Body->isInPlt() && Body->NeedsCopyOrPltAddr) |
| 1123 | ESym->st_other |= STO_MIPS_PLT; |
| 1124 | if (Config->Relocatable) { |
| 1125 | auto *D = dyn_cast<DefinedRegular<ELFT>>(Body); |
| 1126 | if (D && D->isMipsPIC()) |
| 1127 | ESym->st_other |= STO_MIPS_PIC; |
| 1128 | } |
| 1129 | } |
| 1130 | ++ESym; |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | template <class ELFT> |
| 1135 | const OutputSectionBase * |
| 1136 | SymbolTableSection<ELFT>::getOutputSection(SymbolBody *Sym) { |
| 1137 | switch (Sym->kind()) { |
| 1138 | case SymbolBody::DefinedSyntheticKind: |
| 1139 | return cast<DefinedSynthetic<ELFT>>(Sym)->Section; |
| 1140 | case SymbolBody::DefinedRegularKind: { |
| 1141 | auto &D = cast<DefinedRegular<ELFT>>(*Sym); |
| 1142 | if (D.Section) |
| 1143 | return D.Section->OutSec; |
| 1144 | break; |
| 1145 | } |
| 1146 | case SymbolBody::DefinedCommonKind: |
| 1147 | return In<ELFT>::Common->OutSec; |
| 1148 | case SymbolBody::SharedKind: |
| 1149 | if (cast<SharedSymbol<ELFT>>(Sym)->needsCopy()) |
| 1150 | return Out<ELFT>::Bss; |
| 1151 | break; |
| 1152 | case SymbolBody::UndefinedKind: |
| 1153 | case SymbolBody::LazyArchiveKind: |
| 1154 | case SymbolBody::LazyObjectKind: |
| 1155 | break; |
| 1156 | } |
| 1157 | return nullptr; |
| 1158 | } |
| 1159 | |
Eugene Leviant | be809a7 | 2016-11-18 06:44:18 +0000 | [diff] [blame] | 1160 | template <class ELFT> |
| 1161 | GnuHashTableSection<ELFT>::GnuHashTableSection() |
| 1162 | : SyntheticSection<ELFT>(SHF_ALLOC, SHT_GNU_HASH, sizeof(uintX_t), |
| 1163 | ".gnu.hash") { |
| 1164 | this->Entsize = ELFT::Is64Bits ? 0 : 4; |
| 1165 | } |
| 1166 | |
| 1167 | template <class ELFT> |
| 1168 | unsigned GnuHashTableSection<ELFT>::calcNBuckets(unsigned NumHashed) { |
| 1169 | if (!NumHashed) |
| 1170 | return 0; |
| 1171 | |
| 1172 | // These values are prime numbers which are not greater than 2^(N-1) + 1. |
| 1173 | // In result, for any particular NumHashed we return a prime number |
| 1174 | // which is not greater than NumHashed. |
| 1175 | static const unsigned Primes[] = { |
| 1176 | 1, 1, 3, 3, 7, 13, 31, 61, 127, 251, |
| 1177 | 509, 1021, 2039, 4093, 8191, 16381, 32749, 65521, 131071}; |
| 1178 | |
| 1179 | return Primes[std::min<unsigned>(Log2_32_Ceil(NumHashed), |
| 1180 | array_lengthof(Primes) - 1)]; |
| 1181 | } |
| 1182 | |
| 1183 | // Bloom filter estimation: at least 8 bits for each hashed symbol. |
| 1184 | // GNU Hash table requirement: it should be a power of 2, |
| 1185 | // the minimum value is 1, even for an empty table. |
| 1186 | // Expected results for a 32-bit target: |
| 1187 | // calcMaskWords(0..4) = 1 |
| 1188 | // calcMaskWords(5..8) = 2 |
| 1189 | // calcMaskWords(9..16) = 4 |
| 1190 | // For a 64-bit target: |
| 1191 | // calcMaskWords(0..8) = 1 |
| 1192 | // calcMaskWords(9..16) = 2 |
| 1193 | // calcMaskWords(17..32) = 4 |
| 1194 | template <class ELFT> |
| 1195 | unsigned GnuHashTableSection<ELFT>::calcMaskWords(unsigned NumHashed) { |
| 1196 | if (!NumHashed) |
| 1197 | return 1; |
| 1198 | return NextPowerOf2((NumHashed - 1) / sizeof(Elf_Off)); |
| 1199 | } |
| 1200 | |
| 1201 | template <class ELFT> void GnuHashTableSection<ELFT>::finalize() { |
| 1202 | unsigned NumHashed = Symbols.size(); |
| 1203 | NBuckets = calcNBuckets(NumHashed); |
| 1204 | MaskWords = calcMaskWords(NumHashed); |
| 1205 | // Second hash shift estimation: just predefined values. |
| 1206 | Shift2 = ELFT::Is64Bits ? 6 : 5; |
| 1207 | |
| 1208 | this->OutSec->Entsize = this->Entsize; |
| 1209 | this->OutSec->Link = this->Link = In<ELFT>::DynSymTab->OutSec->SectionIndex; |
| 1210 | this->Size = sizeof(Elf_Word) * 4 // Header |
| 1211 | + sizeof(Elf_Off) * MaskWords // Bloom Filter |
| 1212 | + sizeof(Elf_Word) * NBuckets // Hash Buckets |
| 1213 | + sizeof(Elf_Word) * NumHashed; // Hash Values |
| 1214 | } |
| 1215 | |
| 1216 | template <class ELFT> void GnuHashTableSection<ELFT>::writeTo(uint8_t *Buf) { |
| 1217 | writeHeader(Buf); |
| 1218 | if (Symbols.empty()) |
| 1219 | return; |
| 1220 | writeBloomFilter(Buf); |
| 1221 | writeHashTable(Buf); |
| 1222 | } |
| 1223 | |
| 1224 | template <class ELFT> |
| 1225 | void GnuHashTableSection<ELFT>::writeHeader(uint8_t *&Buf) { |
| 1226 | auto *P = reinterpret_cast<Elf_Word *>(Buf); |
| 1227 | *P++ = NBuckets; |
| 1228 | *P++ = In<ELFT>::DynSymTab->getNumSymbols() - Symbols.size(); |
| 1229 | *P++ = MaskWords; |
| 1230 | *P++ = Shift2; |
| 1231 | Buf = reinterpret_cast<uint8_t *>(P); |
| 1232 | } |
| 1233 | |
| 1234 | template <class ELFT> |
| 1235 | void GnuHashTableSection<ELFT>::writeBloomFilter(uint8_t *&Buf) { |
| 1236 | unsigned C = sizeof(Elf_Off) * 8; |
| 1237 | |
| 1238 | auto *Masks = reinterpret_cast<Elf_Off *>(Buf); |
| 1239 | for (const SymbolData &Sym : Symbols) { |
| 1240 | size_t Pos = (Sym.Hash / C) & (MaskWords - 1); |
| 1241 | uintX_t V = (uintX_t(1) << (Sym.Hash % C)) | |
| 1242 | (uintX_t(1) << ((Sym.Hash >> Shift2) % C)); |
| 1243 | Masks[Pos] |= V; |
| 1244 | } |
| 1245 | Buf += sizeof(Elf_Off) * MaskWords; |
| 1246 | } |
| 1247 | |
| 1248 | template <class ELFT> |
| 1249 | void GnuHashTableSection<ELFT>::writeHashTable(uint8_t *Buf) { |
| 1250 | Elf_Word *Buckets = reinterpret_cast<Elf_Word *>(Buf); |
| 1251 | Elf_Word *Values = Buckets + NBuckets; |
| 1252 | |
| 1253 | int PrevBucket = -1; |
| 1254 | int I = 0; |
| 1255 | for (const SymbolData &Sym : Symbols) { |
| 1256 | int Bucket = Sym.Hash % NBuckets; |
| 1257 | assert(PrevBucket <= Bucket); |
| 1258 | if (Bucket != PrevBucket) { |
| 1259 | Buckets[Bucket] = Sym.Body->DynsymIndex; |
| 1260 | PrevBucket = Bucket; |
| 1261 | if (I > 0) |
| 1262 | Values[I - 1] |= 1; |
| 1263 | } |
| 1264 | Values[I] = Sym.Hash & ~1; |
| 1265 | ++I; |
| 1266 | } |
| 1267 | if (I > 0) |
| 1268 | Values[I - 1] |= 1; |
| 1269 | } |
| 1270 | |
| 1271 | static uint32_t hashGnu(StringRef Name) { |
| 1272 | uint32_t H = 5381; |
| 1273 | for (uint8_t C : Name) |
| 1274 | H = (H << 5) + H + C; |
| 1275 | return H; |
| 1276 | } |
| 1277 | |
| 1278 | // Add symbols to this symbol hash table. Note that this function |
| 1279 | // destructively sort a given vector -- which is needed because |
| 1280 | // GNU-style hash table places some sorting requirements. |
| 1281 | template <class ELFT> |
| 1282 | void GnuHashTableSection<ELFT>::addSymbols(std::vector<SymbolTableEntry> &V) { |
| 1283 | // Ideally this will just be 'auto' but GCC 6.1 is not able |
| 1284 | // to deduce it correctly. |
| 1285 | std::vector<SymbolTableEntry>::iterator Mid = |
| 1286 | std::stable_partition(V.begin(), V.end(), [](const SymbolTableEntry &S) { |
| 1287 | return S.Symbol->isUndefined(); |
| 1288 | }); |
| 1289 | if (Mid == V.end()) |
| 1290 | return; |
| 1291 | for (auto I = Mid, E = V.end(); I != E; ++I) { |
| 1292 | SymbolBody *B = I->Symbol; |
| 1293 | size_t StrOff = I->StrTabOffset; |
| 1294 | Symbols.push_back({B, StrOff, hashGnu(B->getName())}); |
| 1295 | } |
| 1296 | |
| 1297 | unsigned NBuckets = calcNBuckets(Symbols.size()); |
| 1298 | std::stable_sort(Symbols.begin(), Symbols.end(), |
| 1299 | [&](const SymbolData &L, const SymbolData &R) { |
| 1300 | return L.Hash % NBuckets < R.Hash % NBuckets; |
| 1301 | }); |
| 1302 | |
| 1303 | V.erase(Mid, V.end()); |
| 1304 | for (const SymbolData &Sym : Symbols) |
| 1305 | V.push_back({Sym.Body, Sym.STName}); |
| 1306 | } |
| 1307 | |
Eugene Leviant | b96e809 | 2016-11-18 09:06:47 +0000 | [diff] [blame] | 1308 | template <class ELFT> |
| 1309 | HashTableSection<ELFT>::HashTableSection() |
| 1310 | : SyntheticSection<ELFT>(SHF_ALLOC, SHT_HASH, sizeof(Elf_Word), ".hash") { |
| 1311 | this->Entsize = sizeof(Elf_Word); |
| 1312 | } |
| 1313 | |
| 1314 | template <class ELFT> void HashTableSection<ELFT>::finalize() { |
| 1315 | this->OutSec->Link = this->Link = In<ELFT>::DynSymTab->OutSec->SectionIndex; |
| 1316 | this->OutSec->Entsize = this->Entsize; |
| 1317 | |
| 1318 | unsigned NumEntries = 2; // nbucket and nchain. |
| 1319 | NumEntries += In<ELFT>::DynSymTab->getNumSymbols(); // The chain entries. |
| 1320 | |
| 1321 | // Create as many buckets as there are symbols. |
| 1322 | // FIXME: This is simplistic. We can try to optimize it, but implementing |
| 1323 | // support for SHT_GNU_HASH is probably even more profitable. |
| 1324 | NumEntries += In<ELFT>::DynSymTab->getNumSymbols(); |
| 1325 | this->Size = NumEntries * sizeof(Elf_Word); |
| 1326 | } |
| 1327 | |
| 1328 | template <class ELFT> void HashTableSection<ELFT>::writeTo(uint8_t *Buf) { |
| 1329 | unsigned NumSymbols = In<ELFT>::DynSymTab->getNumSymbols(); |
| 1330 | auto *P = reinterpret_cast<Elf_Word *>(Buf); |
| 1331 | *P++ = NumSymbols; // nbucket |
| 1332 | *P++ = NumSymbols; // nchain |
| 1333 | |
| 1334 | Elf_Word *Buckets = P; |
| 1335 | Elf_Word *Chains = P + NumSymbols; |
| 1336 | |
| 1337 | for (const SymbolTableEntry &S : In<ELFT>::DynSymTab->getSymbols()) { |
| 1338 | SymbolBody *Body = S.Symbol; |
| 1339 | StringRef Name = Body->getName(); |
| 1340 | unsigned I = Body->DynsymIndex; |
| 1341 | uint32_t Hash = hashSysV(Name) % NumSymbols; |
| 1342 | Chains[I] = Buckets[Hash]; |
| 1343 | Buckets[Hash] = I; |
| 1344 | } |
| 1345 | } |
| 1346 | |
Eugene Leviant | ff23d3e | 2016-11-18 14:35:03 +0000 | [diff] [blame] | 1347 | template <class ELFT> |
| 1348 | PltSection<ELFT>::PltSection() |
| 1349 | : SyntheticSection<ELFT>(SHF_ALLOC | SHF_EXECINSTR, SHT_PROGBITS, 16, |
| 1350 | ".plt") {} |
| 1351 | |
| 1352 | template <class ELFT> void PltSection<ELFT>::writeTo(uint8_t *Buf) { |
| 1353 | // At beginning of PLT, we have code to call the dynamic linker |
| 1354 | // to resolve dynsyms at runtime. Write such code. |
| 1355 | Target->writePltHeader(Buf); |
| 1356 | size_t Off = Target->PltHeaderSize; |
| 1357 | |
| 1358 | for (auto &I : Entries) { |
| 1359 | const SymbolBody *B = I.first; |
| 1360 | unsigned RelOff = I.second; |
| 1361 | uint64_t Got = B->getGotPltVA<ELFT>(); |
| 1362 | uint64_t Plt = this->getVA() + Off; |
| 1363 | Target->writePlt(Buf + Off, Got, Plt, B->PltIndex, RelOff); |
| 1364 | Off += Target->PltEntrySize; |
| 1365 | } |
| 1366 | } |
| 1367 | |
| 1368 | template <class ELFT> void PltSection<ELFT>::addEntry(SymbolBody &Sym) { |
| 1369 | Sym.PltIndex = Entries.size(); |
| 1370 | unsigned RelOff = In<ELFT>::RelaPlt->getRelocOffset(); |
| 1371 | Entries.push_back(std::make_pair(&Sym, RelOff)); |
| 1372 | } |
| 1373 | |
| 1374 | template <class ELFT> size_t PltSection<ELFT>::getSize() const { |
| 1375 | return Target->PltHeaderSize + Entries.size() * Target->PltEntrySize; |
| 1376 | } |
| 1377 | |
Eugene Leviant | a113a41 | 2016-11-21 09:24:43 +0000 | [diff] [blame] | 1378 | template <class ELFT> |
| 1379 | GdbIndexSection<ELFT>::GdbIndexSection() |
| 1380 | : SyntheticSection<ELFT>(0, SHT_PROGBITS, 1, ".gdb_index") {} |
| 1381 | |
| 1382 | template <class ELFT> void GdbIndexSection<ELFT>::parseDebugSections() { |
| 1383 | std::vector<InputSection<ELFT> *> &IS = |
| 1384 | static_cast<OutputSection<ELFT> *>(Out<ELFT>::DebugInfo)->Sections; |
| 1385 | |
| 1386 | for (InputSection<ELFT> *I : IS) |
| 1387 | readDwarf(I); |
| 1388 | } |
| 1389 | |
| 1390 | template <class ELFT> |
| 1391 | void GdbIndexSection<ELFT>::readDwarf(InputSection<ELFT> *I) { |
| 1392 | std::vector<std::pair<uintX_t, uintX_t>> CuList = readCuList(I); |
| 1393 | CompilationUnits.insert(CompilationUnits.end(), CuList.begin(), CuList.end()); |
| 1394 | } |
| 1395 | |
| 1396 | template <class ELFT> void GdbIndexSection<ELFT>::finalize() { |
| 1397 | parseDebugSections(); |
| 1398 | |
| 1399 | // GdbIndex header consist from version fields |
| 1400 | // and 5 more fields with different kinds of offsets. |
| 1401 | CuTypesOffset = CuListOffset + CompilationUnits.size() * CompilationUnitSize; |
| 1402 | } |
| 1403 | |
| 1404 | template <class ELFT> void GdbIndexSection<ELFT>::writeTo(uint8_t *Buf) { |
| 1405 | write32le(Buf, 7); // Write Version |
| 1406 | write32le(Buf + 4, CuListOffset); // CU list offset |
| 1407 | write32le(Buf + 8, CuTypesOffset); // Types CU list offset |
| 1408 | write32le(Buf + 12, CuTypesOffset); // Address area offset |
| 1409 | write32le(Buf + 16, CuTypesOffset); // Symbol table offset |
| 1410 | write32le(Buf + 20, CuTypesOffset); // Constant pool offset |
| 1411 | Buf += 24; |
| 1412 | |
| 1413 | // Write the CU list. |
| 1414 | for (std::pair<uintX_t, uintX_t> CU : CompilationUnits) { |
| 1415 | write64le(Buf, CU.first); |
| 1416 | write64le(Buf + 8, CU.second); |
| 1417 | Buf += 16; |
| 1418 | } |
| 1419 | } |
| 1420 | |
Eugene Leviant | 952eb4d | 2016-11-21 15:52:10 +0000 | [diff] [blame] | 1421 | template <class ELFT> |
| 1422 | EhFrameHeader<ELFT>::EhFrameHeader() |
| 1423 | : SyntheticSection<ELFT>(SHF_ALLOC, SHT_PROGBITS, 1, ".eh_frame_hdr") {} |
| 1424 | |
| 1425 | // .eh_frame_hdr contains a binary search table of pointers to FDEs. |
| 1426 | // Each entry of the search table consists of two values, |
| 1427 | // the starting PC from where FDEs covers, and the FDE's address. |
| 1428 | // It is sorted by PC. |
| 1429 | template <class ELFT> void EhFrameHeader<ELFT>::writeTo(uint8_t *Buf) { |
| 1430 | const endianness E = ELFT::TargetEndianness; |
| 1431 | |
| 1432 | // Sort the FDE list by their PC and uniqueify. Usually there is only |
| 1433 | // one FDE for a PC (i.e. function), but if ICF merges two functions |
| 1434 | // into one, there can be more than one FDEs pointing to the address. |
| 1435 | auto Less = [](const FdeData &A, const FdeData &B) { return A.Pc < B.Pc; }; |
| 1436 | std::stable_sort(Fdes.begin(), Fdes.end(), Less); |
| 1437 | auto Eq = [](const FdeData &A, const FdeData &B) { return A.Pc == B.Pc; }; |
| 1438 | Fdes.erase(std::unique(Fdes.begin(), Fdes.end(), Eq), Fdes.end()); |
| 1439 | |
| 1440 | Buf[0] = 1; |
| 1441 | Buf[1] = DW_EH_PE_pcrel | DW_EH_PE_sdata4; |
| 1442 | Buf[2] = DW_EH_PE_udata4; |
| 1443 | Buf[3] = DW_EH_PE_datarel | DW_EH_PE_sdata4; |
| 1444 | write32<E>(Buf + 4, Out<ELFT>::EhFrame->Addr - this->getVA() - 4); |
| 1445 | write32<E>(Buf + 8, Fdes.size()); |
| 1446 | Buf += 12; |
| 1447 | |
| 1448 | uintX_t VA = this->getVA(); |
| 1449 | for (FdeData &Fde : Fdes) { |
| 1450 | write32<E>(Buf, Fde.Pc - VA); |
| 1451 | write32<E>(Buf + 4, Fde.FdeVA - VA); |
| 1452 | Buf += 8; |
| 1453 | } |
| 1454 | } |
| 1455 | |
| 1456 | template <class ELFT> size_t EhFrameHeader<ELFT>::getSize() const { |
| 1457 | // .eh_frame_hdr has a 12 bytes header followed by an array of FDEs. |
| 1458 | return 12 + Out<ELFT>::EhFrame->NumFdes * 8; |
| 1459 | } |
| 1460 | |
Eugene Leviant | e9bab5d | 2016-11-21 16:59:33 +0000 | [diff] [blame] | 1461 | template <class ELFT> |
Rui Ueyama | b38ddb1 | 2016-11-21 19:46:04 +0000 | [diff] [blame] | 1462 | void EhFrameHeader<ELFT>::addFde(uint32_t Pc, uint32_t FdeVA) { |
| 1463 | Fdes.push_back({Pc, FdeVA}); |
| 1464 | } |
| 1465 | |
| 1466 | template <class ELFT> |
Eugene Leviant | e9bab5d | 2016-11-21 16:59:33 +0000 | [diff] [blame] | 1467 | VersionDefinitionSection<ELFT>::VersionDefinitionSection() |
| 1468 | : SyntheticSection<ELFT>(SHF_ALLOC, SHT_GNU_verdef, sizeof(uint32_t), |
| 1469 | ".gnu.version_d") {} |
| 1470 | |
| 1471 | static StringRef getFileDefName() { |
| 1472 | if (!Config->SoName.empty()) |
| 1473 | return Config->SoName; |
| 1474 | return Config->OutputFile; |
| 1475 | } |
| 1476 | |
| 1477 | template <class ELFT> void VersionDefinitionSection<ELFT>::finalize() { |
| 1478 | FileDefNameOff = In<ELFT>::DynStrTab->addString(getFileDefName()); |
| 1479 | for (VersionDefinition &V : Config->VersionDefinitions) |
| 1480 | V.NameOff = In<ELFT>::DynStrTab->addString(V.Name); |
| 1481 | |
| 1482 | this->OutSec->Link = this->Link = In<ELFT>::DynStrTab->OutSec->SectionIndex; |
| 1483 | |
| 1484 | // sh_info should be set to the number of definitions. This fact is missed in |
| 1485 | // documentation, but confirmed by binutils community: |
| 1486 | // https://sourceware.org/ml/binutils/2014-11/msg00355.html |
| 1487 | this->OutSec->Info = this->Info = getVerDefNum(); |
| 1488 | } |
| 1489 | |
| 1490 | template <class ELFT> |
| 1491 | void VersionDefinitionSection<ELFT>::writeOne(uint8_t *Buf, uint32_t Index, |
| 1492 | StringRef Name, size_t NameOff) { |
| 1493 | auto *Verdef = reinterpret_cast<Elf_Verdef *>(Buf); |
| 1494 | Verdef->vd_version = 1; |
| 1495 | Verdef->vd_cnt = 1; |
| 1496 | Verdef->vd_aux = sizeof(Elf_Verdef); |
| 1497 | Verdef->vd_next = sizeof(Elf_Verdef) + sizeof(Elf_Verdaux); |
| 1498 | Verdef->vd_flags = (Index == 1 ? VER_FLG_BASE : 0); |
| 1499 | Verdef->vd_ndx = Index; |
| 1500 | Verdef->vd_hash = hashSysV(Name); |
| 1501 | |
| 1502 | auto *Verdaux = reinterpret_cast<Elf_Verdaux *>(Buf + sizeof(Elf_Verdef)); |
| 1503 | Verdaux->vda_name = NameOff; |
| 1504 | Verdaux->vda_next = 0; |
| 1505 | } |
| 1506 | |
| 1507 | template <class ELFT> |
| 1508 | void VersionDefinitionSection<ELFT>::writeTo(uint8_t *Buf) { |
| 1509 | writeOne(Buf, 1, getFileDefName(), FileDefNameOff); |
| 1510 | |
| 1511 | for (VersionDefinition &V : Config->VersionDefinitions) { |
| 1512 | Buf += sizeof(Elf_Verdef) + sizeof(Elf_Verdaux); |
| 1513 | writeOne(Buf, V.Id, V.Name, V.NameOff); |
| 1514 | } |
| 1515 | |
| 1516 | // Need to terminate the last version definition. |
| 1517 | Elf_Verdef *Verdef = reinterpret_cast<Elf_Verdef *>(Buf); |
| 1518 | Verdef->vd_next = 0; |
| 1519 | } |
| 1520 | |
| 1521 | template <class ELFT> size_t VersionDefinitionSection<ELFT>::getSize() const { |
| 1522 | return (sizeof(Elf_Verdef) + sizeof(Elf_Verdaux)) * getVerDefNum(); |
| 1523 | } |
| 1524 | |
| 1525 | template <class ELFT> |
| 1526 | VersionTableSection<ELFT>::VersionTableSection() |
| 1527 | : SyntheticSection<ELFT>(SHF_ALLOC, SHT_GNU_versym, sizeof(uint16_t), |
| 1528 | ".gnu.version") {} |
| 1529 | |
| 1530 | template <class ELFT> void VersionTableSection<ELFT>::finalize() { |
| 1531 | this->OutSec->Entsize = this->Entsize = sizeof(Elf_Versym); |
| 1532 | // At the moment of june 2016 GNU docs does not mention that sh_link field |
| 1533 | // should be set, but Sun docs do. Also readelf relies on this field. |
| 1534 | this->OutSec->Link = this->Link = In<ELFT>::DynSymTab->OutSec->SectionIndex; |
| 1535 | } |
| 1536 | |
| 1537 | template <class ELFT> size_t VersionTableSection<ELFT>::getSize() const { |
| 1538 | return sizeof(Elf_Versym) * (In<ELFT>::DynSymTab->getSymbols().size() + 1); |
| 1539 | } |
| 1540 | |
| 1541 | template <class ELFT> void VersionTableSection<ELFT>::writeTo(uint8_t *Buf) { |
| 1542 | auto *OutVersym = reinterpret_cast<Elf_Versym *>(Buf) + 1; |
| 1543 | for (const SymbolTableEntry &S : In<ELFT>::DynSymTab->getSymbols()) { |
| 1544 | OutVersym->vs_index = S.Symbol->symbol()->VersionId; |
| 1545 | ++OutVersym; |
| 1546 | } |
| 1547 | } |
| 1548 | |
| 1549 | template <class ELFT> |
| 1550 | VersionNeedSection<ELFT>::VersionNeedSection() |
| 1551 | : SyntheticSection<ELFT>(SHF_ALLOC, SHT_GNU_verneed, sizeof(uint32_t), |
| 1552 | ".gnu.version_r") { |
| 1553 | // Identifiers in verneed section start at 2 because 0 and 1 are reserved |
| 1554 | // for VER_NDX_LOCAL and VER_NDX_GLOBAL. |
| 1555 | // First identifiers are reserved by verdef section if it exist. |
| 1556 | NextIndex = getVerDefNum() + 1; |
| 1557 | } |
| 1558 | |
| 1559 | template <class ELFT> |
| 1560 | void VersionNeedSection<ELFT>::addSymbol(SharedSymbol<ELFT> *SS) { |
| 1561 | if (!SS->Verdef) { |
| 1562 | SS->symbol()->VersionId = VER_NDX_GLOBAL; |
| 1563 | return; |
| 1564 | } |
| 1565 | SharedFile<ELFT> *F = SS->file(); |
| 1566 | // If we don't already know that we need an Elf_Verneed for this DSO, prepare |
| 1567 | // to create one by adding it to our needed list and creating a dynstr entry |
| 1568 | // for the soname. |
| 1569 | if (F->VerdefMap.empty()) |
| 1570 | Needed.push_back({F, In<ELFT>::DynStrTab->addString(F->getSoName())}); |
| 1571 | typename SharedFile<ELFT>::NeededVer &NV = F->VerdefMap[SS->Verdef]; |
| 1572 | // If we don't already know that we need an Elf_Vernaux for this Elf_Verdef, |
| 1573 | // prepare to create one by allocating a version identifier and creating a |
| 1574 | // dynstr entry for the version name. |
| 1575 | if (NV.Index == 0) { |
| 1576 | NV.StrTab = In<ELFT>::DynStrTab->addString( |
| 1577 | SS->file()->getStringTable().data() + SS->Verdef->getAux()->vda_name); |
| 1578 | NV.Index = NextIndex++; |
| 1579 | } |
| 1580 | SS->symbol()->VersionId = NV.Index; |
| 1581 | } |
| 1582 | |
| 1583 | template <class ELFT> void VersionNeedSection<ELFT>::writeTo(uint8_t *Buf) { |
| 1584 | // The Elf_Verneeds need to appear first, followed by the Elf_Vernauxs. |
| 1585 | auto *Verneed = reinterpret_cast<Elf_Verneed *>(Buf); |
| 1586 | auto *Vernaux = reinterpret_cast<Elf_Vernaux *>(Verneed + Needed.size()); |
| 1587 | |
| 1588 | for (std::pair<SharedFile<ELFT> *, size_t> &P : Needed) { |
| 1589 | // Create an Elf_Verneed for this DSO. |
| 1590 | Verneed->vn_version = 1; |
| 1591 | Verneed->vn_cnt = P.first->VerdefMap.size(); |
| 1592 | Verneed->vn_file = P.second; |
| 1593 | Verneed->vn_aux = |
| 1594 | reinterpret_cast<char *>(Vernaux) - reinterpret_cast<char *>(Verneed); |
| 1595 | Verneed->vn_next = sizeof(Elf_Verneed); |
| 1596 | ++Verneed; |
| 1597 | |
| 1598 | // Create the Elf_Vernauxs for this Elf_Verneed. The loop iterates over |
| 1599 | // VerdefMap, which will only contain references to needed version |
| 1600 | // definitions. Each Elf_Vernaux is based on the information contained in |
| 1601 | // the Elf_Verdef in the source DSO. This loop iterates over a std::map of |
| 1602 | // pointers, but is deterministic because the pointers refer to Elf_Verdef |
| 1603 | // data structures within a single input file. |
| 1604 | for (auto &NV : P.first->VerdefMap) { |
| 1605 | Vernaux->vna_hash = NV.first->vd_hash; |
| 1606 | Vernaux->vna_flags = 0; |
| 1607 | Vernaux->vna_other = NV.second.Index; |
| 1608 | Vernaux->vna_name = NV.second.StrTab; |
| 1609 | Vernaux->vna_next = sizeof(Elf_Vernaux); |
| 1610 | ++Vernaux; |
| 1611 | } |
| 1612 | |
| 1613 | Vernaux[-1].vna_next = 0; |
| 1614 | } |
| 1615 | Verneed[-1].vn_next = 0; |
| 1616 | } |
| 1617 | |
| 1618 | template <class ELFT> void VersionNeedSection<ELFT>::finalize() { |
| 1619 | this->OutSec->Link = this->Link = In<ELFT>::DynStrTab->OutSec->SectionIndex; |
| 1620 | this->OutSec->Info = this->Info = Needed.size(); |
| 1621 | } |
| 1622 | |
| 1623 | template <class ELFT> size_t VersionNeedSection<ELFT>::getSize() const { |
| 1624 | unsigned Size = Needed.size() * sizeof(Elf_Verneed); |
| 1625 | for (const std::pair<SharedFile<ELFT> *, size_t> &P : Needed) |
| 1626 | Size += P.first->VerdefMap.size() * sizeof(Elf_Vernaux); |
| 1627 | return Size; |
| 1628 | } |
| 1629 | |
Rafael Espindola | 682a5bc | 2016-11-08 14:42:34 +0000 | [diff] [blame] | 1630 | template InputSection<ELF32LE> *elf::createCommonSection(); |
| 1631 | template InputSection<ELF32BE> *elf::createCommonSection(); |
| 1632 | template InputSection<ELF64LE> *elf::createCommonSection(); |
| 1633 | template InputSection<ELF64BE> *elf::createCommonSection(); |
Rui Ueyama | e8a6102 | 2016-11-05 23:05:47 +0000 | [diff] [blame] | 1634 | |
Rafael Espindola | c0e47fb | 2016-11-08 14:56:27 +0000 | [diff] [blame] | 1635 | template InputSection<ELF32LE> *elf::createInterpSection(); |
| 1636 | template InputSection<ELF32BE> *elf::createInterpSection(); |
| 1637 | template InputSection<ELF64LE> *elf::createInterpSection(); |
| 1638 | template InputSection<ELF64BE> *elf::createInterpSection(); |
Rui Ueyama | e288eef | 2016-11-02 18:58:44 +0000 | [diff] [blame] | 1639 | |
Rui Ueyama | 3da3f06 | 2016-11-10 20:20:37 +0000 | [diff] [blame] | 1640 | template MergeInputSection<ELF32LE> *elf::createCommentSection(); |
| 1641 | template MergeInputSection<ELF32BE> *elf::createCommentSection(); |
| 1642 | template MergeInputSection<ELF64LE> *elf::createCommentSection(); |
| 1643 | template MergeInputSection<ELF64BE> *elf::createCommentSection(); |
| 1644 | |
Simon Atanasyan | fa03b0f | 2016-11-09 21:37:06 +0000 | [diff] [blame] | 1645 | template class elf::MipsAbiFlagsSection<ELF32LE>; |
| 1646 | template class elf::MipsAbiFlagsSection<ELF32BE>; |
| 1647 | template class elf::MipsAbiFlagsSection<ELF64LE>; |
| 1648 | template class elf::MipsAbiFlagsSection<ELF64BE>; |
| 1649 | |
Simon Atanasyan | ce02cf0 | 2016-11-09 21:36:56 +0000 | [diff] [blame] | 1650 | template class elf::MipsOptionsSection<ELF32LE>; |
| 1651 | template class elf::MipsOptionsSection<ELF32BE>; |
| 1652 | template class elf::MipsOptionsSection<ELF64LE>; |
| 1653 | template class elf::MipsOptionsSection<ELF64BE>; |
| 1654 | |
| 1655 | template class elf::MipsReginfoSection<ELF32LE>; |
| 1656 | template class elf::MipsReginfoSection<ELF32BE>; |
| 1657 | template class elf::MipsReginfoSection<ELF64LE>; |
| 1658 | template class elf::MipsReginfoSection<ELF64BE>; |
| 1659 | |
Rui Ueyama | 6dc7fcb | 2016-11-01 20:28:21 +0000 | [diff] [blame] | 1660 | template class elf::BuildIdSection<ELF32LE>; |
| 1661 | template class elf::BuildIdSection<ELF32BE>; |
| 1662 | template class elf::BuildIdSection<ELF64LE>; |
| 1663 | template class elf::BuildIdSection<ELF64BE>; |
| 1664 | |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 1665 | template class elf::GotSection<ELF32LE>; |
| 1666 | template class elf::GotSection<ELF32BE>; |
| 1667 | template class elf::GotSection<ELF64LE>; |
| 1668 | template class elf::GotSection<ELF64BE>; |
| 1669 | |
Simon Atanasyan | 725dc14 | 2016-11-16 21:01:02 +0000 | [diff] [blame] | 1670 | template class elf::MipsGotSection<ELF32LE>; |
| 1671 | template class elf::MipsGotSection<ELF32BE>; |
| 1672 | template class elf::MipsGotSection<ELF64LE>; |
| 1673 | template class elf::MipsGotSection<ELF64BE>; |
| 1674 | |
Eugene Leviant | 41ca327 | 2016-11-10 09:48:29 +0000 | [diff] [blame] | 1675 | template class elf::GotPltSection<ELF32LE>; |
| 1676 | template class elf::GotPltSection<ELF32BE>; |
| 1677 | template class elf::GotPltSection<ELF64LE>; |
| 1678 | template class elf::GotPltSection<ELF64BE>; |
Eugene Leviant | 22eb026 | 2016-11-14 09:16:00 +0000 | [diff] [blame] | 1679 | |
| 1680 | template class elf::StringTableSection<ELF32LE>; |
| 1681 | template class elf::StringTableSection<ELF32BE>; |
| 1682 | template class elf::StringTableSection<ELF64LE>; |
| 1683 | template class elf::StringTableSection<ELF64BE>; |
Eugene Leviant | 6380ce2 | 2016-11-15 12:26:55 +0000 | [diff] [blame] | 1684 | |
| 1685 | template class elf::DynamicSection<ELF32LE>; |
| 1686 | template class elf::DynamicSection<ELF32BE>; |
| 1687 | template class elf::DynamicSection<ELF64LE>; |
| 1688 | template class elf::DynamicSection<ELF64BE>; |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 1689 | |
| 1690 | template class elf::RelocationSection<ELF32LE>; |
| 1691 | template class elf::RelocationSection<ELF32BE>; |
| 1692 | template class elf::RelocationSection<ELF64LE>; |
| 1693 | template class elf::RelocationSection<ELF64BE>; |
Eugene Leviant | 9230db9 | 2016-11-17 09:16:34 +0000 | [diff] [blame] | 1694 | |
| 1695 | template class elf::SymbolTableSection<ELF32LE>; |
| 1696 | template class elf::SymbolTableSection<ELF32BE>; |
| 1697 | template class elf::SymbolTableSection<ELF64LE>; |
| 1698 | template class elf::SymbolTableSection<ELF64BE>; |
Eugene Leviant | be809a7 | 2016-11-18 06:44:18 +0000 | [diff] [blame] | 1699 | |
| 1700 | template class elf::GnuHashTableSection<ELF32LE>; |
| 1701 | template class elf::GnuHashTableSection<ELF32BE>; |
| 1702 | template class elf::GnuHashTableSection<ELF64LE>; |
| 1703 | template class elf::GnuHashTableSection<ELF64BE>; |
Eugene Leviant | b96e809 | 2016-11-18 09:06:47 +0000 | [diff] [blame] | 1704 | |
| 1705 | template class elf::HashTableSection<ELF32LE>; |
| 1706 | template class elf::HashTableSection<ELF32BE>; |
| 1707 | template class elf::HashTableSection<ELF64LE>; |
| 1708 | template class elf::HashTableSection<ELF64BE>; |
Eugene Leviant | ff23d3e | 2016-11-18 14:35:03 +0000 | [diff] [blame] | 1709 | |
| 1710 | template class elf::PltSection<ELF32LE>; |
| 1711 | template class elf::PltSection<ELF32BE>; |
| 1712 | template class elf::PltSection<ELF64LE>; |
| 1713 | template class elf::PltSection<ELF64BE>; |
Eugene Leviant | a113a41 | 2016-11-21 09:24:43 +0000 | [diff] [blame] | 1714 | |
| 1715 | template class elf::GdbIndexSection<ELF32LE>; |
| 1716 | template class elf::GdbIndexSection<ELF32BE>; |
| 1717 | template class elf::GdbIndexSection<ELF64LE>; |
| 1718 | template class elf::GdbIndexSection<ELF64BE>; |
Eugene Leviant | 952eb4d | 2016-11-21 15:52:10 +0000 | [diff] [blame] | 1719 | |
| 1720 | template class elf::EhFrameHeader<ELF32LE>; |
| 1721 | template class elf::EhFrameHeader<ELF32BE>; |
| 1722 | template class elf::EhFrameHeader<ELF64LE>; |
| 1723 | template class elf::EhFrameHeader<ELF64BE>; |
Eugene Leviant | e9bab5d | 2016-11-21 16:59:33 +0000 | [diff] [blame] | 1724 | |
| 1725 | template class elf::VersionTableSection<ELF32LE>; |
| 1726 | template class elf::VersionTableSection<ELF32BE>; |
| 1727 | template class elf::VersionTableSection<ELF64LE>; |
| 1728 | template class elf::VersionTableSection<ELF64BE>; |
| 1729 | |
| 1730 | template class elf::VersionNeedSection<ELF32LE>; |
| 1731 | template class elf::VersionNeedSection<ELF32BE>; |
| 1732 | template class elf::VersionNeedSection<ELF64LE>; |
| 1733 | template class elf::VersionNeedSection<ELF64BE>; |
| 1734 | |
| 1735 | template class elf::VersionDefinitionSection<ELF32LE>; |
| 1736 | template class elf::VersionDefinitionSection<ELF32BE>; |
| 1737 | template class elf::VersionDefinitionSection<ELF64LE>; |
| 1738 | template class elf::VersionDefinitionSection<ELF64BE>; |