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 @@ -32,7 +32,7 @@ # CHECK-NEXT: 2 .bbb 00000008 0000000000011000 DATA # CHECK-NEXT: 3 .ccc 00000008 0000000000014000 DATA -## Check output sections ALIGN modificator +## Check output section ALIGN modifier # RUN: echo "SECTIONS { \ # RUN: . = 0x10000; \ # RUN: .aaa : { *(.aaa) } \ @@ -41,6 +41,17 @@ # RUN: }" > %t2.script # RUN: ld.lld -o %t2 --script %t2.script %t # RUN: llvm-objdump -section-headers %t2 | FileCheck %s + +## Check output section ALIGN modifier with -r +# RUN: ld.lld -r -o %t2.o --script %t2.script %t +# RUN: llvm-readelf -s %t2.o | 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; \