Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] Pushing Inferior Function Arguments onto Stack on   PowerPC64 machines
@ 2006-10-03 19:15 Janani Janakiraman
  2006-10-03 19:20 ` Daniel Jacobowitz
  0 siblings, 1 reply; 12+ messages in thread
From: Janani Janakiraman @ 2006-10-03 19:15 UTC (permalink / raw)
  To: gdb-patches

This fixes a problem on Powerpc 64 machines while running gdb on 64 bit 
programs. The problem is with the alignment of the function arguments
when they are pushed to the stack in the ppc64_sysv_abi_push_dummy_call.
GCC expects the values to be right aligned.


gdb:
2006-10-02  Janani Janakiraman <janani@us.ibm.com>
	* ppc-sysv-tdep.c: Remove the hack for GCC. Right align 
	  the values on the stack.

Index: gdb/ppc-sysv-tdep.c
===================================================================
*** ppc-sysv-tdep.c.orig	2006-09-29 15:52:35.000000000 -0500
--- ppc-sysv-tdep.c	2006-09-29 15:57:55.000000000 -0500
*************** ppc64_sysv_abi_push_dummy_call (struct g
*** 786,806 ****
  		      if (len > tdep->wordsize)
  			len = tdep->wordsize;
  		      memset (regval, 0, sizeof regval);
! 		      /* WARNING: cagney/2003-09-21: As best I can
! 		         tell, the ABI specifies that the value should
! 		         be left aligned.  Unfortunately, GCC doesn't
! 		         do this - it instead right aligns even sized
! 		         values and puts odd sized values on the
! 		         stack.  Work around that by putting both a
! 		         left and right aligned value into the
! 		         register (hopefully no one notices :-^).
! 		         Arrrgh!  */
! 		      /* Left aligned (8 byte values such as pointers
! 		         fill the buffer).  */
! 		      memcpy (regval, val + byte, len);
! 		      /* Right aligned (but only if even).  */
! 		      if (len == 1 || len == 2 || len == 4)
! 			memcpy (regval + tdep->wordsize - len,
  				val + byte, len);
  		      regcache_cooked_write (regcache, greg, regval);
  		    }
--- 786,793 ----
  		      if (len > tdep->wordsize)
  			len = tdep->wordsize;
  		      memset (regval, 0, sizeof regval);
! 		      /* GCC expects values to be right aligned */
! 		      memcpy (regval + tdep->wordsize - len,
  				val + byte, len);
  		      regcache_cooked_write (regcache, greg, regval);
  		    }


GDB Test from testsuite -- results before the patch. 
Note, after the patch is applied,
the results are as expected by the test case. 

GCC Version ---- gcc (GCC) 4.1.0 (SUSE Linux)

gdb.base/call-ar-st.exp: continue to 1281
(gdb)print print_small_structs(*struct1, *struct2, *struct3, *struct4, 
*flags, *flags_combo, *three_char,*five_char, *int_char_combo, *d1, *d2, *d3, 
*f1, *f2, *f3)

alpha

gamma

epsilon

alpha

gamma

epsilon

ch1: y	ch2: n

Contents of three_char_t: 

			  <----- This should be  "a   b   c"

Contents of five_char_t: 


o	p	         <----- This should be "l   m   n   o   p"
....


Janani Janakiraman


^ permalink raw reply	[flat|nested] 12+ messages in thread
* [patch] Pushing Inferior Function Arguments onto Stack on   PowerPC64 machines
@ 2006-10-04 19:00 janani
  2006-10-04 19:11 ` Daniel Jacobowitz
  0 siblings, 1 reply; 12+ messages in thread
From: janani @ 2006-10-04 19:00 UTC (permalink / raw)
  To: gdb-patches; +Cc: pgilliam, janani

