[PATCH] AIX 32-bit core loading, high section addresses.

Pedro Alves palves@redhat.com
Fri Mar 7 12:54:00 GMT 2014

On 03/07/2014 06:38 AM, Alan Modra wrote:
> On Thu, Mar 06, 2014 at 02:09:54PM +0000, Pedro Alves wrote:
>> 	* rs6000-core.c: Include bfd_stdint.h.
>> 	(rs6000coff_core_p): Cast pointer to bfd_vma through uintptr_t
>> 	instead of through long.
> OK, but wouldn't unsigned long work just as well?

Sure, though as we're converting pointers to integers,
uintptr_t looks more self-documenting to me.  I just now
found ptr_to_uint defined and used in the file:

 /* Borrowed from <sys/inttypes.h> on recent AIX versions.  */
 typedef unsigned long ptr_to_uint;

so I switched to use that too for consistency.

This whole file would obviously ideally be made host-independent
anyway, not relying on host headers with pointers, but,
in general, now that bfd uses GCC_HEADER_STDINT/ has
bfd_stdint.h, is there still a reason for avoiding uintptr_t?
AFAICS, bfd_stdint.h guarantees it'll be defined on all hosts.

Anyway, pushed as below.  Thanks!

AIX 32-bit core loading, high section addresses.

I noticed GDB was failing to enable threading support for 32-bit AIX
cores.  I traced it to failure to read variables from libpthreads.a.
The issue is that data for that library is loaded at a high address,
and bfd is sign extending the section addresses:

 (gdb) info files
 Symbols from "/home/palves/crash".
 Local core dump file:
	 `/home/palves/core', file type aixcoff-rs6000.
	 0x2ff22000 - 0x2ff23000 is .stack
	 0x20000000 - 0x200316e0 is .data
	 0x20000e90 - 0x200016c0 is .data
	 0xfffffffff0254000 - 0xfffffffff0297920 is .data
	 0xfffffffff07b46a8 - 0xfffffffff07b47c8 is .data
	 0xfffffffff0298000 - 0xfffffffff029bfcc is .data
	 0xfffffffff06dafe0 - 0xfffffffff07b3838 is .data
 Local exec file:
	 `/home/palves/crash', file type aixcoff-rs6000.
	 Entry point: 0x20001394
	 0x10000150 - 0x10000e90 is .text
	 0x20000e90 - 0x2000149c is .data
	 0x2000149c - 0x200016c0 is .bss
	 0xd053b124 - 0xd053e15f is .text in /usr/lib/libpthreads.a(shr_comm.o)
	 0xf0254000 - 0xf0297920 is .data in /usr/lib/libpthreads.a(shr_comm.o)
	 0xf0254450 - 0xf0297920 is .bss in /usr/lib/libpthreads.a(shr_comm.o)
	 0xd053a280 - 0xd053aabe is .text in /usr/lib/libcrypt.a(shr.o)
	 0xf07b46a8 - 0xf07b47c8 is .data in /usr/lib/libcrypt.a(shr.o)
	 0xf07b47c8 - 0xf07b47c8 is .bss in /usr/lib/libcrypt.a(shr.o)
	 0xd04fb180 - 0xd053917e is .text in /usr/lib/libpthreads.a(shr_xpg5.o)
	 0xf0298000 - 0xf029bfcc is .data in /usr/lib/libpthreads.a(shr_xpg5.o)
	 0xf029bf64 - 0xf029bfcc is .bss in /usr/lib/libpthreads.a(shr_xpg5.o)
	 0xd0100900 - 0xd04fa39c is .text in /usr/lib/libc.a(shr.o)
	 0xf06dafe0 - 0xf07b3838 is .data in /usr/lib/libc.a(shr.o)
	 0xf0751e94 - 0xf07b3838 is .bss in /usr/lib/libc.a(shr.o)

	0xfffffffff0298000 - 0xfffffffff029bfcc is .data

Those are the bfd section start/end addresses.  It't not visible here:

	 0xf0298000 - 0xf029bfcc is .data in /usr/lib/libpthreads.a(shr_xpg5.o)

... just because GDB trims that number to 32-bit when printing.

GDB then fails to find the memory for libpthreads.a variables in the
core, and falls back to reading it directly from the executable (which
yields the values as originally initialized in the code).


 (gdb) p &__n_pthreads
 $2 = (<data variable, no debug info> *) 0xf074fda8 <__n_pthreads>
 (gdb) p __n_pthreads
 $1 = -1

That should have returned 2 instead of -1.

2014-03-07  Pedro Alves  <palves@redhat.com>

	* rs6000-core.c (rs6000coff_core_p): Cast pointers to bfd_vma
	through ptr_to_uint instead of through long.
 bfd/ChangeLog     | 5 +++++
 bfd/rs6000-core.c | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 253e061..5f2bdb2 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-07  Pedro Alves  <palves@redhat.com>
+	* rs6000-core.c (rs6000coff_core_p): Cast pointers to bfd_vma
+	through ptr_to_uint instead of through long.
 2014-03-06  Nick Clifton  <nickc@redhat.com>
 	PR 16664
diff --git a/bfd/rs6000-core.c b/bfd/rs6000-core.c
index afc81cb..8f2f3a0 100644
--- a/bfd/rs6000-core.c
+++ b/bfd/rs6000-core.c
@@ -583,7 +583,7 @@ rs6000coff_core_p (bfd *abfd)
 	    ldi_core = ldinfo.l32.ldinfo_core;
 	    ldi_datasize = ldinfo.l32.ldinfo_datasize;
-	    ldi_dataorg = (bfd_vma) (long) ldinfo.l32.ldinfo_dataorg;
+	    ldi_dataorg = (bfd_vma) (ptr_to_uint) ldinfo.l32.ldinfo_dataorg;
 	    ldi_next = ldinfo.l32.ldinfo_next;
@@ -625,7 +625,7 @@ rs6000coff_core_p (bfd *abfd)
-		vminfo_addr = (bfd_vma) (long) vminfo.old.vminfo_addr;
+		vminfo_addr = (bfd_vma) (ptr_to_uint) vminfo.old.vminfo_addr;
 		vminfo_size = vminfo.old.vminfo_size;
 		vminfo_offset = vminfo.old.vminfo_offset;

More information about the Binutils mailing list