summaryrefslogtreecommitdiff
path: root/tools/llvm-readobj
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-03-25 23:44:25 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-03-25 23:44:25 +0000
commit81c66bcc13b85515db1e17c4e06034d2a2046cd1 (patch)
tree6eb342e22b75a2921ebf9530eeb06703a845cdbe /tools/llvm-readobj
parent6a0f060f64dbe08623b84dae55c8651d12c25705 (diff)
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
Diffstat (limited to 'tools/llvm-readobj')
-rw-r--r--tools/llvm-readobj/ELFDumper.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp
index 94b76d00e79..4cd339347ad 100644
--- a/tools/llvm-readobj/ELFDumper.cpp
+++ b/tools/llvm-readobj/ELFDumper.cpp
@@ -626,7 +626,7 @@ template <class ELFT>
void ELFDumper<ELFT>::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<ELFT>::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<ELFT>::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) \