This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
PATCH: SHN_XINDEX support is broken
- From: "H. J. Lu" <hjl at lucon dot org>
- To: binutils at sources dot redhat dot com
- Cc: amodra at bigpond dot net dot au
- Date: Fri, 4 Feb 2005 16:24:12 -0800
- Subject: PATCH: SHN_XINDEX support is broken
- References: <20050204234328.GA11070@lucon.org>
On Fri, Feb 04, 2005 at 03:43:28PM -0800, H. J. Lu wrote:
> Hi Alan,
>
> SHN_XINDEX support doesn't work. I have a testcase to show it. The
> problem is that binutils assumes the full symbol table is available
> before all sections are processed. It only works without SHN_XINDEX
> since SHT_REL/SHT_RELA sections will load SHT_SYMTAB. The problem
> affects both bfd and readelf. I will see what I can do.
>
>
This patch fixes bfd. I will fix readelf later.
H.J.
----
2005-02-04 H.J. Lu <hongjiu.lu@intel.com>
* elfcode.h (elf_object_p): Read in SHT_SYMTAB and
SHT_SYMTAB_SHNDX sections first.
--- bfd/elfcode.h.ext 2005-01-30 09:33:38.000000000 -0800
+++ bfd/elfcode.h 2005-02-04 16:20:50.585023878 -0800
@@ -725,20 +725,51 @@ elf_object_p (bfd *abfd)
if (i_ehdrp->e_shstrndx != 0 && i_ehdrp->e_shoff)
{
- unsigned int num_sec;
+ unsigned int num_sec, sec_count;
shstrtab = bfd_elf_get_str_section (abfd, i_ehdrp->e_shstrndx);
if (!shstrtab)
goto got_no_match;
+ /* We need to read in SHT_SYMTAB and SHT_SYMTAB_SHNDX sections
+ first since bfd_section_from_shdr may use them. */
+ num_sec = elf_numsections (abfd);
+ sec_count = (num_sec < SHN_LORESERVE) ? 1 : 0;
+ for (shindex = 1; sec_count < 2 && shindex < num_sec; shindex++)
+ {
+ Elf_Internal_Shdr *hdr = elf_elfsections (abfd)[shindex];
+ switch (hdr->sh_type)
+ {
+ case SHT_SYMTAB:
+ case SHT_SYMTAB_SHNDX:
+ if (! bfd_section_from_shdr (abfd, shindex))
+ goto got_no_match;
+ sec_count++;
+ break;
+ default:
+ break;
+ }
+ if (shindex == SHN_LORESERVE - 1)
+ shindex += SHN_HIRESERVE + 1 - SHN_LORESERVE;
+ }
+
/* Once all of the section headers have been read and converted, we
can start processing them. Note that the first section header is
a dummy placeholder entry, so we ignore it. */
num_sec = elf_numsections (abfd);
for (shindex = 1; shindex < num_sec; shindex++)
{
- if (! bfd_section_from_shdr (abfd, shindex))
- goto got_no_match;
+ Elf_Internal_Shdr *hdr = elf_elfsections (abfd)[shindex];
+ switch (hdr->sh_type)
+ {
+ case SHT_SYMTAB:
+ case SHT_SYMTAB_SHNDX:
+ break;
+ default:
+ if (! bfd_section_from_shdr (abfd, shindex))
+ goto got_no_match;
+ break;
+ }
if (shindex == SHN_LORESERVE - 1)
shindex += SHN_HIRESERVE + 1 - SHN_LORESERVE;
}