Run fabricateDefaultCommands before fixSectionAlignments.

This allows us to remove the PageAlign field. It will also allow
moving fabricateDefaultCommands earlier.

llvm-svn: 304513
This commit is contained in:
Rafael Espindola 2017-06-02 01:37:58 +00:00
parent 26115924a2
commit 0f7dc0e2d0
3 changed files with 12 additions and 12 deletions

View File

@ -464,10 +464,6 @@ void LinkerScript::fabricateDefaultCommands() {
auto I = Config->SectionStartMap.find(Sec->Name);
if (I != Config->SectionStartMap.end())
OSCmd->AddrExpr = [=] { return I->second; };
else if (Sec->PageAlign)
OSCmd->AddrExpr = [=] {
return alignTo(Script->getDot(), Config->MaxPageSize);
};
Commands.push_back(OSCmd);
if (Sec->Sections.size()) {

View File

@ -59,10 +59,6 @@ public:
Alignment = Val;
}
// If true, this section will be page aligned on disk.
// Typically the first section of each PT_LOAD segment has this flag.
bool PageAlign = false;
// Pointer to the first section in PT_LOAD segment, which this section
// also resides in. This field is used to correctly compute file offset
// of a section. When two sections share the same load segment, difference

View File

@ -258,9 +258,9 @@ template <class ELFT> void Writer<ELFT>::run() {
return;
if (!Script->Opt.HasSections) {
Script->fabricateDefaultCommands();
if (!Config->Relocatable)
fixSectionAlignments();
Script->fabricateDefaultCommands();
} else {
Script->synchronize();
}
@ -1504,15 +1504,23 @@ void Writer<ELFT>::addPtArmExid(std::vector<PhdrEntry> &Phdrs) {
// first section after PT_GNU_RELRO have to be page aligned so that the dynamic
// linker can set the permissions.
template <class ELFT> void Writer<ELFT>::fixSectionAlignments() {
auto PageAlign = [](OutputSection *Sec) {
OutputSectionCommand *Cmd = Script->getCmd(Sec);
if (Cmd && !Cmd->AddrExpr)
Cmd->AddrExpr = [=] {
return alignTo(Script->getDot(), Config->MaxPageSize);
};
};
for (const PhdrEntry &P : Phdrs)
if (P.p_type == PT_LOAD && P.First)
P.First->PageAlign = true;
PageAlign(P.First);
for (const PhdrEntry &P : Phdrs) {
if (P.p_type != PT_GNU_RELRO)
continue;
if (P.First)
P.First->PageAlign = true;
PageAlign(P.First);
// Find the first section after PT_GNU_RELRO. If it is in a PT_LOAD we
// have to align it to a page.
auto End = OutputSections.end();
@ -1521,7 +1529,7 @@ template <class ELFT> void Writer<ELFT>::fixSectionAlignments() {
continue;
OutputSection *Sec = *(I + 1);
if (needsPtLoad(Sec))
Sec->PageAlign = true;
PageAlign(Sec);
}
}