Index: llvm/trunk/test/tools/llvm-readobj/stack-sizes.test =================================================================== --- llvm/trunk/test/tools/llvm-readobj/stack-sizes.test +++ llvm/trunk/test/tools/llvm-readobj/stack-sizes.test @@ -192,17 +192,21 @@ # RUN: llvm-readobj --stack-sizes %t04 2> %t04-llvm.err | FileCheck %s --check-prefix=WRONGSECTION-LLVM # RUN: FileCheck %s < %t04-llvm.err --check-prefix=WRONGSECTION-ERR -DFILE=%t04 +# RUN: llvm-readelf --stack-sizes --demangle %t04 2>&1 | FileCheck %s --check-prefix=WRONGSECTION-DEMANGLE-ERR -DFILE=%t04 +# RUN: llvm-readobj --stack-sizes --demangle %t04 2>&1 | FileCheck %s --check-prefix=WRONGSECTION-DEMANGLE-ERR -DFILE=%t04 + # WRONGSECTION-GNU: Size Function -# WRONGSECTION-GNU-NEXT: 8 foo +# WRONGSECTION-GNU-NEXT: 8 _Z3foof # WRONGSECTION-LLVM: StackSizes [ # WRONGSECTION-LLVM-NEXT: Entry { -# WRONGSECTION-LLVM-NEXT: Function: foo +# WRONGSECTION-LLVM-NEXT: Function: _Z3foof # WRONGSECTION-LLVM-NEXT: Size: 0x8 # WRONGSECTION-LLVM-NEXT: } # WRONGSECTION-LLVM-NEXT: ] -# WRONGSECTION-ERR: warning: '[[FILE]]': relocation symbol foo is not in the expected section +# WRONGSECTION-ERR: warning: '[[FILE]]': relocation symbol '_Z3foof' is not in the expected section +# WRONGSECTION-DEMANGLE-ERR: warning: '[[FILE]]': relocation symbol 'foo(float)' is not in the expected section --- !ELF FileHeader: @@ -228,10 +232,10 @@ Info: .stack_sizes Relocations: - Offset: 0 - Symbol: foo + Symbol: _Z3foof Type: R_X86_64_64 Symbols: - - Name: foo + - Name: _Z3foof Section: .text Type: STT_FUNC Binding: STB_GLOBAL @@ -309,6 +313,9 @@ # RUN: llvm-readobj --stack-sizes %t07 2> %t07-llvm.err | FileCheck %s --check-prefix=BADSECTION-OUT-LLVM # RUN: FileCheck %s < %t07-llvm.err --check-prefix=BADSECTION-ERR -DFILE=%t07 +# RUN: llvm-readelf --stack-sizes --demangle %t07 2>&1 | FileCheck %s --check-prefix=BADSECTION-DEMANGLE-ERR -DFILE=%t07 +# RUN: llvm-readobj --stack-sizes --demangle %t07 2>&1 | FileCheck %s --check-prefix=BADSECTION-DEMANGLE-ERR -DFILE=%t07 + # BADSECTION-OUT-GNU: Size Function # BADSECTION-OUT-GNU: 8 ? @@ -319,7 +326,8 @@ # BADSECTION-OUT-LLVM-NEXT: } # BADSECTION-OUT-LLVM-NEXT: ] -# BADSECTION-ERR: warning: '[[FILE]]': cannot identify the section for relocation symbol foo +# BADSECTION-ERR: warning: '[[FILE]]': cannot identify the section for relocation symbol '_Z3foof' +# BADSECTION-DEMANGLE-ERR: warning: '[[FILE]]': cannot identify the section for relocation symbol 'foo(float)' --- !ELF FileHeader: @@ -341,10 +349,10 @@ Info: .stack_sizes Relocations: - Offset: 0 - Symbol: foo + Symbol: _Z3foof Type: R_X86_64_64 Symbols: - - Name: foo + - Name: _Z3foof ## An invalid section index. Index: 10 Type: STT_FUNC @@ -540,8 +548,8 @@ # ARCHIVEWARN-GNU:File: [[FILE]]({{.*04}}) # ARCHIVEWARN-GNU:Stack Sizes: # ARCHIVEWARN-GNU-NEXT: Size Function -# ARCHIVEWARN-GNU:{{.*}}: warning: '{{.*04}}': relocation symbol foo is not in the expected section -# ARCHIVEWARN-GNU: 8 foo +# ARCHIVEWARN-GNU:{{.*}}: warning: '{{.*04}}': relocation symbol '_Z3foof' is not in the expected section +# ARCHIVEWARN-GNU: 8 _Z3foof # ARCHIVEWARN-GNU:File: [[FILE]]({{.*01}}) # ARCHIVEWARN-GNU:Stack Sizes: # ARCHIVEWARN-GNU-NEXT: Size Function @@ -553,9 +561,9 @@ # ARCHIVEWARN-LLVM: File: [[FILE]]({{.*04}}) # ARCHIVEWARN-LLVM: StackSizes [ -# ARCHIVEWARN-LLVM: warning: '{{.*04}}': relocation symbol foo is not in the expected section +# ARCHIVEWARN-LLVM: warning: '{{.*04}}': relocation symbol '_Z3foof' is not in the expected section # ARCHIVEWARN-LLVM-NEXT: Entry { -# ARCHIVEWARN-LLVM-NEXT: Function: foo +# ARCHIVEWARN-LLVM-NEXT: Function: _Z3foof # ARCHIVEWARN-LLVM-NEXT: Size: 0x8 # ARCHIVEWARN-LLVM-NEXT: } # ARCHIVEWARN-LLVM-NEXT: ] Index: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp +++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp @@ -4688,6 +4688,26 @@ OS << "printELFLinkerOptions not implemented!\n"; } +// Used for printing section names in places where possible errors can be +// ignored. +static StringRef getSectionName(const SectionRef &Sec) { + Expected NameOrErr = Sec.getName(); + if (NameOrErr) + return *NameOrErr; + consumeError(NameOrErr.takeError()); + return ""; +} + +// Used for printing symbol names in places where possible errors can be +// ignored. +static std::string getSymbolName(const ELFSymbolRef &Sym) { + Expected NameOrErr = Sym.getName(); + if (NameOrErr) + return maybeDemangle(*NameOrErr); + consumeError(NameOrErr.takeError()); + return ""; +} + template void DumpStyle::printFunctionStackSize( const ELFObjectFile *Obj, uint64_t SymValue, SectionRef FunctionSec, @@ -4712,18 +4732,12 @@ 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 { + if (FuncSym.BasicSymbolRef::getObject()) + FuncName = getSymbolName(FuncSym); + else reportWarning( createError("could not identify function symbol for stack size entry"), Obj->getFileName()); - } // Extract the size. The expectation is that Offset is pointing to the right // place, i.e. past the function address. @@ -4765,23 +4779,17 @@ // Ensure that the relocation symbol is in the function section, i.e. the // section where the functions whose stack sizes we are reporting are // located. - StringRef SymName = "?"; - Expected NameOrErr = RelocSym->getName(); - if (NameOrErr) - SymName = *NameOrErr; - else - consumeError(NameOrErr.takeError()); - auto SectionOrErr = RelocSym->getSection(); if (!SectionOrErr) { reportWarning( - createError("cannot identify the section for relocation symbol " + - SymName), + createError("cannot identify the section for relocation symbol '" + + getSymbolName(*RelocSym) + "'"), FileStr); consumeError(SectionOrErr.takeError()); } else if (*SectionOrErr != FunctionSec) { - reportWarning(createError("relocation symbol " + SymName + - " is not in the expected section"), + reportWarning(createError("relocation symbol '" + + getSymbolName(*RelocSym) + + "' is not in the expected section"), FileStr); // Pretend that the symbol is in the correct section and report its // stack size anyway. @@ -4810,16 +4818,6 @@ Data, &Offset); } -// Used for printing section names in places where possible errors can be -// ignored. -static StringRef getSectionName(const SectionRef &Sec) { - Expected NameOrErr = Sec.getName(); - if (NameOrErr) - return *NameOrErr; - consumeError(NameOrErr.takeError()); - return ""; -} - template void DumpStyle::printNonRelocatableStackSizes( const ELFObjectFile *Obj, std::function PrintHeader) {