public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Why mips32 addr2line doesn't work
@ 2005-07-07 21:57 Paul Koning
  2005-07-08 15:51 ` PATCH: fix dwarf2 handling of signed addresses Paul Koning
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Koning @ 2005-07-07 21:57 UTC (permalink / raw)
  To: binutils

Addr2line works by taking the supplied address and finding a matching
section (using bfd_get_section_vma).  On mips32, that returns a 64 bit
address, sign extended of course as required by MIPS.

So to lookup a kernel address, I have to pass the adress with ffffffff
prefixed to it, to extend it to 64 bits, otherwise the section isn't
found.  That's odd given that this isn't how addresses are displayed
for 32 bit MIPS images -- for example, "nm" shows only the 32 bit
values, not the 64 bit sign-extended values.

Once I get past that step in the program, the next step is to look
through the compilation units for a match in the function and line
number tables.

Guess what?  Those have 32 bit addresses in them, and they are NOT
sign extended.  So no match can ever be found.

If I pass the 32-bit address without the sign extend, then the 64 bit
section address check fails, because that one DOES have sign extended
addresses. 

I get the feeling that this whole thing is quite thoroughly broken,
with addresses sign-extended (as required) in a few spots, and
zero-extended in many others.  Admittedly it's rather weird to treat
addresses as signed, but that IS the MIPS rule.

I'm tempted to hack bdf-in.h to make bfd_vma a signed long long...

Any suggestions?  Are there any easy fixes that come to mind or is
this going to take wholesale surgery?

     paul

^ permalink raw reply	[flat|nested] 6+ messages in thread

* PATCH: fix dwarf2 handling of signed addresses
  2005-07-07 21:57 Why mips32 addr2line doesn't work Paul Koning
@ 2005-07-08 15:51 ` Paul Koning
  2005-07-08 16:02   ` Eric Christopher
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Koning @ 2005-07-08 15:51 UTC (permalink / raw)
  To: binutils

I reported yesterday that addr2line doesn't work correctly for MIPS
kernel addresses because sign extending of addresses is done
inconsistently.

The attached patch fixes that problem.  I can't apply it (no write
privs -- but I do have a copyright assignment in place).

      paul

2005-07-08  Paul Koning  <pkoning@equallogic.com>

	* dwarf2.c (read_address): Check sign_extend_vma to handle targets
	where addresses are sign extended.

Index: dwarf2.c
===================================================================
RCS file: /cvs/src/src/bfd/dwarf2.c,v
retrieving revision 1.75
diff -u -r1.75 dwarf2.c
--- dwarf2.c	6 Jul 2005 13:43:21 -0000	1.75
+++ dwarf2.c	8 Jul 2005 15:36:38 -0000
@@ -347,16 +347,35 @@
 static bfd_uint64_t
 read_address (struct comp_unit *unit, bfd_byte *buf)
 {
-  switch (unit->addr_size)
+  int signed_vma = get_elf_backend_data (unit->abfd)->sign_extend_vma;
+
+  if (signed_vma)
     {
-    case 8:
-      return bfd_get_64 (unit->abfd, buf);
-    case 4:
-      return bfd_get_32 (unit->abfd, buf);
-    case 2:
-      return bfd_get_16 (unit->abfd, buf);
-    default:
-      abort ();
+      switch (unit->addr_size)
+	{
+	case 8:
+	  return bfd_get_signed_64 (unit->abfd, buf);
+	case 4:
+	  return bfd_get_signed_32 (unit->abfd, buf);
+	case 2:
+	  return bfd_get_signed_16 (unit->abfd, buf);
+	default:
+	  abort ();
+	}
+    }
+  else
+    {
+      switch (unit->addr_size)
+	{
+	case 8:
+	  return bfd_get_64 (unit->abfd, buf);
+	case 4:
+	  return bfd_get_32 (unit->abfd, buf);
+	case 2:
+	  return bfd_get_16 (unit->abfd, buf);
+	default:
+	  abort ();
+	}
     }
 }
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: fix dwarf2 handling of signed addresses
  2005-07-08 15:51 ` PATCH: fix dwarf2 handling of signed addresses Paul Koning
