summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2016-12-15 07:27:28 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2016-12-15 07:27:28 +0000
commit14460e0216bf3bee7efe53c527c9cf6c217e4364 (patch)
treee576d034c9bb4185ece766bdf24171cd623ec8b2
parent7dfa62687c181d5ffad0be3dfdf9763f22374d22 (diff)
downloadbcm5719-llvm-14460e0216bf3bee7efe53c527c9cf6c217e4364.tar.gz
bcm5719-llvm-14460e0216bf3bee7efe53c527c9cf6c217e4364.zip
[ELF] - Do not crash when move location counter backward.
PR31335 shows that we do that in next case: SECTIONS { .text 0x2000 : {. = 0x100 ; *(.text) } } though documentations says that "If . is used inside a section description however, it refers to the byte offset from the start of that section, not an absolute address. " looks does not work as documented in bfd (as mentioned in comments for PR31335). Until we find out the expected behavior was suggested at least not to 'crash', what we do after trying to generate huge file. Differential revision: https://reviews.llvm.org/D27712 llvm-svn: 289782
-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