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

Andrew Pinski pinskia@gmail.com
Thu May 31 22:12:00 GMT 2012


Hi,
  After
	2011-03-30  Catherine Moore  <clm@codesourcery.com>

	* 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).
The pc becomes all -1.  The reason is ((bfd_vma) -1) <<
bed->s->arch_size produces an undefined value as bed->s->arch_size is
64 so shifting by left by more than 63 is undefined.
The attached patch fixes the problem by not doing the sign extending
if the size of bfd_vma is equal to or less than the arch size.

OK?  Tested on mips64-linux-gnu and x86_64-linux-gnu.

Thanks,
Andrew Pinski

2012-04-31  Andrew Pinski  <apinski@cavium.com>

	* addr2line.c (translate_addresses): Don't try to
	sign extend the pc if the sizeof vma is less or equal
	to the arch_size.
-------------- next part --------------
Index: addr2line.c
===================================================================
RCS file: /cvs/src/src/binutils/addr2line.c,v
retrieving revision 1.40
diff -u -p -r1.40 addr2line.c
--- addr2line.c	13 Oct 2011 15:33:32 -0000	1.40
+++ addr2line.c	31 May 2012 22:11:06 -0000
@@ -221,7 +221,8 @@ translate_addresses (bfd *abfd, asection
       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 - 1))
+	  && sizeof(bfd_vma) > bed->s->arch_size)
 	pc |= ((bfd_vma) -1) << bed->s->arch_size;
 
       if (with_addresses)


More information about the Binutils mailing list