head -r356426 32-bit powerpc : clang vs gcc9 C-ABI: *not* the same: clang is doing -maix-struct-return style

Mark Millard marklmi at yahoo.com
Sun Jan 12 21:04:12 UTC 2020


system-clang (C) handles returning example struct based on it
being on the stack (-maix-struct-return style); gcc9 via
registers r3 and r4 (-msvr4-struct-return style). So this
somewhat tracks what was observed for the C++ ABI.

The evidence from on a old G4 PowerMac3,6 . . .

The source code:

# more just_struct.c
struct two {
  int a,b;
};

struct two f(void) {
   struct two r= { 0, 1};
   return r;
}


# cc -std=c99 -pedantic -g -O2 -c just_struct.c
# objdump -d --prefix-addresses just_struct.o | more

just_struct.o:     file format elf32-powerpc-freebsd

Disassembly of section .text:
00000000 <f> li      r4,1
00000004 <f+0x4> stw     r4,4(r3)
00000008 <f+0x8> li      r4,0
0000000c <f+0xc> stw     r4,0(r3)
00000010 <f+0x10> blr

So it expect r3 to point to the space the caller
provided, probably via stack space.

This appears to be -maix-struct-return style.


# /usr/local/bin/powerpc-unknown-freebsd13.0-gcc9 -std=c99 -pedantic -g -O2 -c just_struct.c
# objdump -d --prefix-addresses just_struct.o | more

just_struct.o:     file format elf32-powerpc-freebsd

Disassembly of section .text:
00000000 <f> li      r3,0
00000004 <f+0x4> li      r4,1
00000008 <f+0x8> blr

So it returned via register r3 and r4.

This appears to be -msvr4-struct-return style.


# gcc9 -std=c99 -pedantic -g -O2 -c just_struct.c
# objdump -d --prefix-addresses just_struct.o | more

just_struct.o:     file format elf32-powerpc-freebsd

Disassembly of section .text:
00000000 <f> li      r3,0
00000004 <f+0x4> li      r4,1
00000008 <f+0x8> blr

So it returned via register r3 and r4.

This appears to be -msvr4-struct-return style.


So is clang using the aix ABI the right ABI?
Or does GCC need to change?


===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)



More information about the freebsd-ppc mailing list