This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Incorrectly using call-clobbered registers
- From: Carlos Sánchez de La Lama <csanchez at teisa dot unican dot es>
- To: Hans-Peter Nilsson <hp at bitrange dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: 06 Mar 2003 15:36:33 +0100
- Subject: Re: Incorrectly using call-clobbered registers
- References: <Pine.BSF.4.44.0303060813440.61059-100000@dair.pair.com>
El jue, 06-03-2003 a las 14:33, Hans-Peter Nilsson escribió:
> On 6 Mar 2003, Carlos Sánchez de La Lama wrote:
>
> > I'm working with a port of gcc for the OpenRISC architecture,
>
> Using GCC CVS, I hope? If not, do that.
Not really using *gcc* CVS. The gcc port for OpenRISC is available at
OpenCores (http://www.opencores.org) CVS, and I think guys at OpenCores
have already got in touch with GNU to make it an official port. The
problem is that they stopped working on gcc-2.95.3 port and now they
only work on gcc-3.1 port. What I'm really working on is on a eCos port
for OpenRISC, but eCos-1.3.1 doesn't compile with gcc-3.1 so I nedd to
use gcc-2.95.3. This is quite a mess of version numbers, but the fact is
*they* are supposed to be the maintainers of current development code,
and no one maintains gcc-2.95.3 for OpenRISC, as it's and old version.
> > but I've a
> > question that I think is better to post here than in OpenRISC forum.
>
> You *bet* it is.
>
> > In that architecture, register r11 is used to hold return value from
> > functions,
>
> (Is there a r12 to go with that, for 64-bit values?)
Not at all. In case a 64-bit value is returned (in fact the problem
arises when the compiler calls internal function muldi3 under certains
circumstances), r11 holds a pointer to a memory position where such
value is.
> > but I've found that in certain cases the compiler uses it as
> > a general register and, before a function call, saves its value on the
> > stack, restoring it *just* after function call,
>
> (By the caller, I presume.)
Yes, the caller puts register saving and restoring code around the
function call.
> > and therefore losing the
> > returned value. The next instructions try to get the value out of r11,
> > but it's not longer there, and as it was a pointer it all end in a
> > Alignment Error.
> >
> > I've been able to fix it by defining macro CALLED_SAVE_PROFITABLE to be
> > always 0, so no fuction-clobbered register is ever use as a general
> > register, but I feel this is not the right way to do it.
>
> That's a kludge. I've never needed to use that macro for the
> two ports I wrote and maintain.
I know, but I wanted to be sure where the problem was. This way now I
know it's a wrong register usage.
> > So, anyone who knows better how all this stuff works, please tell me
> > what to do.
>
> You should start the process to submit the port to the FSF and
> ask (for you or another) to be maintainer. Really. Resistance
> is futile. QED.
I bet ;-) that it sould be done by OpenRISC guys, shouldn't it?
> > Should I put r11 in FIXED_REGISTERS macro, so it's never
> > used?
>
> No.
>
> > Please help me.
>
> I think your machine description has a bug that causes this
> behaviour. Perhaps or perhaps not as trivial as r11 missing
> from CALL_USED_REGISTERS or incorrectly described as a parameter
> register through the other macros, for example (but not
> restricted to) FUNCTION_VALUE and FUNCTION_VALUE_REGNO_P. Read
> the documentation forwards and backwards a few times.
>
> And give us your port! :-) Then someone *might just* take your
> failing code example (which you didn't send) and look at your
> port and perhaps say something useful *just because it doesn't
> take much time -- the port already at his/her hands in the
> checked out CVS*.
>
> brgds, H-P
>
If really wanted, I can upload the actual code I have. This includes
changes I've done from OpenRISC code available in CVS. But, again,
it's not the *last* development version.
Thank you very much for your quick answer :-)
Best regards,
Carlos Sánchez de La Lama <csanchez at teisa dot unican dot es>