[LNT] r333081 - lnt profile upgrade command for large Spec2017 perf.data aborts.

Kristof Beyls via llvm-commits llvm-commits at lists.llvm.org
Wed May 23 05:56:57 PDT 2018


Author: kbeyls
Date: Wed May 23 05:56:57 2018
New Revision: 333081

URL: http://llvm.org/viewvc/llvm-project?rev=333081&view=rev
Log:
lnt profile upgrade command for large Spec2017 perf.data aborts.

This patch addresses issue with *stack smashing* while processing large
perf.data files (>350 MB) e.g. obtained during Spec2017 sub-benchmarks' runs:
Example lnt profile upgrade failure:

$ lnt profile upgrade perf.data.510.parest_r.0 perf.data.510.parest_r.0.lnt
*** stack smashing detected ***: /opt/venv_lnt/bin/python terminated

The arbitrary size of temp buffers One, Two, Three & Four in function
NmOutput::fetchSymbols() is in some circumstances too small and buffer(s)
overflow while processing line of data.

This commit fixes that.

Patch by Przemek Wirkus.

Differential Revision: https://reviews.llvm.org/D46433


Modified:
    lnt/trunk/lnt/testing/profile/cPerf.cpp

Modified: lnt/trunk/lnt/testing/profile/cPerf.cpp
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/testing/profile/cPerf.cpp?rev=333081&r1=333080&r2=333081&view=diff
==============================================================================
--- lnt/trunk/lnt/testing/profile/cPerf.cpp (original)
+++ lnt/trunk/lnt/testing/profile/cPerf.cpp Wed May 23 05:56:57 2018
@@ -280,20 +280,25 @@ public:
       if (Len == -1)
         break;
 
-      char One[32], Two[32], Three[32], Four[512];
-      if (sscanf(Line, "%s %s %s %s", One, Two, Three, Four) < 4)
-        continue;
+      std::vector<std::string> SplittedLine;
+      if (splitLine(std::string(Line), SplittedLine) < 4)
+        continue; 
+
+      const std::string& One = SplittedLine[0];
+      const std::string& Two = SplittedLine[1];
+      const std::string& Three = SplittedLine[2];
+      std::string& Four = SplittedLine[3];
 
       char *EndPtr = NULL;
-      uint64_t Start = strtoull(One, &EndPtr, 16);
-      if (EndPtr == One)
+      uint64_t Start = strtoull(One.c_str(), &EndPtr, 16);
+      if (EndPtr == One.c_str())
         continue;
-      uint64_t Extent = strtoull(Two, &EndPtr, 16);
-      if (EndPtr == Two)
+      uint64_t Extent = strtoull(Two.c_str(), &EndPtr, 16);
+      if (EndPtr == Two.c_str())
         continue;
-      if (strlen(Three) != 1)
+      if (Three.length() != 1)
         continue;
-      switch (Three[0]) {
+      switch (Three.front()) {
       default:
         continue;
       case 'T':
@@ -304,10 +309,9 @@ public:
       case 'w': // Weak object (not tagged as such)
         break;
       }
-      std::string S(Four);
-      if (S.back() == '\n')
-        S.pop_back();
-      push_back({Start, Start + Extent, S});
+      if (Four.back() == '\n')
+        Four.pop_back();
+      push_back({Start, Start + Extent, Four});
     }
     if (Line)
       free(Line);
@@ -326,6 +330,16 @@ public:
     auto NewEnd = std::unique(begin(), end());
     erase(NewEnd, end());
   }
+
+protected:
+  int splitLine(const std::string& line, std::vector<std::string>& output, char delim = ' ') {
+    std::stringstream ss(line);
+    std::string token;
+    while (std::getline(ss, token, delim)) {
+        output.push_back(token);
+    }
+    return output.size();
+  }
 };
 
 class ObjdumpOutput {




More information about the llvm-commits mailing list