[llvm] ab546ea - Fix a case where multiple symbols with zero size would cause duplicate entries in gsym files.

Greg Clayton via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 28 18:26:39 PDT 2021


Author: Greg Clayton
Date: 2021-06-28T18:26:26-07:00
New Revision: ab546ead3bf720b1789ddb2e093c398409ec3679

URL: https://github.com/llvm/llvm-project/commit/ab546ead3bf720b1789ddb2e093c398409ec3679
DIFF: https://github.com/llvm/llvm-project/commit/ab546ead3bf720b1789ddb2e093c398409ec3679.diff

LOG: Fix a case where multiple symbols with zero size would cause duplicate entries in gsym files.

Symbol tables can have symbols with no size in mach-o files that were failing to get combined into a single entry. This resulted in many duplicate entries for the same address and made gsym files larger.

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

Added: 
    

Modified: 
    llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
    llvm/unittests/DebugInfo/GSYM/GSYMTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
index 5d0f01382c2ec..1c20a59469dc2 100644
--- a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
+++ b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
@@ -224,9 +224,13 @@ llvm::Error GsymCreator::finalize(llvm::raw_ostream &OS) {
   Funcs.erase(
       removeIfBinary(Funcs.begin(), Funcs.end(),
                      [&](const auto &Prev, const auto &Curr) {
-                       if (Prev.Range.intersects(Curr.Range)) {
-                         // Overlapping address ranges.
-                         if (Prev.Range == Curr.Range) {
+                       // Empty ranges won't intersect, but we still need to
+                       // catch the case where we have multiple symbols at the
+                       // same address and coalesce them.
+                       const bool ranges_equal = Prev.Range == Curr.Range;
+                       if (ranges_equal || Prev.Range.intersects(Curr.Range)) {
+                         // Overlapping ranges or empty identical ranges.
+                         if (ranges_equal) {
                            // Same address range. Check if one is from debug
                            // info and the other is from a symbol table. If
                            // so, then keep the one with debug info. Our

diff  --git a/llvm/unittests/DebugInfo/GSYM/GSYMTest.cpp b/llvm/unittests/DebugInfo/GSYM/GSYMTest.cpp
index caefd500ecdd5..2376b09999053 100644
--- a/llvm/unittests/DebugInfo/GSYM/GSYMTest.cpp
+++ b/llvm/unittests/DebugInfo/GSYM/GSYMTest.cpp
@@ -2518,3 +2518,27 @@ TEST(GSYMTest, TestDWARFDeadStripAddr8) {
   StringRef MethodName = GR->getString(ExpFI->Name);
   EXPECT_EQ(MethodName, "main");
 }
+
+TEST(GSYMTest, TestGsymCreatorMultipleSymbolsWithNoSize) {
+  // Multiple symbols at the same address with zero size were being emitted
+  // instead of being combined into a single entry. This function tests to make
+  // sure we only get one symbol.
+  uint8_t UUID[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
+  GsymCreator GC;
+  GC.setUUID(UUID);
+  constexpr uint64_t BaseAddr = 0x1000;
+  constexpr uint8_t AddrOffSize = 1;
+  const uint32_t Func1Name = GC.insertString("foo");
+  const uint32_t Func2Name = GC.insertString("bar");
+  GC.addFunctionInfo(FunctionInfo(BaseAddr, 0, Func1Name));
+  GC.addFunctionInfo(FunctionInfo(BaseAddr, 0, Func2Name));
+  Error Err = GC.finalize(llvm::nulls());
+  ASSERT_FALSE(Err);
+  TestEncodeDecode(GC, llvm::support::little, GSYM_VERSION, AddrOffSize,
+                   BaseAddr,
+                   1, // NumAddresses
+                   ArrayRef<uint8_t>(UUID));
+  TestEncodeDecode(GC, llvm::support::big, GSYM_VERSION, AddrOffSize, BaseAddr,
+                   1, // NumAddresses
+                   ArrayRef<uint8_t>(UUID));
+}


        


More information about the llvm-commits mailing list