[lld] r250463 - ELF2: Do not treat .strtab specially when creating sections.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 16 12:53:54 PDT 2015


On Fri, Oct 16, 2015 at 7:37 AM, Rafael EspĂ­ndola <
rafael.espindola at gmail.com> wrote:

> Hi,
>
> This and previous patches add more walks over all the output sections.
>
> A normal file normally has less than 100 output sections, so this is
> not normally a problem, but it is possible to craft a file with an
> arbitrary large number of output sections. I am not sure if we care
> about it or not. I just wanted to make sure you know about the
> possibility.
>

Total number of function calls did not change. Previously, we call two
functions from one for-loop, and now they are called separately from two
for-loops. So the cost by this change is one for-each loop and no more than
that. If that's a complex data structure, I would probably care, but this
is a std::vector. I believe that that's extremely cheap.


> Cheers,
> Rafael
>
>
>
> On 15 October 2015 at 17:50, Rui Ueyama via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
> > Author: ruiu
> > Date: Thu Oct 15 16:50:30 2015
> > New Revision: 250463
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=250463&view=rev
> > Log:
> > ELF2: Do not treat .strtab specially when creating sections.
> >
> > String table is added to end of the file so that all the other sections
> > are finalized before string table. But we can just add section names to
> > the string table before calling finalize() on any section instead.
> >
> > Modified:
> >     lld/trunk/ELF/Writer.cpp
> >
> > Modified: lld/trunk/ELF/Writer.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=250463&r1=250462&r2=250463&view=diff
> >
> ==============================================================================
> > --- lld/trunk/ELF/Writer.cpp (original)
> > +++ lld/trunk/ELF/Writer.cpp Thu Oct 15 16:50:30 2015
> > @@ -470,7 +470,10 @@ template <class ELFT> void Writer<ELFT>:
> >    }
> >    addCommonSymbols(CommonSymbols);
> >
> > +  // This order is not the same as the final output order
> > +  // because we sort the sections using their attributes below.
> >    OutputSections.push_back(Out<ELFT>::SymTab);
> > +  OutputSections.push_back(Out<ELFT>::StrTab);
> >    if (isOutputDynamic()) {
> >      OutputSections.push_back(Out<ELFT>::DynSymTab);
> >      OutputSections.push_back(Out<ELFT>::HashTab);
> > @@ -487,21 +490,19 @@ template <class ELFT> void Writer<ELFT>:
> >    std::stable_sort(OutputSections.begin(), OutputSections.end(),
> >                     compareOutputSections<ELFT>);
> >
> > -  // Always put StrTabSec last so that no section names are added to it
> after
> > -  // it's finalized.
> > -  OutputSections.push_back(Out<ELFT>::StrTab);
> > -
> >    for (unsigned I = 0, N = OutputSections.size(); I < N; ++I)
> >      OutputSections[I]->SectionIndex = I + 1;
> >
> > -  // Fill the DynStrTab early.
> > +  for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections)
> > +    Out<ELFT>::StrTab->add(Sec->getName());
> > +
> > +  // Fill the DynStrTab early because Dynamic adds strings to
> > +  // DynStrTab but .dynstr may appear before .dynamic.
> >    Out<ELFT>::Dynamic->finalize();
> >
> > -  // Fix each section's header (e.g. sh_size, sh_link, etc.)
> > -  for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections) {
> > -    Out<ELFT>::StrTab->add(Sec->getName());
> > +  // Fill other section headers.
> > +  for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections)
> >      Sec->finalize();
> > -  }
> >
> >    // If we have a .opd section (used under PPC64 for function
> descriptors),
> >    // store a pointer to it here so that we can use it later when
> processing
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151016/20babf6b/attachment.html>


More information about the llvm-commits mailing list