Exception Handling Bug (smashing global registers) -- 19990628and earlier

Melissa O'Neill oneill@cs.sfu.ca
Wed Jun 30 15:43:00 GMT 1999


I wrote:
>> It seems the code that handles exceptions doesn't take account of
>> global register assignments a program may have, at least on
>> solaris-sparc platforms.

... and Mike Stump replied:
> My take is this, printf is a call.  The registers are documented as
> being destroyed by calls.

Documented where?   Before I posted I trawled Sun's on-line documentation
to see what it said about these registers, and about the only thing I
found was that they were `application registers'.  My take on this is
that they're free for my application to do what it likes with, and
certainly not that they are free for the system to smash at its whim.

One place where this view was echoed was on Usenet, where Casper Dik
of Sun Microsystems wrote:
! The %g2-%g4 registers are reserved for the *application*.  The SV SPARC
! ABI document further explains that as "System software .. preserves
! these registers' values for the application."  So the complaint about
! the registers being corrupted by library calls is justified.
!
! memcpy() uses %g2 as scratch register, but it saves it first
! (at one time, %g2 wasn't saved and this was detected as a bug by the
! ABI conformance tests)
!
(See < http://www.deja.com/=dnc/getdoc.xp?AN=219820856 > for the article,
which is in a thread about global registers and threads).

Certainly my experience is that the calls to the Solaris C libraries
don't smash these registers (if they did, Sun wouldn't have considered
it an OS bug when some of their library functions did smash them and
fix it, as they did for an memcpy bug and a thread library bug (#1265722)).

> Either don't call anything, or recompile your entire application with
> those flags.  In this context, your entire application means all code
> that you can call (directly or indirectly).  This includes libc,
> libgcc, libstdc++ and all third party libraries.

I would classify libgcc as system software, and so it should respect
the SV ABI.  Whether you classify something like the STL as system
software is a matter for debate perhaps, but I would.

> Welcome to the world of -ffixed-.
>
> You could do call saved, but the compiler may need a little bit of
> work to support that.

If libgcc is going to use these registers at all, it seems clear that
they have to be call saved.

    Melissa.



More information about the Gcc mailing list