]> granicus.if.org Git - llvm/commitdiff
Simplify getStringTableIndex.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 1 Nov 2016 20:56:15 +0000 (20:56 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 1 Nov 2016 20:56:15 +0000 (20:56 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285747 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/ELF.h

index 10f61ad2f285fd51e14bd9f30f9bed5197d955ca..8e28b1dc2b445329ef1ad128f17a1bd2c02a61ad 100644 (file)
@@ -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() const {
   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, std::error_code &EC)
   }
 
   // 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()))