[PATCH] D21828: Make SymbolTable::findAll to return only defined symbols.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 28 20:32:23 PDT 2016


ruiu created this revision.
ruiu added a reviewer: davide.
ruiu added a subscriber: llvm-commits.

We allowed the function to return a vector that contains nullptrs
which is weird. This change makes the function to return only
defined symbols.

http://reviews.llvm.org/D21828

Files:
  ELF/SymbolTable.cpp

Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -457,19 +457,26 @@
   return SymVector[It->second]->body();
 }
 
+// Returns a list of defined symbols that match with a given glob pattern.
 template <class ELFT>
 std::vector<SymbolBody *> SymbolTable<ELFT>::findAll(StringRef Pattern) {
   // Fast-path. Fallback to find() if Pattern doesn't contain any wildcard
   // characters.
-  bool HasWildcards = (Pattern.find_first_of("?*") != StringRef::npos);
-  if (!HasWildcards)
-    return {find(Pattern)};
-
-  std::vector<SymbolBody *> Result;
-  for (auto &It : Symtab)
-    if (matchStr(Pattern, It.first.Val))
-      Result.push_back(SymVector[It.second]->body());
-  return Result;
+  if (Pattern.find_first_of("?*") == StringRef::npos) {
+    if (SymbolBody *B = find(Pattern))
+      if (!B->isUndefined())
+        return {B};
+    return {};
+  }
+
+  std::vector<SymbolBody *> Res;
+  for (auto &It : Symtab) {
+    StringRef Name = It.first.Val;
+    SymbolBody *B = SymVector[It.second]->body();
+    if (!B->isUndefined() && matchStr(Pattern, Name))
+      Res.push_back(B);
+  }
+  return Res;
 }
 
 template <class ELFT>
@@ -572,14 +579,15 @@
   size_t I = 2;
   for (Version &V : Config->SymbolVersions) {
     for (StringRef Name : V.Globals) {
-      for (SymbolBody *B : findAll(Name)) {
-        if (!B || B->isUndefined()) {
-          if (Config->NoUndefinedVersion)
-            error("version script assignment of " + V.Name + " to symbol " +
-                  Name + " failed: symbol not defined");
-          continue;
-        }
+      std::vector<SymbolBody *> Syms = findAll(Name);
+      if (Syms.empty()) {
+        if (Config->NoUndefinedVersion)
+          error("version script assignment of " + V.Name + " to symbol " +
+                Name + " failed: symbol not defined");
+        continue;
+      }
 
+      for (SymbolBody *B : Syms) {
         if (B->symbol()->VersionId != VER_NDX_GLOBAL &&
             B->symbol()->VersionId != VER_NDX_LOCAL)
           warning("duplicate symbol " + Name + " in version script");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21828.62172.patch
Type: text/x-patch
Size: 2157 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160629/3de60924/attachment.bin>


More information about the llvm-commits mailing list