Skip to content

Commit

Permalink
[ELF] - Linkerscript: Implement two argument version of ALIGN()
Browse files Browse the repository at this point in the history
Fixes http://llvm.org/PR31129

Patch by Alexander Richardson!

Differential Revision: https://reviews.llvm.org/D27848

llvm-svn: 289968
  • Loading branch information
rui314 committed Dec 16, 2016
1 parent 55e7d65 commit 5d804dc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lld/ELF/LinkerScript.cpp
Expand Up @@ -1736,7 +1736,14 @@ Expr ScriptParser::readPrimary() {
if (Tok == "ASSERT")
return readAssert();
if (Tok == "ALIGN") {
Expr E = readParenExpr();
expect("(");
Expr E = readExpr();
if (consume(",")) {
Expr E2 = readExpr();
expect(")");
return [=](uint64_t Dot) { return alignTo(E(Dot), E2(Dot)); };
}
expect(")");
return [=](uint64_t Dot) { return alignTo(Dot, E(Dot)); };
}
if (Tok == "CONSTANT") {
Expand Down
22 changes: 22 additions & 0 deletions lld/test/ELF/linkerscript/align.s
Expand Up @@ -21,6 +21,28 @@
# RUN: }" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-objdump -section-headers %t1 | FileCheck %s

## Check that the two argument version of ALIGN command works
# RUN: echo "SECTIONS { \
# RUN: . = ALIGN(0x1234, 0x10000); \
# RUN: .aaa : \
# RUN: { \
# RUN: *(.aaa) \
# RUN: } \
# RUN: . = ALIGN(., 4096); \
# RUN: .bbb : \
# RUN: { \
# RUN: *(.bbb) \
# RUN: } \
# RUN: . = ALIGN(., 4096 * 4); \
# RUN: .ccc : \
# RUN: { \
# RUN: *(.ccc) \
# RUN: } \
# RUN: }" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-objdump -section-headers %t1 | FileCheck %s

# CHECK: Sections:
# CHECK-NEXT: Idx Name Size Address Type
# CHECK-NEXT: 0 00000000 0000000000000000
Expand Down

0 comments on commit 5d804dc

Please sign in to comment.