[lld] r282060 - [ELF] - Linkerscript: reimplement readSectionExcludes()

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 21 01:53:22 PDT 2016


Author: grimar
Date: Wed Sep 21 03:53:21 2016
New Revision: 282060

URL: http://llvm.org/viewvc/llvm-project?rev=282060&view=rev
Log:
[ELF] - Linkerscript: reimplement readSectionExcludes()

It is not only a bit more straightforward now, but also next 2 issues are solved:

* It just crashed on ".foo : { *(EXCLUDE_FILE (*file1.o)) }" before.
* It accepted multiple EXCLUDE_FILEs in a row.

Differential revision: https://reviews.llvm.org/D24726

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/test/ELF/linkerscript/exclude-multiple.s

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=282060&r1=282059&r2=282060&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Sep 21 03:53:21 2016
@@ -1072,30 +1072,24 @@ SortSectionPolicy ScriptParser::readSort
 // * Include .foo.2 from every file but a.o
 // * Include .foo.3 from every file but b.o
 void ScriptParser::readSectionExcludes(InputSectionDescription *Cmd) {
-  Regex ExcludeFileRe;
-  std::vector<StringRef> V;
-
-  while (!Error) {
-    if (skip(")")) {
-      Cmd->SectionPatterns.push_back(
-          {std::move(ExcludeFileRe), compileGlobPatterns(V)});
-      return;
-    }
-
+  while (!Error && peek() != ")") {
+    Regex ExcludeFileRe;
     if (skip("EXCLUDE_FILE")) {
-      if (!V.empty()) {
-        Cmd->SectionPatterns.push_back(
-            {std::move(ExcludeFileRe), compileGlobPatterns(V)});
-        V.clear();
-      }
-
       expect("(");
       ExcludeFileRe = readFilePatterns();
-      continue;
     }
 
-    V.push_back(next());
+    std::vector<StringRef> V;
+    while (!Error && peek() != ")" && peek() != "EXCLUDE_FILE")
+      V.push_back(next());
+
+    if (!V.empty())
+      Cmd->SectionPatterns.push_back(
+          {std::move(ExcludeFileRe), compileGlobPatterns(V)});
+    else
+      setError("section pattern is expected");
   }
+  expect(")");
 }
 
 InputSectionDescription *

Modified: lld/trunk/test/ELF/linkerscript/exclude-multiple.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/exclude-multiple.s?rev=282060&r1=282059&r2=282060&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/exclude-multiple.s (original)
+++ lld/trunk/test/ELF/linkerscript/exclude-multiple.s Wed Sep 21 03:53:21 2016
@@ -18,6 +18,15 @@
 # CHECK-NEXT: Contents of section .foo.3:
 # CHECK-NEXT:  06000000 00000000
 
+# RUN: echo "SECTIONS { .foo : { *(EXCLUDE_FILE (*file1.o) EXCLUDE_FILE (*file2.o) .foo.3) } }" > %t2.script
+# RUN: not ld.lld -script %t2.script %tfile1.o %tfile2.o %tfile3.o -o %t2.o 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=ERR
+# ERR: section pattern is expected
+
+# RUN: echo "SECTIONS { .foo : { *(EXCLUDE_FILE (*file1.o)) } }" > %t3.script
+# RUN: not ld.lld -script %t3.script %tfile1.o %tfile2.o %tfile3.o -o %t2.o 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=ERR
+
 .section .foo.1,"a"
  .quad 1
 




More information about the llvm-commits mailing list