1 //===- OutputSections.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 #include "OutputSections.h" 11 #include "Config.h" 12 #include "SymbolTable.h" 13 #include "Target.h" 14 #include "llvm/Support/MathExtras.h" 15 16 using namespace llvm; 17 using namespace llvm::object; 18 using namespace llvm::support::endian; 19 using namespace llvm::ELF; 20 21 using namespace lld; 22 using namespace lld::elf2; 23 24 template <class ELFT> 25 OutputSectionBase<ELFT>::OutputSectionBase(StringRef Name, uint32_t sh_type, 26 uintX_t sh_flags) 27 : Name(Name) { 28 memset(&Header, 0, sizeof(Elf_Shdr)); 29 Header.sh_type = sh_type; 30 Header.sh_flags = sh_flags; 31 } 32 33 template <class ELFT> 34 GotPltSection<ELFT>::GotPltSection() 35 : OutputSectionBase<ELFT>(".got.plt", llvm::ELF::SHT_PROGBITS, 36 llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE) { 37 this->Header.sh_addralign = sizeof(uintX_t); 38 // .got.plt has 3 reserved entry 39 Entries.resize(3); 40 } 41 42 template <class ELFT> void GotPltSection<ELFT>::addEntry(SymbolBody *Sym) { 43 Sym->GotPltIndex = Entries.size(); 44 Entries.push_back(Sym); 45 } 46 47 template <class ELFT> bool GotPltSection<ELFT>::empty() const { 48 return Entries.size() == 3; 49 } 50 51 template <class ELFT> 52 typename GotPltSection<ELFT>::uintX_t 53 GotPltSection<ELFT>::getEntryAddr(const SymbolBody &B) const { 54 return this->getVA() + B.GotPltIndex * sizeof(uintX_t); 55 } 56 57 template <class ELFT> void GotPltSection<ELFT>::finalize() { 58 this->Header.sh_size = Entries.size() * sizeof(uintX_t); 59 } 60 61 template <class ELFT> void GotPltSection<ELFT>::writeTo(uint8_t *Buf) { 62 write<uintX_t, ELFT::TargetEndianness, sizeof(uintX_t)>( 63 Buf, Out<ELFT>::Dynamic->getVA()); 64 for (const SymbolBody *B : Entries) { 65 if (B) 66 Target->writeGotPltEntry(Buf, Out<ELFT>::Plt->getEntryAddr(*B)); 67 Buf += sizeof(uintX_t); 68 } 69 } 70 71 template <class ELFT> 72 GotSection<ELFT>::GotSection() 73 : OutputSectionBase<ELFT>(".got", llvm::ELF::SHT_PROGBITS, 74 llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE) { 75 this->Header.sh_addralign = sizeof(uintX_t); 76 } 77 78 template <class ELFT> void GotSection<ELFT>::addEntry(SymbolBody *Sym) { 79 Sym->GotIndex = Entries.size(); 80 Entries.push_back(Sym); 81 } 82 83 template <class ELFT> 84 typename GotSection<ELFT>::uintX_t 85 GotSection<ELFT>::getEntryAddr(const SymbolBody &B) const { 86 return this->getVA() + B.GotIndex * sizeof(uintX_t); 87 } 88 89 template <class ELFT> void GotSection<ELFT>::writeTo(uint8_t *Buf) { 90 for (const SymbolBody *B : Entries) { 91 uint8_t *Entry = Buf; 92 Buf += sizeof(uintX_t); 93 if (canBePreempted(B, false)) 94 continue; // The dynamic linker will take care of it. 95 uintX_t VA = getSymVA<ELFT>(*B); 96 write<uintX_t, ELFT::TargetEndianness, sizeof(uintX_t)>(Entry, VA); 97 } 98 } 99 100 template <class ELFT> 101 PltSection<ELFT>::PltSection() 102 : OutputSectionBase<ELFT>(".plt", llvm::ELF::SHT_PROGBITS, 103 llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR) { 104 this->Header.sh_addralign = 16; 105 } 106 107 template <class ELFT> void PltSection<ELFT>::writeTo(uint8_t *Buf) { 108 size_t Off = 0; 109 bool LazyReloc = Target->supportsLazyRelocations(); 110 if (LazyReloc) { 111 // First write PLT[0] entry which is special. 112 Target->writePltZeroEntry(Buf, Out<ELFT>::GotPlt->getVA(), this->getVA()); 113 Off += Target->getPltZeroEntrySize(); 114 } 115 for (const SymbolBody *E : Entries) { 116 uint64_t Got = LazyReloc ? Out<ELFT>::GotPlt->getEntryAddr(*E) 117 : Out<ELFT>::Got->getEntryAddr(*E); 118 uint64_t Plt = this->getVA() + Off; 119 Target->writePltEntry(Buf + Off, Got, Plt, E->PltIndex); 120 Off += Target->getPltEntrySize(); 121 } 122 } 123 124 template <class ELFT> void PltSection<ELFT>::addEntry(SymbolBody *Sym) { 125 Sym->PltIndex = Entries.size(); 126 Entries.push_back(Sym); 127 } 128 129 template <class ELFT> 130 typename PltSection<ELFT>::uintX_t 131 PltSection<ELFT>::getEntryAddr(const SymbolBody &B) const { 132 return this->getVA() + Target->getPltZeroEntrySize() + 133 B.PltIndex * Target->getPltEntrySize(); 134 } 135 136 template <class ELFT> void PltSection<ELFT>::finalize() { 137 this->Header.sh_size = Target->getPltZeroEntrySize() + 138 Entries.size() * Target->getPltEntrySize(); 139 } 140 141 template <class ELFT> 142 RelocationSection<ELFT>::RelocationSection(StringRef Name, bool IsRela) 143 : OutputSectionBase<ELFT>(Name, 144 IsRela ? llvm::ELF::SHT_RELA : llvm::ELF::SHT_REL, 145 llvm::ELF::SHF_ALLOC), 146 IsRela(IsRela) { 147 this->Header.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel); 148 this->Header.sh_addralign = ELFT::Is64Bits ? 8 : 4; 149 } 150 151 template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) { 152 const unsigned EntrySize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel); 153 for (const DynamicReloc<ELFT> &Rel : Relocs) { 154 auto *P = reinterpret_cast<Elf_Rel *>(Buf); 155 Buf += EntrySize; 156 157 const InputSection<ELFT> &C = Rel.C; 158 const Elf_Rel &RI = Rel.RI; 159 uint32_t SymIndex = RI.getSymbol(Config->Mips64EL); 160 const ObjectFile<ELFT> &File = *C.getFile(); 161 SymbolBody *Body = File.getSymbolBody(SymIndex); 162 if (Body) 163 Body = Body->repl(); 164 165 uint32_t Type = RI.getType(Config->Mips64EL); 166 bool NeedsCopy = Body && Target->relocNeedsCopy(Type, *Body); 167 bool NeedsGot = Body && Target->relocNeedsGot(Type, *Body); 168 bool CanBePreempted = canBePreempted(Body, NeedsGot); 169 bool LazyReloc = Body && Target->supportsLazyRelocations() && 170 Target->relocNeedsPlt(Type, *Body); 171 172 if (CanBePreempted) { 173 if (NeedsGot) 174 P->setSymbolAndType(Body->getDynamicSymbolTableIndex(), 175 LazyReloc ? Target->getPltReloc() 176 : Target->getGotReloc(), 177 Config->Mips64EL); 178 else 179 P->setSymbolAndType(Body->getDynamicSymbolTableIndex(), 180 NeedsCopy ? Target->getCopyReloc() : Type, 181 Config->Mips64EL); 182 } else { 183 P->setSymbolAndType(0, Target->getRelativeReloc(), Config->Mips64EL); 184 } 185 186 if (NeedsGot) { 187 if (LazyReloc) 188 P->r_offset = Out<ELFT>::GotPlt->getEntryAddr(*Body); 189 else 190 P->r_offset = Out<ELFT>::Got->getEntryAddr(*Body); 191 } else if (NeedsCopy) { 192 P->r_offset = Out<ELFT>::Bss->getVA() + 193 dyn_cast<SharedSymbol<ELFT>>(Body)->OffsetInBSS; 194 } else { 195 P->r_offset = RI.r_offset + C.OutSec->getVA() + C.OutSecOff; 196 } 197 198 uintX_t OrigAddend = 0; 199 if (IsRela && !NeedsGot) 200 OrigAddend = static_cast<const Elf_Rela &>(RI).r_addend; 201 202 uintX_t Addend; 203 if (NeedsCopy) 204 Addend = 0; 205 else if (CanBePreempted) 206 Addend = OrigAddend; 207 else if (Body) 208 Addend = getSymVA<ELFT>(cast<ELFSymbolBody<ELFT>>(*Body)) + OrigAddend; 209 else if (IsRela) 210 Addend = getLocalRelTarget(File, static_cast<const Elf_Rela &>(RI)); 211 else 212 Addend = getLocalRelTarget(File, RI); 213 214 if (IsRela) 215 static_cast<Elf_Rela *>(P)->r_addend = Addend; 216 } 217 } 218 219 template <class ELFT> void RelocationSection<ELFT>::finalize() { 220 this->Header.sh_link = Out<ELFT>::DynSymTab->SectionIndex; 221 this->Header.sh_size = Relocs.size() * this->Header.sh_entsize; 222 } 223 224 template <class ELFT> 225 InterpSection<ELFT>::InterpSection() 226 : OutputSectionBase<ELFT>(".interp", llvm::ELF::SHT_PROGBITS, 227 llvm::ELF::SHF_ALLOC) { 228 this->Header.sh_size = Config->DynamicLinker.size() + 1; 229 this->Header.sh_addralign = 1; 230 } 231 232 template <class ELFT> 233 void OutputSectionBase<ELFT>::writeHeaderTo(Elf_Shdr *SHdr) { 234 Header.sh_name = Out<ELFT>::ShStrTab->getOffset(Name); 235 *SHdr = Header; 236 } 237 238 template <class ELFT> void InterpSection<ELFT>::writeTo(uint8_t *Buf) { 239 memcpy(Buf, Config->DynamicLinker.data(), Config->DynamicLinker.size()); 240 } 241 242 template <class ELFT> 243 HashTableSection<ELFT>::HashTableSection() 244 : OutputSectionBase<ELFT>(".hash", llvm::ELF::SHT_HASH, 245 llvm::ELF::SHF_ALLOC) { 246 this->Header.sh_entsize = sizeof(Elf_Word); 247 this->Header.sh_addralign = sizeof(Elf_Word); 248 } 249 250 static uint32_t hashSysv(StringRef Name) { 251 uint32_t H = 0; 252 for (char C : Name) { 253 H = (H << 4) + C; 254 uint32_t G = H & 0xf0000000; 255 if (G) 256 H ^= G >> 24; 257 H &= ~G; 258 } 259 return H; 260 } 261 262 template <class ELFT> void HashTableSection<ELFT>::finalize() { 263 this->Header.sh_link = Out<ELFT>::DynSymTab->SectionIndex; 264 265 unsigned NumEntries = 2; // nbucket and nchain. 266 NumEntries += Out<ELFT>::DynSymTab->getNumSymbols(); // The chain entries. 267 268 // Create as many buckets as there are symbols. 269 // FIXME: This is simplistic. We can try to optimize it, but implementing 270 // support for SHT_GNU_HASH is probably even more profitable. 271 NumEntries += Out<ELFT>::DynSymTab->getNumSymbols(); 272 this->Header.sh_size = NumEntries * sizeof(Elf_Word); 273 } 274 275 template <class ELFT> void HashTableSection<ELFT>::writeTo(uint8_t *Buf) { 276 unsigned NumSymbols = Out<ELFT>::DynSymTab->getNumSymbols(); 277 auto *P = reinterpret_cast<Elf_Word *>(Buf); 278 *P++ = NumSymbols; // nbucket 279 *P++ = NumSymbols; // nchain 280 281 Elf_Word *Buckets = P; 282 Elf_Word *Chains = P + NumSymbols; 283 284 for (SymbolBody *Body : Out<ELFT>::DynSymTab->getSymbols()) { 285 StringRef Name = Body->getName(); 286 unsigned I = Body->getDynamicSymbolTableIndex(); 287 uint32_t Hash = hashSysv(Name) % NumSymbols; 288 Chains[I] = Buckets[Hash]; 289 Buckets[Hash] = I; 290 } 291 } 292 293 static uint32_t hashGnu(StringRef Name) { 294 uint32_t H = 5381; 295 for (uint8_t C : Name) 296 H = (H << 5) + H + C; 297 return H; 298 } 299 300 template <class ELFT> 301 GnuHashTableSection<ELFT>::GnuHashTableSection() 302 : OutputSectionBase<ELFT>(".gnu.hash", llvm::ELF::SHT_GNU_HASH, 303 llvm::ELF::SHF_ALLOC) { 304 this->Header.sh_entsize = ELFT::Is64Bits ? 0 : 4; 305 this->Header.sh_addralign = ELFT::Is64Bits ? 8 : 4; 306 } 307 308 template <class ELFT> 309 unsigned GnuHashTableSection<ELFT>::calcNBuckets(unsigned NumHashed) { 310 if (!NumHashed) 311 return 0; 312 313 // These values are prime numbers which are not greater than 2^(N-1) + 1. 314 // In result, for any particular NumHashed we return a prime number 315 // which is not greater than NumHashed. 316 static const unsigned Primes[] = { 317 1, 1, 3, 3, 7, 13, 31, 61, 127, 251, 318 509, 1021, 2039, 4093, 8191, 16381, 32749, 65521, 131071}; 319 320 return Primes[std::min<unsigned>(Log2_32_Ceil(NumHashed), 321 array_lengthof(Primes) - 1)]; 322 } 323 324 // Bloom filter estimation: at least 8 bits for each hashed symbol. 325 // GNU Hash table requirement: it should be a power of 2, 326 // the minimum value is 1, even for an empty table. 327 // Expected results for a 32-bit target: 328 // calcMaskWords(0..4) = 1 329 // calcMaskWords(5..8) = 2 330 // calcMaskWords(9..16) = 4 331 // For a 64-bit target: 332 // calcMaskWords(0..8) = 1 333 // calcMaskWords(9..16) = 2 334 // calcMaskWords(17..32) = 4 335 template <class ELFT> 336 unsigned GnuHashTableSection<ELFT>::calcMaskWords(unsigned NumHashed) { 337 if (!NumHashed) 338 return 1; 339 return NextPowerOf2((NumHashed - 1) / sizeof(Elf_Off)); 340 } 341 342 template <class ELFT> void GnuHashTableSection<ELFT>::finalize() { 343 unsigned NumHashed = HashedSymbols.size(); 344 NBuckets = calcNBuckets(NumHashed); 345 MaskWords = calcMaskWords(NumHashed); 346 // Second hash shift estimation: just predefined values. 347 Shift2 = ELFT::Is64Bits ? 6 : 5; 348 349 this->Header.sh_link = Out<ELFT>::DynSymTab->SectionIndex; 350 this->Header.sh_size = sizeof(Elf_Word) * 4 // Header 351 + sizeof(Elf_Off) * MaskWords // Bloom Filter 352 + sizeof(Elf_Word) * NBuckets // Hash Buckets 353 + sizeof(Elf_Word) * NumHashed; // Hash Values 354 } 355 356 template <class ELFT> void GnuHashTableSection<ELFT>::writeTo(uint8_t *Buf) { 357 writeHeader(Buf); 358 if (HashedSymbols.empty()) 359 return; 360 writeBloomFilter(Buf); 361 writeHashTable(Buf); 362 } 363 364 template <class ELFT> 365 void GnuHashTableSection<ELFT>::writeHeader(uint8_t *&Buf) { 366 auto *P = reinterpret_cast<Elf_Word *>(Buf); 367 *P++ = NBuckets; 368 *P++ = Out<ELFT>::DynSymTab->getNumSymbols() - HashedSymbols.size(); 369 *P++ = MaskWords; 370 *P++ = Shift2; 371 Buf = reinterpret_cast<uint8_t *>(P); 372 } 373 374 template <class ELFT> 375 void GnuHashTableSection<ELFT>::writeBloomFilter(uint8_t *&Buf) { 376 unsigned C = sizeof(Elf_Off) * 8; 377 378 auto *Masks = reinterpret_cast<Elf_Off *>(Buf); 379 for (const HashedSymbolData &Item : HashedSymbols) { 380 size_t Pos = (Item.Hash / C) & (MaskWords - 1); 381 uintX_t V = (uintX_t(1) << (Item.Hash % C)) | 382 (uintX_t(1) << ((Item.Hash >> Shift2) % C)); 383 Masks[Pos] |= V; 384 } 385 Buf += sizeof(Elf_Off) * MaskWords; 386 } 387 388 template <class ELFT> 389 void GnuHashTableSection<ELFT>::writeHashTable(uint8_t *Buf) { 390 Elf_Word *Buckets = reinterpret_cast<Elf_Word *>(Buf); 391 Elf_Word *Values = Buckets + NBuckets; 392 393 int PrevBucket = -1; 394 int I = 0; 395 for (const HashedSymbolData &Item : HashedSymbols) { 396 int Bucket = Item.Hash % NBuckets; 397 assert(PrevBucket <= Bucket); 398 if (Bucket != PrevBucket) { 399 Buckets[Bucket] = Item.Body->getDynamicSymbolTableIndex(); 400 PrevBucket = Bucket; 401 if (I > 0) 402 Values[I - 1] |= 1; 403 } 404 Values[I] = Item.Hash & ~1; 405 ++I; 406 } 407 if (I > 0) 408 Values[I - 1] |= 1; 409 } 410 411 static bool includeInGnuHashTable(SymbolBody *B) { 412 // Assume that includeInDynamicSymtab() is already checked. 413 return !B->isUndefined(); 414 } 415 416 template <class ELFT> 417 void GnuHashTableSection<ELFT>::addSymbols(std::vector<SymbolBody *> &Symbols) { 418 std::vector<SymbolBody *> NotHashed; 419 NotHashed.reserve(Symbols.size()); 420 HashedSymbols.reserve(Symbols.size()); 421 for (SymbolBody *B : Symbols) { 422 if (includeInGnuHashTable(B)) 423 HashedSymbols.push_back(HashedSymbolData{B, hashGnu(B->getName())}); 424 else 425 NotHashed.push_back(B); 426 } 427 if (HashedSymbols.empty()) 428 return; 429 430 unsigned NBuckets = calcNBuckets(HashedSymbols.size()); 431 std::stable_sort(HashedSymbols.begin(), HashedSymbols.end(), 432 [&](const HashedSymbolData &L, const HashedSymbolData &R) { 433 return L.Hash % NBuckets < R.Hash % NBuckets; 434 }); 435 436 Symbols = std::move(NotHashed); 437 for (const HashedSymbolData &Item : HashedSymbols) 438 Symbols.push_back(Item.Body); 439 } 440 441 template <class ELFT> 442 DynamicSection<ELFT>::DynamicSection(SymbolTable<ELFT> &SymTab) 443 : OutputSectionBase<ELFT>(".dynamic", llvm::ELF::SHT_DYNAMIC, 444 llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE), 445 SymTab(SymTab) { 446 Elf_Shdr &Header = this->Header; 447 Header.sh_addralign = ELFT::Is64Bits ? 8 : 4; 448 Header.sh_entsize = ELFT::Is64Bits ? 16 : 8; 449 } 450 451 template <class ELFT> void DynamicSection<ELFT>::finalize() { 452 if (this->Header.sh_size) 453 return; // Already finalized. 454 455 Elf_Shdr &Header = this->Header; 456 Header.sh_link = Out<ELFT>::DynStrTab->SectionIndex; 457 458 unsigned NumEntries = 0; 459 if (Out<ELFT>::RelaDyn->hasRelocs()) { 460 ++NumEntries; // DT_RELA / DT_REL 461 ++NumEntries; // DT_RELASZ / DT_RELSZ 462 ++NumEntries; // DT_RELAENT / DT_RELENT 463 } 464 if (Out<ELFT>::RelaPlt && Out<ELFT>::RelaPlt->hasRelocs()) { 465 ++NumEntries; // DT_JMPREL 466 ++NumEntries; // DT_PLTRELSZ 467 ++NumEntries; // DT_PLTGOT 468 ++NumEntries; // DT_PLTREL 469 } 470 471 ++NumEntries; // DT_SYMTAB 472 ++NumEntries; // DT_SYMENT 473 ++NumEntries; // DT_STRTAB 474 ++NumEntries; // DT_STRSZ 475 if (Out<ELFT>::GnuHashTab) 476 ++NumEntries; // DT_GNU_HASH 477 if (Out<ELFT>::HashTab) 478 ++NumEntries; // DT_HASH 479 480 if (!Config->RPath.empty()) { 481 ++NumEntries; // DT_RUNPATH / DT_RPATH 482 Out<ELFT>::DynStrTab->add(Config->RPath); 483 } 484 485 if (!Config->SoName.empty()) { 486 ++NumEntries; // DT_SONAME 487 Out<ELFT>::DynStrTab->add(Config->SoName); 488 } 489 490 if (PreInitArraySec) 491 NumEntries += 2; 492 if (InitArraySec) 493 NumEntries += 2; 494 if (FiniArraySec) 495 NumEntries += 2; 496 497 for (const std::unique_ptr<SharedFile<ELFT>> &F : SymTab.getSharedFiles()) { 498 if (!F->isNeeded()) 499 continue; 500 Out<ELFT>::DynStrTab->add(F->getSoName()); 501 ++NumEntries; 502 } 503 504 if (Symbol *S = SymTab.getSymbols().lookup(Config->Init)) 505 InitSym = dyn_cast<ELFSymbolBody<ELFT>>(S->Body); 506 if (Symbol *S = SymTab.getSymbols().lookup(Config->Fini)) 507 FiniSym = dyn_cast<ELFSymbolBody<ELFT>>(S->Body); 508 if (InitSym) 509 ++NumEntries; // DT_INIT 510 if (FiniSym) 511 ++NumEntries; // DT_FINI 512 513 if (Config->Bsymbolic) 514 DtFlags |= DF_SYMBOLIC; 515 if (Config->ZNodelete) 516 DtFlags1 |= DF_1_NODELETE; 517 if (Config->ZNow) { 518 DtFlags |= DF_BIND_NOW; 519 DtFlags1 |= DF_1_NOW; 520 } 521 if (Config->ZOrigin) { 522 DtFlags |= DF_ORIGIN; 523 DtFlags1 |= DF_1_ORIGIN; 524 } 525 526 if (DtFlags) 527 ++NumEntries; // DT_FLAGS 528 if (DtFlags1) 529 ++NumEntries; // DT_FLAGS_1 530 ++NumEntries; // DT_NULL 531 532 Header.sh_size = NumEntries * Header.sh_entsize; 533 } 534 535 template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) { 536 auto *P = reinterpret_cast<Elf_Dyn *>(Buf); 537 538 auto WritePtr = [&](int32_t Tag, uint64_t Val) { 539 P->d_tag = Tag; 540 P->d_un.d_ptr = Val; 541 ++P; 542 }; 543 544 auto WriteVal = [&](int32_t Tag, uint32_t Val) { 545 P->d_tag = Tag; 546 P->d_un.d_val = Val; 547 ++P; 548 }; 549 550 if (Out<ELFT>::RelaDyn->hasRelocs()) { 551 bool IsRela = Out<ELFT>::RelaDyn->isRela(); 552 WritePtr(IsRela ? DT_RELA : DT_REL, Out<ELFT>::RelaDyn->getVA()); 553 WriteVal(IsRela ? DT_RELASZ : DT_RELSZ, Out<ELFT>::RelaDyn->getSize()); 554 WriteVal(IsRela ? DT_RELAENT : DT_RELENT, 555 IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel)); 556 } 557 if (Out<ELFT>::RelaPlt && Out<ELFT>::RelaPlt->hasRelocs()) { 558 WritePtr(DT_JMPREL, Out<ELFT>::RelaPlt->getVA()); 559 WriteVal(DT_PLTRELSZ, Out<ELFT>::RelaPlt->getSize()); 560 WritePtr(DT_PLTGOT, Out<ELFT>::GotPlt->getVA()); 561 WriteVal(DT_PLTREL, Out<ELFT>::RelaPlt->isRela() ? DT_RELA : DT_REL); 562 } 563 564 WritePtr(DT_SYMTAB, Out<ELFT>::DynSymTab->getVA()); 565 WritePtr(DT_SYMENT, sizeof(Elf_Sym)); 566 WritePtr(DT_STRTAB, Out<ELFT>::DynStrTab->getVA()); 567 WriteVal(DT_STRSZ, Out<ELFT>::DynStrTab->data().size()); 568 if (Out<ELFT>::GnuHashTab) 569 WritePtr(DT_GNU_HASH, Out<ELFT>::GnuHashTab->getVA()); 570 if (Out<ELFT>::HashTab) 571 WritePtr(DT_HASH, Out<ELFT>::HashTab->getVA()); 572 573 if (!Config->RPath.empty()) 574 575 // If --enable-new-dtags is set lld emits DT_RUNPATH 576 // instead of DT_RPATH. The two tags are functionally 577 // equivalent except for the following: 578 // - DT_RUNPATH is searched after LD_LIBRARY_PATH, while 579 // DT_RPATH is searched before. 580 // - DT_RUNPATH is used only to search for direct 581 // dependencies of the object it's contained in, while 582 // DT_RPATH is used for indirect dependencies as well. 583 WriteVal(Config->EnableNewDtags ? DT_RUNPATH : DT_RPATH, 584 Out<ELFT>::DynStrTab->getOffset(Config->RPath)); 585 586 if (!Config->SoName.empty()) 587 WriteVal(DT_SONAME, Out<ELFT>::DynStrTab->getOffset(Config->SoName)); 588 589 auto WriteArray = [&](int32_t T1, int32_t T2, 590 const OutputSectionBase<ELFT> *Sec) { 591 if (!Sec) 592 return; 593 WritePtr(T1, Sec->getVA()); 594 WriteVal(T2, Sec->getSize()); 595 }; 596 WriteArray(DT_PREINIT_ARRAY, DT_PREINIT_ARRAYSZ, PreInitArraySec); 597 WriteArray(DT_INIT_ARRAY, DT_INIT_ARRAYSZ, InitArraySec); 598 WriteArray(DT_FINI_ARRAY, DT_FINI_ARRAYSZ, FiniArraySec); 599 600 for (const std::unique_ptr<SharedFile<ELFT>> &F : SymTab.getSharedFiles()) 601 if (F->isNeeded()) 602 WriteVal(DT_NEEDED, Out<ELFT>::DynStrTab->getOffset(F->getSoName())); 603 604 if (InitSym) 605 WritePtr(DT_INIT, getSymVA<ELFT>(*InitSym)); 606 if (FiniSym) 607 WritePtr(DT_FINI, getSymVA<ELFT>(*FiniSym)); 608 if (DtFlags) 609 WriteVal(DT_FLAGS, DtFlags); 610 if (DtFlags1) 611 WriteVal(DT_FLAGS_1, DtFlags1); 612 WriteVal(DT_NULL, 0); 613 } 614 615 template <class ELFT> 616 OutputSection<ELFT>::OutputSection(StringRef Name, uint32_t sh_type, 617 uintX_t sh_flags) 618 : OutputSectionBase<ELFT>(Name, sh_type, sh_flags) {} 619 620 template <class ELFT> 621 void OutputSection<ELFT>::addSection(InputSection<ELFT> *C) { 622 Sections.push_back(C); 623 C->OutSec = this; 624 uint32_t Align = C->getAlign(); 625 if (Align > this->Header.sh_addralign) 626 this->Header.sh_addralign = Align; 627 628 uintX_t Off = this->Header.sh_size; 629 Off = RoundUpToAlignment(Off, Align); 630 C->OutSecOff = Off; 631 Off += C->getSize(); 632 this->Header.sh_size = Off; 633 } 634 635 template <class ELFT> 636 typename ELFFile<ELFT>::uintX_t lld::elf2::getSymVA(const SymbolBody &S) { 637 switch (S.kind()) { 638 case SymbolBody::DefinedSyntheticKind: { 639 auto &D = cast<DefinedSynthetic<ELFT>>(S); 640 return D.Section.getVA() + D.Sym.st_value; 641 } 642 case SymbolBody::DefinedAbsoluteKind: 643 return cast<DefinedAbsolute<ELFT>>(S).Sym.st_value; 644 case SymbolBody::DefinedRegularKind: { 645 const auto &DR = cast<DefinedRegular<ELFT>>(S); 646 InputSectionBase<ELFT> &SC = DR.Section; 647 return SC.OutSec->getVA() + SC.getOffset(DR.Sym); 648 } 649 case SymbolBody::DefinedCommonKind: 650 return Out<ELFT>::Bss->getVA() + cast<DefinedCommon<ELFT>>(S).OffsetInBSS; 651 case SymbolBody::SharedKind: { 652 auto &SS = cast<SharedSymbol<ELFT>>(S); 653 if (SS.NeedsCopy) 654 return Out<ELFT>::Bss->getVA() + SS.OffsetInBSS; 655 return 0; 656 } 657 case SymbolBody::UndefinedKind: 658 return 0; 659 case SymbolBody::LazyKind: 660 assert(S.isUsedInRegularObj() && "Lazy symbol reached writer"); 661 return 0; 662 } 663 llvm_unreachable("Invalid symbol kind"); 664 } 665 666 // Returns a VA which a relocatin RI refers to. Used only for local symbols. 667 // For non-local symbols, use getSymVA instead. 668 template <class ELFT, bool IsRela> 669 typename ELFFile<ELFT>::uintX_t 670 lld::elf2::getLocalRelTarget(const ObjectFile<ELFT> &File, 671 const Elf_Rel_Impl<ELFT, IsRela> &RI) { 672 typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym; 673 typedef typename ELFFile<ELFT>::uintX_t uintX_t; 674 675 uintX_t Addend = getAddend<ELFT>(RI); 676 677 // PPC64 has a special relocation representing the TOC base pointer 678 // that does not have a corresponding symbol. 679 if (Config->EMachine == EM_PPC64 && RI.getType(false) == R_PPC64_TOC) 680 return getPPC64TocBase() + Addend; 681 682 const Elf_Sym *Sym = 683 File.getObj().getRelocationSymbol(&RI, File.getSymbolTable()); 684 685 if (!Sym) 686 error("Unsupported relocation without symbol"); 687 688 // According to the ELF spec reference to a local symbol from outside 689 // the group are not allowed. Unfortunately .eh_frame breaks that rule 690 // and must be treated specially. For now we just replace the symbol with 691 // 0. 692 InputSectionBase<ELFT> *Section = File.getSection(*Sym); 693 if (Section == &InputSection<ELFT>::Discarded) 694 return Addend; 695 696 uintX_t VA = Section->OutSec->getVA(); 697 if (isa<InputSection<ELFT>>(Section)) 698 return VA + Section->getOffset(*Sym) + Addend; 699 700 uintX_t Offset = Sym->st_value; 701 if (Sym->getType() == STT_SECTION) { 702 Offset += Addend; 703 Addend = 0; 704 } 705 return VA + cast<MergeInputSection<ELFT>>(Section)->getOffset(Offset) + 706 Addend; 707 } 708 709 // Returns true if a symbol can be replaced at load-time by a symbol 710 // with the same name defined in other ELF executable or DSO. 711 bool lld::elf2::canBePreempted(const SymbolBody *Body, bool NeedsGot) { 712 if (!Body) 713 return false; // Body is a local symbol. 714 if (Body->isShared()) 715 return true; 716 717 if (Body->isUndefined()) { 718 if (!Body->isWeak()) 719 return true; 720 721 // This is an horrible corner case. Ideally we would like to say that any 722 // undefined symbol can be preempted so that the dynamic linker has a 723 // chance of finding it at runtime. 724 // 725 // The problem is that the code sequence used to test for weak undef 726 // functions looks like 727 // if (func) func() 728 // If the code is -fPIC the first reference is a load from the got and 729 // everything works. 730 // If the code is not -fPIC there is no reasonable way to solve it: 731 // * A relocation writing to the text segment will fail (it is ro). 732 // * A copy relocation doesn't work for functions. 733 // * The trick of using a plt entry as the address would fail here since 734 // the plt entry would have a non zero address. 735 // Since we cannot do anything better, we just resolve the symbol to 0 and 736 // don't produce a dynamic relocation. 737 // 738 // As an extra hack, assume that if we are producing a shared library the 739 // user knows what he or she is doing and can handle a dynamic relocation. 740 return Config->Shared || NeedsGot; 741 } 742 if (!Config->Shared) 743 return false; 744 return Body->getVisibility() == STV_DEFAULT; 745 } 746 747 template <class ELFT> void OutputSection<ELFT>::writeTo(uint8_t *Buf) { 748 for (InputSection<ELFT> *C : Sections) 749 C->writeTo(Buf); 750 } 751 752 template <class ELFT> 753 MergeOutputSection<ELFT>::MergeOutputSection(StringRef Name, uint32_t sh_type, 754 uintX_t sh_flags) 755 : OutputSectionBase<ELFT>(Name, sh_type, sh_flags) {} 756 757 template <class ELFT> void MergeOutputSection<ELFT>::writeTo(uint8_t *Buf) { 758 if (shouldTailMerge()) { 759 StringRef Data = Builder.data(); 760 memcpy(Buf, Data.data(), Data.size()); 761 return; 762 } 763 for (const std::pair<StringRef, size_t> &P : Builder.getMap()) { 764 StringRef Data = P.first; 765 memcpy(Buf + P.second, Data.data(), Data.size()); 766 } 767 } 768 769 static size_t findNull(StringRef S, size_t EntSize) { 770 // Optimize the common case. 771 if (EntSize == 1) 772 return S.find(0); 773 774 for (unsigned I = 0, N = S.size(); I != N; I += EntSize) { 775 const char *B = S.begin() + I; 776 if (std::all_of(B, B + EntSize, [](char C) { return C == 0; })) 777 return I; 778 } 779 return StringRef::npos; 780 } 781 782 template <class ELFT> 783 void MergeOutputSection<ELFT>::addSection(MergeInputSection<ELFT> *S) { 784 S->OutSec = this; 785 uint32_t Align = S->getAlign(); 786 if (Align > this->Header.sh_addralign) 787 this->Header.sh_addralign = Align; 788 789 ArrayRef<uint8_t> D = S->getSectionData(); 790 StringRef Data((const char *)D.data(), D.size()); 791 uintX_t EntSize = S->getSectionHdr()->sh_entsize; 792 uintX_t Offset = 0; 793 794 if (this->Header.sh_flags & SHF_STRINGS) { 795 while (!Data.empty()) { 796 size_t End = findNull(Data, EntSize); 797 if (End == StringRef::npos) 798 error("String is not null terminated"); 799 StringRef Entry = Data.substr(0, End + EntSize); 800 size_t OutputOffset = Builder.add(Entry); 801 if (shouldTailMerge()) 802 OutputOffset = -1; 803 S->Offsets.push_back(std::make_pair(Offset, OutputOffset)); 804 uintX_t Size = End + EntSize; 805 Data = Data.substr(Size); 806 Offset += Size; 807 } 808 } else { 809 for (unsigned I = 0, N = Data.size(); I != N; I += EntSize) { 810 StringRef Entry = Data.substr(I, EntSize); 811 size_t OutputOffset = Builder.add(Entry); 812 S->Offsets.push_back(std::make_pair(Offset, OutputOffset)); 813 Offset += EntSize; 814 } 815 } 816 } 817 818 template <class ELFT> 819 unsigned MergeOutputSection<ELFT>::getOffset(StringRef Val) { 820 return Builder.getOffset(Val); 821 } 822 823 template <class ELFT> bool MergeOutputSection<ELFT>::shouldTailMerge() const { 824 return Config->Optimize >= 2 && this->Header.sh_flags & SHF_STRINGS; 825 } 826 827 template <class ELFT> void MergeOutputSection<ELFT>::finalize() { 828 if (shouldTailMerge()) 829 Builder.finalize(); 830 this->Header.sh_size = Builder.getSize(); 831 } 832 833 template <class ELFT> 834 StringTableSection<ELFT>::StringTableSection(StringRef Name, bool Dynamic) 835 : OutputSectionBase<ELFT>(Name, llvm::ELF::SHT_STRTAB, 836 Dynamic ? (uintX_t)llvm::ELF::SHF_ALLOC : 0), 837 Dynamic(Dynamic) { 838 this->Header.sh_addralign = 1; 839 } 840 841 template <class ELFT> void StringTableSection<ELFT>::writeTo(uint8_t *Buf) { 842 StringRef Data = StrTabBuilder.data(); 843 memcpy(Buf, Data.data(), Data.size()); 844 } 845 846 template <class ELFT> bool lld::elf2::includeInSymtab(const SymbolBody &B) { 847 if (!B.isUsedInRegularObj()) 848 return false; 849 850 // Don't include synthetic symbols like __init_array_start in every output. 851 if (auto *U = dyn_cast<DefinedAbsolute<ELFT>>(&B)) 852 if (&U->Sym == &DefinedAbsolute<ELFT>::IgnoreUndef) 853 return false; 854 855 return true; 856 } 857 858 bool lld::elf2::includeInDynamicSymtab(const SymbolBody &B) { 859 uint8_t V = B.getVisibility(); 860 if (V != STV_DEFAULT && V != STV_PROTECTED) 861 return false; 862 863 if (Config->ExportDynamic || Config->Shared) 864 return true; 865 return B.isUsedInDynamicReloc(); 866 } 867 868 template <class ELFT> 869 bool lld::elf2::shouldKeepInSymtab(const ObjectFile<ELFT> &File, 870 StringRef SymName, 871 const typename ELFFile<ELFT>::Elf_Sym &Sym) { 872 if (Sym.getType() == STT_SECTION) 873 return false; 874 875 // If sym references a section in a discarded group, don't keep it. 876 if (File.getSection(Sym) == &InputSection<ELFT>::Discarded) 877 return false; 878 879 if (Config->DiscardNone) 880 return true; 881 882 // ELF defines dynamic locals as symbols which name starts with ".L". 883 return !(Config->DiscardLocals && SymName.startswith(".L")); 884 } 885 886 template <class ELFT> 887 SymbolTableSection<ELFT>::SymbolTableSection( 888 SymbolTable<ELFT> &Table, StringTableSection<ELFT> &StrTabSec) 889 : OutputSectionBase<ELFT>( 890 StrTabSec.isDynamic() ? ".dynsym" : ".symtab", 891 StrTabSec.isDynamic() ? llvm::ELF::SHT_DYNSYM : llvm::ELF::SHT_SYMTAB, 892 StrTabSec.isDynamic() ? (uintX_t)llvm::ELF::SHF_ALLOC : 0), 893 Table(Table), StrTabSec(StrTabSec) { 894 typedef OutputSectionBase<ELFT> Base; 895 typename Base::Elf_Shdr &Header = this->Header; 896 897 Header.sh_entsize = sizeof(Elf_Sym); 898 Header.sh_addralign = ELFT::Is64Bits ? 8 : 4; 899 } 900 901 template <class ELFT> void SymbolTableSection<ELFT>::finalize() { 902 if (this->Header.sh_size) 903 return; // Already finalized. 904 905 this->Header.sh_size = getNumSymbols() * sizeof(Elf_Sym); 906 this->Header.sh_link = StrTabSec.SectionIndex; 907 this->Header.sh_info = NumLocals + 1; 908 909 if (!StrTabSec.isDynamic()) { 910 std::stable_sort(Symbols.begin(), Symbols.end(), 911 [](SymbolBody *L, SymbolBody *R) { 912 return getSymbolBinding(L) == STB_LOCAL && 913 getSymbolBinding(R) != STB_LOCAL; 914 }); 915 return; 916 } 917 if (Out<ELFT>::GnuHashTab) 918 // NB: It also sorts Symbols to meet the GNU hash table requirements. 919 Out<ELFT>::GnuHashTab->addSymbols(Symbols); 920 size_t I = 0; 921 for (SymbolBody *B : Symbols) 922 B->setDynamicSymbolTableIndex(++I); 923 } 924 925 template <class ELFT> 926 void SymbolTableSection<ELFT>::addLocalSymbol(StringRef Name) { 927 StrTabSec.add(Name); 928 ++NumVisible; 929 ++NumLocals; 930 } 931 932 template <class ELFT> 933 void SymbolTableSection<ELFT>::addSymbol(SymbolBody *Body) { 934 StrTabSec.add(Body->getName()); 935 Symbols.push_back(Body); 936 ++NumVisible; 937 } 938 939 template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) { 940 Buf += sizeof(Elf_Sym); 941 942 // All symbols with STB_LOCAL binding precede the weak and global symbols. 943 // .dynsym only contains global symbols. 944 if (!Config->DiscardAll && !StrTabSec.isDynamic()) 945 writeLocalSymbols(Buf); 946 947 writeGlobalSymbols(Buf); 948 } 949 950 template <class ELFT> 951 void SymbolTableSection<ELFT>::writeLocalSymbols(uint8_t *&Buf) { 952 // Iterate over all input object files to copy their local symbols 953 // to the output symbol table pointed by Buf. 954 for (const std::unique_ptr<ObjectFile<ELFT>> &File : Table.getObjectFiles()) { 955 Elf_Sym_Range Syms = File->getLocalSymbols(); 956 for (const Elf_Sym &Sym : Syms) { 957 ErrorOr<StringRef> SymNameOrErr = Sym.getName(File->getStringTable()); 958 error(SymNameOrErr); 959 StringRef SymName = *SymNameOrErr; 960 if (!shouldKeepInSymtab<ELFT>(*File, SymName, Sym)) 961 continue; 962 963 auto *ESym = reinterpret_cast<Elf_Sym *>(Buf); 964 uintX_t VA = 0; 965 if (Sym.st_shndx == SHN_ABS) { 966 ESym->st_shndx = SHN_ABS; 967 VA = Sym.st_value; 968 } else { 969 InputSectionBase<ELFT> *Section = File->getSection(Sym); 970 if (!Section->isLive()) 971 continue; 972 const OutputSectionBase<ELFT> *OutSec = Section->OutSec; 973 ESym->st_shndx = OutSec->SectionIndex; 974 VA += OutSec->getVA() + Section->getOffset(Sym); 975 } 976 ESym->st_name = StrTabSec.getOffset(SymName); 977 ESym->st_size = Sym.st_size; 978 ESym->setBindingAndType(Sym.getBinding(), Sym.getType()); 979 ESym->st_value = VA; 980 Buf += sizeof(*ESym); 981 } 982 } 983 } 984 985 template <class ELFT> 986 void SymbolTableSection<ELFT>::writeGlobalSymbols(uint8_t *Buf) { 987 // Write the internal symbol table contents to the output symbol table 988 // pointed by Buf. 989 auto *ESym = reinterpret_cast<Elf_Sym *>(Buf); 990 for (SymbolBody *Body : Symbols) { 991 const OutputSectionBase<ELFT> *OutSec = nullptr; 992 993 switch (Body->kind()) { 994 case SymbolBody::DefinedSyntheticKind: 995 OutSec = &cast<DefinedSynthetic<ELFT>>(Body)->Section; 996 break; 997 case SymbolBody::DefinedRegularKind: { 998 auto *Sym = cast<DefinedRegular<ELFT>>(Body->repl()); 999 if (!Sym->Section.isLive()) 1000 continue; 1001 OutSec = Sym->Section.OutSec; 1002 break; 1003 } 1004 case SymbolBody::DefinedCommonKind: 1005 OutSec = Out<ELFT>::Bss; 1006 break; 1007 case SymbolBody::SharedKind: { 1008 if (cast<SharedSymbol<ELFT>>(Body)->NeedsCopy) 1009 OutSec = Out<ELFT>::Bss; 1010 break; 1011 } 1012 case SymbolBody::UndefinedKind: 1013 case SymbolBody::DefinedAbsoluteKind: 1014 case SymbolBody::LazyKind: 1015 break; 1016 } 1017 1018 StringRef Name = Body->getName(); 1019 ESym->st_name = StrTabSec.getOffset(Name); 1020 1021 unsigned char Type = STT_NOTYPE; 1022 uintX_t Size = 0; 1023 if (const auto *EBody = dyn_cast<ELFSymbolBody<ELFT>>(Body)) { 1024 const Elf_Sym &InputSym = EBody->Sym; 1025 Type = InputSym.getType(); 1026 Size = InputSym.st_size; 1027 } 1028 1029 ESym->setBindingAndType(getSymbolBinding(Body), Type); 1030 ESym->st_size = Size; 1031 ESym->setVisibility(Body->getVisibility()); 1032 ESym->st_value = getSymVA<ELFT>(*Body); 1033 1034 if (isa<DefinedAbsolute<ELFT>>(Body)) 1035 ESym->st_shndx = SHN_ABS; 1036 else if (OutSec) 1037 ESym->st_shndx = OutSec->SectionIndex; 1038 1039 ++ESym; 1040 } 1041 } 1042 1043 template <class ELFT> 1044 uint8_t SymbolTableSection<ELFT>::getSymbolBinding(SymbolBody *Body) { 1045 uint8_t Visibility = Body->getVisibility(); 1046 if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED) 1047 return STB_LOCAL; 1048 if (const auto *EBody = dyn_cast<ELFSymbolBody<ELFT>>(Body)) 1049 return EBody->Sym.getBinding(); 1050 return Body->isWeak() ? STB_WEAK : STB_GLOBAL; 1051 } 1052 1053 namespace lld { 1054 namespace elf2 { 1055 template class OutputSectionBase<ELF32LE>; 1056 template class OutputSectionBase<ELF32BE>; 1057 template class OutputSectionBase<ELF64LE>; 1058 template class OutputSectionBase<ELF64BE>; 1059 1060 template class GotPltSection<ELF32LE>; 1061 template class GotPltSection<ELF32BE>; 1062 template class GotPltSection<ELF64LE>; 1063 template class GotPltSection<ELF64BE>; 1064 1065 template class GotSection<ELF32LE>; 1066 template class GotSection<ELF32BE>; 1067 template class GotSection<ELF64LE>; 1068 template class GotSection<ELF64BE>; 1069 1070 template class PltSection<ELF32LE>; 1071 template class PltSection<ELF32BE>; 1072 template class PltSection<ELF64LE>; 1073 template class PltSection<ELF64BE>; 1074 1075 template class RelocationSection<ELF32LE>; 1076 template class RelocationSection<ELF32BE>; 1077 template class RelocationSection<ELF64LE>; 1078 template class RelocationSection<ELF64BE>; 1079 1080 template class InterpSection<ELF32LE>; 1081 template class InterpSection<ELF32BE>; 1082 template class InterpSection<ELF64LE>; 1083 template class InterpSection<ELF64BE>; 1084 1085 template class GnuHashTableSection<ELF32LE>; 1086 template class GnuHashTableSection<ELF32BE>; 1087 template class GnuHashTableSection<ELF64LE>; 1088 template class GnuHashTableSection<ELF64BE>; 1089 1090 template class HashTableSection<ELF32LE>; 1091 template class HashTableSection<ELF32BE>; 1092 template class HashTableSection<ELF64LE>; 1093 template class HashTableSection<ELF64BE>; 1094 1095 template class DynamicSection<ELF32LE>; 1096 template class DynamicSection<ELF32BE>; 1097 template class DynamicSection<ELF64LE>; 1098 template class DynamicSection<ELF64BE>; 1099 1100 template class OutputSection<ELF32LE>; 1101 template class OutputSection<ELF32BE>; 1102 template class OutputSection<ELF64LE>; 1103 template class OutputSection<ELF64BE>; 1104 1105 template class MergeOutputSection<ELF32LE>; 1106 template class MergeOutputSection<ELF32BE>; 1107 template class MergeOutputSection<ELF64LE>; 1108 template class MergeOutputSection<ELF64BE>; 1109 1110 template class StringTableSection<ELF32LE>; 1111 template class StringTableSection<ELF32BE>; 1112 template class StringTableSection<ELF64LE>; 1113 template class StringTableSection<ELF64BE>; 1114 1115 template class SymbolTableSection<ELF32LE>; 1116 template class SymbolTableSection<ELF32BE>; 1117 template class SymbolTableSection<ELF64LE>; 1118 template class SymbolTableSection<ELF64BE>; 1119 1120 template ELFFile<ELF32LE>::uintX_t getSymVA<ELF32LE>(const SymbolBody &); 1121 template ELFFile<ELF32BE>::uintX_t getSymVA<ELF32BE>(const SymbolBody &); 1122 template ELFFile<ELF64LE>::uintX_t getSymVA<ELF64LE>(const SymbolBody &); 1123 template ELFFile<ELF64BE>::uintX_t getSymVA<ELF64BE>(const SymbolBody &); 1124 1125 template ELFFile<ELF32LE>::uintX_t 1126 getLocalRelTarget(const ObjectFile<ELF32LE> &, 1127 const ELFFile<ELF32LE>::Elf_Rel &); 1128 template ELFFile<ELF32BE>::uintX_t 1129 getLocalRelTarget(const ObjectFile<ELF32BE> &, 1130 const ELFFile<ELF32BE>::Elf_Rel &); 1131 template ELFFile<ELF64LE>::uintX_t 1132 getLocalRelTarget(const ObjectFile<ELF64LE> &, 1133 const ELFFile<ELF64LE>::Elf_Rel &); 1134 template ELFFile<ELF64BE>::uintX_t 1135 getLocalRelTarget(const ObjectFile<ELF64BE> &, 1136 const ELFFile<ELF64BE>::Elf_Rel &); 1137 1138 template ELFFile<ELF32LE>::uintX_t 1139 getLocalRelTarget(const ObjectFile<ELF32LE> &, 1140 const ELFFile<ELF32LE>::Elf_Rela &); 1141 template ELFFile<ELF32BE>::uintX_t 1142 getLocalRelTarget(const ObjectFile<ELF32BE> &, 1143 const ELFFile<ELF32BE>::Elf_Rela &); 1144 template ELFFile<ELF64LE>::uintX_t 1145 getLocalRelTarget(const ObjectFile<ELF64LE> &, 1146 const ELFFile<ELF64LE>::Elf_Rela &); 1147 template ELFFile<ELF64BE>::uintX_t 1148 getLocalRelTarget(const ObjectFile<ELF64BE> &, 1149 const ELFFile<ELF64BE>::Elf_Rela &); 1150 1151 template bool includeInSymtab<ELF32LE>(const SymbolBody &); 1152 template bool includeInSymtab<ELF32BE>(const SymbolBody &); 1153 template bool includeInSymtab<ELF64LE>(const SymbolBody &); 1154 template bool includeInSymtab<ELF64BE>(const SymbolBody &); 1155 1156 template bool shouldKeepInSymtab<ELF32LE>(const ObjectFile<ELF32LE> &, 1157 StringRef, 1158 const ELFFile<ELF32LE>::Elf_Sym &); 1159 template bool shouldKeepInSymtab<ELF32BE>(const ObjectFile<ELF32BE> &, 1160 StringRef, 1161 const ELFFile<ELF32BE>::Elf_Sym &); 1162 template bool shouldKeepInSymtab<ELF64LE>(const ObjectFile<ELF64LE> &, 1163 StringRef, 1164 const ELFFile<ELF64LE>::Elf_Sym &); 1165 template bool shouldKeepInSymtab<ELF64BE>(const ObjectFile<ELF64BE> &, 1166 StringRef, 1167 const ELFFile<ELF64BE>::Elf_Sym &); 1168 } 1169 } 1170