[PATCH] D23442: [ELF] - Remove excessive loop in LinkerScript<ELFT>::assignAddresses()
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 12 03:28:46 PDT 2016
grimar created this revision.
grimar added a reviewer: ruiu.
grimar added subscribers: llvm-commits, grimar, davide, evgeny777.
After 278461 "Create only one section for a name in LinkerScript."
this loop is excessive. Patch also reorders code slightly to use early return.
https://reviews.llvm.org/D23442
Files:
ELF/LinkerScript.cpp
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -362,39 +362,39 @@
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<OutputSectionCommand>(Base.get());
- for (OutputSectionBase<ELFT> *Sec : *OutputSections) {
- if (Sec->getName() != Cmd->Name)
- continue;
+ auto I = llvm::find_if(*OutputSections, [&](OutputSectionBase<ELFT> *S) {
+ return S->getName() == Cmd->Name;
+ });
+ if (I == OutputSections->end())
+ continue;
+ OutputSectionBase<ELFT> *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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23442.67815.patch
Type: text/x-patch
Size: 2223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160812/5639bb44/attachment.bin>
More information about the llvm-commits
mailing list