1*ec02198aSmrg@c Copyright (C) 1988-2020 Free Software Foundation, Inc.
210d565efSmrg@c This is part of the GCC manual.
310d565efSmrg@c For copying conditions, see the file gcc.texi.
410d565efSmrg
510d565efSmrg@node Interface
610d565efSmrg@chapter Interfacing to GCC Output
710d565efSmrg@cindex interfacing to GCC output
810d565efSmrg@cindex run-time conventions
910d565efSmrg@cindex function call conventions
1010d565efSmrg@cindex conventions, run-time
1110d565efSmrg
1210d565efSmrgGCC is normally configured to use the same function calling convention
1310d565efSmrgnormally in use on the target system.  This is done with the
1410d565efSmrgmachine-description macros described (@pxref{Target Macros}).
1510d565efSmrg
1610d565efSmrg@cindex unions, returning
1710d565efSmrg@cindex structures, returning
1810d565efSmrg@cindex returning structures and unions
1910d565efSmrgHowever, returning of structure and union values is done differently on
2010d565efSmrgsome target machines.  As a result, functions compiled with PCC
2110d565efSmrgreturning such types cannot be called from code compiled with GCC,
2210d565efSmrgand vice versa.  This does not cause trouble often because few Unix
2310d565efSmrglibrary routines return structures or unions.
2410d565efSmrg
2510d565efSmrgGCC code returns structures and unions that are 1, 2, 4 or 8 bytes
2610d565efSmrglong in the same registers used for @code{int} or @code{double} return
2710d565efSmrgvalues.  (GCC typically allocates variables of such types in
2810d565efSmrgregisters also.)  Structures and unions of other sizes are returned by
2910d565efSmrgstoring them into an address passed by the caller (usually in a
3010d565efSmrgregister).  The target hook @code{TARGET_STRUCT_VALUE_RTX}
3110d565efSmrgtells GCC where to pass this address.
3210d565efSmrg
3310d565efSmrgBy contrast, PCC on most target machines returns structures and unions
3410d565efSmrgof any size by copying the data into an area of static storage, and then
3510d565efSmrgreturning the address of that storage as if it were a pointer value.
3610d565efSmrgThe caller must copy the data from that memory area to the place where
3710d565efSmrgthe value is wanted.  This is slower than the method used by GCC, and
3810d565efSmrgfails to be reentrant.
3910d565efSmrg
4010d565efSmrgOn some target machines, such as RISC machines and the 80386, the
4110d565efSmrgstandard system convention is to pass to the subroutine the address of
4210d565efSmrgwhere to return the value.  On these machines, GCC has been
4310d565efSmrgconfigured to be compatible with the standard compiler, when this method
4410d565efSmrgis used.  It may not be compatible for structures of 1, 2, 4 or 8 bytes.
4510d565efSmrg
4610d565efSmrg@cindex argument passing
4710d565efSmrg@cindex passing arguments
4810d565efSmrgGCC uses the system's standard convention for passing arguments.  On
4910d565efSmrgsome machines, the first few arguments are passed in registers; in
5010d565efSmrgothers, all are passed on the stack.  It would be possible to use
5110d565efSmrgregisters for argument passing on any machine, and this would probably
5210d565efSmrgresult in a significant speedup.  But the result would be complete
5310d565efSmrgincompatibility with code that follows the standard convention.  So this
5410d565efSmrgchange is practical only if you are switching to GCC as the sole C
5510d565efSmrgcompiler for the system.  We may implement register argument passing on
5610d565efSmrgcertain machines once we have a complete GNU system so that we can
5710d565efSmrgcompile the libraries with GCC@.
5810d565efSmrg
5910d565efSmrgOn some machines (particularly the SPARC), certain types of arguments
6010d565efSmrgare passed ``by invisible reference''.  This means that the value is
6110d565efSmrgstored in memory, and the address of the memory location is passed to
6210d565efSmrgthe subroutine.
6310d565efSmrg
6410d565efSmrg@cindex @code{longjmp} and automatic variables
6510d565efSmrgIf you use @code{longjmp}, beware of automatic variables.  ISO C says that
6610d565efSmrgautomatic variables that are not declared @code{volatile} have undefined
6710d565efSmrgvalues after a @code{longjmp}.  And this is all GCC promises to do,
6810d565efSmrgbecause it is very difficult to restore register variables correctly, and
6910d565efSmrgone of GCC's features is that it can put variables in registers without
7010d565efSmrgyour asking it to.
71