From: George Rimar Date: Fri, 12 Aug 2016 19:32:45 +0000 (+0000) Subject: [ELF] - Remove excessive loop in LinkerScript::assignAddresses() X-Git-Tag: llvmorg-4.0.0-rc1~12554 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b6c52e8dfac5717f89c7a16a102331937c2dbe26;p=platform%2Fupstream%2Fllvm.git [ELF] - Remove excessive loop in LinkerScript::assignAddresses() After 278461 "Create only one section for a name in LinkerScript." this loop is excessive. Patch also reorders code slightly to use early return. Differential revision: https://reviews.llvm.org/D23442 llvm-svn: 278554 --- diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 1c24614..95b28e2 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -362,39 +362,39 @@ template void LinkerScript::assignAddresses() { continue; } - // Find all the sections with required name. There can be more than - // one section with such name, if the alignment, flags or type - // attribute differs. auto *Cmd = cast(Base.get()); - for (OutputSectionBase *Sec : *OutputSections) { - if (Sec->getName() != Cmd->Name) - continue; + auto I = llvm::find_if(*OutputSections, [&](OutputSectionBase *S) { + return S->getName() == Cmd->Name; + }); + if (I == OutputSections->end()) + continue; + OutputSectionBase *Sec = *I; - if (Cmd->AddrExpr) - Dot = Cmd->AddrExpr(Dot); + if (Cmd->AddrExpr) + Dot = Cmd->AddrExpr(Dot); - if (Cmd->AlignExpr) - Sec->updateAlignment(Cmd->AlignExpr(Dot)); + if (Cmd->AlignExpr) + Sec->updateAlignment(Cmd->AlignExpr(Dot)); - if ((Sec->getFlags() & SHF_TLS) && Sec->getType() == SHT_NOBITS) { - uintX_t TVA = Dot + ThreadBssOffset; - TVA = alignTo(TVA, Sec->getAlignment()); - Sec->setVA(TVA); - assignOffsets(Sec); - ThreadBssOffset = TVA - Dot + Sec->getSize(); - continue; - } + if ((Sec->getFlags() & SHF_TLS) && Sec->getType() == SHT_NOBITS) { + uintX_t TVA = Dot + ThreadBssOffset; + TVA = alignTo(TVA, Sec->getAlignment()); + Sec->setVA(TVA); + assignOffsets(Sec); + ThreadBssOffset = TVA - Dot + Sec->getSize(); + continue; + } - if (Sec->getFlags() & SHF_ALLOC) { - Dot = alignTo(Dot, Sec->getAlignment()); - Sec->setVA(Dot); - assignOffsets(Sec); - MinVA = std::min(MinVA, Dot); - Dot += Sec->getSize(); - continue; - } + if (!(Sec->getFlags() & SHF_ALLOC)) { Sec->assignOffsets(); + continue; } + + Dot = alignTo(Dot, Sec->getAlignment()); + Sec->setVA(Dot); + assignOffsets(Sec); + MinVA = std::min(MinVA, Dot); + Dot += Sec->getSize(); } // ELF and Program headers need to be right before the first section in