Skip to content

Commit dffc141

Browse files
author
George Rimar
committedApr 22, 2016
[ELF] - Implemented linkerscript ALIGN command
ALIGN(exp) Return the location counter (.) aligned to the next exp boundary. (https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/expressions.html) Patch implements this command. This fixes PR27406. Differential revision: http://reviews.llvm.org/D19364 llvm-svn: 267145
1 parent b1bfd50 commit dffc141

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
 

‎lld/ELF/LinkerScript.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ uint64_t LinkerScript<ELFT>::parsePrimary(ArrayRef<StringRef> &Tokens) {
9494
return 0;
9595
return V;
9696
}
97+
if (Tok == "ALIGN") {
98+
if (!expect(Tokens, "("))
99+
return 0;
100+
uint64_t V = parseExpr(Tokens);
101+
if (!expect(Tokens, ")"))
102+
return 0;
103+
return alignTo(Dot, V);
104+
}
97105
return getInteger(Tok);
98106
}
99107

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

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# REQUIRES: x86
2+
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
3+
4+
# RUN: echo "SECTIONS { \
5+
# RUN: . = 0x10000; \
6+
# RUN: .aaa : \
7+
# RUN: { \
8+
# RUN: *(.aaa) \
9+
# RUN: } \
10+
# RUN: . = ALIGN(4096); \
11+
# RUN: .bbb : \
12+
# RUN: { \
13+
# RUN: *(.bbb) \
14+
# RUN: } \
15+
# RUN: . = ALIGN(4096 * 4); \
16+
# RUN: .ccc : \
17+
# RUN: { \
18+
# RUN: *(.ccc) \
19+
# RUN: } \
20+
# RUN: }" > %t.script
21+
# RUN: ld.lld -o %t1 --script %t.script %t
22+
# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
23+
# CHECK: Sections:
24+
# CHECK-NEXT: Idx Name Size Address Type
25+
# CHECK-NEXT: 0 00000000 0000000000000000
26+
# CHECK-NEXT: 1 .aaa 00000008 0000000000010000 DATA
27+
# CHECK-NEXT: 2 .bbb 00000008 0000000000011000 DATA
28+
# CHECK-NEXT: 3 .ccc 00000008 0000000000014000 DATA
29+
30+
.global _start
31+
_start:
32+
nop
33+
34+
.section .aaa, "a"
35+
.quad 0
36+
37+
.section .bbb, "a"
38+
.quad 0
39+
40+
.section .ccc, "a"
41+
.quad 0

0 commit comments

Comments
 (0)
Please sign in to comment.