Index: lld/ELF/ICF.cpp =================================================================== --- lld/ELF/ICF.cpp +++ lld/ELF/ICF.cpp @@ -435,8 +435,8 @@ if (Config->EMachine == EM_ARM) for (InputSectionBase *Sec : InputSections) if (auto *S = dyn_cast(Sec)) - if (S->Flags & SHF_LINK_ORDER) - S->Live = S->getLinkOrderDep()->Live; + if (S->LinkOrderSection) + S->Live = S->LinkOrderSection->Live; } // ICF entry point function. Index: lld/ELF/InputSection.h =================================================================== --- lld/ELF/InputSection.h +++ lld/ELF/InputSection.h @@ -163,8 +163,6 @@ return getFile()->getObj(); } - InputSection *getLinkOrderDep() const; - void uncompress(); // Returns a source location string. Used to construct an error message. @@ -184,6 +182,8 @@ return llvm::makeArrayRef((const T *)Data.data(), S / sizeof(T)); } + InputSection *LinkOrderSection = nullptr; + private: // A pointer that owns uncompressed data if a section is compressed by zlib. // Since the feature is not used often, this is usually a nullptr. Index: lld/ELF/InputSection.cpp =================================================================== --- lld/ELF/InputSection.cpp +++ lld/ELF/InputSection.cpp @@ -91,6 +91,16 @@ return Type != SHT_REL && Type != SHT_RELA; } +static InputSection *getLinkOrderSection(InputFile *File, uint32_t Link) { + InputSectionBase *Sec = File->getSections()[Link]; + if (!isa(Sec)) { + error("Merge and .eh_frame sections are not supported with " + "SHF_LINK_ORDER " + toString(Sec)); + return nullptr; + } + return cast(Sec); +} + InputSectionBase::InputSectionBase(InputFile *File, uint64_t Flags, uint32_t Type, uint64_t Entsize, uint32_t Link, uint32_t Info, @@ -104,6 +114,11 @@ NumRelocations = 0; AreRelocsRela = false; + if ((Flags & SHF_LINK_ORDER) && Link) { + LinkOrderSection = getLinkOrderSection(File, Link); + Flags &= ~(uint64_t)SHF_LINK_ORDER; + } + // The ELF spec states that a value of 0 means the section has // no alignment constraits. uint32_t V = std::max(Alignment, 1); @@ -229,18 +244,6 @@ return getOffset(Sym.Value); } -InputSection *InputSectionBase::getLinkOrderDep() const { - if ((Flags & SHF_LINK_ORDER) && Link != 0) { - InputSectionBase *L = File->getSections()[Link]; - if (auto *IS = dyn_cast(L)) - return IS; - error( - "Merge and .eh_frame sections are not supported with SHF_LINK_ORDER " + - toString(L)); - } - return nullptr; -} - // Returns a source location string. Used to construct an error message. template std::string InputSectionBase::getLocation(uint64_t Offset) { Index: lld/ELF/OutputSections.cpp =================================================================== --- lld/ELF/OutputSections.cpp +++ lld/ELF/OutputSections.cpp @@ -421,8 +421,8 @@ if (A->kind() == InputSectionBase::Synthetic || B->kind() == InputSectionBase::Synthetic) return false; - InputSection *LA = A->getLinkOrderDep(); - InputSection *LB = B->getLinkOrderDep(); + InputSection *LA = A->LinkOrderSection; + InputSection *LB = B->LinkOrderSection; OutputSection *AOut = LA->getParent(); OutputSection *BOut = LB->getParent(); if (AOut != BOut) @@ -467,7 +467,7 @@ // SHF_LINK_ORDER flag. The dependency is indicated by the sh_link field. We // need to translate the InputSection sh_link to the OutputSection sh_link, // all InputSections in the OutputSection have the same dependency. - if (auto *D = Sections.front()->getLinkOrderDep()) + if (auto *D = Sections.front()->LinkOrderSection) Link = D->getParent()->SectionIndex; } Index: lld/ELF/SyntheticSections.cpp =================================================================== --- lld/ELF/SyntheticSections.cpp +++ lld/ELF/SyntheticSections.cpp @@ -2312,7 +2312,7 @@ }); auto L = cast(*ISD); InputSection *Highest = L->Sections[L->Sections.size() - 2]; - InputSection *LS = Highest->getLinkOrderDep(); + InputSection *LS = Highest->LinkOrderSection; uint64_t S = LS->getParent()->Addr + LS->getOffset(LS->getSize()); uint64_t P = getVA(); Target->relocateOne(Buf, R_ARM_PREL31, S - P);