[llvm] r372867 - [llvm-readobj/llvm-readelf] - .stack_sizes: demangle symbol names in warnings reported.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 06:16:43 PDT 2019
Author: grimar
Date: Wed Sep 25 06:16:43 2019
New Revision: 372867
URL: http://llvm.org/viewvc/llvm-project?rev=372867&view=rev
Log:
[llvm-readobj/llvm-readelf] - .stack_sizes: demangle symbol names in warnings reported.
I started this patch as a refactoring, tried to make a helper for
getting symbol names, similar to how we get section names
used in warning messages.
So this patch cleanups the code and fixes an issue: symbol names
in warning messages were not demangled.
Differential revision: https://reviews.llvm.org/D68012
Modified:
llvm/trunk/test/tools/llvm-readobj/stack-sizes.test
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
Modified: llvm/trunk/test/tools/llvm-readobj/stack-sizes.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/stack-sizes.test?rev=372867&r1=372866&r2=372867&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/stack-sizes.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/stack-sizes.test Wed Sep 25 06:16:43 2019
@@ -192,17 +192,21 @@ Symbols:
# 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 @@ Sections:
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 @@ Symbols:
# 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 @@ Symbols:
# 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 @@ Sections:
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 @@ Symbols:
# 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 @@ Symbols:
# 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: ]
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=372867&r1=372866&r2=372867&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Wed Sep 25 06:16:43 2019
@@ -4688,6 +4688,26 @@ void GNUStyle<ELFT>::printELFLinkerOptio
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<StringRef> 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<StringRef> NameOrErr = Sym.getName();
+ if (NameOrErr)
+ return maybeDemangle(*NameOrErr);
+ consumeError(NameOrErr.takeError());
+ return "<?>";
+}
+
template <class ELFT>
void DumpStyle<ELFT>::printFunctionStackSize(
const ELFObjectFile<ELFT> *Obj, uint64_t SymValue, SectionRef FunctionSec,
@@ -4712,18 +4732,12 @@ void DumpStyle<ELFT>::printFunctionStack
std::string FuncName = "?";
// A valid SymbolRef has a non-null object file pointer.
- if (FuncSym.BasicSymbolRef::getObject()) {
- // Extract the symbol name.
- Expected<StringRef> 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 @@ void DumpStyle<ELFT>::printStackSize(con
// 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<StringRef> 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 @@ void DumpStyle<ELFT>::printStackSize(con
Data, &Offset);
}
-// Used for printing section names in places where possible errors can be
-// ignored.
-static StringRef getSectionName(const SectionRef &Sec) {
- Expected<StringRef> NameOrErr = Sec.getName();
- if (NameOrErr)
- return *NameOrErr;
- consumeError(NameOrErr.takeError());
- return "<?>";
-}
-
template <class ELFT>
void DumpStyle<ELFT>::printNonRelocatableStackSizes(
const ELFObjectFile<ELFT> *Obj, std::function<void()> PrintHeader) {
More information about the llvm-commits
mailing list