Patch: _bfd_elf_find_nearest_line

Andrew Haley aph@cambridge.redhat.com
Fri Sep 6 08:31:00 GMT 2002


There's a bug in _bfd_elf_find_nearest_line.

Try this:

~ > gcc hello.c 
~ > nm a.out | grep main
08048378 T main
~ > addr2line -f 08048378
??
/usr/src/build/87998-i386/BUILD/glibc-2.2.5/csu/init.c:0

The problem in _bfd_elf_find_nearest_line is here:

----------------------------------------------------------------------------
  if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
					     &found, filename_ptr,
					     functionname_ptr, line_ptr,
					     &elf_tdata (abfd)->line_info))
    return false;
  if (found)
    return true;
----------------------------------------------------------------------------

Unfortunately, _bfd_stab_section_find_nearest_line() returns
found=true if it's found a .stab section, not if it's actually found a
symbol.  You have to check the data that it returned to find that.

I have no idea why _bfd_stab_section_find_nearest_line() works in this
way, but it looks intentional.  I can't find a comment to indicate
what *found is actually supposed to mean, so I can't tell if this is
actually a bug.  Maybe some code relies on this behaviour.

My patch, which is appended, fixes things:

~ > /local/aph/binutils/build/binutils/addr2line -f 0x08048379
main
??:0

Andrew.


2002-09-06  Andrew Haley  <aph@cambridge.redhat.com>

	* elf.c (_bfd_elf_find_nearest_line): Check functionname_ptr and
	line_ptr before deciding we've found a symbol.

Index: elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.160
diff -p -2 -c -r1.160 elf.c
*** elf.c	22 Aug 2002 01:27:20 -0000	1.160
--- elf.c	6 Sep 2002 15:20:06 -0000
*************** _bfd_elf_find_nearest_line (abfd, sectio
*** 6042,6046 ****
  					     &elf_tdata (abfd)->line_info))
      return false;
!   if (found)
      return true;
  
--- 6042,6046 ----
  					     &elf_tdata (abfd)->line_info))
      return false;
!   if (found && (*functionname_ptr || *line_ptr))
      return true;
  



More information about the Java mailing list