llvm.org GIT mirror llvm / 09ad805
Don't use a DenseMap to handle SHT_SYMTAB_SHNDX. It is already a convenient table. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244333 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
1 changed file(s) with 9 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
1414 #define LLVM_OBJECT_ELF_H
1515
1616 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/DenseMap.h"
1817 #include "llvm/ADT/PointerIntPair.h"
1918 #include "llvm/ADT/SmallVector.h"
2019 #include "llvm/ADT/StringSwitch.h"
101100 const Elf_Shdr *DotDynSymSec = nullptr; // Dynamic symbol table section.
102101
103102 const Elf_Shdr *SymbolTableSectionHeaderIndex = nullptr;
104 DenseMap ExtendedSymbolTable;
105103
106104 public:
107105 template
262260
263261 template
264262 ELF::Elf64_Word
265 ELFFile::getExtendedSymbolTableIndex(const Elf_Sym *symb) const {
266 assert(symb->st_shndx == ELF::SHN_XINDEX);
267 return ExtendedSymbolTable.lookup(symb);
263 ELFFile::getExtendedSymbolTableIndex(const Elf_Sym *Sym) const {
264 assert(Sym->st_shndx == ELF::SHN_XINDEX);
265 unsigned Index = Sym - symbol_begin();
266
267 // FIXME: error checking
268 const Elf_Word *ShndxTable = reinterpret_cast(
269 base() + SymbolTableSectionHeaderIndex->sh_offset);
270 return ShndxTable[Index];
268271 }
269272
270273 template
272275 ELFFile::getSection(const Elf_Sym *symb) const {
273276 uint32_t Index = symb->st_shndx;
274277 if (Index == ELF::SHN_XINDEX)
275 return getSection(ExtendedSymbolTable.lookup(symb));
278 return getSection(getExtendedSymbolTableIndex(symb));
276279 if (Index == ELF::SHN_UNDEF || Index >= ELF::SHN_LORESERVE)
277280 return nullptr;
278281 return getSection(symb->st_shndx);
443446 DotShstrtab = *SymtabOrErr;
444447 }
445448
446 // Build symbol name side-mapping if there is one.
447 if (SymbolTableSectionHeaderIndex) {
448 const Elf_Word *ShndxTable = reinterpret_cast(base() +
449 SymbolTableSectionHeaderIndex->sh_offset);
450 for (const Elf_Sym &S : symbols()) {
451 if (*ShndxTable != ELF::SHN_UNDEF)
452 ExtendedSymbolTable[&S] = *ShndxTable;
453 ++ShndxTable;
454 }
455 }
456
457449 EC = std::error_code();
458450 }
459451