[PATCH] D26537: Fix llvm-symbolizer to correctly sort a symbol array and calculate symbol sizes

Kuba Brecka via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 10 18:27:17 PST 2016


kubabrecka created this revision.
kubabrecka added reviewers: aprantl, dvyukov, kcc, rafael.
kubabrecka added subscribers: llvm-commits, zaks.anna.
kubabrecka set the repository for this revision to rL LLVM.

I noticed that llvm-symbolizer gives wrong results sometimes, this was due to incorrect sizes of some symbols.  The reason for that was an incorrectly sorted array in computeSymbolSizes.  The comparison function used subtraction of unsigned types, which is incorrect.  Let's change this to return explicit -1 or 1.


Repository:
  rL LLVM

https://reviews.llvm.org/D26537

Files:
  lib/Object/SymbolSize.cpp


Index: lib/Object/SymbolSize.cpp
===================================================================
--- lib/Object/SymbolSize.cpp
+++ lib/Object/SymbolSize.cpp
@@ -27,8 +27,10 @@
 
 static int compareAddress(const SymEntry *A, const SymEntry *B) {
   if (A->SectionID != B->SectionID)
-    return A->SectionID - B->SectionID;
-  return A->Address - B->Address;
+    return A->SectionID < B->SectionID ? -1 : 1;
+  if (A->Address != B->Address)
+    return A->Address < B->Address ? -1 : 1;
+  return 0;
 }
 
 static unsigned getSectionID(const ObjectFile &O, SectionRef Sec) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26537.77587.patch
Type: text/x-patch
Size: 578 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161111/a4a68da5/attachment.bin>


More information about the llvm-commits mailing list