> Is Andrew's comment about the ABI correct, or incorrect?  Do you know
>> for sure?
>> ! 		 		       /* WARNING: cagney/2003-09-21: As best I can
>> ! 		 		          tell, the ABI specifies that the value should
>> ! 		 		          be left aligned.  Unfortunately, GCC doesn't
>> ! 		 		          do this - it instead right aligns even sized
>> ! 		 		          values and puts odd sized values on the
>> ! 		 		          stack.  Work around that by putting both a
>> ! 		 		          left and right aligned value into the
>> ! 		 		          register (hopefully no one notices :-^).
>> ! 		 		          Arrrgh!  */

> -- 
> Daniel Jacobowitz
> CodeSourcery


I am new to this, so my interpretation might not be completely  
accurate, but the way I read the note below ( a snippet from the GNU  
GCC Manual about passing function arguments in registers) is that  
since PPC64 is big endian, even though the default is to pad downward  
(i.e. right align), if the size if greater than the size of an int,  
you need to pad upward (left align).
.......

FUNCTION_ARG_PADDING (mode, type)
     If defined, a C expression which determines whether, and in which  
direction, to pad out an argument with extra space. The value should  
be of type enum direction: either upward to pad above the argument,  
downward to pad below, or none to inhibit padding.

     The amount of padding is always just enough to reach the next  
multiple of FUNCTION_ARG_BOUNDARY; this macro does not control it.

     This macro has a default definition which is right for most  
systems. For little-endian machines, the default is to pad upward. For  
big-endian machines, the default is to pad downward for an argument of  
constant size shorter than an int, and upward otherwise.
.....

Janani Janakiraman


^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re:  [patch] Pushing Inferior Function Arguments onto Stack on    PowerPC64 machines
@ 2006-10-04 19:54 janani
  0 siblings, 0 replies; 12+ messages in thread
From: janani @ 2006-10-04 19:54 UTC (permalink / raw)
  To: gdb-patches; +Cc: janani, drow

Sorry about the email address goofup. Am trying to use a new account  
so that HTML tags don't get in the way. Have to figure out a way to  
enable me to receive email at this address. My other external email  
address is janani@us.ibm.com

 From reading the PPC64 Platform ABI  at
http://www.freestandards.org/spec/ELF/ppc64/PPC-elf64abi-1.9.html
( see section 3.1.7)  it appears that on Big Endian machines,
values are  left aligned. But looks like GCC has different rules and  
right aligns the values which are put on the
registers. This matches  Andrew Cagney  comment in the code, that says  
that ABI specifies that the values
should be left aligned. But like I said in my earlier note, GCC  
appears to want the values to be
right aligned.  Would appreciate another set of eyes looking at it as  
I don't have too much experience
in this area.

Daniel Jacobowitz <drow@false.org> wrote on 10/04/2006 02:10:56 PM:

> On Wed, Oct 04, 2006 at 03:00:34PM -0400, janani@linux.ibm.com wrote:
> > I am new to this, so my interpretation might not be completely  >  
> accurate, but the way I read the note below ( a snippet from the GNU  
>  > GCC Manual about passing function arguments in registers) is that  
>  > since PPC64 is big endian, even though the default is to pad  
> downward  > (i.e. right align), if the size if greater than the size  
> of an int,  > you need to pad upward (left align).
>
> You're trying to answer the wrong question :-)
>
> It's not "what does GCC do", but "what does the platform ABI say we
> should do".  Is GCC conforming to the ABI?  Is the ABI wrong, or out of
> date, or was Andrew's reading of it wrong, or...
>
> There could be a real problem here, so it's important that we
> understand what is _supposed_ to happen before we make a change.
> If GCC is violating the ABI, then either GCC or the ABI may need to be
> updated.  If GDB is misinterpreting the ABI, then just GDB needs to be
> changed.
>
> -- 
> Daniel Jacobowitz
> CodeSourcery

