[llvm] c3914bf - [[lvm-readelf/obj] - Remove `tryGetSectionName` helper.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 24 00:41:00 PST 2020
Author: Georgii Rymar
Date: 2020-11-24T11:34:27+03:00
New Revision: c3914bf28e3902c0e039eb31d2f36112a606dc58
URL: https://github.com/llvm/llvm-project/commit/c3914bf28e3902c0e039eb31d2f36112a606dc58
DIFF: https://github.com/llvm/llvm-project/commit/c3914bf28e3902c0e039eb31d2f36112a606dc58.diff
LOG: [[lvm-readelf/obj] - Remove `tryGetSectionName` helper.
D91867 introduced the `tryGetSectionName` helper.
But we have `getPrintableSectionName` member with the similar
behavior which we can reuse. This patch does it.
Differential revision: https://reviews.llvm.org/D91954
Added:
Modified:
llvm/test/tools/llvm-readobj/ELF/groups.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/ELF/groups.test b/llvm/test/tools/llvm-readobj/ELF/groups.test
index afdc63e9dc0b5..492c7a5ecd7a7 100644
--- a/llvm/test/tools/llvm-readobj/ELF/groups.test
+++ b/llvm/test/tools/llvm-readobj/ELF/groups.test
@@ -294,8 +294,8 @@ Symbols:
# RUN: FileCheck -DFILE=%t.name.o %s --check-prefix=NAME-GNU --implicit-check-not=warning:
# NAME-LLVM: Groups {
-# NAME-LLVM-NEXT: warning: '[[FILE]]': unable to get the name of the SHT_GROUP section with index 1: a section [index 1] has an invalid sh_name (0xaaaa) offset which goes past the end of the section name string table
-# NAME-LLVM-NEXT: warning: '[[FILE]]': unable to get the name of the SHT_PROGBITS section with index 5: a section [index 5] has an invalid sh_name (0xbbbb) offset which goes past the end of the section name string table
+# NAME-LLVM-NEXT: warning: '[[FILE]]': unable to get the name of SHT_GROUP section with index 1: a section [index 1] has an invalid sh_name (0xaaaa) offset which goes past the end of the section name string table
+# NAME-LLVM-NEXT: warning: '[[FILE]]': unable to get the name of SHT_PROGBITS section with index 5: a section [index 5] has an invalid sh_name (0xbbbb) offset which goes past the end of the section name string table
# NAME-LLVM-NEXT: Group {
# NAME-LLVM-NEXT: Name: <?> (43690)
# NAME-LLVM-NEXT: Index: 1
@@ -322,8 +322,8 @@ Symbols:
# NAME-LLVM-NEXT: }
# NAME-LLVM-NEXT: }
-# NAME-GNU: warning: '[[FILE]]': unable to get the name of the SHT_GROUP section with index 1: a section [index 1] has an invalid sh_name (0xaaaa) offset which goes past the end of the section name string table
-# NAME-GNU-NEXT: warning: '[[FILE]]': unable to get the name of the SHT_PROGBITS section with index 5: a section [index 5] has an invalid sh_name (0xbbbb) offset which goes past the end of the section name string table
+# NAME-GNU: warning: '[[FILE]]': unable to get the name of SHT_GROUP section with index 1: a section [index 1] has an invalid sh_name (0xaaaa) offset which goes past the end of the section name string table
+# NAME-GNU-NEXT: warning: '[[FILE]]': unable to get the name of SHT_PROGBITS section with index 5: a section [index 5] has an invalid sh_name (0xbbbb) offset which goes past the end of the section name string table
# NAME-GNU-EMPTY:
# NAME-GNU-NEXT: COMDAT group section [ 1] `<?>' [foo] contains 2 sections:
# NAME-GNU-NEXT: [Index] Name
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index c5eb2d628b0b5..34be3aa0a350a 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -3581,19 +3581,6 @@ template <class ELFT> void GNUStyle<ELFT>::printFileHeaders() {
printFields(OS, "Section header string table index:", Str);
}
-template <class ELFT>
-static StringRef tryGetSectionName(const ELFFile<ELFT> &Obj,
- const typename ELFT::Shdr &Sec,
- DumpStyle<ELFT> &Dump) {
- if (Expected<StringRef> SecNameOrErr = Obj.getSectionName(Sec))
- return *SecNameOrErr;
- else
- Dump.reportUniqueWarning(createError("unable to get the name of the " +
- describe(Obj, Sec) + ": " +
- toString(SecNameOrErr.takeError())));
- return "<?>";
-}
-
template <class ELFT> std::vector<GroupSection> DumpStyle<ELFT>::getGroups() {
auto GetSignature = [&](const Elf_Sym &Sym, unsigned SymNdx,
const Elf_Shdr &Symtab) -> StringRef {
@@ -3655,7 +3642,7 @@ template <class ELFT> std::vector<GroupSection> DumpStyle<ELFT>::getGroups() {
toString(ContentsOrErr.takeError())));
}
- Ret.push_back({tryGetSectionName(Obj, Sec, *this),
+ Ret.push_back({getPrintableSectionName(Sec),
maybeDemangle(Signature),
Sec.sh_name,
I - 1,
@@ -3670,7 +3657,7 @@ template <class ELFT> std::vector<GroupSection> DumpStyle<ELFT>::getGroups() {
std::vector<GroupMember> &GM = Ret.back().Members;
for (uint32_t Ndx : Data.slice(1)) {
if (Expected<const Elf_Shdr *> SecOrErr = Obj.getSection(Ndx)) {
- GM.push_back({tryGetSectionName(Obj, **SecOrErr, *this), Ndx});
+ GM.push_back({getPrintableSectionName(**SecOrErr), Ndx});
} else {
reportUniqueWarning(
createError("unable to get the section with index " + Twine(Ndx) +
More information about the llvm-commits
mailing list