public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Cagney <cagney@gnu.org>
To: Alan Modra <amodra@bigpond.net.au>
Cc: binutils@sources.redhat.com
Subject: Re: BFD: /home/cagney/tmp/a.out(.rela.plt): relocation 0 has invalid symbol index 1
Date: Wed, 26 Jan 2005 20:33:00 -0000	[thread overview]
Message-ID: <41F7FE5F.3060703@gnu.org> (raw)
In-Reply-To: <20050125103011.GC17250@bubble.modra.org>

Alan Modra wrote:
> On Tue, Jan 25, 2005 at 08:23:59PM +1030, Alan Modra wrote:
> 
>>On Mon, Jan 24, 2005 at 04:51:12PM -0500, Andrew Cagney wrote:
>>
>>>$ nm --synthetic ...
>>>BFD: /home/cagney/tmp/a.out(.rela.plt): relocation 0 has invalid symbol 
>>>index 1
>>>10010900 ? *ABS*@plt
>>>10010918 B bar
>>
>>It's a bug.  _bfd_elf_get_synthetic_symtab is trying to slurp dynamic
>>relocs before the dynamic symbol table has been read.
>>
>>"nm -D --synthetic" works.  It looks like "nm --synthetic" is supposed
>>to work too.  Oh well, fixing.
> 
> 
> As well as fixing the above, I've restricted the relocs returned by
> _bfd_elf_canonicalize_dynamic_reloc to those for loadable sections.
> The idea is to exclude debug relocs, and any other weird stuff that
> generally isn't of interest for "objdump -dR".

Works for me.

 >  I see gdb makes
> calls to bfd_canonicalize_dynamic_reloc too, but I think gdb/dbxread.c
> and gdb/solib-frv.c aren't interested in debug relocs either.

Agreed.

thanks!
Andrew

