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 "EhFrame.h" 13 #include "LinkerScript.h" 14 #include "Memory.h" 15 #include "Strings.h" 16 #include "SymbolTable.h" 17 #include "SyntheticSections.h" 18 #include "Target.h" 19 #include "lld/Core/Parallel.h" 20 #include "llvm/Support/Dwarf.h" 21 #include "llvm/Support/MD5.h" 22 #include "llvm/Support/MathExtras.h" 23 #include "llvm/Support/SHA1.h" 24 25 using namespace llvm; 26 using namespace llvm::dwarf; 27 using namespace llvm::object; 28 using namespace llvm::support::endian; 29 using namespace llvm::ELF; 30 31 using namespace lld; 32 using namespace lld::elf; 33 34 OutputSectionBase::OutputSectionBase(StringRef Name, uint32_t Type, 35 uint64_t Flags) 36 : Name(Name) { 37 this->Type = Type; 38 this->Flags = Flags; 39 this->Addralign = 1; 40 } 41 42 uint32_t OutputSectionBase::getPhdrFlags() const { 43 uint32_t Ret = PF_R; 44 if (Flags & SHF_WRITE) 45 Ret |= PF_W; 46 if (Flags & SHF_EXECINSTR) 47 Ret |= PF_X; 48 return Ret; 49 } 50 51 template <class ELFT> 52 void OutputSectionBase::writeHeaderTo(typename ELFT::Shdr *Shdr) { 53 Shdr->sh_entsize = Entsize; 54 Shdr->sh_addralign = Addralign; 55 Shdr->sh_type = Type; 56 Shdr->sh_offset = Offset; 57 Shdr->sh_flags = Flags; 58 Shdr->sh_info = Info; 59 Shdr->sh_link = Link; 60 Shdr->sh_addr = Addr; 61 Shdr->sh_size = Size; 62 Shdr->sh_name = ShName; 63 } 64 65 template <class ELFT> static uint64_t getEntsize(uint32_t Type) { 66 switch (Type) { 67 case SHT_RELA: 68 return sizeof(typename ELFT::Rela); 69 case SHT_REL: 70 return sizeof(typename ELFT::Rel); 71 case SHT_MIPS_REGINFO: 72 return sizeof(Elf_Mips_RegInfo<ELFT>); 73 case SHT_MIPS_OPTIONS: 74 return sizeof(Elf_Mips_Options<ELFT>) + sizeof(Elf_Mips_RegInfo<ELFT>); 75 case SHT_MIPS_ABIFLAGS: 76 return sizeof(Elf_Mips_ABIFlags<ELFT>); 77 default: 78 return 0; 79 } 80 } 81 82 template <class ELFT> 83 OutputSection<ELFT>::OutputSection(StringRef Name, uint32_t Type, uintX_t Flags) 84 : OutputSectionBase(Name, Type, Flags) { 85 this->Entsize = getEntsize<ELFT>(Type); 86 } 87 88 template <typename ELFT> 89 static bool compareByFilePosition(InputSection<ELFT> *A, 90 InputSection<ELFT> *B) { 91 auto *LA = cast<InputSection<ELFT>>(A->getLinkOrderDep()); 92 auto *LB = cast<InputSection<ELFT>>(B->getLinkOrderDep()); 93 OutputSectionBase *AOut = LA->OutSec; 94 OutputSectionBase *BOut = LB->OutSec; 95 if (AOut != BOut) 96 return AOut->SectionIndex < BOut->SectionIndex; 97 return LA->OutSecOff < LB->OutSecOff; 98 } 99 100 template <class ELFT> void OutputSection<ELFT>::finalize() { 101 if ((this->Flags & SHF_LINK_ORDER) && !this->Sections.empty()) { 102 std::sort(Sections.begin(), Sections.end(), compareByFilePosition<ELFT>); 103 Size = 0; 104 assignOffsets(); 105 106 // We must preserve the link order dependency of sections with the 107 // SHF_LINK_ORDER flag. The dependency is indicated by the sh_link field. We 108 // need to translate the InputSection sh_link to the OutputSection sh_link, 109 // all InputSections in the OutputSection have the same dependency. 110 if (auto *D = this->Sections.front()->getLinkOrderDep()) 111 this->Link = D->OutSec->SectionIndex; 112 } 113 114 uint32_t Type = this->Type; 115 if (!Config->Relocatable || (Type != SHT_RELA && Type != SHT_REL)) 116 return; 117 118 this->Link = In<ELFT>::SymTab->OutSec->SectionIndex; 119 // sh_info for SHT_REL[A] sections should contain the section header index of 120 // the section to which the relocation applies. 121 InputSectionBase<ELFT> *S = Sections[0]->getRelocatedSection(); 122 this->Info = S->OutSec->SectionIndex; 123 } 124 125 template <class ELFT> 126 void OutputSection<ELFT>::addSection(InputSectionData *C) { 127 assert(C->Live); 128 auto *S = cast<InputSection<ELFT>>(C); 129 Sections.push_back(S); 130 S->OutSec = this; 131 this->updateAlignment(S->Alignment); 132 // Keep sh_entsize value of the input section to be able to perform merging 133 // later during a final linking using the generated relocatable object. 134 if (Config->Relocatable && (S->Flags & SHF_MERGE)) 135 this->Entsize = S->Entsize; 136 } 137 138 // This function is called after we sort input sections 139 // and scan relocations to setup sections' offsets. 140 template <class ELFT> void OutputSection<ELFT>::assignOffsets() { 141 uintX_t Off = this->Size; 142 for (InputSection<ELFT> *S : Sections) { 143 Off = alignTo(Off, S->Alignment); 144 S->OutSecOff = Off; 145 Off += S->getSize(); 146 } 147 this->Size = Off; 148 } 149 150 template <class ELFT> 151 void OutputSection<ELFT>::sort( 152 std::function<unsigned(InputSection<ELFT> *S)> Order) { 153 typedef std::pair<unsigned, InputSection<ELFT> *> Pair; 154 auto Comp = [](const Pair &A, const Pair &B) { return A.first < B.first; }; 155 156 std::vector<Pair> V; 157 for (InputSection<ELFT> *S : Sections) 158 V.push_back({Order(S), S}); 159 std::stable_sort(V.begin(), V.end(), Comp); 160 Sections.clear(); 161 for (Pair &P : V) 162 Sections.push_back(P.second); 163 } 164 165 // Sorts input sections by section name suffixes, so that .foo.N comes 166 // before .foo.M if N < M. Used to sort .{init,fini}_array.N sections. 167 // We want to keep the original order if the priorities are the same 168 // because the compiler keeps the original initialization order in a 169 // translation unit and we need to respect that. 170 // For more detail, read the section of the GCC's manual about init_priority. 171 template <class ELFT> void OutputSection<ELFT>::sortInitFini() { 172 // Sort sections by priority. 173 sort([](InputSection<ELFT> *S) { return getPriority(S->Name); }); 174 } 175 176 // Returns true if S matches /Filename.?\.o$/. 177 static bool isCrtBeginEnd(StringRef S, StringRef Filename) { 178 if (!S.endswith(".o")) 179 return false; 180 S = S.drop_back(2); 181 if (S.endswith(Filename)) 182 return true; 183 return !S.empty() && S.drop_back().endswith(Filename); 184 } 185 186 static bool isCrtbegin(StringRef S) { return isCrtBeginEnd(S, "crtbegin"); } 187 static bool isCrtend(StringRef S) { return isCrtBeginEnd(S, "crtend"); } 188 189 // .ctors and .dtors are sorted by this priority from highest to lowest. 190 // 191 // 1. The section was contained in crtbegin (crtbegin contains 192 // some sentinel value in its .ctors and .dtors so that the runtime 193 // can find the beginning of the sections.) 194 // 195 // 2. The section has an optional priority value in the form of ".ctors.N" 196 // or ".dtors.N" where N is a number. Unlike .{init,fini}_array, 197 // they are compared as string rather than number. 198 // 199 // 3. The section is just ".ctors" or ".dtors". 200 // 201 // 4. The section was contained in crtend, which contains an end marker. 202 // 203 // In an ideal world, we don't need this function because .init_array and 204 // .ctors are duplicate features (and .init_array is newer.) However, there 205 // are too many real-world use cases of .ctors, so we had no choice to 206 // support that with this rather ad-hoc semantics. 207 template <class ELFT> 208 static bool compCtors(const InputSection<ELFT> *A, 209 const InputSection<ELFT> *B) { 210 bool BeginA = isCrtbegin(A->getFile()->getName()); 211 bool BeginB = isCrtbegin(B->getFile()->getName()); 212 if (BeginA != BeginB) 213 return BeginA; 214 bool EndA = isCrtend(A->getFile()->getName()); 215 bool EndB = isCrtend(B->getFile()->getName()); 216 if (EndA != EndB) 217 return EndB; 218 StringRef X = A->Name; 219 StringRef Y = B->Name; 220 assert(X.startswith(".ctors") || X.startswith(".dtors")); 221 assert(Y.startswith(".ctors") || Y.startswith(".dtors")); 222 X = X.substr(6); 223 Y = Y.substr(6); 224 if (X.empty() && Y.empty()) 225 return false; 226 return X < Y; 227 } 228 229 // Sorts input sections by the special rules for .ctors and .dtors. 230 // Unfortunately, the rules are different from the one for .{init,fini}_array. 231 // Read the comment above. 232 template <class ELFT> void OutputSection<ELFT>::sortCtorsDtors() { 233 std::stable_sort(Sections.begin(), Sections.end(), compCtors<ELFT>); 234 } 235 236 // Fill [Buf, Buf + Size) with Filler. Filler is written in big 237 // endian order. This is used for linker script "=fillexp" command. 238 void fill(uint8_t *Buf, size_t Size, uint32_t Filler) { 239 uint8_t V[4]; 240 write32be(V, Filler); 241 size_t I = 0; 242 for (; I + 4 < Size; I += 4) 243 memcpy(Buf + I, V, 4); 244 memcpy(Buf + I, V, Size - I); 245 } 246 247 template <class ELFT> void OutputSection<ELFT>::writeTo(uint8_t *Buf) { 248 if (uint32_t Filler = Script<ELFT>::X->getFiller(this->Name)) 249 fill(Buf, this->Size, Filler); 250 251 auto Fn = [=](InputSection<ELFT> *IS) { IS->writeTo(Buf); }; 252 if (Config->Threads) 253 parallel_for_each(Sections.begin(), Sections.end(), Fn); 254 else 255 std::for_each(Sections.begin(), Sections.end(), Fn); 256 257 // Linker scripts may have BYTE()-family commands with which you 258 // can write arbitrary bytes to the output. Process them if any. 259 Script<ELFT>::X->writeDataBytes(this->Name, Buf); 260 } 261 262 template <class ELFT> 263 EhOutputSection<ELFT>::EhOutputSection() 264 : OutputSectionBase(".eh_frame", SHT_PROGBITS, SHF_ALLOC) {} 265 266 // Search for an existing CIE record or create a new one. 267 // CIE records from input object files are uniquified by their contents 268 // and where their relocations point to. 269 template <class ELFT> 270 template <class RelTy> 271 CieRecord *EhOutputSection<ELFT>::addCie(EhSectionPiece &Piece, 272 EhInputSection<ELFT> *Sec, 273 ArrayRef<RelTy> Rels) { 274 const endianness E = ELFT::TargetEndianness; 275 if (read32<E>(Piece.data().data() + 4) != 0) 276 fatal("CIE expected at beginning of .eh_frame: " + Sec->Name); 277 278 SymbolBody *Personality = nullptr; 279 unsigned FirstRelI = Piece.FirstRelocation; 280 if (FirstRelI != (unsigned)-1) 281 Personality = &Sec->getFile()->getRelocTargetSym(Rels[FirstRelI]); 282 283 // Search for an existing CIE by CIE contents/relocation target pair. 284 CieRecord *Cie = &CieMap[{Piece.data(), Personality}]; 285 286 // If not found, create a new one. 287 if (Cie->Piece == nullptr) { 288 Cie->Piece = &Piece; 289 Cies.push_back(Cie); 290 } 291 return Cie; 292 } 293 294 // There is one FDE per function. Returns true if a given FDE 295 // points to a live function. 296 template <class ELFT> 297 template <class RelTy> 298 bool EhOutputSection<ELFT>::isFdeLive(EhSectionPiece &Piece, 299 EhInputSection<ELFT> *Sec, 300 ArrayRef<RelTy> Rels) { 301 unsigned FirstRelI = Piece.FirstRelocation; 302 if (FirstRelI == (unsigned)-1) 303 fatal("FDE doesn't reference another section"); 304 const RelTy &Rel = Rels[FirstRelI]; 305 SymbolBody &B = Sec->getFile()->getRelocTargetSym(Rel); 306 auto *D = dyn_cast<DefinedRegular<ELFT>>(&B); 307 if (!D || !D->Section) 308 return false; 309 InputSectionBase<ELFT> *Target = D->Section->Repl; 310 return Target && Target->Live; 311 } 312 313 // .eh_frame is a sequence of CIE or FDE records. In general, there 314 // is one CIE record per input object file which is followed by 315 // a list of FDEs. This function searches an existing CIE or create a new 316 // one and associates FDEs to the CIE. 317 template <class ELFT> 318 template <class RelTy> 319 void EhOutputSection<ELFT>::addSectionAux(EhInputSection<ELFT> *Sec, 320 ArrayRef<RelTy> Rels) { 321 const endianness E = ELFT::TargetEndianness; 322 323 DenseMap<size_t, CieRecord *> OffsetToCie; 324 for (EhSectionPiece &Piece : Sec->Pieces) { 325 // The empty record is the end marker. 326 if (Piece.size() == 4) 327 return; 328 329 size_t Offset = Piece.InputOff; 330 uint32_t ID = read32<E>(Piece.data().data() + 4); 331 if (ID == 0) { 332 OffsetToCie[Offset] = addCie(Piece, Sec, Rels); 333 continue; 334 } 335 336 uint32_t CieOffset = Offset + 4 - ID; 337 CieRecord *Cie = OffsetToCie[CieOffset]; 338 if (!Cie) 339 fatal("invalid CIE reference"); 340 341 if (!isFdeLive(Piece, Sec, Rels)) 342 continue; 343 Cie->FdePieces.push_back(&Piece); 344 NumFdes++; 345 } 346 } 347 348 template <class ELFT> 349 void EhOutputSection<ELFT>::addSection(InputSectionData *C) { 350 auto *Sec = cast<EhInputSection<ELFT>>(C); 351 Sec->OutSec = this; 352 this->updateAlignment(Sec->Alignment); 353 Sections.push_back(Sec); 354 355 // .eh_frame is a sequence of CIE or FDE records. This function 356 // splits it into pieces so that we can call 357 // SplitInputSection::getSectionPiece on the section. 358 Sec->split(); 359 if (Sec->Pieces.empty()) 360 return; 361 362 if (Sec->NumRelocations) { 363 if (Sec->AreRelocsRela) 364 addSectionAux(Sec, Sec->relas()); 365 else 366 addSectionAux(Sec, Sec->rels()); 367 return; 368 } 369 addSectionAux(Sec, makeArrayRef<Elf_Rela>(nullptr, nullptr)); 370 } 371 372 template <class ELFT> 373 static void writeCieFde(uint8_t *Buf, ArrayRef<uint8_t> D) { 374 memcpy(Buf, D.data(), D.size()); 375 376 // Fix the size field. -4 since size does not include the size field itself. 377 const endianness E = ELFT::TargetEndianness; 378 write32<E>(Buf, alignTo(D.size(), sizeof(typename ELFT::uint)) - 4); 379 } 380 381 template <class ELFT> void EhOutputSection<ELFT>::finalize() { 382 if (this->Size) 383 return; // Already finalized. 384 385 size_t Off = 0; 386 for (CieRecord *Cie : Cies) { 387 Cie->Piece->OutputOff = Off; 388 Off += alignTo(Cie->Piece->size(), sizeof(uintX_t)); 389 390 for (EhSectionPiece *Fde : Cie->FdePieces) { 391 Fde->OutputOff = Off; 392 Off += alignTo(Fde->size(), sizeof(uintX_t)); 393 } 394 } 395 this->Size = Off; 396 } 397 398 template <class ELFT> static uint64_t readFdeAddr(uint8_t *Buf, int Size) { 399 const endianness E = ELFT::TargetEndianness; 400 switch (Size) { 401 case DW_EH_PE_udata2: 402 return read16<E>(Buf); 403 case DW_EH_PE_udata4: 404 return read32<E>(Buf); 405 case DW_EH_PE_udata8: 406 return read64<E>(Buf); 407 case DW_EH_PE_absptr: 408 if (ELFT::Is64Bits) 409 return read64<E>(Buf); 410 return read32<E>(Buf); 411 } 412 fatal("unknown FDE size encoding"); 413 } 414 415 // Returns the VA to which a given FDE (on a mmap'ed buffer) is applied to. 416 // We need it to create .eh_frame_hdr section. 417 template <class ELFT> 418 typename ELFT::uint EhOutputSection<ELFT>::getFdePc(uint8_t *Buf, size_t FdeOff, 419 uint8_t Enc) { 420 // The starting address to which this FDE applies is 421 // stored at FDE + 8 byte. 422 size_t Off = FdeOff + 8; 423 uint64_t Addr = readFdeAddr<ELFT>(Buf + Off, Enc & 0x7); 424 if ((Enc & 0x70) == DW_EH_PE_absptr) 425 return Addr; 426 if ((Enc & 0x70) == DW_EH_PE_pcrel) 427 return Addr + this->Addr + Off; 428 fatal("unknown FDE size relative encoding"); 429 } 430 431 template <class ELFT> void EhOutputSection<ELFT>::writeTo(uint8_t *Buf) { 432 const endianness E = ELFT::TargetEndianness; 433 for (CieRecord *Cie : Cies) { 434 size_t CieOffset = Cie->Piece->OutputOff; 435 writeCieFde<ELFT>(Buf + CieOffset, Cie->Piece->data()); 436 437 for (EhSectionPiece *Fde : Cie->FdePieces) { 438 size_t Off = Fde->OutputOff; 439 writeCieFde<ELFT>(Buf + Off, Fde->data()); 440 441 // FDE's second word should have the offset to an associated CIE. 442 // Write it. 443 write32<E>(Buf + Off + 4, Off + 4 - CieOffset); 444 } 445 } 446 447 for (EhInputSection<ELFT> *S : Sections) 448 S->relocate(Buf, nullptr); 449 450 // Construct .eh_frame_hdr. .eh_frame_hdr is a binary search table 451 // to get a FDE from an address to which FDE is applied. So here 452 // we obtain two addresses and pass them to EhFrameHdr object. 453 if (In<ELFT>::EhFrameHdr) { 454 for (CieRecord *Cie : Cies) { 455 uint8_t Enc = getFdeEncoding<ELFT>(Cie->Piece); 456 for (SectionPiece *Fde : Cie->FdePieces) { 457 uintX_t Pc = getFdePc(Buf, Fde->OutputOff, Enc); 458 uintX_t FdeVA = this->Addr + Fde->OutputOff; 459 In<ELFT>::EhFrameHdr->addFde(Pc, FdeVA); 460 } 461 } 462 } 463 } 464 465 template <class ELFT> 466 MergeOutputSection<ELFT>::MergeOutputSection(StringRef Name, uint32_t Type, 467 uintX_t Flags, uintX_t Alignment) 468 : OutputSectionBase(Name, Type, Flags), 469 Builder(StringTableBuilder::RAW, Alignment) {} 470 471 template <class ELFT> void MergeOutputSection<ELFT>::writeTo(uint8_t *Buf) { 472 Builder.write(Buf); 473 } 474 475 template <class ELFT> 476 void MergeOutputSection<ELFT>::addSection(InputSectionData *C) { 477 auto *Sec = cast<MergeInputSection<ELFT>>(C); 478 Sec->OutSec = this; 479 this->updateAlignment(Sec->Alignment); 480 this->Entsize = Sec->Entsize; 481 Sections.push_back(Sec); 482 } 483 484 template <class ELFT> bool MergeOutputSection<ELFT>::shouldTailMerge() const { 485 return (this->Flags & SHF_STRINGS) && Config->Optimize >= 2; 486 } 487 488 template <class ELFT> void MergeOutputSection<ELFT>::finalize() { 489 // Add all string pieces to the string table builder to create section 490 // contents. If we are not tail-optimizing, offsets of strings are fixed 491 // when they are added to the builder (string table builder contains a 492 // hash table from strings to offsets), so we record them if available. 493 for (MergeInputSection<ELFT> *Sec : Sections) { 494 for (size_t I = 0, E = Sec->Pieces.size(); I != E; ++I) { 495 if (!Sec->Pieces[I].Live) 496 continue; 497 uint32_t OutputOffset = Builder.add(Sec->getData(I)); 498 499 // Save the offset in the generated string table. 500 if (!shouldTailMerge()) 501 Sec->Pieces[I].OutputOff = OutputOffset; 502 } 503 } 504 505 // Fix the string table content. After this, the contents 506 // will never change. 507 if (shouldTailMerge()) 508 Builder.finalize(); 509 else 510 Builder.finalizeInOrder(); 511 this->Size = Builder.getSize(); 512 513 // finalize() fixed tail-optimized strings, so we can now get 514 // offsets of strings. Get an offset for each string and save it 515 // to a corresponding StringPiece for easy access. 516 if (shouldTailMerge()) 517 for (MergeInputSection<ELFT> *Sec : Sections) 518 for (size_t I = 0, E = Sec->Pieces.size(); I != E; ++I) 519 if (Sec->Pieces[I].Live) 520 Sec->Pieces[I].OutputOff = Builder.getOffset(Sec->getData(I)); 521 } 522 523 template <class ELFT> 524 static typename ELFT::uint getOutFlags(InputSectionBase<ELFT> *S) { 525 return S->Flags & ~SHF_GROUP & ~SHF_COMPRESSED; 526 } 527 528 template <class ELFT> 529 static SectionKey<ELFT::Is64Bits> createKey(InputSectionBase<ELFT> *C, 530 StringRef OutsecName) { 531 typedef typename ELFT::uint uintX_t; 532 uintX_t Flags = getOutFlags(C); 533 534 // For SHF_MERGE we create different output sections for each alignment. 535 // This makes each output section simple and keeps a single level mapping from 536 // input to output. 537 // In case of relocatable object generation we do not try to perform merging 538 // and treat SHF_MERGE sections as regular ones, but also create different 539 // output sections for them to allow merging at final linking stage. 540 uintX_t Alignment = 0; 541 if (isa<MergeInputSection<ELFT>>(C) || 542 (Config->Relocatable && (C->Flags & SHF_MERGE))) 543 Alignment = std::max<uintX_t>(C->Alignment, C->Entsize); 544 545 return SectionKey<ELFT::Is64Bits>{OutsecName, C->Type, Flags, Alignment}; 546 } 547 548 template <class ELFT> 549 std::pair<OutputSectionBase *, bool> 550 OutputSectionFactory<ELFT>::create(InputSectionBase<ELFT> *C, 551 StringRef OutsecName) { 552 SectionKey<ELFT::Is64Bits> Key = createKey(C, OutsecName); 553 return create(Key, C); 554 } 555 556 template <class ELFT> 557 std::pair<OutputSectionBase *, bool> 558 OutputSectionFactory<ELFT>::create(const SectionKey<ELFT::Is64Bits> &Key, 559 InputSectionBase<ELFT> *C) { 560 uintX_t Flags = getOutFlags(C); 561 OutputSectionBase *&Sec = Map[Key]; 562 if (Sec) { 563 Sec->Flags |= Flags; 564 return {Sec, false}; 565 } 566 567 uint32_t Type = C->Type; 568 switch (C->kind()) { 569 case InputSectionBase<ELFT>::Regular: 570 case InputSectionBase<ELFT>::Synthetic: 571 Sec = make<OutputSection<ELFT>>(Key.Name, Type, Flags); 572 break; 573 case InputSectionBase<ELFT>::EHFrame: 574 return {Out<ELFT>::EhFrame, false}; 575 case InputSectionBase<ELFT>::Merge: 576 Sec = make<MergeOutputSection<ELFT>>(Key.Name, Type, Flags, Key.Alignment); 577 break; 578 } 579 return {Sec, true}; 580 } 581 582 template <bool Is64Bits> 583 typename lld::elf::SectionKey<Is64Bits> 584 DenseMapInfo<lld::elf::SectionKey<Is64Bits>>::getEmptyKey() { 585 return SectionKey<Is64Bits>{DenseMapInfo<StringRef>::getEmptyKey(), 0, 0, 0}; 586 } 587 588 template <bool Is64Bits> 589 typename lld::elf::SectionKey<Is64Bits> 590 DenseMapInfo<lld::elf::SectionKey<Is64Bits>>::getTombstoneKey() { 591 return SectionKey<Is64Bits>{DenseMapInfo<StringRef>::getTombstoneKey(), 0, 0, 592 0}; 593 } 594 595 template <bool Is64Bits> 596 unsigned 597 DenseMapInfo<lld::elf::SectionKey<Is64Bits>>::getHashValue(const Key &Val) { 598 return hash_combine(Val.Name, Val.Type, Val.Flags, Val.Alignment); 599 } 600 601 template <bool Is64Bits> 602 bool DenseMapInfo<lld::elf::SectionKey<Is64Bits>>::isEqual(const Key &LHS, 603 const Key &RHS) { 604 return DenseMapInfo<StringRef>::isEqual(LHS.Name, RHS.Name) && 605 LHS.Type == RHS.Type && LHS.Flags == RHS.Flags && 606 LHS.Alignment == RHS.Alignment; 607 } 608 609 namespace llvm { 610 template struct DenseMapInfo<SectionKey<true>>; 611 template struct DenseMapInfo<SectionKey<false>>; 612 } 613 614 namespace lld { 615 namespace elf { 616 617 template void OutputSectionBase::writeHeaderTo<ELF32LE>(ELF32LE::Shdr *Shdr); 618 template void OutputSectionBase::writeHeaderTo<ELF32BE>(ELF32BE::Shdr *Shdr); 619 template void OutputSectionBase::writeHeaderTo<ELF64LE>(ELF64LE::Shdr *Shdr); 620 template void OutputSectionBase::writeHeaderTo<ELF64BE>(ELF64BE::Shdr *Shdr); 621 622 template class OutputSection<ELF32LE>; 623 template class OutputSection<ELF32BE>; 624 template class OutputSection<ELF64LE>; 625 template class OutputSection<ELF64BE>; 626 627 template class EhOutputSection<ELF32LE>; 628 template class EhOutputSection<ELF32BE>; 629 template class EhOutputSection<ELF64LE>; 630 template class EhOutputSection<ELF64BE>; 631 632 template class MergeOutputSection<ELF32LE>; 633 template class MergeOutputSection<ELF32BE>; 634 template class MergeOutputSection<ELF64LE>; 635 template class MergeOutputSection<ELF64BE>; 636 637 template class OutputSectionFactory<ELF32LE>; 638 template class OutputSectionFactory<ELF32BE>; 639 template class OutputSectionFactory<ELF64LE>; 640 template class OutputSectionFactory<ELF64BE>; 641 } 642 } 643