1*8feb0f0bSmrg@c Copyright (C) 1988-2020 Free Software Foundation, Inc. 21debfc3dSmrg@c This is part of the GCC manual. 31debfc3dSmrg@c For copying conditions, see the file gcc.texi. 41debfc3dSmrg 51debfc3dSmrg@node Interface 61debfc3dSmrg@chapter Interfacing to GCC Output 71debfc3dSmrg@cindex interfacing to GCC output 81debfc3dSmrg@cindex run-time conventions 91debfc3dSmrg@cindex function call conventions 101debfc3dSmrg@cindex conventions, run-time 111debfc3dSmrg 121debfc3dSmrgGCC is normally configured to use the same function calling convention 131debfc3dSmrgnormally in use on the target system. This is done with the 141debfc3dSmrgmachine-description macros described (@pxref{Target Macros}). 151debfc3dSmrg 161debfc3dSmrg@cindex unions, returning 171debfc3dSmrg@cindex structures, returning 181debfc3dSmrg@cindex returning structures and unions 191debfc3dSmrgHowever, returning of structure and union values is done differently on 201debfc3dSmrgsome target machines. As a result, functions compiled with PCC 211debfc3dSmrgreturning such types cannot be called from code compiled with GCC, 221debfc3dSmrgand vice versa. This does not cause trouble often because few Unix 231debfc3dSmrglibrary routines return structures or unions. 241debfc3dSmrg 251debfc3dSmrgGCC code returns structures and unions that are 1, 2, 4 or 8 bytes 261debfc3dSmrglong in the same registers used for @code{int} or @code{double} return 271debfc3dSmrgvalues. (GCC typically allocates variables of such types in 281debfc3dSmrgregisters also.) Structures and unions of other sizes are returned by 291debfc3dSmrgstoring them into an address passed by the caller (usually in a 301debfc3dSmrgregister). The target hook @code{TARGET_STRUCT_VALUE_RTX} 311debfc3dSmrgtells GCC where to pass this address. 321debfc3dSmrg 331debfc3dSmrgBy contrast, PCC on most target machines returns structures and unions 341debfc3dSmrgof any size by copying the data into an area of static storage, and then 351debfc3dSmrgreturning the address of that storage as if it were a pointer value. 361debfc3dSmrgThe caller must copy the data from that memory area to the place where 371debfc3dSmrgthe value is wanted. This is slower than the method used by GCC, and 381debfc3dSmrgfails to be reentrant. 391debfc3dSmrg 401debfc3dSmrgOn some target machines, such as RISC machines and the 80386, the 411debfc3dSmrgstandard system convention is to pass to the subroutine the address of 421debfc3dSmrgwhere to return the value. On these machines, GCC has been 431debfc3dSmrgconfigured to be compatible with the standard compiler, when this method 441debfc3dSmrgis used. It may not be compatible for structures of 1, 2, 4 or 8 bytes. 451debfc3dSmrg 461debfc3dSmrg@cindex argument passing 471debfc3dSmrg@cindex passing arguments 481debfc3dSmrgGCC uses the system's standard convention for passing arguments. On 491debfc3dSmrgsome machines, the first few arguments are passed in registers; in 501debfc3dSmrgothers, all are passed on the stack. It would be possible to use 511debfc3dSmrgregisters for argument passing on any machine, and this would probably 521debfc3dSmrgresult in a significant speedup. But the result would be complete 531debfc3dSmrgincompatibility with code that follows the standard convention. So this 541debfc3dSmrgchange is practical only if you are switching to GCC as the sole C 551debfc3dSmrgcompiler for the system. We may implement register argument passing on 561debfc3dSmrgcertain machines once we have a complete GNU system so that we can 571debfc3dSmrgcompile the libraries with GCC@. 581debfc3dSmrg 591debfc3dSmrgOn some machines (particularly the SPARC), certain types of arguments 601debfc3dSmrgare passed ``by invisible reference''. This means that the value is 611debfc3dSmrgstored in memory, and the address of the memory location is passed to 621debfc3dSmrgthe subroutine. 631debfc3dSmrg 641debfc3dSmrg@cindex @code{longjmp} and automatic variables 651debfc3dSmrgIf you use @code{longjmp}, beware of automatic variables. ISO C says that 661debfc3dSmrgautomatic variables that are not declared @code{volatile} have undefined 671debfc3dSmrgvalues after a @code{longjmp}. And this is all GCC promises to do, 681debfc3dSmrgbecause it is very difficult to restore register variables correctly, and 691debfc3dSmrgone of GCC's features is that it can put variables in registers without 701debfc3dSmrgyour asking it to. 71