Create .symtab_shndxr only when needed.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 25 Mar 2014 23:44:25 +0000 (23:44 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 25 Mar 2014 23:44:25 +0000 (23:44 +0000)
commit81c66bcc13b85515db1e17c4e06034d2a2046cd1
tree6eb342e22b75a2921ebf9530eeb06703a845cdbe
parent6a0f060f64dbe08623b84dae55c8651d12c25705
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
lib/MC/ELFObjectWriter.cpp
test/MC/ELF/many-section.s [deleted file]
test/MC/ELF/many-sections-2.s
test/MC/ELF/many-sections.s [new file with mode: 0644]
tools/llvm-readobj/ELFDumper.cpp