Handle the case where 'local' is the name of a global in a version script:
{ global : local; local: *; };

llvm-svn: 294343
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 26e814b..fe0a3cf 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -1995,7 +1995,7 @@
       continue;
     }
 
-    if (peek() == "}" || peek() == "local" || Error)
+    if (peek() == "}" || (peek() == "local" && peek(1) == ":") || Error)
       break;
     StringRef Tok = next();
     Ret.push_back({unquote(Tok), false, hasWildcard(Tok)});
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index 79f3cd3..474895f 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -156,11 +156,14 @@
   return Tokens[Pos++];
 }
 
-StringRef ScriptParserBase::peek() {
-  StringRef Tok = next();
-  if (Error)
-    return "";
-  --Pos;
+StringRef ScriptParserBase::peek(unsigned N) {
+  StringRef Tok;
+  for (unsigned I = 0; I <= N; ++I) {
+    Tok = next();
+    if (Error)
+      return "";
+  }
+  Pos = Pos - N - 1;
   return Tok;
 }
 
diff --git a/lld/ELF/ScriptParser.h b/lld/ELF/ScriptParser.h
index 264c497..42ae267 100644
--- a/lld/ELF/ScriptParser.h
+++ b/lld/ELF/ScriptParser.h
@@ -28,7 +28,7 @@
   static StringRef skipSpace(StringRef S);
   bool atEOF();
   StringRef next();
-  StringRef peek();
+  StringRef peek(unsigned N = 0);
   void skip();
   bool consume(StringRef Tok);
   void expect(StringRef Expect);
diff --git a/lld/test/ELF/version-script-glob.s b/lld/test/ELF/version-script-glob.s
index 330c068..8149ead 100644
--- a/lld/test/ELF/version-script-glob.s
+++ b/lld/test/ELF/version-script-glob.s
@@ -14,6 +14,9 @@
         .globl zed1
 zed1:
 
+        .globl local
+local:
+
 # CHECK:      DynamicSymbols [
 # CHECK-NEXT:   Symbol {
 # CHECK-NEXT:     Name:
@@ -43,3 +46,27 @@
 # CHECK-NEXT:     Section: .text
 # CHECK-NEXT:   }
 # CHECK-NEXT: ]
+
+# RUN: echo "{ global : local; local: *; };" > %t1.script
+# RUN: ld.lld -shared --version-script %t1.script %t.o -o %t1.so
+
+# LOCAL:      DynamicSymbols [
+# LOCAL-NEXT:   Symbol {
+# LOCAL-NEXT:     Name:
+# LOCAL-NEXT:     Value: 0x0
+# LOCAL-NEXT:     Size: 0
+# LOCAL-NEXT:     Binding: Local
+# LOCAL-NEXT:     Type: None
+# LOCAL-NEXT:     Other: 0
+# LOCAL-NEXT:     Section: Undefined
+# LOCAL-NEXT:   }
+# LOCAL-NEXT:   Symbol {
+# LOCAL-NEXT:     Name: local
+# LOCAL-NEXT:     Value: 0x1000
+# LOCAL-NEXT:     Size: 0
+# LOCAL-NEXT:     Binding: Global
+# LOCAL-NEXT:     Type: None
+# LOCAL-NEXT:     Other: 0
+# LOCAL-NEXT:     Section: .text
+# LOCAL-NEXT:   }
+# LOCAL-NEXT: ]