From: Mark Kettenis <mark.kettenis@xs4all.nl>
To: yao@codesourcery.com
Cc: gdb-patches@sourceware.org
Subject: Re: [patch] Handle return small struct in rs600 (size is not 4/8)
Date: Mon, 15 Aug 2011 16:06:00 -0000 [thread overview]
Message-ID: <201108151605.p7FG5F1Z004428@glazunov.sibelius.xs4all.nl> (raw)
In-Reply-To: <4E4939A9.70000@codesourcery.com> (message from Yao Qi on Mon, 15 Aug 2011 23:22:17 +0800)
> X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,TW_CP,TW_EG
> Date: Mon, 15 Aug 2011 23:22:17 +0800
> From: Yao Qi <yao@codesourcery.com>
>
> Hi,
> It looks to me that ppc-sysv-tdep.c:do_ppc_sysv_return_value doesn't
> consider the case that returning a small struct (size <= 8) whose size
> is not 4 or 8.
>
> Supposing we have a struct defined as below,
>
> struct C
> {char c1; char c2; char c3;};
> struct C c;
> c.c1 = 'a'; c.c2 = 'b'; c.c3 = 'c';
>
> The raw memory content of c is 0x616263XX (big-endian) or 0xXX636261
> (little-endian). When returning c, according to Power Arch ABI:
> "Aggregates or unions whose size is less than or equal to eight bytes
> shall be returned in r3 and r4, as if they were first stored in memory
> area and then the low-addressed word were loaded in r3 and the
> high-addressed word were loaded into r4.", the content of r3 should be
> 0x616263 (big-endian) or 0x636261 (little-endian).
That's not how I read the ABI. If you store that struct in a
zero-initialized 8-byte buffer you'll have the following sequence of 8
bytes:
0x61 0x62 0x63 0x00 0x00 0x00 0x00 0x00
Viewed as two big-endian words this becomes:
0x61626300 0x00000000
and as two little-endian words this becomes:
0x00636261 0x00000000
So in the little-endian case r3 will indeed be 0x636261 like you say,
but in the big-endian case r3 will be 0x61626300.
> When gdb reads r3's content via regcache_cooked_read into a buf, the
> content of buf looks like this,
> buf: [0] [1] [2] [3]
> big-endian : 00 61 62 63
> little-endian : 61 62 63 00
If that's really what you're seeing, then GCC must not implement this
part of the ABI correctly. Not really surprising since GCC has a long
history of getting corner cases like this wrong.
Now the question is if this just happens to be broken in the
particular version of GCC you're using or whether this has always been
broken. Eh, wait a moment...
...what version of GDB are you looking at? The current code in
ppc-sysv-tdep.c already handles the broken way GCC implements this.
Just make sure your target uses ppc_sysv_abi_broken_return_value()
instead of ppc_sysv_abi_return_value(). The NetBSD/powerpc and
OpenBSD/powerpc targets already do this. Guessing that you're on
Linux and that GCC is the primary compiler on that platform, it
probably needs that same treatment.
> Regression tested on a powerpc variant board. Many fails in
> gdb.base/structs.exp are fixed. Is this patch OK?
So no, I'd say this isn't ok.
next prev parent reply other threads:[~2011-08-15 16:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-15 15:22 Yao Qi
2011-08-15 15:42 ` [patch] Handle return small struct in ppc " Yao Qi
2011-08-15 16:06 ` Mark Kettenis [this message]
2011-08-15 16:56 ` [patch] Handle return small struct in rs600 " Yao Qi
2011-08-15 17:27 ` Pedro Alves
2011-08-15 18:54 ` Andreas Schwab
2011-08-16 1:41 ` Yao Qi
2011-08-15 17:57 ` Andreas Schwab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201108151605.p7FG5F1Z004428@glazunov.sibelius.xs4all.nl \
--to=mark.kettenis@xs4all.nl \
--cc=gdb-patches@sourceware.org \
--cc=yao@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox