[lld] r279256 - [ELF] - Linkerscript: implemented SUBALIGN() command.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 19 08:18:24 PDT 2016
Author: grimar
Date: Fri Aug 19 10:18:23 2016
New Revision: 279256
URL: http://llvm.org/viewvc/llvm-project?rev=279256&view=rev
Log:
[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
Added:
lld/trunk/test/ELF/linkerscript/linkerscript-subalign.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=279256&r1=279255&r2=279256&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Aug 19 10:18:23 2016
@@ -283,9 +283,14 @@ void LinkerScript<ELFT>::createSections(
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 @@ ScriptParser::readOutputSectionDescripti
Cmd->LmaExpr = readParenExpr();
if (skip("ALIGN"))
Cmd->AlignExpr = readParenExpr();
+ if (skip("SUBALIGN"))
+ Cmd->SubalignExpr = readParenExpr();
// Parse constraints.
if (skip("ONLY_IF_RO"))
Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=279256&r1=279255&r2=279256&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Fri Aug 19 10:18:23 2016
@@ -81,6 +81,7 @@ struct OutputSectionCommand : BaseComman
Expr AddrExpr;
Expr AlignExpr;
Expr LmaExpr;
+ Expr SubalignExpr;
std::vector<std::unique_ptr<BaseCommand>> Commands;
std::vector<StringRef> Phdrs;
std::vector<uint8_t> Filler;
Added: lld/trunk/test/ELF/linkerscript/linkerscript-subalign.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/linkerscript-subalign.s?rev=279256&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/linkerscript-subalign.s (added)
+++ lld/trunk/test/ELF/linkerscript/linkerscript-subalign.s Fri Aug 19 10:18:23 2016
@@ -0,0 +1,43 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+
+# RUN: echo "SECTIONS { .aaa : { *(.aaa.*) } }" > %t1.script
+# RUN: ld.lld -o %t1 --script %t1.script %t1.o
+# RUN: llvm-objdump -s %t1 | FileCheck -check-prefix=NOALIGN %s
+# NOALIGN: Contents of section .aaa:
+# NOALIGN-NEXT: 01000000 00000000 00000000 00000000
+# NOALIGN-NEXT: 00000000 00000000 00000000 00000000
+# NOALIGN-NEXT: 02000000 00000000 00000000 00000000
+# NOALIGN-NEXT: 00000000 00000000 00000000 00000000
+# NOALIGN-NEXT: 03000000 00000000 00000000 00000000
+# NOALIGN-NEXT: 00000000 00000000 00000000 00000000
+# NOALIGN-NEXT: 00000000 00000000 00000000 00000000
+# NOALIGN-NEXT: 00000000 00000000 00000000 00000000
+# NOALIGN-NEXT: 04000000 00000000
+
+# RUN: echo "SECTIONS { .aaa : SUBALIGN(1) { *(.aaa.*) } }" > %t2.script
+# RUN: ld.lld -o %t2 --script %t2.script %t1.o
+# RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=SUBALIGN %s
+# SUBALIGN: Contents of section .aaa:
+# SUBALIGN: 01000000 00000000 02000000 00000000
+# SUBALIGN: 03000000 00000000 04000000 00000000
+
+.global _start
+_start:
+ nop
+
+.section .aaa.1, "a"
+.align 16
+.quad 1
+
+.section .aaa.2, "a"
+.align 32
+.quad 2
+
+.section .aaa.3, "a"
+.align 64
+.quad 3
+
+.section .aaa.4, "a"
+.align 128
+.quad 4
More information about the llvm-commits
mailing list