[Bug c/84762] New: GCC for PowerPC32 violates the SysV ABI spec for small struct returns
sirl at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Mar 8 14:58:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84762
Bug ID: 84762
Summary: GCC for PowerPC32 violates the SysV ABI spec for small
struct returns
Product: gcc
Version: 6.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: sirl at gcc dot gnu.org
Target Milestone: ---
Host: x86_64-linux
Target: powerpc-eabi
For an example like:
struct smallstruct { char a; char b; char c; };
struct smallstruct f(void)
{
struct smallstruct s = { 0x11, 0x22, 0x33 };
return s;
}
r3 should look like 0x11223300, but GCC returns 0x00112233 in r3 (with the '00'
part actually being undefined).
The relevant part of the spec
https://www.polyomino.org.uk/publications/2011/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf:
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. Bits beyond the last member of the structure or union are not defined.
Or the older http://refspecs.linux-foundation.org/elf/elfspec_ppc.pdf says
nearly the same (with an additional alignment clause):
A structure or union whose size is less than or equal to 8 bytes shall be
returned in r3 and r4, as if it were first stored in an 8-byte aligned memory
area and then the low-addressed word were loaded into r3 and the high-addressed
word into r4. Bits beyond the last member of the structure or union are not
defined.
This was discovered during parameter passing tests as a difference to a
proprietary compiler.
As it is probably too late in the game to change GCC, this is more a
documentation request I guess.
Eventually -msvr4-struct-return could be extended to
-msvr4-struct-return={sysv,gnu} with 'gnu' as the (compile-time configurable?)
default.
More information about the Gcc-bugs
mailing list