Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -402,7 +402,8 @@ // is given, input sections are aligned to that value, whether the // given value is larger or smaller than the original section alignment. if (Sec->SubalignExpr) { - uint32_t Subalign = Sec->SubalignExpr().getValue(); + uint32_t Subalign = + std::max((uint64_t)1, Sec->SubalignExpr().getValue()); for (InputSectionBase *S : V) S->Alignment = Subalign; } Index: test/ELF/linkerscript/subalign.s =================================================================== --- test/ELF/linkerscript/subalign.s +++ test/ELF/linkerscript/subalign.s @@ -22,6 +22,17 @@ # SUBALIGN: 01000000 00000000 02000000 00000000 # SUBALIGN: 03000000 00000000 04000000 00000000 +## Test we do not fail when dot(.) is used inside SUBALIGN. That is not +## consistent with ld.bfd. +# RUN: echo "SECTIONS { . = 0x32; .aaa : SUBALIGN(.) { *(.aaa*) } }" > %t3.script +# RUN: ld.lld %t1.o --script %t3.script -o %t3 +# RUN: llvm-objdump -s %t3 | FileCheck -check-prefix=SUBALIGN %s + +## Test we are able to link with zero alignment, this is consistent with bfd 2.26.1. +# RUN: echo "SECTIONS { .aaa : SUBALIGN(0) { *(.aaa*) } }" > %t4.script +# RUN: ld.lld %t1.o --script %t4.script -o %t4 +# RUN: llvm-objdump -s %t4 | FileCheck -check-prefix=SUBALIGN %s + .global _start _start: nop