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
This commit is contained in:
Rafael Espindola
2014-03-25 23:44:25 +00:00
parent 6a0f060f64
commit 81c66bcc13
5 changed files with 338 additions and 158685 deletions

View File

@ -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) \