This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix addr2line and -msym32 and mips64 (Linux kernel)


On Thu, May 31, 2012 at 03:12:01PM -0700, Andrew Pinski wrote:
> 	* addr2line.c (translate_addresses): Sign extend the pc
> 	if sign_extend_vma is enabled.
> 
> Using addr2line is broken on mips64-linux-gnu with the Linux kernel (-msym32).

That's odd.  I fixed this horrible code quite a while ago, but it
doesn't look like I committed it, or even posted it.

Now committed.

	* addr2line.c (translate_addresses): Truncate input addresses to
	arch_size bits.  Avoid undefined shift.  Print '?' for zero line.

Index: binutils/addr2line.c
===================================================================
RCS file: /cvs/src/src/binutils/addr2line.c,v
retrieving revision 1.40
diff -u -p -r1.40 addr2line.c
--- binutils/addr2line.c	13 Oct 2011 15:33:32 -0000	1.40
+++ binutils/addr2line.c	23 Jan 2012 01:38:49 -0000
@@ -196,8 +196,6 @@ find_offset_in_section (bfd *abfd, asect
 static void
 translate_addresses (bfd *abfd, asection *section)
 {
-  const struct elf_backend_data * bed;
-
   int read_stdin = (naddr == 0);
 
   for (;;)
@@ -218,11 +216,15 @@ translate_addresses (bfd *abfd, asection
 	  pc = bfd_scan_vma (*addr++, NULL, 16);
 	}
 
-      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
-	  && (bed = get_elf_backend_data (abfd)) != NULL
-	  && bed->sign_extend_vma
-	  && (pc & (bfd_vma) 1 << (bed->s->arch_size - 1)))
-	pc |= ((bfd_vma) -1) << bed->s->arch_size;
+      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+	{
+	  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
+	  bfd_vma sign = (bfd_vma) 1 << (bed->s->arch_size - 1);
+
+	  pc &= (sign << 1) - 1;
+	  if (bed->sign_extend_vma)
+	    pc = (pc ^ sign) - sign;
+	}
 
       if (with_addresses)
         {
@@ -290,7 +292,11 @@ translate_addresses (bfd *abfd, asection
                     filename = h + 1;
                 }
 
-              printf ("%s:%u\n", filename ? filename : "??", line);
+              printf ("%s:", filename ? filename : "??");
+	      if (line != 0)
+		printf ("%u\n", line);
+	      else
+		printf ("?\n");
               if (!unwind_inlines)
                 found = FALSE;
               else

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]