Skip to content

Commit 5d804dc

Browse files
committedDec 16, 2016
[ELF] - Linkerscript: Implement two argument version of ALIGN()
Fixes http://llvm.org/PR31129 Patch by Alexander Richardson! Differential Revision: https://reviews.llvm.org/D27848 llvm-svn: 289968
1 parent 55e7d65 commit 5d804dc

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
 

‎lld/ELF/LinkerScript.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,14 @@ Expr ScriptParser::readPrimary() {
17361736
if (Tok == "ASSERT")
17371737
return readAssert();
17381738
if (Tok == "ALIGN") {
1739-
Expr E = readParenExpr();
1739+
expect("(");
1740+
Expr E = readExpr();
1741+
if (consume(",")) {
1742+
Expr E2 = readExpr();
1743+
expect(")");
1744+
return [=](uint64_t Dot) { return alignTo(E(Dot), E2(Dot)); };
1745+
}
1746+
expect(")");
17401747
return [=](uint64_t Dot) { return alignTo(Dot, E(Dot)); };
17411748
}
17421749
if (Tok == "CONSTANT") {

‎lld/test/ELF/linkerscript/align.s

+22
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@
2121
# RUN: }" > %t.script
2222
# RUN: ld.lld -o %t1 --script %t.script %t
2323
# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
24+
25+
## Check that the two argument version of ALIGN command works
26+
# RUN: echo "SECTIONS { \
27+
# RUN: . = ALIGN(0x1234, 0x10000); \
28+
# RUN: .aaa : \
29+
# RUN: { \
30+
# RUN: *(.aaa) \
31+
# RUN: } \
32+
# RUN: . = ALIGN(., 4096); \
33+
# RUN: .bbb : \
34+
# RUN: { \
35+
# RUN: *(.bbb) \
36+
# RUN: } \
37+
# RUN: . = ALIGN(., 4096 * 4); \
38+
# RUN: .ccc : \
39+
# RUN: { \
40+
# RUN: *(.ccc) \
41+
# RUN: } \
42+
# RUN: }" > %t.script
43+
# RUN: ld.lld -o %t1 --script %t.script %t
44+
# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
45+
2446
# CHECK: Sections:
2547
# CHECK-NEXT: Idx Name Size Address Type
2648
# CHECK-NEXT: 0 00000000 0000000000000000

0 commit comments

Comments
 (0)
Please sign in to comment.