Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -322,8 +322,7 @@ if (Sec.sh_link >= Sections.size()) fatal(toString(this) + ": invalid sh_link index: " + Twine(Sec.sh_link)); - auto *IS = cast>(Sections[Sec.sh_link]); - IS->DependentSections.push_back(Sections[I]); + Sections[Sec.sh_link]->DependentSections.push_back(Sections[I]); } } } Index: ELF/InputSection.h =================================================================== --- ELF/InputSection.h +++ ELF/InputSection.h @@ -128,6 +128,9 @@ // this but instead this->Repl. InputSectionBase *Repl; + // InputSections that are dependent on us (reverse dependency for GC) + llvm::TinyPtrVector *> DependentSections; + // Returns the size of this section (even if this is a common or BSS.) size_t getSize() const; @@ -281,9 +284,6 @@ // to. The writer sets a value. uint64_t OutSecOff = 0; - // InputSections that are dependent on us (reverse dependency for GC) - llvm::TinyPtrVector *> DependentSections; - static bool classof(const InputSectionData *S); InputSectionBase *getRelocatedSection(); Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -277,11 +277,7 @@ for (InputSectionBase *S : V) { S->Live = false; reportDiscarded(S); - - InputSection *IS = dyn_cast>(S); - if (!IS || IS->DependentSections.empty()) - continue; - discard(IS->DependentSections); + discard(S->DependentSections); } }