]> granicus.if.org Git - llvm/commitdiff
[Symbolize] Uniquify sorted vector<pair<SymbolDesc, StringRef>>
authorFangrui Song <maskray@google.com>
Sat, 6 Apr 2019 02:18:56 +0000 (02:18 +0000)
committerFangrui Song <maskray@google.com>
Sat, 6 Apr 2019 02:18:56 +0000 (02:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357833 91177308-0d34-0410-b5e6-96231b3b80d8

lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
lib/DebugInfo/Symbolize/SymbolizableObjectFile.h

index a92fe123c3b742f915000e7a847ea317a4d8a896..e6e0de05f5de719acf1871ba545ebbde060fc282 100644 (file)
@@ -81,10 +81,22 @@ SymbolizableObjectFile::create(object::ObjectFile *Obj,
 
   std::vector<std::pair<SymbolDesc, StringRef>> &Fs = res->Functions,
                                                 &Os = res->Objects;
-  llvm::sort(Fs);
-  Fs.erase(std::unique(Fs.begin(), Fs.end()), Fs.end());
-  llvm::sort(Os);
-  Os.erase(std::unique(Os.begin(), Os.end()), Os.end());
+  auto Uniquify = [](std::vector<std::pair<SymbolDesc, StringRef>> &S) {
+    // Sort by (Addr,Size,Name). If several SymbolDescs share the same Addr,
+    // pick the one with the largest Size. This helps us avoid symbols with no
+    // size information (Size=0).
+    llvm::sort(S);
+    auto I = S.begin(), E = S.end(), J = S.begin();
+    while (I != E) {
+      auto OI = I;
+      while (++I != E && OI->first.Addr == I->first.Addr) {
+      }
+      *J++ = I[-1];
+    }
+    S.erase(J, S.end());
+  };
+  Uniquify(Fs);
+  Uniquify(Os);
 
   return std::move(res);
 }
@@ -205,9 +217,6 @@ bool SymbolizableObjectFile::getNameFromSymbolTable(SymbolRef::Type Type,
                                                     uint64_t &Size) const {
   const auto &Symbols = Type == SymbolRef::ST_Function ? Functions : Objects;
   std::pair<SymbolDesc, StringRef> SD{{Address, UINT64_C(-1)}, StringRef()};
-  // SymbolDescs are sorted by (Addr,Size), if several SymbolDescs share the
-  // same Addr, pick the one with the largest Size. This helps us avoid symbols
-  // with no size information (Size=0).
   auto SymbolIterator = llvm::upper_bound(Symbols, SD);
   if (SymbolIterator == Symbols.begin())
     return false;
index ed2f89b2e4daa3633e96bf7919f35c4aaa87944d..d5510cb1b8e4eb1e8b8bb2ea5e0bca996167e9be 100644 (file)
@@ -75,9 +75,6 @@ private:
     // the following symbol.
     uint64_t Size;
 
-    bool operator==(const SymbolDesc &RHS) const {
-      return Addr == RHS.Addr && Size == RHS.Size;
-    }
     bool operator<(const SymbolDesc &RHS) const {
       return Addr != RHS.Addr ? Addr < RHS.Addr : Size < RHS.Size;
     }