These function attributes are supported by the x86 back end:
cdecl
On the x86-32 targets, the cdecl
attribute causes the compiler to assume that the calling function pops off the stack space used to pass arguments. This is useful to override the effects of the -mrtd switch.
fastcall
On x86-32 targets, the fastcall
attribute causes the compiler to pass the first argument (if of integral type) in the register ECX and the second argument (if of integral type) in the register EDX. Subsequent and other typed arguments are passed on the stack. The called function pops the arguments off the stack. If the number of arguments is variable all arguments are pushed on the stack.
thiscall
On x86-32 targets, the thiscall
attribute causes the compiler to pass the first argument (if of integral type) in the register ECX. Subsequent and other typed arguments are passed on the stack. The called function pops the arguments off the stack. If the number of arguments is variable all arguments are pushed on the stack. The thiscall
attribute is intended for C++ non-static member functions. As a GCC extension, this calling convention can be used for C functions and for static member methods.
ms_abi
sysv_abi
On 32-bit and 64-bit x86 targets, you can use an ABI attribute to indicate which calling convention should be used for a function. The ms_abi
attribute tells the compiler to use the Microsoft ABI, while the sysv_abi
attribute tells the compiler to use the ABI used on GNU/Linux and other systems. The default is to use the Microsoft ABI when targeting Windows. On all other systems, the default is the x86/AMD ABI.
Note, the ms_abi
attribute for Microsoft Windows 64-bit targets currently requires the -maccumulate-outgoing-args option.
callee_pop_aggregate_return (number)
On x86-32 targets, you can use this attribute to control how aggregates are returned in memory. If the caller is responsible for popping the hidden pointer together with the rest of the arguments, specify number equal to zero. If callee is responsible for popping the hidden pointer, specify number equal to one.
The default x86-32 ABI assumes that the callee pops the stack for hidden pointer. However, on x86-32 Microsoft Windows targets, the compiler assumes that the caller pops the stack for hidden pointer.
ms_hook_prologue
On 32-bit and 64-bit x86 targets, you can use this function attribute to make GCC generate the “hot-patching” function prologue used in Win32 API functions in Microsoft Windows XP Service Pack 2 and newer.
regparm (number)
On x86-32 targets, the regparm
attribute causes the compiler to pass arguments number one to number if they are of integral type in registers EAX, EDX, and ECX instead of on the stack. Functions that take a variable number of arguments continue to be passed all of their arguments on the stack.
Beware that on some ELF systems this attribute is unsuitable for global functions in shared libraries with lazy binding (which is the default). Lazy binding sends the first call via resolving code in the loader, which might assume EAX, EDX and ECX can be clobbered, as per the standard calling conventions. Solaris 8 is affected by this. Systems with the GNU C Library version 2.1 or higher and FreeBSD are believed to be safe since the loaders there save EAX, EDX and ECX. (Lazy binding can be disabled with the linker or the loader if desired, to avoid the problem.)
sseregparm
On x86-32 targets with SSE support, the sseregparm
attribute causes the compiler to pass up to 3 floating-point arguments in SSE registers instead of on the stack. Functions that take a variable number of arguments continue to pass all of their floating-point arguments on the stack.
force_align_arg_pointer
On x86 targets, the force_align_arg_pointer
attribute may be applied to individual function definitions, generating an alternate prologue and epilogue that realigns the run-time stack if necessary. This supports mixing legacy codes that run with a 4-byte aligned stack with modern codes that keep a 16-byte stack for SSE compatibility.
stdcall
On x86-32 targets, the stdcall
attribute causes the compiler to assume that the called function pops off the stack space used to pass arguments, unless it takes a variable number of arguments.
no_caller_saved_registers
Use this attribute to indicate that the specified function has no caller-saved registers. That is, all registers are callee-saved. For example, this attribute can be used for a function called from an interrupt handler. The compiler generates proper function entry and exit sequences to save and restore any modified registers, except for the EFLAGS register. Since GCC doesn’t preserve MPX, SSE, MMX nor x87 states, the GCC option -mgeneral-regs-only should be used to compile functions with no_caller_saved_registers
attribute.
interrupt
Use this attribute to indicate that the specified function is an interrupt handler or an exception handler (depending on parameters passed to the function, explained further). The compiler generates function entry and exit sequences suitable for use in an interrupt handler when this attribute is present. The IRET
instruction, instead of the RET
instruction, is used to return from interrupt handlers. All registers, except for the EFLAGS register which is restored by the IRET
instruction, are preserved by the compiler. Since GCC doesn’t preserve MPX, SSE, MMX nor x87 states, the GCC option -mgeneral-regs-only should be used to compile interrupt and exception handlers.
Any interruptible-without-stack-switch code must be compiled with -mno-red-zone since interrupt handlers can and will, because of the hardware design, touch the red zone.
An interrupt handler must be declared with a mandatory pointer argument:
struct interrupt_frame; __attribute__ ((interrupt)) void f (struct interrupt_frame *frame) { }
and you must define struct interrupt_frame
as described in the processor’s manual.
Exception handlers differ from interrupt handlers because the system pushes an error code on the stack. An exception handler declaration is similar to that for an interrupt handler, but with a different mandatory function signature. The compiler arranges to pop the error code off the stack before the IRET
instruction.
#ifdef __x86_64__ typedef unsigned long long int uword_t; #else typedef unsigned int uword_t; #endif struct interrupt_frame; __attribute__ ((interrupt)) void f (struct interrupt_frame *frame, uword_t error_code) { ... }
Exception handlers should only be used for exceptions that push an error code; you should use an interrupt handler in other cases. The system will crash if the wrong kind of handler is used.
target (options)
As discussed in Common Function Attributes, this attribute allows specification of target-specific compilation options.
On the x86, the following options are allowed:
Enable/disable the generation of the advanced bit instructions.
Enable/disable the generation of the AES instructions.
See Function Multiversioning, where it is used to specify the default function version.
Enable/disable the generation of the MMX instructions.
Enable/disable the generation of the PCLMUL instructions.
Enable/disable the generation of the POPCNT instruction.
Enable/disable the generation of the SSE instructions.
Enable/disable the generation of the SSE2 instructions.
Enable/disable the generation of the SSE3 instructions.
Enable/disable the generation of the SSE4 instructions (both SSE4.1 and SSE4.2).
Enable/disable the generation of the sse4.1 instructions.
Enable/disable the generation of the sse4.2 instructions.
Enable/disable the generation of the SSE4A instructions.
Enable/disable the generation of the FMA4 instructions.
Enable/disable the generation of the XOP instructions.
Enable/disable the generation of the LWP instructions.
Enable/disable the generation of the SSSE3 instructions.
Enable/disable the generation of the CLD before string moves.
Enable/disable the generation of the sin
, cos
, and sqrt
instructions on the 387 floating-point unit.
Enable/disable the generation of floating point that depends on IEEE arithmetic.
Enable/disable inlining of string operations.
Enable/disable the generation of the inline code to do small string operations and calling the library routines for large operations.
Do/do not align destination of inlined string operations.
Enable/disable the generation of RCPSS, RCPPS, RSQRTSS and RSQRTPS instructions followed an additional Newton-Raphson step instead of doing a floating-point division.
Specify the architecture to generate code for in compiling the function.
Specify the architecture to tune for in compiling the function.
Specify which floating-point unit to use. You must specify the target("fpmath=sse,387")
option as target("fpmath=sse+387")
because the comma would separate different options.
On the x86, the inliner does not inline a function that has different target options than the caller, unless the callee has a subset of the target options of the caller. For example a function declared with target("sse3")
can inline a function with target("sse2")
, since -msse3
implies -msse2
.
Next: Xstormy16 Function Attributes, Previous: Visium Function Attributes, Up: Function Attributes [Contents][Index]
© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/x86-Function-Attributes.html