> 
> bfd/
> 	* elf.c (_bfd_elf_get_dynamic_reloc_upper_bound): Only include
> 	loadable reloc sections.
> 	(_bfd_elf_canonicalize_dynamic_reloc): Likewise.
> 	(_bfd_elf_get_synthetic_symtab): Return 0 if no dynamic syms.
> binutils/
> 	* nm.c (display_rel_file): Read dynamic syms before calling
> 	bfd_get_synthetic_symtab.
> 
> Index: bfd/elf.c
> ===================================================================
> RCS file: /cvs/src/src/bfd/elf.c,v
> retrieving revision 1.260
> diff -u -p -r1.260 elf.c
> --- bfd/elf.c	7 Jan 2005 09:52:00 -0000	1.260
> +++ bfd/elf.c	25 Jan 2005 10:07:51 -0000
> @@ -5977,10 +5977,10 @@ _bfd_elf_canonicalize_dynamic_symtab (bf
>    return symcount;
>  }
>  
> -/* Return the size required for the dynamic reloc entries.  Any
> -   section that was actually installed in the BFD, and has type
> -   SHT_REL or SHT_RELA, and uses the dynamic symbol table, is
> -   considered to be a dynamic reloc section.  */
> +/* Return the size required for the dynamic reloc entries.  Any loadable
> +   section that was actually installed in the BFD, and has type SHT_REL
> +   or SHT_RELA, and uses the dynamic symbol table, is considered to be a
> +   dynamic reloc section.  */
>  
>  long
>  _bfd_elf_get_dynamic_reloc_upper_bound (bfd *abfd)
> @@ -5996,7 +5996,8 @@ _bfd_elf_get_dynamic_reloc_upper_bound (
>  
>    ret = sizeof (arelent *);
>    for (s = abfd->sections; s != NULL; s = s->next)
> -    if (elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd)
> +    if ((s->flags & SEC_LOAD) != 0
> +	&& elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd)
>  	&& (elf_section_data (s)->this_hdr.sh_type == SHT_REL
>  	    || elf_section_data (s)->this_hdr.sh_type == SHT_RELA))
>        ret += ((s->size / elf_section_data (s)->this_hdr.sh_entsize)
> @@ -6005,14 +6006,13 @@ _bfd_elf_get_dynamic_reloc_upper_bound (
>    return ret;
>  }
>  
> -/* Canonicalize the dynamic relocation entries.  Note that we return
> -   the dynamic relocations as a single block, although they are
> -   actually associated with particular sections; the interface, which
> -   was designed for SunOS style shared libraries, expects that there
> -   is only one set of dynamic relocs.  Any section that was actually
> -   installed in the BFD, and has type SHT_REL or SHT_RELA, and uses
> -   the dynamic symbol table, is considered to be a dynamic reloc
> -   section.  */
> +/* Canonicalize the dynamic relocation entries.  Note that we return the
> +   dynamic relocations as a single block, although they are actually
> +   associated with particular sections; the interface, which was
> +   designed for SunOS style shared libraries, expects that there is only
> +   one set of dynamic relocs.  Any loadable section that was actually
> +   installed in the BFD, and has type SHT_REL or SHT_RELA, and uses the
> +   dynamic symbol table, is considered to be a dynamic reloc section.  */
>  
>  long
>  _bfd_elf_canonicalize_dynamic_reloc (bfd *abfd,
> @@ -6033,7 +6033,8 @@ _bfd_elf_canonicalize_dynamic_reloc (bfd
>    ret = 0;
>    for (s = abfd->sections; s != NULL; s = s->next)
>      {
> -      if (elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd)
> +      if ((s->flags & SEC_LOAD) != 0
> +	  && elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd)
>  	  && (elf_section_data (s)->this_hdr.sh_type == SHT_REL
>  	      || elf_section_data (s)->this_hdr.sh_type == SHT_RELA))
>  	{
> @@ -7908,7 +7909,7 @@ long
>  _bfd_elf_get_synthetic_symtab (bfd *abfd,
>  			       long symcount ATTRIBUTE_UNUSED,
>  			       asymbol **syms ATTRIBUTE_UNUSED,
> -			       long dynsymcount ATTRIBUTE_UNUSED,
> +			       long dynsymcount,
>  			       asymbol **dynsyms,
>  			       asymbol **ret)
>  {
> @@ -7924,10 +7925,14 @@ _bfd_elf_get_synthetic_symtab (bfd *abfd
>    char *names;
>    asection *plt;
>  
> +  *ret = NULL;
> +
>    if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0)
>      return 0;
>  
> -  *ret = NULL;
> +  if (dynsymcount <= 0)
> +    return 0;
> +
>    if (!bed->plt_sym_val)
>      return 0;
>  
> Index: binutils/nm.c
> ===================================================================
> RCS file: /cvs/src/src/binutils/nm.c,v
> retrieving revision 1.43
> diff -u -p -r1.43 nm.c
> --- binutils/nm.c	14 Oct 2004 09:36:54 -0000	1.43
> +++ binutils/nm.c	25 Jan 2005 10:07:56 -0000
> @@ -1026,8 +1026,18 @@ display_rel_file (bfd *abfd, bfd *archiv
>  	}
>        else
>  	{
> +	  long storage = bfd_get_dynamic_symtab_upper_bound (abfd);
> +
>  	  static_count = symcount;
>  	  static_syms = minisyms;
> +
> +	  if (storage > 0)
> +	    {
> +	      dyn_syms = xmalloc (storage);
> +	      dyn_count = bfd_canonicalize_dynamic_symtab (abfd, dyn_syms);
> +	      if (dyn_count < 0)
> +		bfd_fatal (bfd_get_filename (abfd));
> +	    }
>  	}
>        synth_count = bfd_get_synthetic_symtab (abfd, static_count, static_syms,
>  					      dyn_count, dyn_syms, &synthsyms);
> 
> 

      reply	other threads:[~2005-01-26 20:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-24 21:51 Andrew Cagney
2005-01-24 21:53 ` Ian Lance Taylor
2005-01-24 22:24   ` Andrew Cagney
2005-01-25  9:54 ` Alan Modra
2005-01-25 10:30   ` Alan Modra
2005-01-26 20:33     ` Andrew Cagney [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41F7FE5F.3060703@gnu.org \
    --to=cagney@gnu.org \
    --cc=amodra@bigpond.net.au \
    --cc=binutils@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).