Index: lld/trunk/ELF/LinkerScript.cpp =================================================================== --- lld/trunk/ELF/LinkerScript.cpp +++ lld/trunk/ELF/LinkerScript.cpp @@ -111,13 +111,9 @@ void LinkerScript::setDot(Expr E, const Twine &Loc, bool InSec) { uint64_t Val = E().getValue(); - if (Val < Dot) { - if (InSec) - error(Loc + ": unable to move location counter backward for: " + - CurAddressState->OutSec->Name); - else - error(Loc + ": unable to move location counter backward"); - } + if (Val < Dot && InSec) + error(Loc + ": unable to move location counter backward for: " + + CurAddressState->OutSec->Name); Dot = Val; // Update to location counter means update to section size. if (InSec) Index: lld/trunk/test/ELF/linkerscript/locationcountererr2.s =================================================================== --- lld/trunk/test/ELF/linkerscript/locationcountererr2.s +++ lld/trunk/test/ELF/linkerscript/locationcountererr2.s @@ -2,8 +2,10 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o # RUN: echo "SECTIONS {" > %t.script # RUN: echo ". = 0x20; . = 0x10; .text : {} }" >> %t.script -# RUN: not ld.lld %t.o --script %t.script -o %t -shared 2>&1 | FileCheck %s -# CHECK: {{.*}}.script:2: unable to move location counter backward +# RUN: ld.lld %t.o --script %t.script -o %t -shared +# RUN: llvm-objdump -section-headers %t | FileCheck %s +# CHECK: Idx Name Size Address +# CHECK: 1 .text 00000000 0000000000000010 # RUN: echo "SECTIONS { . = 0x20; . = ASSERT(0x1, "foo"); }" > %t2.script # RUN: ld.lld %t.o --script %t2.script -o %t -shared Index: lld/trunk/test/ELF/linkerscript/out-of-order.s =================================================================== --- lld/trunk/test/ELF/linkerscript/out-of-order.s +++ lld/trunk/test/ELF/linkerscript/out-of-order.s @@ -1,9 +1,18 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-linux %s -o %t.o # RUN: echo "SECTIONS { .data 0x4000 : { *(.data) } .text 0x2000 : { *(.text) } }" > %t.script -# RUN: not ld.lld -o %t.so --script %t.script %t.o -shared 2>&1 | FileCheck %s +# RUN: ld.lld -o %t.so --script %t.script %t.o -shared +# RUN: llvm-objdump -section-headers %t.so | FileCheck %s -# CHECK: error: {{.*}}.script:1: unable to move location counter backward +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address Type +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK-NEXT: 1 .data 00000008 0000000000004000 DATA +# CHECK-NEXT: 2 .dynamic 00000060 0000000000004008 +# CHECK-NEXT: 3 .text 00000008 0000000000002000 TEXT DATA +# CHECK-NEXT: 4 .dynsym 00000018 0000000000002008 +# CHECK-NEXT: 5 .hash 00000010 0000000000002020 +# CHECK-NEXT: 6 .dynstr 00000001 0000000000002030 .quad 0 .data