[PATCH] D42681: [ELF] - Remove unused synthetic sections correctly.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 30 13:32:52 PST 2018


George Rimar via Phabricator <reviews at reviews.llvm.org> writes:


> Index: ELF/Writer.cpp
> ===================================================================
> --- ELF/Writer.cpp
> +++ ELF/Writer.cpp
> @@ -1314,23 +1314,26 @@
>      if (!OS || !SS->empty())
>        continue;
>  
> -    std::vector<BaseCommand *>::iterator Empty = OS->SectionCommands.end();
> -    for (auto I = OS->SectionCommands.begin(), E = OS->SectionCommands.end();
> -         I != E; ++I) {
> -      BaseCommand *B = *I;
> +    // If we reach here, then SS is an unused synthetic section and we want to
> +    // remove it from corresponding input section description of output section.
> +    for (BaseCommand *B : OS->SectionCommands) {
>        if (auto *ISD = dyn_cast<InputSectionDescription>(B)) {
> -        llvm::erase_if(ISD->Sections,
> -                       [=](InputSection *IS) { return IS == SS; });
> -        if (ISD->Sections.empty())
> -          Empty = I;
> +        auto It = llvm::find(ISD->Sections, SS);
> +        if (It == ISD->Sections.end())
> +          continue;
> +        ISD->Sections.erase(It);
> +        break;

This can keep using erase_if:

    for (BaseCommand *B : OS->SectionCommands)
      if (auto *ISD = dyn_cast<InputSectionDescription>(B))
        llvm::erase_if(ISD->Sections,
                       [=](InputSection *IS) { return IS == SS; });

LGTM with that.

Cheers,
Rafael


More information about the llvm-commits mailing list