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
This commit is contained in:
Greg Clayton
2021-06-28 16:32:36 -07:00
parent 323bcbdba0
commit ab546ead3b
2 changed files with 31 additions and 3 deletions

View File

@@ -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

View File

@@ -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));
}