@ 2005-07-08 16:02   ` Eric Christopher
  2005-07-08 16:06     ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Christopher @ 2005-07-08 16:02 UTC (permalink / raw)
  To: Paul Koning; +Cc: binutils


> The attached patch fixes that problem.  I can't apply it (no write
> privs -- but I do have a copyright assignment in place).
> 

This is enough to sponsor you for write approval. You've done work in
the past and appear to want to continue doing so. Go ahead and put in
the request with me as the sponsor.

> 2005-07-08  Paul Koning  <pkoning@equallogic.com>
> 
> 	* dwarf2.c (read_address): Check sign_extend_vma to handle targets
> 	where addresses are sign extended.

My only reservation for this is that we should be sign extending every
address no matter what and that this points to a bug in our code
elsewhere.

-eric

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: fix dwarf2 handling of signed addresses
  2005-07-08 16:02   ` Eric Christopher
@ 2005-07-08 16:06     ` Daniel Jacobowitz
  2005-07-08 16:15       ` Eric Christopher
  2005-07-08 21:42       ` Paul Koning
  0 siblings, 2 replies; 6+ messages in thread
From: Daniel Jacobowitz @ 2005-07-08 16:06 UTC (permalink / raw)
  To: Eric Christopher; +Cc: Paul Koning, binutils

On Fri, Jul 08, 2005 at 09:02:09AM -0700, Eric Christopher wrote:
> > 2005-07-08  Paul Koning  <pkoning@equallogic.com>
> > 
> > 	* dwarf2.c (read_address): Check sign_extend_vma to handle targets
> > 	where addresses are sign extended.
> 
> My only reservation for this is that we should be sign extending every
> address no matter what and that this points to a bug in our code
> elsewhere.

Are you sure?  Remember, many targets zero extend - Paul's patch looks
sensible to me.

FWIW GDB has many of the same problems.  That's why GDB still doesn't
use DWARF-2 unwinding on MIPS; someone needs to take another stab at
that.

-- 
Daniel Jacobowitz
CodeSourcery, LLC

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: fix dwarf2 handling of signed addresses
  2005-07-08 16:06     ` Daniel Jacobowitz
@ 2005-07-08 16:15       ` Eric Christopher
  2005-07-08 21:42       ` Paul Koning
  1 sibling, 0 replies; 6+ messages in thread
From: Eric Christopher @ 2005-07-08 16:15 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: Paul Koning, binutils


> > My only reservation for this is that we should be sign extending every
> > address no matter what and that this points to a bug in our code
> > elsewhere.
> 
> Are you sure?  Remember, many targets zero extend - Paul's patch looks
> sensible to me.
> 

Of course it's fine, it's in target independent code. I really shouldn't
review the first thing in the morning. :) That said, that it fixes code
in mips still makes me feel wonky.

-eric

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: fix dwarf2 handling of signed addresses
  2005-07-08 16:06     ` Daniel Jacobowitz
  2005-07-08 16:15       ` Eric Christopher
@ 2005-07-08 21:42       ` Paul Koning
  1 sibling, 0 replies; 6+ messages in thread
From: Paul Koning @ 2005-07-08 21:42 UTC (permalink / raw)
  To: drow; +Cc: echristo, binutils

>>>>> "Daniel" == Daniel Jacobowitz <drow@false.org> writes:

 Daniel> On Fri, Jul 08, 2005 at 09:02:09AM -0700, Eric Christopher
 Daniel> wrote:
 >> > 2005-07-08 Paul Koning <pkoning@equallogic.com>
 >> > 
 >> > * dwarf2.c (read_address): Check sign_extend_vma to handle
 >> targets > where addresses are sign extended.
 >> 
 >> My only reservation for this is that we should be sign extending
 >> every address no matter what and that this points to a bug in our
 >> code elsewhere.

 Daniel> Are you sure?  Remember, many targets zero extend - Paul's
 Daniel> patch looks sensible to me.

After offline message from Daniel saying "approved" I've committed
this. 

Thanks!

      paul

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-07-08 21:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-07 21:57 Why mips32 addr2line doesn't work Paul Koning
2005-07-08 15:51 ` PATCH: fix dwarf2 handling of signed addresses Paul Koning
2005-07-08 16:02   ` Eric Christopher
2005-07-08 16:06     ` Daniel Jacobowitz
2005-07-08 16:15       ` Eric Christopher
2005-07-08 21:42       ` Paul Koning

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).