diff --git a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp --- a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp +++ b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp @@ -224,9 +224,13 @@ 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 --- a/llvm/unittests/DebugInfo/GSYM/GSYMTest.cpp +++ b/llvm/unittests/DebugInfo/GSYM/GSYMTest.cpp @@ -2518,3 +2518,27 @@ 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(UUID)); + TestEncodeDecode(GC, llvm::support::big, GSYM_VERSION, AddrOffSize, BaseAddr, + 1, // NumAddresses + ArrayRef(UUID)); +}