Index: test/tools/llvm-readobj/stack-sizes.test =================================================================== --- test/tools/llvm-readobj/stack-sizes.test +++ test/tools/llvm-readobj/stack-sizes.test @@ -101,6 +101,7 @@ # EXEC-GNU: Size Function # EXEC-GNU-NEXT: 16 foo # EXEC-GNU-NEXT: 32 bar +# EXEC-GNU-NEXT: 32 baz # EXEC-GNU-NOT:{{.}} # EXEC-LLVM: StackSizes [ @@ -112,6 +113,10 @@ # EXEC-LLVM-NEXT: Function: bar # EXEC-LLVM-NEXT: Size: 0x20 # EXEC-LLVM-NEXT: } +# EXEC-LLVM-NEXT: Entry { +# EXEC-LLVM-NEXT: Function: baz +# EXEC-LLVM-NEXT: Size: 0x20 +# EXEC-LLVM-NEXT: } # EXEC-LLVM-NEXT: ] --- !ELF @@ -140,6 +145,11 @@ Value: 0x20 Type: STT_FUNC Binding: STB_GLOBAL + - Name: baz + Section: .text + Value: 0x20 + Type: STT_FUNC + Binding: STB_GLOBAL ## Check that we report an error when we find relocations whose offsets point outside ## of the .stack_sizes section. @@ -433,6 +443,10 @@ # MULTIPLE-LLVM-NEXT: Function: bar # MULTIPLE-LLVM-NEXT: Size: 0x20 # MULTIPLE-LLVM-NEXT: } +# MULTIPLE-LLVM-NEXT: Entry { +# MULTIPLE-LLVM-NEXT: Function: baz +# MULTIPLE-LLVM-NEXT: Size: 0x20 +# MULTIPLE-LLVM-NEXT: } # MULTIPLE-LLVM-NEXT: ] ## Check that we do not consider symbols that are not function symbols, even though Index: tools/llvm-readobj/ELFDumper.cpp =================================================================== --- tools/llvm-readobj/ELFDumper.cpp +++ tools/llvm-readobj/ELFDumper.cpp @@ -4694,35 +4694,19 @@ const StringRef SectionName, DataExtractor Data, uint64_t *Offset) { // This function ignores potentially erroneous input, unless it is directly // related to stack size reporting. - SymbolRef FuncSym; + + // Find all the function symbols that match SymValue and are in FunctionSec. + std::vector FuncSyms; for (const ELFSymbolRef &Symbol : Obj->symbols()) { Expected SymAddrOrErr = Symbol.getAddress(); if (!SymAddrOrErr) { consumeError(SymAddrOrErr.takeError()); continue; } - if (Symbol.getELFType() == ELF::STT_FUNC && *SymAddrOrErr == SymValue) { + if (Symbol.getELFType() == ELF::STT_FUNC && *SymAddrOrErr == SymValue) // Check if the symbol is in the right section. - if (FunctionSec.containsSymbol(Symbol)) { - FuncSym = Symbol; - break; - } - } - } - - std::string FuncName = "?"; - // A valid SymbolRef has a non-null object file pointer. - if (FuncSym.BasicSymbolRef::getObject()) { - // Extract the symbol name. - Expected FuncNameOrErr = FuncSym.getName(); - if (FuncNameOrErr) - FuncName = maybeDemangle(*FuncNameOrErr); - else - consumeError(FuncNameOrErr.takeError()); - } else { - reportWarning( - createError("could not identify function symbol for stack size entry"), - Obj->getFileName()); + if (FunctionSec.containsSymbol(Symbol)) + FuncSyms.push_back(Symbol); } // Extract the size. The expectation is that Offset is pointing to the right @@ -4738,7 +4722,31 @@ SectionName.data()), Obj->getFileName()); - printStackSizeEntry(StackSize, FuncName); + // If we didn't find any matching symbols, print one entry with an unknown + // function symbol name and issue a warning. + if (FuncSyms.empty()) { + reportWarning( + createError("could not identify function symbol for stack size entry"), + Obj->getFileName()); + printStackSizeEntry(StackSize, "?"); + } + + for (const SymbolRef &FuncSym : FuncSyms) { + std::string FuncName = "?"; + // A valid SymbolRef has a non-null object file pointer. + if (FuncSym.BasicSymbolRef::getObject()) { + // Extract the symbol name. + Expected FuncNameOrErr = FuncSym.getName(); + if (FuncNameOrErr) + FuncName = maybeDemangle(*FuncNameOrErr); + else + consumeError(FuncNameOrErr.takeError()); + } else + reportWarning( + createError("could not identify function symbol for stack size entry"), + Obj->getFileName()); + printStackSizeEntry(StackSize, FuncName); + } } template