public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
* Structure-return bug on powerpc32
@ 2009-05-22 19:32 Wim Lewis
  2009-05-22 19:55 ` Andreas Tobler
  0 siblings, 1 reply; 7+ messages in thread
From: Wim Lewis @ 2009-05-22 19:32 UTC (permalink / raw)
  To: libffi-discuss

I've been looking into some libffi test failures on netbsd/ppc. To  
make a long story short, under some circumstances (returning a small  
aggregate that's not a multiple of 4 bytes), ffi_call() will write  
past the end of the buffer passed to rvalue.

In the cls_6byte.c test, this manifests itself as the first field in  
g_dbl getting mysteriously set to zero after the call to ffi_call()  
in main, since g_dbl is allocated after res_dbl with no padding.  
(This surprised me a little, but the debugger confirms that &g_dbl is  
six bytes higher than &res_dbl.) As a result, the *next* test in that  
file will fail, since g_dbl no longer has the expected value.

The actual clobbering takes place at this point in src/powerpc/sysv.S:

 > L(smst_8byte):
 >         stw     %r3,0(%r30)
 >         stw     %r4,4(%r30)
 >         b       L(done_return_value)

where r30 contains 'rvalue'. This ends up writing 8 bytes even for a  
6-byte return struct.

I'm not familiar enough with ppc assembly to suggest a patch; I'm not  
really sure what the code immediately before the smst_8byte label is  
doing. One idea is to do a read-modify-write and use insrwi/rlwinm to  
modify only the portion of the word containing the returned struct.  
But the struct may be aligned at the end of a memory region, so maybe  
the only correct implementation for oddly-sized aggregates is a  
sequence of rotates and stswi or stbu instructions.


regards
    Wim Lewis / wiml@hhhh.org


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

end of thread, other threads:[~2009-06-04  7:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-22 19:32 Structure-return bug on powerpc32 Wim Lewis
2009-05-22 19:55 ` Andreas Tobler
2009-05-22 22:32   ` Wim Lewis
2009-05-30  1:41     ` Structure-return bug on powerpc32 (patch) Wim Lewis
2009-06-01 19:45       ` Andreas Tobler
2009-06-01 19:58         ` Anthony Green
2009-06-04  7:01         ` Wim Lewis

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