Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -868,6 +868,11 @@ if (!Sec) continue; + // Handle align (e.g. ".foo : ALIGN(16) { ... }"). + if (Sec->AlignExpr) + Sec->Alignment = + std::max(Sec->Alignment, Sec->AlignExpr().getValue()); + // A live output section means that some input section was added to it. It // might have been removed (if it was empty synthetic section), but we at // least know the flags. @@ -906,10 +911,6 @@ error("memory region '" + Sec->LMARegionName + "' not declared"); } Sec->MemRegion = findMemoryRegion(Sec); - // Handle align (e.g. ".foo : ALIGN(16) { ... }"). - if (Sec->AlignExpr) - Sec->Alignment = - std::max(Sec->Alignment, Sec->AlignExpr().getValue()); } } Index: test/ELF/linkerscript/align.s =================================================================== --- test/ELF/linkerscript/align.s +++ test/ELF/linkerscript/align.s @@ -42,6 +42,23 @@ # RUN: ld.lld -o %t2 --script %t2.script %t # RUN: llvm-objdump -section-headers %t2 | FileCheck %s +## Check output sections ALIGN modificator with -r +# RUN: echo "SECTIONS { \ +# RUN: . = 0x10000; \ +# RUN: .aaa : { *(.aaa) } \ +# RUN: .bbb : ALIGN(4096) { *(.bbb) } \ +# RUN: .ccc : ALIGN(4096 * 4) { *(.ccc) } \ +# RUN: }" > %t6.script +# RUN: ld.lld -r -o %t2 --script %t2.script %t +# RUN: llvm-readelf -s %t2 | FileCheck -check-prefix ALIGN %s + +# ALIGN: Section Headers: +# ALIGN-NEXT: Name Type Address Off Size ES Flg Lk Inf Al +# ALIGN-NEXT: NULL 0000000000000000 000000 000000 00 +# ALIGN-NEXT: .aaa PROGBITS 0000000000000000 000040 000008 00 A 0 0 1 +# ALIGN-NEXT: .bbb PROGBITS 0000000000000000 001000 000008 00 A 0 0 4096 +# ALIGN-NEXT: .ccc PROGBITS 0000000000000000 004000 000008 00 A 0 0 16384 + ## Check use of variables in align expressions: # RUN: echo "VAR = 0x1000; \ # RUN: __code_base__ = 0x10000; \