gcc: x86 Function Attributes

1 
1 6.31.33 x86 Function Attributes
1 -------------------------------
1 
1 These function attributes are supported by the x86 back end:
1 
1 'cdecl'
1      On the x86-32 targets, the 'cdecl' attribute causes the compiler to
1      assume that the calling function pops off the stack space used to
1      pass arguments.  This is useful to override the effects of the
1      '-mrtd' switch.
1 
1 'fastcall'
1      On x86-32 targets, the 'fastcall' attribute causes the compiler to
1      pass the first argument (if of integral type) in the register ECX
1      and the second argument (if of integral type) in the register EDX.
1      Subsequent and other typed arguments are passed on the stack.  The
1      called function pops the arguments off the stack.  If the number of
1      arguments is variable all arguments are pushed on the stack.
1 
1 'thiscall'
1      On x86-32 targets, the 'thiscall' attribute causes the compiler to
1      pass the first argument (if of integral type) in the register ECX.
1      Subsequent and other typed arguments are passed on the stack.  The
1      called function pops the arguments off the stack.  If the number of
1      arguments is variable all arguments are pushed on the stack.  The
1      'thiscall' attribute is intended for C++ non-static member
1      functions.  As a GCC extension, this calling convention can be used
1      for C functions and for static member methods.
1 
1 'ms_abi'
1 'sysv_abi'
1 
1      On 32-bit and 64-bit x86 targets, you can use an ABI attribute to
1      indicate which calling convention should be used for a function.
1      The 'ms_abi' attribute tells the compiler to use the Microsoft ABI,
1      while the 'sysv_abi' attribute tells the compiler to use the ABI
1      used on GNU/Linux and other systems.  The default is to use the
1      Microsoft ABI when targeting Windows.  On all other systems, the
1      default is the x86/AMD ABI.
1 
1      Note, the 'ms_abi' attribute for Microsoft Windows 64-bit targets
1      currently requires the '-maccumulate-outgoing-args' option.
1 
1 'callee_pop_aggregate_return (NUMBER)'
1 
1      On x86-32 targets, you can use this attribute to control how
1      aggregates are returned in memory.  If the caller is responsible
1      for popping the hidden pointer together with the rest of the
1      arguments, specify NUMBER equal to zero.  If callee is responsible
1      for popping the hidden pointer, specify NUMBER equal to one.
1 
1      The default x86-32 ABI assumes that the callee pops the stack for
1      hidden pointer.  However, on x86-32 Microsoft Windows targets, the
1      compiler assumes that the caller pops the stack for hidden pointer.
1 
1 'ms_hook_prologue'
1 
1      On 32-bit and 64-bit x86 targets, you can use this function
1      attribute to make GCC generate the "hot-patching" function prologue
1      used in Win32 API functions in Microsoft Windows XP Service Pack 2
1      and newer.
1 
1 'naked'
1      This attribute allows the compiler to construct the requisite
1      function declaration, while allowing the body of the function to be
1      assembly code.  The specified function will not have
1      prologue/epilogue sequences generated by the compiler.  Only basic
11      'asm' statements can safely be included in naked functions (⇒
      Basic Asm).  While using extended 'asm' or a mixture of basic
