[lld] r281393 - Split scanVersionScript. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 13 13:51:31 PDT 2016


Author: ruiu
Date: Tue Sep 13 15:51:30 2016
New Revision: 281393

URL: http://llvm.org/viewvc/llvm-project?rev=281393&view=rev
Log:
Split scanVersionScript. NFC.

Modified:
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/SymbolTable.h

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=281393&r1=281392&r2=281393&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Tue Sep 13 15:51:30 2016
@@ -643,30 +643,35 @@ findAllDemangled(const std::map<std::str
   return Res;
 }
 
+// If there's only one anonymous version definition in a version
+// script file, the script does not actullay define any symbol version,
+// but just specifies symbols visibilities. We assume that the script was
+// in the form of { global: foo; bar; local *; }. So, local is default.
+// In this function, we make specified symbols global.
+template <class ELFT> void SymbolTable<ELFT>::handleAnonymousVersion() {
+  std::vector<StringRef> Patterns;
+  for (SymbolVersion &Sym : Config->VersionScriptGlobals) {
+    if (hasWildcard(Sym.Name)) {
+      Patterns.push_back(Sym.Name);
+      continue;
+    }
+    if (SymbolBody *B = find(Sym.Name))
+      B->symbol()->VersionId = VER_NDX_GLOBAL;
+  }
+  if (Patterns.empty())
+    return;
+  Regex Re = compileGlobPatterns(Patterns);
+  std::vector<SymbolBody *> Syms = findAll(Re);
+  for (SymbolBody *B : Syms)
+    B->symbol()->VersionId = VER_NDX_GLOBAL;
+}
+
 // This function processes version scripts by updating VersionId
 // member of symbols.
 template <class ELFT> void SymbolTable<ELFT>::scanVersionScript() {
-  // If there's only one anonymous version definition in a version
-  // script file, the script does not actullay define any symbol version,
-  // but just specifies symbols visibilities. We assume that the script was
-  // in the form of { global: foo; bar; local *; }. So, local is default.
-  // Here, we make specified symbols global.
+  // Handle edge cases first.
   if (!Config->VersionScriptGlobals.empty()) {
-    std::vector<StringRef> Globs;
-    for (SymbolVersion &Sym : Config->VersionScriptGlobals) {
-      if (hasWildcard(Sym.Name)) {
-        Globs.push_back(Sym.Name);
-        continue;
-      }
-      if (SymbolBody *B = find(Sym.Name))
-        B->symbol()->VersionId = VER_NDX_GLOBAL;
-    }
-    if (Globs.empty())
-      return;
-    Regex Re = compileGlobPatterns(Globs);
-    std::vector<SymbolBody *> Syms = findAll(Re);
-    for (SymbolBody *B : Syms)
-      B->symbol()->VersionId = VER_NDX_GLOBAL;
+    handleAnonymousVersion();
     return;
   }
 

Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=281393&r1=281392&r2=281393&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Tue Sep 13 15:51:30 2016
@@ -102,6 +102,7 @@ private:
   void reportDuplicate(SymbolBody *Existing, InputFile *NewFile);
 
   std::map<std::string, std::vector<SymbolBody *>> getDemangledSyms();
+  void handleAnonymousVersion();
 
   struct SymIndex {
     SymIndex(int Idx, bool Traced) : Idx(Idx), Traced(Traced) {}




More information about the llvm-commits mailing list