Re: [PATCH/RFA] Update m68k function return value handling

Mark Kettenis
2004-05-04T17:20:03Z

Date: Tue, 04 May 2004 01:51:35 +0000
From: Michael Snyder <msnyder@redhat.com>

Mark Kettenis wrote:
> Hi Andreas,
>
> Here's a patch that converts the m68k to the new function return value
> handling mechanism. I tried very hard to make it possible to deal
> with all the different m68k ABI's. I'm pretty sure I've got it right
> for at least OpenBSD, NetBSD and Linux. On other systems it can't
> really be worse than the old code.

Unfortunately, it can. The problem is that when you use the new
gdbarch_return_value_p method, print_return_value simply gives up
on any function that returns a struct via a pointer argument
(what we refer to as the "struct convention"). I don't know why
it does (esp. in view of all the code you've added for determining
eg. which register this pointer is passed in), but it does.

This has been discussed in the past. The problem is that on almost
every target, you cannot reliably tell where the return value is
stored. On some targets you can't even tell this when the call is
finished; I believe Andrew said this was the case on powerpc. Anyway,
most targets, and m68k might be one of them, can tell where the
structure is stored when the function is finished. I've promised to
look into it some time ago (since i386 is in a similar situation).
Just didn't find the time yet...

This is especially bad for cross-m68k targets, since when
pcc_struct_convention is used, m68k_reg_struct_return_p
always returns false. BTW this is wrong for gcc m68k-elf,
so I don't understand why pcc_struct_convention is set for
all cross targets...

Hmm. I looked at GCC, to see what the "default" convention would be,
and config/m68k/m68k.h implicates that all structures would be
returned in static storage. I somehow overlooked that the majority,
if not all, "embedded" targets use config/m68k/m68kemb.h, which
overrides the default in config/m68k/m68k.h to return small structures
in registers. So it seems I've simply looked in the wrong place and
chose the wrong default. Feel free to change it to reg_struct_return.
The Linux, OpenBSD and NetBSD targets should be immune to such a
change. If you don't get to making the change I'll do so in a few
days.