1      'asm' and C code may appear to work, they cannot be depended upon
1      to work reliably and are not supported.
1 
1 'regparm (NUMBER)'
1      On x86-32 targets, the 'regparm' attribute causes the compiler to
1      pass arguments number one to NUMBER if they are of integral type in
1      registers EAX, EDX, and ECX instead of on the stack.  Functions
1      that take a variable number of arguments continue to be passed all
1      of their arguments on the stack.
1 
1      Beware that on some ELF systems this attribute is unsuitable for
1      global functions in shared libraries with lazy binding (which is
1      the default).  Lazy binding sends the first call via resolving code
1      in the loader, which might assume EAX, EDX and ECX can be
1      clobbered, as per the standard calling conventions.  Solaris 8 is
1      affected by this.  Systems with the GNU C Library version 2.1 or
1      higher and FreeBSD are believed to be safe since the loaders there
1      save EAX, EDX and ECX. (Lazy binding can be disabled with the
1      linker or the loader if desired, to avoid the problem.)
1 
1 'sseregparm'
1      On x86-32 targets with SSE support, the 'sseregparm' attribute
1      causes the compiler to pass up to 3 floating-point arguments in SSE
1      registers instead of on the stack.  Functions that take a variable
1      number of arguments continue to pass all of their floating-point
1      arguments on the stack.
1 
1 'force_align_arg_pointer'
1      On x86 targets, the 'force_align_arg_pointer' attribute may be
1      applied to individual function definitions, generating an alternate
1      prologue and epilogue that realigns the run-time stack if
1      necessary.  This supports mixing legacy codes that run with a
1      4-byte aligned stack with modern codes that keep a 16-byte stack
1      for SSE compatibility.
1 
1 'stdcall'
1      On x86-32 targets, the 'stdcall' attribute causes the compiler to
1      assume that the called function pops off the stack space used to
1      pass arguments, unless it takes a variable number of arguments.
1 
1 'no_caller_saved_registers'
1      Use this attribute to indicate that the specified function has no
1      caller-saved registers.  That is, all registers are callee-saved.
1      For example, this attribute can be used for a function called from
1      an interrupt handler.  The compiler generates proper function entry
1      and exit sequences to save and restore any modified registers,
1      except for the EFLAGS register.  Since GCC doesn't preserve MPX,
1      SSE, MMX nor x87 states, the GCC option '-mgeneral-regs-only'
1      should be used to compile functions with
1      'no_caller_saved_registers' attribute.
1 
1 'interrupt'
1      Use this attribute to indicate that the specified function is an
1      interrupt handler or an exception handler (depending on parameters
1      passed to the function, explained further).  The compiler generates
1      function entry and exit sequences suitable for use in an interrupt
1      handler when this attribute is present.  The 'IRET' instruction,
1      instead of the 'RET' instruction, is used to return from interrupt
1      handlers.  All registers, except for the EFLAGS register which is
1      restored by the 'IRET' instruction, are preserved by the compiler.
1      Since GCC doesn't preserve MPX, SSE, MMX nor x87 states, the GCC
1      option '-mgeneral-regs-only' should be used to compile interrupt
1      and exception handlers.
1 
1      Any interruptible-without-stack-switch code must be compiled with
1      '-mno-red-zone' since interrupt handlers can and will, because of
1      the hardware design, touch the red zone.
1 
1      An interrupt handler must be declared with a mandatory pointer
1      argument:
1 
1           struct interrupt_frame;
1 
1           __attribute__ ((interrupt))
1           void
1           f (struct interrupt_frame *frame)
1           {
1           }
1 
1      and you must define 'struct interrupt_frame' as described in the
1      processor's manual.
1 
1      Exception handlers differ from interrupt handlers because the
1      system pushes an error code on the stack.  An exception handler
1      declaration is similar to that for an interrupt handler, but with a
1      different mandatory function signature.  The compiler arranges to
1      pop the error code off the stack before the 'IRET' instruction.
1 
1           #ifdef __x86_64__
1           typedef unsigned long long int uword_t;
1           #else
1           typedef unsigned int uword_t;
1           #endif
1 
1           struct interrupt_frame;
1 
1           __attribute__ ((interrupt))
1           void
1           f (struct interrupt_frame *frame, uword_t error_code)
1           {
1             ...
1           }
1 
1      Exception handlers should only be used for exceptions that push an
1      error code; you should use an interrupt handler in other cases.
1      The system will crash if the wrong kind of handler is used.
1 
1 'target (OPTIONS)'
1      As discussed in ⇒Common Function Attributes, this attribute
1      allows specification of target-specific compilation options.
1 
1      On the x86, the following options are allowed:
1      '3dnow'
1      'no-3dnow'
1           Enable/disable the generation of the 3DNow! instructions.
1 
1      '3dnowa'
1      'no-3dnowa'
1           Enable/disable the generation of the enhanced 3DNow!
1           instructions.
1 
1      'abm'
1      'no-abm'
1           Enable/disable the generation of the advanced bit
1           instructions.
1 
1      'adx'
1      'no-adx'
1           Enable/disable the generation of the ADX instructions.
1 
1      'aes'
1      'no-aes'
1           Enable/disable the generation of the AES instructions.
1 
1      'avx'
1      'no-avx'
1           Enable/disable the generation of the AVX instructions.
1 
1      'avx2'
1      'no-avx2'
1           Enable/disable the generation of the AVX2 instructions.
1 
1      'avx5124fmaps'
1      'no-avx5124fmaps'
1           Enable/disable the generation of the AVX5124FMAPS
1           instructions.
1 
1      'avx5124vnniw'
1      'no-avx5124vnniw'
1           Enable/disable the generation of the AVX5124VNNIW
1           instructions.
1 
1      'avx512bitalg'
1      'no-avx512bitalg'
1           Enable/disable the generation of the AVX512BITALG
1           instructions.
1 
1      'avx512bw'
1      'no-avx512bw'
1           Enable/disable the generation of the AVX512BW instructions.
1 
1      'avx512cd'
1      'no-avx512cd'
1           Enable/disable the generation of the AVX512CD instructions.
1 
1      'avx512dq'
1      'no-avx512dq'
1           Enable/disable the generation of the AVX512DQ instructions.
1 
1      'avx512er'
1      'no-avx512er'
1           Enable/disable the generation of the AVX512ER instructions.
1 
1      'avx512f'
1      'no-avx512f'
1           Enable/disable the generation of the AVX512F instructions.
1 
1      'avx512ifma'
1      'no-avx512ifma'
1           Enable/disable the generation of the AVX512IFMA instructions.
1 
1      'avx512pf'
1      'no-avx512pf'
1           Enable/disable the generation of the AVX512PF instructions.
1 
1      'avx512vbmi'
1      'no-avx512vbmi'
1           Enable/disable the generation of the AVX512VBMI instructions.
1 
1      'avx512vbmi2'
1      'no-avx512vbmi2'
1           Enable/disable the generation of the AVX512VBMI2 instructions.
1 
1      'avx512vl'
1      'no-avx512vl'
1           Enable/disable the generation of the AVX512VL instructions.
1 
1      'avx512vnni'
1      'no-avx512vnni'
1           Enable/disable the generation of the AVX512VNNI instructions.
1 
1      'avx512vpopcntdq'
1      'no-avx512vpopcntdq'
1           Enable/disable the generation of the AVX512VPOPCNTDQ
1           instructions.
1 
1      'bmi'
1      'no-bmi'
1           Enable/disable the generation of the BMI instructions.
1 
1      'bmi2'
1      'no-bmi2'
1           Enable/disable the generation of the BMI2 instructions.
1 
1      'clflushopt'
1      'no-clflushopt'
1           Enable/disable the generation of the CLFLUSHOPT instructions.
1 
1      'clwb'
1      'no-clwb'
1           Enable/disable the generation of the CLWB instructions.
1 
1      'clzero'
1      'no-clzero'
1           Enable/disable the generation of the CLZERO instructions.
1 
1      'crc32'
1      'no-crc32'
1           Enable/disable the generation of the CRC32 instructions.
1 
1      'cx16'
1      'no-cx16'
1           Enable/disable the generation of the CMPXCHG16B instructions.
1 
1      'default'
1           ⇒Function Multiversioning, where it is used to specify
1           the default function version.
1 
1      'f16c'
1      'no-f16c'
1           Enable/disable the generation of the F16C instructions.
1 
1      'fma'
1      'no-fma'
1           Enable/disable the generation of the FMA instructions.
1 
1      'fma4'
1      'no-fma4'
1           Enable/disable the generation of the FMA4 instructions.
1 
1      'fsgsbase'
1      'no-fsgsbase'
1           Enable/disable the generation of the FSGSBASE instructions.
1 
1      'fxsr'
1      'no-fxsr'
1           Enable/disable the generation of the FXSR instructions.
1 
1      'gfni'
1      'no-gfni'
1           Enable/disable the generation of the GFNI instructions.
1 
1      'hle'
1      'no-hle'
1           Enable/disable the generation of the HLE instruction prefixes.
1 
1      'lwp'
1      'no-lwp'
1           Enable/disable the generation of the LWP instructions.
1 
1      'lzcnt'
1      'no-lzcnt'
1           Enable/disable the generation of the LZCNT instructions.
1 
1      'mmx'
1      'no-mmx'
1           Enable/disable the generation of the MMX instructions.
1 
1      'movbe'
1      'no-movbe'
1           Enable/disable the generation of the MOVBE instructions.
1 
1      'movdir64b'
1      'no-movdir64b'
1           Enable/disable the generation of the MOVDIR64B instructions.
1 
1      'movdiri'
1      'no-movdiri'
1           Enable/disable the generation of the MOVDIRI instructions.
1 
1      'mwaitx'
1      'no-mwaitx'
1           Enable/disable the generation of the MWAITX instructions.
1 
1      'pclmul'
1      'no-pclmul'
1           Enable/disable the generation of the PCLMUL instructions.
1 
1      'pconfig'
1      'no-pconfig'
1           Enable/disable the generation of the PCONFIG instructions.
1 
1      'pku'
1      'no-pku'
1           Enable/disable the generation of the PKU instructions.
1 
1      'popcnt'
1      'no-popcnt'
1           Enable/disable the generation of the POPCNT instruction.
1 
1      'prefetchwt1'
1      'no-prefetchwt1'
1           Enable/disable the generation of the PREFETCHWT1 instructions.
1 
1      'prfchw'
1      'no-prfchw'
1           Enable/disable the generation of the PREFETCHW instruction.
1 
1      'rdpid'
1      'no-rdpid'
1           Enable/disable the generation of the RDPID instructions.
1 
1      'rdrnd'
1      'no-rdrnd'
1           Enable/disable the generation of the RDRND instructions.
1 
1      'rdseed'
1      'no-rdseed'
1           Enable/disable the generation of the RDSEED instructions.
1 
1      'rtm'
1      'no-rtm'
1           Enable/disable the generation of the RTM instructions.
1 
1      'sahf'
1      'no-sahf'
1           Enable/disable the generation of the SAHF instructions.
1 
1      'sgx'
1      'no-sgx'
1           Enable/disable the generation of the SGX instructions.
1 
1      'sha'
1      'no-sha'
1           Enable/disable the generation of the SHA instructions.
1 
1      'shstk'
1      'no-shstk'
1           Enable/disable the shadow stack built-in functions from CET.
1 
1      'sse'
1      'no-sse'
1           Enable/disable the generation of the SSE instructions.
1 
1      'sse2'
1      'no-sse2'
1           Enable/disable the generation of the SSE2 instructions.
1 
1      'sse3'
1      'no-sse3'
1           Enable/disable the generation of the SSE3 instructions.
1 
1      'sse4'
1      'no-sse4'
1           Enable/disable the generation of the SSE4 instructions (both
1           SSE4.1 and SSE4.2).
1 
1      'sse4.1'
1      'no-sse4.1'
1           Enable/disable the generation of the sse4.1 instructions.
1 
1      'sse4.2'
1      'no-sse4.2'
1           Enable/disable the generation of the sse4.2 instructions.
1 
1      'sse4a'
1      'no-sse4a'
1           Enable/disable the generation of the SSE4A instructions.
1 
1      'ssse3'
1      'no-ssse3'
1           Enable/disable the generation of the SSSE3 instructions.
1 
1      'tbm'
1      'no-tbm'
1           Enable/disable the generation of the TBM instructions.
1 
1      'vaes'
1      'no-vaes'
1           Enable/disable the generation of the VAES instructions.
1 
1      'vpclmulqdq'
1      'no-vpclmulqdq'
1           Enable/disable the generation of the VPCLMULQDQ instructions.
1 
1      'wbnoinvd'
1      'no-wbnoinvd'
1           Enable/disable the generation of the WBNOINVD instructions.
1 
1      'xop'
1      'no-xop'
1           Enable/disable the generation of the XOP instructions.
1 
1      'xsave'
1      'no-xsave'
1           Enable/disable the generation of the XSAVE instructions.
1 
1      'xsavec'
1      'no-xsavec'
1           Enable/disable the generation of the XSAVEC instructions.
1 
1      'xsaveopt'
1      'no-xsaveopt'
1           Enable/disable the generation of the XSAVEOPT instructions.
1 
1      'xsaves'
1      'no-xsaves'
1           Enable/disable the generation of the XSAVES instructions.
1 
1      'cld'
1      'no-cld'
1           Enable/disable the generation of the CLD before string moves.
1 
1      'fancy-math-387'
1      'no-fancy-math-387'
1           Enable/disable the generation of the 'sin', 'cos', and 'sqrt'
1           instructions on the 387 floating-point unit.
1 
1      'ieee-fp'
1      'no-ieee-fp'
1           Enable/disable the generation of floating point that depends
1           on IEEE arithmetic.
1 
1      'inline-all-stringops'
1      'no-inline-all-stringops'
1           Enable/disable inlining of string operations.
1 
1      'inline-stringops-dynamically'
1      'no-inline-stringops-dynamically'
1           Enable/disable the generation of the inline code to do small
1           string operations and calling the library routines for large
1           operations.
1 
1      'align-stringops'
1      'no-align-stringops'
1           Do/do not align destination of inlined string operations.
1 
1      'recip'
1      'no-recip'
1           Enable/disable the generation of RCPSS, RCPPS, RSQRTSS and
1           RSQRTPS instructions followed an additional Newton-Raphson
1           step instead of doing a floating-point division.
1 
1      'arch=ARCH'
1           Specify the architecture to generate code for in compiling the
1           function.
1 
1      'tune=TUNE'
1           Specify the architecture to tune for in compiling the
1           function.
1 
1      'fpmath=FPMATH'
1           Specify which floating-point unit to use.  You must specify
1           the 'target("fpmath=sse,387")' option as
1           'target("fpmath=sse+387")' because the comma would separate
1           different options.
1 
1      'indirect_branch("CHOICE")'
1           On x86 targets, the 'indirect_branch' attribute causes the
1           compiler to convert indirect call and jump with CHOICE.
1           'keep' keeps indirect call and jump unmodified.  'thunk'
1           converts indirect call and jump to call and return thunk.
1           'thunk-inline' converts indirect call and jump to inlined call
1           and return thunk.  'thunk-extern' converts indirect call and
1           jump to external call and return thunk provided in a separate
1           object file.
1 
1      'function_return("CHOICE")'
1           On x86 targets, the 'function_return' attribute causes the
1           compiler to convert function return with CHOICE.  'keep' keeps
1           function return unmodified.  'thunk' converts function return
1           to call and return thunk.  'thunk-inline' converts function
1           return to inlined call and return thunk.  'thunk-extern'
1           converts function return to external call and return thunk
1           provided in a separate object file.
1 
1      'nocf_check'
1           The 'nocf_check' attribute on a function is used to inform the
1           compiler that the function's prologue should not be
1           instrumented when compiled with the '-fcf-protection=branch'
1           option.  The compiler assumes that the function's address is a
1           valid target for a control-flow transfer.
1 
1           The 'nocf_check' attribute on a type of pointer to function is
1           used to inform the compiler that a call through the pointer
1           should not be instrumented when compiled with the
1           '-fcf-protection=branch' option.  The compiler assumes that
1           the function's address from the pointer is a valid target for
1           a control-flow transfer.  A direct function call through a
1           function name is assumed to be a safe call thus direct calls
1           are not instrumented by the compiler.
1 
1           The 'nocf_check' attribute is applied to an object's type.  In
1           case of assignment of a function address or a function pointer
1           to another pointer, the attribute is not carried over from the
1           right-hand object's type; the type of left-hand object stays
1           unchanged.  The compiler checks for 'nocf_check' attribute
1           mismatch and reports a warning in case of mismatch.
1 
1                {
1                int foo (void) __attribute__(nocf_check);
1                void (*foo1)(void) __attribute__(nocf_check);
1                void (*foo2)(void);
1 
1                /* foo's address is assumed to be valid.  */
1                int
1                foo (void)
1 
1                  /* This call site is not checked for control-flow
1                     validity.  */
1                  (*foo1)();
1 
1                  /* A warning is issued about attribute mismatch.  */
1                  foo1 = foo2;
1 
1                  /* This call site is still not checked.  */
1                  (*foo1)();
1 
1                  /* This call site is checked.  */
1                  (*foo2)();
1 
1                  /* A warning is issued about attribute mismatch.  */
1                  foo2 = foo1;
1 
1                  /* This call site is still checked.  */
1                  (*foo2)();
1 
1                  return 0;
1                }
1 
1      On the x86, the inliner does not inline a function that has
1      different target options than the caller, unless the callee has a
1      subset of the target options of the caller.  For example a function
1      declared with 'target("sse3")' can inline a function with
1      'target("sse2")', since '-msse3' implies '-msse2'.
1