[lld] r281049 - Recommit [ELF] - Versionscript: do not treat non-wildcarded names as wildcards.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 9 07:35:37 PDT 2016


Author: grimar
Date: Fri Sep  9 09:35:36 2016
New Revision: 281049

URL: http://llvm.org/viewvc/llvm-project?rev=281049&view=rev
Log:
Recommit [ELF] - Versionscript: do not treat non-wildcarded names as wildcards.

Fixed code that was not checked before on windows for me, because of testcases that are
disabled on that platform atm.

Inital commit message:
"[ELF] - Versionscript: do not treat non-wildcarded names as wildcards."
Previously we incorrectly handled cases when symbol name in extern c++ tag
was enclosed in quotes. Next case was treated as wildcard:

GLIBCXX_3.4 {                                                                   
    extern "C++" {  
    "aaa*"
   }
But it should have not. Quotes around aaa here means that we should have do exact
name matching.
That is PR30268 which has name with pointer is interpreted as wildcard by lld:

extern "C++" {                                                              
    "operator delete[](void*)";

Patch fixes the issue.

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

Added:
    lld/trunk/test/ELF/version-script-extern-exact.s
      - copied unchanged from r281045, lld/trunk/test/ELF/version-script-extern-exact.s
Modified:
    lld/trunk/ELF/Config.h
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/ScriptParser.cpp
    lld/trunk/ELF/Strings.cpp
    lld/trunk/ELF/Strings.h
    lld/trunk/ELF/SymbolListFile.cpp
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/test/ELF/invalid-dynamic-list.test

Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=281049&r1=281048&r2=281049&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Fri Sep  9 09:35:36 2016
@@ -45,6 +45,7 @@ enum class UnresolvedPolicy { NoUndef, R
 struct SymbolVersion {
   llvm::StringRef Name;
   bool IsExternCpp;
+  bool HasWildcards;
 };
 
 // This struct contains symbols version definition that

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=281049&r1=281048&r2=281049&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Sep  9 09:35:36 2016
@@ -785,7 +785,7 @@ void ScriptParser::readAsNeeded() {
   bool Orig = Config->AsNeeded;
   Config->AsNeeded = true;
   while (!Error && !skip(")"))
-    addFile(next());
+    addFile(unquote(next()));
   Config->AsNeeded = Orig;
 }
 
@@ -811,13 +811,13 @@ void ScriptParser::readGroup() {
     if (Tok == "AS_NEEDED")
       readAsNeeded();
     else
-      addFile(Tok);
+      addFile(unquote(Tok));
   }
 }
 
 void ScriptParser::readInclude() {
   StringRef Tok = next();
-  auto MBOrErr = MemoryBuffer::getFile(Tok);
+  auto MBOrErr = MemoryBuffer::getFile(unquote(Tok));
   if (!MBOrErr) {
     setError("cannot open " + Tok);
     return;
@@ -833,7 +833,7 @@ void ScriptParser::readOutput() {
   expect("(");
   StringRef Tok = next();
   if (Config->OutputFile.empty())
-    Config->OutputFile = Tok;
+    Config->OutputFile = unquote(Tok);
   expect(")");
 }
 
@@ -896,7 +896,7 @@ void ScriptParser::readSearchDir() {
   expect("(");
   StringRef Tok = next();
   if (!Config->Nostdlib)
-    Config->SearchPaths.push_back(Tok);
+    Config->SearchPaths.push_back(unquote(Tok));
   expect(")");
 }
 
@@ -1004,7 +1004,7 @@ Expr ScriptParser::readAssert() {
   expect("(");
   Expr E = readExpr();
   expect(",");
-  StringRef Msg = next();
+  StringRef Msg = unquote(next());
   expect(")");
   return [=](uint64_t Dot) {
     uint64_t V = E(Dot);
@@ -1421,13 +1421,14 @@ void ScriptParser::readLocal() {
 }
 
 void ScriptParser::readExtern(std::vector<SymbolVersion> *Globals) {
-  expect("C++");
+  expect("\"C++\"");
   expect("{");
 
   for (;;) {
     if (peek() == "}" || Error)
       break;
-    Globals->push_back({next(), true});
+    bool HasWildcard = !peek().startswith("\"") && hasWildcard(peek());
+    Globals->push_back({unquote(next()), true, HasWildcard});
     expect(";");
   }
 
@@ -1450,7 +1451,7 @@ void ScriptParser::readGlobal(StringRef
     if (Cur == "}" || Cur == "local:" || Error)
       return;
     next();
-    Globals->push_back({Cur, false});
+    Globals->push_back({unquote(Cur), false, hasWildcard(Cur)});
     expect(";");
   }
 }

Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=281049&r1=281048&r2=281049&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Fri Sep  9 09:35:36 2016
@@ -60,14 +60,17 @@ std::vector<StringRef> ScriptParserBase:
     if (S.empty())
       return Ret;
 
-    // Quoted token.
+    // Quoted token. Note that double-quote characters are parts of a token
+    // because, in a glob match context, only unquoted tokens are interpreted
+    // as glob patterns. Double-quoted tokens are literal patterns in that
+    // context.
     if (S.startswith("\"")) {
       size_t E = S.find("\"", 1);
       if (E == StringRef::npos) {
         error("unclosed quote");
         return {};
       }
-      Ret.push_back(S.substr(1, E - 1));
+      Ret.push_back(S.take_front(E + 1));
       S = S.substr(E + 1);
       continue;
     }

Modified: lld/trunk/ELF/Strings.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Strings.cpp?rev=281049&r1=281048&r2=281049&view=diff
==============================================================================
--- lld/trunk/ELF/Strings.cpp (original)
+++ lld/trunk/ELF/Strings.cpp Fri Sep  9 09:35:36 2016
@@ -24,6 +24,12 @@ bool elf::hasWildcard(StringRef S) {
   return S.find_first_of("?*[") != StringRef::npos;
 }
 
+StringRef elf::unquote(StringRef S) {
+  if (!S.startswith("\""))
+    return S;
+  return S.substr(1, S.size() - 2);
+}
+
 // Converts a glob pattern to a regular expression.
 static std::string toRegex(StringRef S) {
   std::string T;

Modified: lld/trunk/ELF/Strings.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Strings.h?rev=281049&r1=281048&r2=281049&view=diff
==============================================================================
--- lld/trunk/ELF/Strings.h (original)
+++ lld/trunk/ELF/Strings.h Fri Sep  9 09:35:36 2016
@@ -20,6 +20,7 @@ llvm::Regex compileGlobPatterns(ArrayRef
 bool hasWildcard(StringRef S);
 std::vector<uint8_t> parseHex(StringRef S);
 bool isValidCIdentifier(StringRef S);
+StringRef unquote(StringRef S);
 
 // Returns a demangled C++ symbol name. If Name is not a mangled
 // name or the system does not provide __cxa_demangle function,

Modified: lld/trunk/ELF/SymbolListFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolListFile.cpp?rev=281049&r1=281048&r2=281049&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolListFile.cpp (original)
+++ lld/trunk/ELF/SymbolListFile.cpp Fri Sep  9 09:35:36 2016
@@ -16,6 +16,7 @@
 #include "SymbolListFile.h"
 #include "Config.h"
 #include "ScriptParser.h"
+#include "Strings.h"
 #include "llvm/Support/MemoryBuffer.h"
 
 using namespace llvm;
@@ -43,7 +44,7 @@ void DynamicListParser::run() {
   while (!atEOF()) {
     expect("{");
     while (!Error) {
-      Config->DynamicList.push_back(next());
+      Config->DynamicList.push_back(unquote(next()));
       expect(";");
       if (skip("}"))
         break;

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=281049&r1=281048&r2=281049&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Fri Sep  9 09:35:36 2016
@@ -18,7 +18,6 @@
 #include "Config.h"
 #include "Error.h"
 #include "LinkerScript.h"
-#include "Strings.h"
 #include "SymbolListFile.h"
 #include "Symbols.h"
 #include "llvm/Bitcode/ReaderWriter.h"
@@ -678,7 +677,7 @@ template <class ELFT> void SymbolTable<E
   // i.e. version definitions not containing any glob meta-characters.
   for (VersionDefinition &V : Config->VersionDefinitions) {
     for (SymbolVersion Sym : V.Globals) {
-      if (hasWildcard(Sym.Name))
+      if (Sym.HasWildcards)
         continue;
       StringRef N = Sym.Name;
       SymbolBody *B = Sym.IsExternCpp ? findDemangled(Demangled, N) : find(N);
@@ -693,7 +692,7 @@ template <class ELFT> void SymbolTable<E
   for (size_t I = Config->VersionDefinitions.size() - 1; I != (size_t)-1; --I) {
     VersionDefinition &V = Config->VersionDefinitions[I];
     for (SymbolVersion &Sym : V.Globals) {
-      if (!hasWildcard(Sym.Name))
+      if (!Sym.HasWildcards)
         continue;
       Regex Re = compileGlobPatterns({Sym.Name});
       std::vector<SymbolBody *> Syms =

Modified: lld/trunk/test/ELF/invalid-dynamic-list.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid-dynamic-list.test?rev=281049&r1=281048&r2=281049&view=diff
==============================================================================
--- lld/trunk/test/ELF/invalid-dynamic-list.test (original)
+++ lld/trunk/test/ELF/invalid-dynamic-list.test Fri Sep  9 09:35:36 2016
@@ -34,4 +34,4 @@
 
 # RUN: echo "{ extern \"BOGUS\" { test }; };" > %t1
 # RUN: not ld.lld --dynamic-list %t1 2>&1 | FileCheck -check-prefix=ERR6 %s
-# ERR6: line 1: ; expected, but got BOGUS
+# ERR6: line 1: ; expected, but got "BOGUS"




More information about the llvm-commits mailing list