[PATCH] D84001: [ELF] Allow mixed SHF_LINK_ORDER & non-SHF_LINK_ORDER sections and sort within InputSectionDescription

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 17 04:19:43 PDT 2020


grimar added inline comments.


================
Comment at: lld/ELF/Writer.cpp:1659
   }
 }
 
----------------
grimar wrote:
> Consider reordering to reduce nesting and to remove `clear()` calls:
> 
> ```
>     // Link order may be distributed across several InputSectionDescriptions.
>     // Sorting is performed separately.
>     for (BaseCommand *base : sec->sectionCommands) {
>       auto *isd = dyn_cast<InputSectionDescription>(base);
>       if (!isd)
>         continue;
> 
>       bool hasLinkOrder = false;
>       std::vector<InputSection **> scriptSections;
>       std::vector<InputSection *> sections;
>       for (InputSection *&isec : isd->sections) {
>         if (isec->flags & SHF_LINK_ORDER) {
>           InputSection *link = isec->getLinkOrderDep();
>           if (link && !link->getParent())
>             error(toString(isec) + ": sh_link points to discarded section " +
>                   toString(link));
>           hasLinkOrder = true;
>         }
>         scriptSections.push_back(&isec);
>         sections.push_back(isec);
>       }
> 
>       if (!hasLinkOrder || errorCount())
>         continue;
> 
>       llvm::stable_sort(sections, compareByFilePosition);
>       for (int i = 0, n = sections.size(); i < n; ++i)
>         *scriptSections[i] = sections[i];
>     }
> ```
Aside: we can replace constructions like:


```
for (BaseCommand *base : sec->sectionCommands) {
  auto *isd = dyn_cast<InputSectionDescription>(base);
  if (!isd)
    continue;
```

with just


```
for (auto *isd: filter<InputSectionDescription>(sec->sectionCommands)) {
```

here and in many other places in LLD if we land D45166 + D45490.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84001/new/

https://reviews.llvm.org/D84001





More information about the llvm-commits mailing list