[PATCH] D29983: [LLD][ELF] Calculate sizes of SHF_ALLOC Synthetic Sections early
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 17 11:05:17 PST 2017
> + if (In<ELFT>::GnuHashTab && In<ELFT>::DynSymTab)
> + In<ELFT>::DynSymTab->addSymbolsToGnuHashTab();
Having the gnu hash implies that we also have a dynamic symbol table,
no?
> // Dynamic section must be the last one in this list and dynamic
> // symbol table section (DynSymTab) must be the first one.
This comment should stay with the definition of the Synthetics array.
> +// Add remaining entries to complete .dynamic contents.
> +template <class ELFT> void DynamicSection<ELFT>::updateAllocSize() {
> + std::vector<Entry> LateEntries = addLateEntries();
> + // +1 for DT_NULL
> + this->Size = (Entries.size() + LateEntries.size() + 1) * this->Entsize;
> +}
> +
> +// Add remaining entries to complete .dynamic contents.
> +template <class ELFT> void DynamicSection<ELFT>::finalize() {
> + this->Link = In<ELFT>::DynStrTab->OutSec->SectionIndex;
> + std::vector<Entry> LateEntries = addLateEntries();
> + Entries.insert(Entries.end(), LateEntries.begin(), LateEntries.end());
> this->OutSec->Entsize = this->Entsize;
> this->OutSec->Link = this->Link;
> -
> // +1 for DT_NULL
> this->Size = (Entries.size() + 1) * this->Entsize;
Can you call updateAllocSize instead? Why do you need to split
addLateEntries btw? The actual number of entries doesn't change when
adding thunks, right? I looks like it should be sufficient to just
populate Entries earlier.
> -template <class ELFT> void GnuHashTableSection<ELFT>::finalize() {
> +template <class ELFT> void GnuHashTableSection<ELFT>::updateAllocSize() {
> unsigned NumHashed = Symbols.size();
> NBuckets = calcNBuckets(NumHashed);
> MaskWords = calcMaskWords(NumHashed);
Do you need to do this in every updateAllocSize?
If I understand it correctly, this patch is in an odd middle ground. I
think I would prefer to either call the full finalize multiple times if
thunks are added or split finalize is 3 methods:
* One that is called early and only once. It would do most of the work
that finalize currently does.
* updateAllocSize, which is empty for most sections and just updates
whatever can change the size in response to other sections changing
size.
* A real finalize method, that is called only once and can set values
that depend on the final address of the sections.
Cheers,
Rafael
More information about the llvm-commits
mailing list