> ! 		 		       /* WARNING: cagney/2003-09-21: As best I can
> ! 		 		          tell, the ABI specifies that the value should
> ! 		 		          be left aligned.  Unfortunately, GCC doesn't
> ! 		 		          do this - it instead right aligns even sized
> ! 		 		          values and puts odd sized values on the
> ! 		 		          stack.  Work around that by putting both a
> ! 		 		          left and right aligned value into the
> ! 		 		          register (hopefully no one notices :-^).
> ! 		 		          Arrrgh!  */
> ! 		 		       /* Left aligned (8 byte values such as pointers
> ! 		 		          fill the buffer).  */
> ! 		 		       memcpy (regval, val + byte, len);
> ! 		 		       /* Right aligned (but only if even).  */
> ! 		 		       if (len == 1 || len == 2 || len == 4)
> ! 		 		 		 memcpy (regval + tdep->wordsize - len,

Janani Janakiraman


^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: [patch] Pushing Inferior Function Arguments onto Stack on  PowerPC64 machines
@ 2006-10-04 21:02 janani
  0 siblings, 0 replies; 12+ messages in thread
From: janani @ 2006-10-04 21:02 UTC (permalink / raw)
  To: gdb-patches; +Cc: janani, drow

Thanks for all the feedback. Will try to write up the fix along the  
lines which Daniel mentioned and post to the list.

Janani

Daniel Jacobowitz <drow@false.org> wrote on 10/04/2006 03:52:21 PM:

> On Wed, Oct 04, 2006 at 04:43:04PM -0400, David Edelsohn wrote:
> > >>>>> Daniel Jacobowitz writes:
> > > >> From reading the PPC64 Platform ABI  at
> > >> http://www.freestandards.org/spec/ELF/ppc64/PPC-elf64abi-1.9.html
> > >> ( see section 3.1.7)  it appears that on Big Endian machines,
> > >> values are  left aligned. But looks like GCC has different  
> rules and right
> > >> aligns the values which are put on the
> > >> registers. This matches  Andrew Cagney  comment in the code,  
> that says that
> > >> ABI specifies that the values
> > >> should be left aligned. But like I said in my earlier note,  
> GCCappears to
> > >> want the values to be
> > >> right aligned.  Would appreciate another set of eyes looking at it as I
> > >> don't have too much experience
> > >> in this area.
> > >    The PPC64 Linux ABI changed.  AIX always pads upwards.  PPC64
> > Linux pads aggregates smaller than a doubleword downward.
> > > "An aggregate or union smaller than one doubleword in size is padded so
> > that it appears in the least significant bits of the doubleword.  All
> > others are padded, if necessary, at their tail."
>
> Thank you (and thanks to Andreas for answering, too).
>
> In that case, the Linux and AIX configurations ought to be calling
> different functions here.  Janani, if you want to try to fix this,
> I would recommend:
>
>   - Rename the existing function.  Add an argument to it, is_linux.
>   - Create a wrapper function with the old name, in the same file,
>     for AIX to use.
>   - Create a wrapper function in ppc-linux-tdep.c which calls it with
>     is_linux == 1.
>   - Call set_gdbarch_push_dummy_call in the PPC64 section of
>     ppc_linux_init_abi.
>
> -- 
> Daniel Jacobowitz
> CodeSourcery



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

end of thread, other threads:[~2006-10-04 21:02 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-03 19:15 [patch] Pushing Inferior Function Arguments onto Stack on PowerPC64 machines Janani Janakiraman
2006-10-03 19:20 ` Daniel Jacobowitz
2006-10-04 19:00 janani
2006-10-04 19:11 ` Daniel Jacobowitz
2006-10-04 19:14   ` Daniel Jacobowitz
2006-10-04 20:19   ` Mark Kettenis
2006-10-04 20:27     ` Andreas Schwab
     [not found]   ` <OFE88464A1.C58B072A-ON872571FD.006ABA69-862571FD.006C7CFB@us.ibm.com>
2006-10-04 20:26     ` Daniel Jacobowitz
     [not found]       ` <drow@false.org>
2006-10-04 20:43         ` David Edelsohn
2006-10-04 20:52           ` Daniel Jacobowitz
2006-10-04 19:54 janani
2006-10-04 21:02 janani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox