[ELF] - Linkerscript: implemented SUBALIGN() command.
You can force input section alignment within an output section by using SUBALIGN. The
value specified overrides any alignment given by input sections, whether larger or smaller.
SUBALIGN is used in many projects in the wild.
Differential revision: https://reviews.llvm.org/D23063
llvm-svn: 279256
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 35a1a61..6b037a0 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -283,9 +283,14 @@
std::tie(OutSec, IsNew) = Factory.create(Head, Cmd->Name);
if (IsNew)
OutputSections->push_back(OutSec);
- for (InputSectionBase<ELFT> *Sec : V)
+
+ uint32_t Subalign = Cmd->SubalignExpr ? Cmd->SubalignExpr(0) : 0;
+ for (InputSectionBase<ELFT> *Sec : V) {
+ if (Subalign)
+ Sec->Alignment = Subalign;
if (!Sec->OutSec)
OutSec->addSection(Sec);
+ }
}
}
@@ -937,6 +942,8 @@
Cmd->LmaExpr = readParenExpr();
if (skip("ALIGN"))
Cmd->AlignExpr = readParenExpr();
+ if (skip("SUBALIGN"))
+ Cmd->SubalignExpr = readParenExpr();
// Parse constraints.
if (skip("ONLY_IF_RO"))