Don't use a DenseMap to handle SHT_SYMTAB_SHNDX.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 7 Aug 2015 16:51:44 +0000 (16:51 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 7 Aug 2015 16:51:44 +0000 (16:51 +0000)
It is already a convenient table.

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

include/llvm/Object/ELF.h

index e91c6e63caa2b4ac68b75c211d9b41f953921eba..3ec28f05dece33a0f4da260dd34cc715dd9c9c76 100644 (file)
@@ -15,7 +15,6 @@
 #define LLVM_OBJECT_ELF_H
 
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -102,7 +101,6 @@ private:
   const Elf_Shdr *DotDynSymSec = nullptr;   // Dynamic symbol table section.
 
   const Elf_Shdr *SymbolTableSectionHeaderIndex = nullptr;
-  DenseMap<const Elf_Sym *, ELF::Elf64_Word> ExtendedSymbolTable;
 
 public:
   template<typename T>
@@ -263,9 +261,14 @@ typedef ELFFile<ELFType<support::big, true>> ELF64BEFile;
 
 template <class ELFT>
 ELF::Elf64_Word
-ELFFile<ELFT>::getExtendedSymbolTableIndex(const Elf_Sym *symb) const {
-  assert(symb->st_shndx == ELF::SHN_XINDEX);
-  return ExtendedSymbolTable.lookup(symb);
+ELFFile<ELFT>::getExtendedSymbolTableIndex(const Elf_Sym *Sym) const {
+  assert(Sym->st_shndx == ELF::SHN_XINDEX);
+  unsigned Index = Sym - symbol_begin();
+
+  // FIXME: error checking
+  const Elf_Word *ShndxTable = reinterpret_cast<const Elf_Word *>(
+      base() + SymbolTableSectionHeaderIndex->sh_offset);
+  return ShndxTable[Index];
 }
 
 template <class ELFT>
@@ -273,7 +276,7 @@ ErrorOr<const typename ELFFile<ELFT>::Elf_Shdr *>
 ELFFile<ELFT>::getSection(const Elf_Sym *symb) const {
   uint32_t Index = symb->st_shndx;
   if (Index == ELF::SHN_XINDEX)
-    return getSection(ExtendedSymbolTable.lookup(symb));
+    return getSection(getExtendedSymbolTableIndex(symb));
   if (Index == ELF::SHN_UNDEF || Index >= ELF::SHN_LORESERVE)
     return nullptr;
   return getSection(symb->st_shndx);
@@ -444,17 +447,6 @@ ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
     DotShstrtab = *SymtabOrErr;
   }
 
-  // Build symbol name side-mapping if there is one.
-  if (SymbolTableSectionHeaderIndex) {
-    const Elf_Word *ShndxTable = reinterpret_cast<const Elf_Word*>(base() +
-                                      SymbolTableSectionHeaderIndex->sh_offset);
-    for (const Elf_Sym &S : symbols()) {
-      if (*ShndxTable != ELF::SHN_UNDEF)
-        ExtendedSymbolTable[&S] = *ShndxTable;
-      ++ShndxTable;
-    }
-  }
-
   EC = std::error_code();
 }