File tree 3 files changed +34
-0
lines changed
3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -226,6 +226,9 @@ void LinkerScript<ELFT>::assignAddresses(
226
226
if (Cmd->AddrExpr )
227
227
Dot = Cmd->AddrExpr (Dot);
228
228
229
+ if (Cmd->AlignExpr )
230
+ Sec->updateAlignment (Cmd->AlignExpr (Dot));
231
+
229
232
if ((Sec->getFlags () & SHF_TLS) && Sec->getType () == SHT_NOBITS) {
230
233
uintX_t TVA = Dot + ThreadBssOffset;
231
234
TVA = alignTo (TVA, Sec->getAlignment ());
@@ -433,6 +436,7 @@ class elf::ScriptParser : public ScriptParserBase {
433
436
std::vector<StringRef> readOutputSectionPhdrs ();
434
437
unsigned readPhdrType ();
435
438
void readProvide (bool Hidden);
439
+ void readAlign (OutputSectionCommand *Cmd);
436
440
437
441
Expr readExpr ();
438
442
Expr readExpr1 (Expr Lhs, int MinPrec);
@@ -671,6 +675,12 @@ void ScriptParser::readKeep(OutputSectionCommand *Cmd) {
671
675
expect (" )" );
672
676
}
673
677
678
+ void ScriptParser::readAlign (OutputSectionCommand *Cmd) {
679
+ expect (" (" );
680
+ Cmd->AlignExpr = readExpr ();
681
+ expect (" )" );
682
+ }
683
+
674
684
void ScriptParser::readOutputSectionDescription (StringRef OutSec) {
675
685
OutputSectionCommand *Cmd = new OutputSectionCommand (OutSec);
676
686
Opt.Commands .emplace_back (Cmd);
@@ -682,6 +692,9 @@ void ScriptParser::readOutputSectionDescription(StringRef OutSec) {
682
692
683
693
expect (" :" );
684
694
695
+ if (skip (" ALIGN" ))
696
+ readAlign (Cmd);
697
+
685
698
// Parse constraints.
686
699
if (skip (" ONLY_IF_RO" ))
687
700
Cmd->Constraint = ConstraintKind::ReadOnly;
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ struct OutputSectionCommand : BaseCommand {
73
73
static bool classof (const BaseCommand *C);
74
74
StringRef Name;
75
75
Expr AddrExpr;
76
+ Expr AlignExpr;
76
77
std::vector<std::unique_ptr<BaseCommand>> Commands;
77
78
std::vector<StringRef> Phdrs;
78
79
std::vector<uint8_t > Filler;
Original file line number Diff line number Diff line change 1
1
# REQUIRES: x86
2
2
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
3
3
4
+ ## Check that ALIGN command workable using location counter
4
5
# RUN: echo "SECTIONS { \
5
6
# RUN: . = 0x10000; \
6
7
# RUN: .aaa : \
27
28
# CHECK-NEXT: 2 .bbb 00000008 0000000000011000 DATA
28
29
# CHECK-NEXT: 3 .ccc 00000008 0000000000014000 DATA
29
30
31
+ ## Check output sections ALIGN modificator
32
+ # RUN: echo "SECTIONS { \
33
+ # RUN: . = 0x10000; \
34
+ # RUN: .aaa : \
35
+ # RUN: { \
36
+ # RUN: *(.aaa) \
37
+ # RUN: } \
38
+ # RUN: .bbb : ALIGN(4096) \
39
+ # RUN: { \
40
+ # RUN: *(.bbb) \
41
+ # RUN: } \
42
+ # RUN: .ccc : ALIGN(4096 * 4) \
43
+ # RUN: { \
44
+ # RUN: *(.ccc) \
45
+ # RUN: } \
46
+ # RUN: }" > %t2.script
47
+ # RUN: ld.lld -o %t2 --script %t2.script %t
48
+ # RUN: llvm-objdump -section-headers %t1 | FileCheck %s
49
+
30
50
.global _start
31
51
_start:
32
52
nop
You can’t perform that action at this time.
0 commit comments