[PATCH] D71017: [llvm-readelf/llvm-readobj] - Remove getSecTypeName() helper.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 4 07:41:04 PST 2019


grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: seiya, rupprecht.
Herald added a project: LLVM.

We do not need it, we have
`object::getELFSectionTypeName` that can be used instead.


https://reviews.llvm.org/D71017

Files:
  llvm/tools/llvm-readobj/ELFDumper.cpp


Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -344,16 +344,6 @@
   getVersionDependencies(const Elf_Shdr *Sec) const;
 };
 
-static StringRef getSecTypeName(unsigned Type) {
-  if (Type == ELF::SHT_GNU_versym)
-    return "SHT_GNU_versym";
-  if (Type == ELF::SHT_GNU_verdef)
-    return "SHT_GNU_verdef";
-  if (Type == ELF::SHT_GNU_verneed)
-    return "SHT_GNU_verneed";
-  llvm_unreachable("unexpected section type");
-}
-
 template <class ELFT>
 static Expected<StringRef> getLinkAsStrtab(const ELFFile<ELFT> *Obj,
                                            const typename ELFT::Shdr *Sec,
@@ -362,15 +352,17 @@
       Obj->getSection(Sec->sh_link);
   if (!StrTabSecOrErr)
     return createError("invalid section linked to " +
-                       getSecTypeName(Sec->sh_type) + " section with index " +
-                       Twine(SecNdx) + ": " +
+                       object::getELFSectionTypeName(
+                           Obj->getHeader()->e_machine, Sec->sh_type) +
+                       " section with index " + Twine(SecNdx) + ": " +
                        toString(StrTabSecOrErr.takeError()));
 
   Expected<StringRef> StrTabOrErr = Obj->getStringTable(*StrTabSecOrErr);
   if (!StrTabOrErr)
     return createError("invalid string table linked to " +
-                       getSecTypeName(Sec->sh_type) + " section with index " +
-                       Twine(SecNdx) + ": " +
+                       object::getELFSectionTypeName(
+                           Obj->getHeader()->e_machine, Sec->sh_type) +
+                       " section with index " + Twine(SecNdx) + ": " +
                        toString(StrTabOrErr.takeError()));
   return *StrTabOrErr;
 }
@@ -3995,8 +3987,10 @@
   else
     this->reportUniqueWarning(
         createError("invalid section linked to " +
-                    getSecTypeName(Sec->sh_type) + " section with index " +
-                    Twine(SecNdx) + ": " + toString(SymTabOrErr.takeError())));
+                    object::getELFSectionTypeName(Obj->getHeader()->e_machine,
+                                                  Sec->sh_type) +
+                    " section with index " + Twine(SecNdx) + ": " +
+                    toString(SymTabOrErr.takeError())));
 
   OS << " Addr: " << format_hex_no_prefix(Sec->sh_addr, 16)
      << "  Offset: " << format_hex(Sec->sh_offset, 8)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71017.232131.patch
Type: text/x-patch
Size: 2516 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191204/38ec79e8/attachment.bin>


More information about the llvm-commits mailing list