summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/LinkerScript.cpp6
-rw-r--r--lld/test/ELF/linkerscript/locationcountererr.s9
2 files changed, 14 insertions, 1 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index bf19914b53c..68f24acad29 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -464,7 +464,11 @@ template <class ELFT> void LinkerScript<ELFT>::process(BaseCommand &Base) {
if (auto *AssignCmd = dyn_cast<SymbolAssignment>(&Base)) {
if (AssignCmd->Name == ".") {
// Update to location counter means update to section size.
- Dot = AssignCmd->Expression(Dot);
+ uintX_t Val = AssignCmd->Expression(Dot);
+ if (Val < Dot)
+ error("unable to move location counter backward for: " +
+ CurOutSec->Name);
+ Dot = Val;
CurOutSec->Size = Dot - CurOutSec->Addr;
return;
}
diff --git a/lld/test/ELF/linkerscript/locationcountererr.s b/lld/test/ELF/linkerscript/locationcountererr.s
new file mode 100644
index 00000000000..7664d8d4691
--- /dev/null
+++ b/lld/test/ELF/linkerscript/locationcountererr.s
@@ -0,0 +1,9 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "SECTIONS { .text 0x2000 : {. = 0x10 ; *(.text) } }" > %t.script
+# RUN: not ld.lld %t --script %t.script -o %t1 2>&1 | FileCheck %s
+# CHECK: unable to move location counter backward for: .text
+
+.globl _start
+_start:
+nop
OpenPOWER on IntegriCloud