Use OutputSectionCommands in assignOffsets.

This allows moving clearOutputSections earlier.

llvm-svn: 304952
This commit is contained in:
Rafael Espindola 2017-06-07 23:08:55 +00:00
parent 27c11dd57e
commit 7204620d32
2 changed files with 11 additions and 8 deletions

View File

@ -101,9 +101,12 @@ void OutputSection::addSection(InputSection *S) {
// This function is called after we sort input sections
// and scan relocations to setup sections' offsets.
void OutputSection::assignOffsets() {
OutputSectionCommand *Cmd = Script->getCmd(this);
uint64_t Off = 0;
for (InputSection *S : Sections)
Off = updateOffset(Off, S);
for (BaseCommand *Base : Cmd->Commands)
if (auto *ISD = dyn_cast<InputSectionDescription>(Base))
for (InputSection *S : ISD->Sections)
Off = updateOffset(Off, S);
this->Size = Off;
}

View File

@ -1216,12 +1216,6 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
Out::ProgramHeaders->Size = sizeof(Elf_Phdr) * Phdrs.size();
}
// Compute the size of .rela.dyn and .rela.plt early since we need
// them to populate .dynamic.
for (SyntheticSection *SS : {In<ELFT>::RelaDyn, In<ELFT>::RelaPlt})
if (SS->getParent() && !SS->empty())
SS->getParent()->assignOffsets();
if (!Script->Opt.HasSections)
Script->fabricateDefaultCommands();
for (BaseCommand *Base : Script->Opt.Commands)
@ -1229,6 +1223,12 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
OutputSectionCommands.push_back(Cmd);
clearOutputSections();
// Compute the size of .rela.dyn and .rela.plt early since we need
// them to populate .dynamic.
for (SyntheticSection *SS : {In<ELFT>::RelaDyn, In<ELFT>::RelaPlt})
if (SS->getParent() && !SS->empty())
SS->getParent()->assignOffsets();
// Dynamic section must be the last one in this list and dynamic
// symbol table section (DynSymTab) must be the first one.
applySynthetic({InX::DynSymTab, InX::Bss, InX::BssRelRo,