[llvm-commits] [llvm] r141614 - /llvm/trunk/lib/Object/ELFObjectFile.cpp

Nick Lewycky nicholas at mxc.ca
Mon Oct 10 17:38:56 PDT 2011


Author: nicholas
Date: Mon Oct 10 19:38:56 2011
New Revision: 141614

URL: http://llvm.org/viewvc/llvm-project?rev=141614&view=rev
Log:
Revert r141605 as it broke tests for llvm-nm.

Modified:
    llvm/trunk/lib/Object/ELFObjectFile.cpp

Modified: llvm/trunk/lib/Object/ELFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ELFObjectFile.cpp?rev=141614&r1=141613&r2=141614&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ELFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/ELFObjectFile.cpp Mon Oct 10 19:38:56 2011
@@ -314,10 +314,10 @@
   const T        *getEntry(const Elf_Shdr *Section, uint32_t Entry) const;
   const Elf_Sym  *getSymbol(DataRefImpl Symb) const;
   const Elf_Shdr *getSection(DataRefImpl index) const;
-  const Elf_Shdr *getSection(uint32_t index) const;
+  const Elf_Shdr *getSection(uint16_t index) const;
   const Elf_Rel  *getRel(DataRefImpl Rel) const;
   const Elf_Rela *getRela(DataRefImpl Rela) const;
-  const char     *getString(uint32_t section, uint32_t offset) const;
+  const char     *getString(uint16_t section, uint32_t offset) const;
   const char     *getString(const Elf_Shdr *section, uint32_t offset) const;
   error_code      getSymbolName(const Elf_Sym *Symb, StringRef &Res) const;
 
@@ -371,9 +371,6 @@
   virtual uint8_t getBytesInAddress() const;
   virtual StringRef getFileFormatName() const;
   virtual unsigned getArch() const;
-
-  uint64_t getNumSections() const;
-  uint64_t getStringTableIndex() const;
 };
 } // end namespace
 
@@ -1070,15 +1067,16 @@
 
   SectionHeaderTable =
     reinterpret_cast<const Elf_Shdr *>(base() + Header->e_shoff);
-  uint64_t SectionTableSize = getNumSections() * Header->e_shentsize;
+  uint32_t SectionTableSize = Header->e_shnum * Header->e_shentsize;
   if (!(  (const uint8_t *)SectionHeaderTable + SectionTableSize
          <= base() + Data->getBufferSize()))
     // FIXME: Proper error handling.
     report_fatal_error("Section table goes past end of file!");
 
-  // To find the symbol tables we walk the section table to find SHT_SYMTAB.
+
+  // To find the symbol tables we walk the section table to find SHT_STMTAB.
   const Elf_Shdr* sh = reinterpret_cast<const Elf_Shdr*>(SectionHeaderTable);
-  for (uint64_t i = 0, e = getNumSections(); i != e; ++i) {
+  for (unsigned i = 0; i < Header->e_shnum; ++i) {
     if (sh->sh_type == ELF::SHT_SYMTAB) {
       SymbolTableSectionsIndexMap[i] = SymbolTableSections.size();
       SymbolTableSections.push_back(sh);
@@ -1096,7 +1094,7 @@
   }
 
   // Get string table sections.
-  dot_shstrtab_sec = getSection(getStringTableIndex());
+  dot_shstrtab_sec = getSection(Header->e_shstrndx);
   if (dot_shstrtab_sec) {
     // Verify that the last byte in the string table in a null.
     if (((const char*)base() + dot_shstrtab_sec->sh_offset)
@@ -1107,7 +1105,7 @@
 
   // Merge this into the above loop.
   for (const char *i = reinterpret_cast<const char *>(SectionHeaderTable),
-                  *e = i + getNumSections() * Header->e_shentsize;
+                  *e = i + Header->e_shnum * Header->e_shentsize;
                    i != e; i += Header->e_shentsize) {
     const Elf_Shdr *sh = reinterpret_cast<const Elf_Shdr*>(i);
     if (sh->sh_type == ELF::SHT_STRTAB) {
@@ -1167,7 +1165,7 @@
   memset(&ret, 0, sizeof(DataRefImpl));
   ret.p = reinterpret_cast<intptr_t>(base()
                                      + Header->e_shoff
-                                     + (Header->e_shentsize*getNumSections()));
+                                     + (Header->e_shentsize * Header->e_shnum));
   return section_iterator(SectionRef(ret, this));
 }
 
@@ -1220,25 +1218,6 @@
   }
 }
 
-template<support::endianness target_endianness, bool is64Bits>
-uint64_t ELFObjectFile<target_endianness, is64Bits>::getNumSections() const {
-  if (Header->e_shnum == ELF::SHN_UNDEF)
-    return SectionHeaderTable->sh_size;
-  return Header->e_shnum;
-}
-
-template<support::endianness target_endianness, bool is64Bits>
-uint64_t
-ELFObjectFile<target_endianness, is64Bits>::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;
-  }
-  return Header->e_shstrndx;
-}
-
 
 template<support::endianness target_endianness, bool is64Bits>
 template<typename T>
@@ -1289,10 +1268,10 @@
 
 template<support::endianness target_endianness, bool is64Bits>
 const typename ELFObjectFile<target_endianness, is64Bits>::Elf_Shdr *
-ELFObjectFile<target_endianness, is64Bits>::getSection(uint32_t index) const {
-  if (index == 0)
+ELFObjectFile<target_endianness, is64Bits>::getSection(uint16_t index) const {
+  if (index == 0 || index >= ELF::SHN_LORESERVE)
     return 0;
-  if (!SectionHeaderTable || index >= getNumSections())
+  if (!SectionHeaderTable || index >= Header->e_shnum)
     // FIXME: Proper error handling.
     report_fatal_error("Invalid section index!");
 
@@ -1303,7 +1282,7 @@
 
 template<support::endianness target_endianness, bool is64Bits>
 const char *ELFObjectFile<target_endianness, is64Bits>
-                         ::getString(uint32_t section,
+                         ::getString(uint16_t section,
                                      ELF::Elf32_Word offset) const {
   return getString(getSection(section), offset);
 }





More information about the llvm-commits mailing list