From 81c66bcc13b85515db1e17c4e06034d2a2046cd1 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 25 Mar 2014 23:44:25 +0000 Subject: Create .symtab_shndxr only when needed. We need .symtab_shndxr if and only if a symbol references a section with an index >= 0xff00. The old code was trying to figure out if the section was needed ahead of time, making it a fairly dependent on the code actually writing the table. It was also somewhat conservative and would create the section in cases where it was not needed. If I remember correctly, the old structure was there so that the sections were created in the same order gas creates them. That was valuable when MC's support for ELF was new and we tested with elf-dump.py. This patch refactors the symbol table creation to another class and makes it obvious that .symtab_shndxr is really only created when we are about to output a reference to a section index >= 0xff00. While here, also improve the tests to use macros. One file is one section short of needing .symtab_shndxr, the second one has just the right number. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204769 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-readobj/ELFDumper.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tools/llvm-readobj/ELFDumper.cpp') diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 94b76d00e7..4cd339347a 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -626,7 +626,7 @@ template void ELFDumper::printSymbol(typename ELFO::Elf_Sym_Iter Symbol) { StringRef SymbolName = errorOrDefault(Obj->getSymbolName(Symbol)); - unsigned SectionIndex = Obj->getSymbolTableIndex(&*Symbol); + unsigned SectionIndex = Symbol->st_shndx; StringRef SectionName; if (SectionIndex == SHN_UNDEF) { SectionName = "Undefined"; @@ -641,6 +641,8 @@ void ELFDumper::printSymbol(typename ELFO::Elf_Sym_Iter Symbol) { } else if (SectionIndex == SHN_COMMON) { SectionName = "Common"; } else { + if (SectionIndex == SHN_XINDEX) + SectionIndex = Obj->getSymbolTableIndex(&*Symbol); assert(SectionIndex != SHN_XINDEX && "getSymbolTableIndex should handle this"); const Elf_Shdr *Sec = Obj->getSection(SectionIndex); @@ -666,7 +668,7 @@ void ELFDumper::printSymbol(typename ELFO::Elf_Sym_Iter Symbol) { makeArrayRef(ElfSymbolBindings)); W.printEnum ("Type", Symbol->getType(), makeArrayRef(ElfSymbolTypes)); W.printNumber("Other", Symbol->st_other); - W.printHex ("Section", SectionName, Symbol->st_shndx); + W.printHex("Section", SectionName, SectionIndex); } #define LLVM_READOBJ_TYPE_CASE(name) \ -- cgit v1.2.3