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

Mark Millard via freebsd-ppc <[email protected]>
Newsgroups gmane.os.freebsd.devel.ppc,gmane.os.freebsd.devel.toolchain
Message-ID <[email protected]>
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)

_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ppc
To unsubscribe, send any mail to "[email protected]"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.