Skip to content

Commit 0f7dc0e

Browse files
committed
Run fabricateDefaultCommands before fixSectionAlignments.
This allows us to remove the PageAlign field. It will also allow moving fabricateDefaultCommands earlier. llvm-svn: 304513
1 parent 2611592 commit 0f7dc0e

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

lld/ELF/LinkerScript.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,6 @@ void LinkerScript::fabricateDefaultCommands() {
464464
auto I = Config->SectionStartMap.find(Sec->Name);
465465
if (I != Config->SectionStartMap.end())
466466
OSCmd->AddrExpr = [=] { return I->second; };
467-
else if (Sec->PageAlign)
468-
OSCmd->AddrExpr = [=] {
469-
return alignTo(Script->getDot(), Config->MaxPageSize);
470-
};
471467

472468
Commands.push_back(OSCmd);
473469
if (Sec->Sections.size()) {

lld/ELF/OutputSections.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ class OutputSection final : public SectionBase {
5959
Alignment = Val;
6060
}
6161

62-
// If true, this section will be page aligned on disk.
63-
// Typically the first section of each PT_LOAD segment has this flag.
64-
bool PageAlign = false;
65-
6662
// Pointer to the first section in PT_LOAD segment, which this section
6763
// also resides in. This field is used to correctly compute file offset
6864
// of a section. When two sections share the same load segment, difference

lld/ELF/Writer.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ template <class ELFT> void Writer<ELFT>::run() {
258258
return;
259259

260260
if (!Script->Opt.HasSections) {
261+
Script->fabricateDefaultCommands();
261262
if (!Config->Relocatable)
262263
fixSectionAlignments();
263-
Script->fabricateDefaultCommands();
264264
} else {
265265
Script->synchronize();
266266
}
@@ -1504,15 +1504,23 @@ void Writer<ELFT>::addPtArmExid(std::vector<PhdrEntry> &Phdrs) {
15041504
// first section after PT_GNU_RELRO have to be page aligned so that the dynamic
15051505
// linker can set the permissions.
15061506
template <class ELFT> void Writer<ELFT>::fixSectionAlignments() {
1507+
auto PageAlign = [](OutputSection *Sec) {
1508+
OutputSectionCommand *Cmd = Script->getCmd(Sec);
1509+
if (Cmd && !Cmd->AddrExpr)
1510+
Cmd->AddrExpr = [=] {
1511+
return alignTo(Script->getDot(), Config->MaxPageSize);
1512+
};
1513+
};
1514+
15071515
for (const PhdrEntry &P : Phdrs)
15081516
if (P.p_type == PT_LOAD && P.First)
1509-
P.First->PageAlign = true;
1517+
PageAlign(P.First);
15101518

15111519
for (const PhdrEntry &P : Phdrs) {
15121520
if (P.p_type != PT_GNU_RELRO)
15131521
continue;
15141522
if (P.First)
1515-
P.First->PageAlign = true;
1523+
PageAlign(P.First);
15161524
// Find the first section after PT_GNU_RELRO. If it is in a PT_LOAD we
15171525
// have to align it to a page.
15181526
auto End = OutputSections.end();
@@ -1521,7 +1529,7 @@ template <class ELFT> void Writer<ELFT>::fixSectionAlignments() {
15211529
continue;
15221530
OutputSection *Sec = *(I + 1);
15231531
if (needsPtLoad(Sec))
1524-
Sec->PageAlign = true;
1532+
PageAlign(Sec);
15251533
}
15261534
}
15271535

0 commit comments

Comments
 (0)