[llvm] r285747 - Simplify getStringTableIndex.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 1 13:56:15 PDT 2016


Author: rafael
Date: Tue Nov  1 15:56:15 2016
New Revision: 285747

URL: http://llvm.org/viewvc/llvm-project?rev=285747&view=rev
Log:
Simplify getStringTableIndex.

The description in the ELF spec is just

---------------------------
If the section name string table section index is greater than or
equal to SHN_LORESERVE (0xff00), this member has the value SHN_XINDEX
(0xffff) and the actual index of the section name string table section
is contained in the sh_link field of the section header at index 0.
---------------------------

So we only have to check for it being SHN_XINDEX. Also, sh_link is
always 32 bits, so don't return an uintX_t.

Modified:
    llvm/trunk/include/llvm/Object/ELF.h

Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=285747&r1=285746&r2=285747&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Tue Nov  1 15:56:15 2016
@@ -154,7 +154,7 @@ public:
   }
 
   uint64_t getNumSections() const;
-  uintX_t getStringTableIndex() const;
+  uint32_t getStringTableIndex() const;
   uint32_t getExtendedSymbolTableIndex(const Elf_Sym *Sym,
                                        const Elf_Shdr *SymTab,
                                        ArrayRef<Elf_Word> ShndxTable) const;
@@ -299,14 +299,9 @@ uint64_t ELFFile<ELFT>::getNumSections()
   return Header->e_shnum;
 }
 
-template <class ELFT>
-typename ELFFile<ELFT>::uintX_t ELFFile<ELFT>::getStringTableIndex() const {
-  if (Header->e_shnum == ELF::SHN_UNDEF) {
-    if (Header->e_shstrndx == ELF::SHN_HIRESERVE)
-      return SectionHeaderTable->sh_link;
-    if (Header->e_shstrndx >= getNumSections())
-      return 0;
-  }
+template <class ELFT> uint32_t ELFFile<ELFT>::getStringTableIndex() const {
+  if (Header->e_shstrndx == ELF::SHN_XINDEX)
+    return SectionHeaderTable->sh_link;
   return Header->e_shstrndx;
 }
 
@@ -363,7 +358,7 @@ ELFFile<ELFT>::ELFFile(StringRef Object,
   }
 
   // Get string table sections.
-  uintX_t StringTableIndex = getStringTableIndex();
+  uint32_t StringTableIndex = getStringTableIndex();
   if (StringTableIndex) {
     ErrorOr<const Elf_Shdr *> StrTabSecOrErr = getSection(StringTableIndex);
     if ((EC = StrTabSecOrErr.getError()))




More information about the llvm-commits mailing list