This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Unsaved register?


On Tue, May 29, 2001 at 04:21:45PM -0700, Erik Walthinsen wrote:
> On 29 May 2001, Geoff Keating wrote:
> 
> > Sure.  Your inline asm clobbers various registers by making the
> > function call, and you haven't mentioned them.
> I thought that a function call was implicitely supposed to restore all the
> state it clobbers?  It's a full C function, no asm at all.  How is the
> calling code supposed to know which registers are going to be clobbered?

The compiler always implements an ABI that describes which registers are
assumed to be clobbered, which are used to pass arguments, which are used to
return arguments, and which registers must be preserved across calls.
Generally if there is an existing ABI or native compiler, GCC uses that ABI.

> I haven't seen anything in the docs about describing to gcc what registers
> a call might clobber, how does one do that?

Either you find the ABI that GCC adheres to and read that, or you have to go
through the code.  For example, the ABI that GCC uses for x86 UNIXes, is the
System V Application Binary Interface, Intel386 Processor Supplement (though
the details of the header files may be different).

To figure it out from the code, you need to first determine the mapping from
register name to register number (look at the REGISTER_NAMES macro in the
<machine.h> file).  Then you look in the FIXED_REGISTERS macro, to see whether
the register has a fixed usage (such as the stack pointer or registers not used
by the compiler).  Then you look in the CALL_USED_MACRO, to see whether or not
the register is not available across calls.  If it is defined, the macro
CONDITIONAL_REGISTER_USAGE overrides the definition of which registers are
fixed, or are considered clobbered across calls.  Finally, you can override
this at compilation time by using the '-ffixed-<reg>', '-fcall-used-<reg>' or
'-fcall-saved-<reg>' switches (replace <reg> with the register name).

One of the things that would be useful is to fully document each of the ABIs
the various ports use in the documentation, rather than refering to non-free
documents (or not documenting it).  However, this is a lot of work.

-- 
Michael Meissner, Red Hat, Inc.  (GCC group)
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]