@@ -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.
15061506template <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