# 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:
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
# 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 ?
# 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:
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
# 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
# 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: ]
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,
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.
// 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.
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) {