[PATCH] D44285: Fix computeSymbolSizes SEGFAULT on invalid file

Teng Qin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 8 19:32:30 PST 2018


palmtenor updated this revision to Diff 137691.

Repository:
  rL LLVM

https://reviews.llvm.org/D44285

Files:
  lib/Object/SymbolSize.cpp


Index: lib/Object/SymbolSize.cpp
===================================================================
--- lib/Object/SymbolSize.cpp
+++ lib/Object/SymbolSize.cpp
@@ -66,23 +66,27 @@
     Addresses.push_back(
         {O.symbol_end(), Address + Size, 0, getSectionID(O, Sec)});
   }
+
+  if (Addresses.empty())
+    return Ret;
+
   array_pod_sort(Addresses.begin(), Addresses.end(), compareAddress);

   // Compute the size as the gap to the next symbol
   for (unsigned I = 0, N = Addresses.size() - 1; I < N; ++I) {
     auto &P = Addresses[I];
     if (P.I == O.symbol_end())
       continue;

     // If multiple symbol have the same address, give both the same size.
     unsigned NextI = I + 1;
     while (NextI < N && Addresses[NextI].Address == P.Address)
       ++NextI;

     uint64_t Size = Addresses[NextI].Address - P.Address;
     P.Address = Size;
   }

   // Assign the sorted symbols in the original order.
   Ret.resize(SymNum);
   for (SymEntry &P : Addresses) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44285.137691.patch
Type: text/x-patch
Size: 982 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180309/41342dc2/attachment.bin>


More information about the llvm-commits mailing list