[PATCH] D23793: [ELF] - Cleanup of scanVersionScript(): do not change local Demangled variable.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 23 02:19:53 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, evgeny777.

Previously if we had version script like

 LIBSAMPLE_2.0 {       
   global:             
     extern "C++" { 
      bar;    
   }; 

Demangled local variable was changed because std::map operator[] added
new element if there was no such key found.
That was confusing to see and unclean to have, patch fixes that making
Demangled to be const.

https://reviews.llvm.org/D23793

Files:
  ELF/SymbolTable.cpp

Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -595,22 +595,32 @@
   Sym->VersionId = Version;
 }
 
+static bool hasExternCpp() {
+  for (VersionDefinition &V : Config->VersionDefinitions)
+    for (SymbolVersion Sym : V.Globals)
+      if (Sym.IsExternCpp)
+        return true;
+  return false;
+}
+
 template <class ELFT>
 std::map<std::string, SymbolBody *> SymbolTable<ELFT>::getDemangledSyms() {
   std::map<std::string, SymbolBody *> Result;
+  if (!hasExternCpp())
+    return Result;
   for (Symbol *Sym : SymVector) {
     SymbolBody *B = Sym->body();
     Result[demangle(B->getName())] = B;
   }
   return Result;
 }
 
-static bool hasExternCpp() {
-  for (VersionDefinition &V : Config->VersionDefinitions)
-    for (SymbolVersion Sym : V.Globals)
-      if (Sym.IsExternCpp)
-        return true;
-  return false;
+static SymbolBody *findDemangled(const std::map<std::string, SymbolBody *> &D,
+                                 StringRef Name) {
+  auto I = D.find(Name);
+  if (I != D.end())
+    return I->second;
+  return nullptr;
 }
 
 // This function processes the --version-script option by marking all global
@@ -639,16 +649,15 @@
   //   matching version tag in the file).
   // Handle exact matches and build a map of demangled externs for
   // quick search during next step.
-  std::map<std::string, SymbolBody *> Demangled;
-  if (hasExternCpp())
-    Demangled = getDemangledSyms();
+  const std::map<std::string, SymbolBody *> Demangled = getDemangledSyms();
 
   for (VersionDefinition &V : Config->VersionDefinitions) {
     for (SymbolVersion Sym : V.Globals) {
       if (hasWildcard(Sym.Name))
         continue;
-      SymbolBody *B = Sym.IsExternCpp ? Demangled[Sym.Name] : find(Sym.Name);
-      setVersionId(B, V.Name, Sym.Name, V.Id);
+      StringRef N = Sym.Name;
+      SymbolBody *B = Sym.IsExternCpp ? findDemangled(Demangled, N) : find(N);
+      setVersionId(B, V.Name, N, V.Id);
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23793.68959.patch
Type: text/x-patch
Size: 2098 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160823/f4d10a48/attachment.bin>


More information about the llvm-commits mailing list