[PATCH] D29983: [LLD][ELF] Calculate sizes of SHF_ALLOC Synthetic Sections early

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 2 10:51:11 PST 2017


peter.smith updated this revision to Diff 90357.
peter.smith added a comment.

Rebased and updated the patch.

I had a go at Rafael's suggestion of renaming the split of finalizeContent into startLayout, updateAllocSize and endLayout. After moving as much of I could into startLayout we aren't left with much in updateAllocSize or endLayout. With this in mind I've tried a different idea that keeps finalizeContent and instead adds updateAllocSize and postThunkContent.

In Writer.cpp I've called updateAllocSize and postThunkContent only on the sections that need changing.

Rafael's email comments for the benefit of Phabriacator:

> +  applySynthetic<ELFT>(Synthetics,
>  +                       [](SyntheticSection<ELFT> *SS) { SS->finalize(); });

For the names, how about:

- startLayout
- updateAllocSize
- endLayout

A more precise set of names would be atLayoutStart, updateAllocSize and
atLayoutEnd, but not sure if it is actually better.

>   }
>   
>   template <class ELFT> void Writer<ELFT>::addPredefinedSections() {
> 
> Index: ELF/SyntheticSections.h
>  ===================================================================
> 
> - ELF/SyntheticSections.h +++ ELF/SyntheticSections.h @@ -47,6 +47,12 @@ virtual ~SyntheticSection() = default; virtual void writeTo(uint8_t *Buf) = 0; virtual size_t getSize() const = 0; +  // Finalize is split up into 3 parts to accommodate Thunks, early finalize +  // should do as much as possible including finalizing the section size

"finalizing" is a bit strong since we have updateAllocSize. It should
compute as good a lower bound as possible.

> +  // If the size calculation needs to be updated during Thunk creation

incomplete sentence.

> +  virtual void updateAllocSize() {}
>  +  // Runs after all content has been added, must not alter section
> size

and all addresses are know?

> +template <class ELFT> void DynamicSection<ELFT>::earlyFinalize() {
> 
>   if (In<ELFT>::RelaDyn->OutSec->Size > 0) {
>     bool IsRela = Config->Rela;
>     add({IsRela ? DT_RELA : DT_REL, In<ELFT>::RelaDyn});
> 
> @@ -941,13 +941,17 @@
> 
>       add({DT_MIPS_RLD_MAP, In<ELFT>::MipsRldMap});
>   }
> 
> - this->OutSec->Entsize = this->Entsize;
> - this->OutSec->Link = this->Link;

Why does setting the link has to be delayed too?

> +template <class ELFT> void SymbolTableSection<ELFT>::finalize() {
>  +  this->OutSec->Link = this->Link = StrTabSec.OutSec->SectionIndex;
>  +  this->OutSec->Entsize = this->Entsize;
>  +
>  +  if (StrTabSec.isDynamic()) {
>  +    this->OutSec->Info = this->Info = 1;

This can be set early, no?

Cheers,
Rafael


https://reviews.llvm.org/D29983

Files:
  ELF/Relocations.cpp
  ELF/Relocations.h
  ELF/SyntheticSections.cpp
  ELF/SyntheticSections.h
  ELF/Writer.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29983.90357.patch
Type: text/x-patch
Size: 8544 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170302/85b378ae/attachment.bin>


More information about the llvm-commits mailing list