[ELF] - Change consume()->expect() in INSERT AFTER parsing.
authorGeorge Rimar <grimar@accesssoftek.com>
Mon, 12 Mar 2018 12:34:43 +0000 (12:34 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Mon, 12 Mar 2018 12:34:43 +0000 (12:34 +0000)
AFTER keyword is mandatory and consume() was
used by mistake here. We accepted broken script before
this patch, testcase shows the issue.

llvm-svn: 327260

lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/insert-broken.test [new file with mode: 0644]

index 29dec11..e23a70d 100644 (file)
@@ -450,7 +450,7 @@ void ScriptParser::readSections() {
   }
 
   if (!atEOF() && consume("INSERT")) {
-    consume("AFTER");
+    expect("AFTER");
     std::vector<BaseCommand *> &Dest = Script->InsertAfterCommands[next()];
     Dest.insert(Dest.end(), V.begin(), V.end());
     return;
diff --git a/lld/test/ELF/linkerscript/insert-broken.test b/lld/test/ELF/linkerscript/insert-broken.test
new file mode 100644 (file)
index 0000000..19bc2ef
--- /dev/null
@@ -0,0 +1,6 @@
+SECTIONS {
+  .foo : { *(.bar) }
+} INSERT .data;
+
+# RUN: not ld.lld -o %t1 --script %s 2>&1 | FileCheck %s
+# CHECK: {{.*}}:3: AFTER expected, but got .data