diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 2ba02fc4df6a..e81119deeb46 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -186,18 +186,18 @@ void elf2::ObjectFile::initializeSections( const ELFFile &Obj = this->ELFObj; for (const Elf_Shdr &Sec : Obj.sections()) { ++I; - if (Sections[I] == &InputSection::Discarded) + if (Sections[I] == InputSection::Discarded) continue; switch (Sec.sh_type) { case SHT_GROUP: - Sections[I] = &InputSection::Discarded; + Sections[I] = InputSection::Discarded; if (ComdatGroups.insert(getShtGroupSignature(Sec)).second) continue; for (uint32_t SecIndex : getShtGroupEntries(Sec)) { if (SecIndex >= Size) fatal("Invalid section index in group"); - Sections[SecIndex] = &InputSection::Discarded; + Sections[SecIndex] = InputSection::Discarded; } break; case SHT_SYMTAB: @@ -222,7 +222,7 @@ void elf2::ObjectFile::initializeSections( // Strictly speaking, a relocation section must be included in the // group of the section it relocates. However, LLVM 3.3 and earlier // would fail to do so, so we gracefully handle that case. - if (RelocatedSection == &InputSection::Discarded) + if (RelocatedSection == InputSection::Discarded) continue; if (!RelocatedSection) fatal("Unsupported relocation reference"); @@ -255,7 +255,7 @@ elf2::ObjectFile::createInputSection(const Elf_Shdr &Sec) { // is controlled only by the command line option (-z execstack) in LLD, // .note.GNU-stack is ignored. if (Name == ".note.GNU-stack") - return &InputSection::Discarded; + return InputSection::Discarded; // A MIPS object file has a special section that contains register // usage info, which needs to be handled by the linker specially. @@ -313,7 +313,7 @@ SymbolBody *elf2::ObjectFile::createSymbolBody(const Elf_Sym *Sym) { case STB_WEAK: case STB_GNU_UNIQUE: { InputSectionBase *Sec = getSection(*Sym); - if (Sec == &InputSection::Discarded) + if (Sec == InputSection::Discarded) return new (Alloc) UndefinedElf(Name, *Sym); return new (Alloc) DefinedRegular(Name, *Sym, Sec); } diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index a00f838a48a8..231d9f1e9fa6 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -28,14 +28,11 @@ InputSectionBase::InputSectionBase(ObjectFile *File, : Header(Header), File(File), SectionKind(SectionKind) { // The garbage collector sets sections' Live bits. // If GC is disabled, all sections are considered live by default. - // NB: "Discarded" section is initialized at start-up and when it - // happens Config is still null. - Live = Config && !Config->GcSections; + Live = !Config->GcSections; // The ELF spec states that a value of 0 means the section has // no alignment constraits. - if (Header) - Align = std::max(Header->sh_addralign, 1); + Align = std::max(Header->sh_addralign, 1); } template StringRef InputSectionBase::getSectionName() const { diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index 2faec9aa52ef..96e7f78f7975 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -50,7 +50,7 @@ public: // Returns the size of this section (even if this is a common or BSS.) size_t getSize() const { return Header->sh_size; } - static InputSectionBase Discarded; + static InputSectionBase *Discarded; StringRef getSectionName() const; const Elf_Shdr *getSectionHdr() const { return Header; } @@ -81,9 +81,8 @@ private: }; template -InputSectionBase - InputSectionBase::Discarded(nullptr, nullptr, - InputSectionBase::Regular); +InputSectionBase * + InputSectionBase::Discarded = (InputSectionBase *)-1ULL; // Usually sections are copied to the output as atomic chunks of data, // but some special types of sections are split into small pieces of data diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index 0fdf512e8a31..c545a8bb9bb6 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -118,7 +118,7 @@ template void elf2::markLive(SymbolTable *Symtab) { // script KEEP command. for (const std::unique_ptr> &F : Symtab->getObjectFiles()) for (InputSectionBase *Sec : F->getSections()) - if (Sec && Sec != &InputSection::Discarded) + if (Sec && Sec != InputSection::Discarded) if (isReserved(Sec) || Script->shouldKeep(Sec)) Enqueue(Sec); diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 7f225ca5b22a..879478ef9dae 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -884,7 +884,7 @@ elf2::getLocalRelTarget(const ObjectFile &File, // the group are not allowed. Unfortunately .eh_frame breaks that rule // and must be treated specially. For now we just replace the symbol with // 0. - if (Section == &InputSection::Discarded || !Section->Live) + if (Section == InputSection::Discarded || !Section->Live) return Addend; uintX_t Offset = Sym->st_value; @@ -1147,7 +1147,7 @@ void EHOutputSection::addSectionAux( if (!HasReloc) fatal("FDE doesn't reference another section"); InputSectionBase *Target = S->getRelocTarget(*RelI); - if (Target != &InputSection::Discarded && Target->Live) { + if (Target != InputSection::Discarded && Target->Live) { uint32_t CieOffset = Offset + 4 - ID; auto I = OffsetToIndex.find(CieOffset); if (I == OffsetToIndex.end()) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 0e9a8af0c5db..0fdffe906e15 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -515,7 +515,7 @@ static bool shouldKeepInSymtab(const ObjectFile &File, StringRef SymName, InputSectionBase *Sec = File.getSection(Sym); // If sym references a section in a discarded group, don't keep it. - if (Sec == &InputSection::Discarded) + if (Sec == InputSection::Discarded) return false; if (Config->DiscardNone) @@ -752,7 +752,7 @@ void reportDiscarded(InputSectionBase *IS, template bool Writer::isDiscarded(InputSectionBase *S) const { - return !S || !S->Live || S == &InputSection::Discarded || + return !S || S == InputSection::Discarded || !S->Live || Script->isDiscarded(S); }