1# =========================================================================== 2# https://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html 3# =========================================================================== 4# 5# SYNOPSIS 6# 7# AX_GCC_FUNC_ATTRIBUTE(ATTRIBUTE) 8# 9# DESCRIPTION 10# 11# This macro checks if the compiler supports one of GCC's function 12# attributes; many other compilers also provide function attributes with 13# the same syntax. Compiler warnings are used to detect supported 14# attributes as unsupported ones are ignored by default so quieting 15# warnings when using this macro will yield false positives. 16# 17# The ATTRIBUTE parameter holds the name of the attribute to be checked. 18# 19# If ATTRIBUTE is supported define HAVE_FUNC_ATTRIBUTE_<ATTRIBUTE>. 20# 21# The macro caches its result in the ax_cv_have_func_attribute_<attribute> 22# variable. 23# 24# The macro currently supports the following function attributes: 25# 26# alias 27# aligned 28# alloc_size 29# always_inline 30# artificial 31# cold 32# const 33# constructor 34# constructor_priority for constructor attribute with priority 35# deprecated 36# destructor 37# dllexport 38# dllimport 39# error 40# externally_visible 41# fallthrough 42# flatten 43# format 44# format_arg 45# gnu_format 46# gnu_inline 47# hot 48# ifunc 49# leaf 50# malloc 51# noclone 52# noinline 53# nonnull 54# noreturn 55# nothrow 56# optimize 57# pure 58# sentinel 59# sentinel_position 60# unused 61# used 62# visibility 63# warning 64# warn_unused_result 65# weak 66# weakref 67# 68# Unsupported function attributes will be tested with a prototype 69# returning an int and not accepting any arguments and the result of the 70# check might be wrong or meaningless so use with care. 71# 72# LICENSE 73# 74# Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com> 75# 76# Copying and distribution of this file, with or without modification, are 77# permitted in any medium without royalty provided the copyright notice 78# and this notice are preserved. This file is offered as-is, without any 79# warranty. 80 81#serial 12 82 83AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [ 84 AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1]) 85 86 AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [ 87 AC_LINK_IFELSE([AC_LANG_PROGRAM([ 88 m4_case([$1], 89 [alias], [ 90 int foo( void ) { return 0; } 91 int bar( void ) __attribute__(($1("foo"))); 92 ], 93 [aligned], [ 94 int foo( void ) __attribute__(($1(32))); 95 ], 96 [alloc_size], [ 97 void *foo(int a) __attribute__(($1(1))); 98 ], 99 [always_inline], [ 100 inline __attribute__(($1)) int foo( void ) { return 0; } 101 ], 102 [artificial], [ 103 inline __attribute__(($1)) int foo( void ) { return 0; } 104 ], 105 [cold], [ 106 int foo( void ) __attribute__(($1)); 107 ], 108 [const], [ 109 int foo( void ) __attribute__(($1)); 110 ], 111 [constructor_priority], [ 112 int foo( void ) __attribute__((__constructor__(65535/2))); 113 ], 114 [constructor], [ 115 int foo( void ) __attribute__(($1)); 116 ], 117 [deprecated], [ 118 int foo( void ) __attribute__(($1(""))); 119 ], 120 [destructor], [ 121 int foo( void ) __attribute__(($1)); 122 ], 123 [dllexport], [ 124 __attribute__(($1)) int foo( void ) { return 0; } 125 ], 126 [dllimport], [ 127 int foo( void ) __attribute__(($1)); 128 ], 129 [error], [ 130 int foo( void ) __attribute__(($1(""))); 131 ], 132 [externally_visible], [ 133 int foo( void ) __attribute__(($1)); 134 ], 135 [fallthrough], [ 136 int foo( void ) {switch (0) { case 1: __attribute__(($1)); case 2: break ; }}; 137 ], 138 [flatten], [ 139 int foo( void ) __attribute__(($1)); 140 ], 141 [format], [ 142 int foo(const char *p, ...) __attribute__(($1(printf, 1, 2))); 143 ], 144 [gnu_format], [ 145 int foo(const char *p, ...) __attribute__((format(gnu_printf, 1, 2))); 146 ], 147 [format_arg], [ 148 char *foo(const char *p) __attribute__(($1(1))); 149 ], 150 [gnu_inline], [ 151 inline __attribute__(($1)) int foo( void ) { return 0; } 152 ], 153 [hot], [ 154 int foo( void ) __attribute__(($1)); 155 ], 156 [ifunc], [ 157 int my_foo( void ) { return 0; } 158 static int (*resolve_foo(void))(void) { return my_foo; } 159 int foo( void ) __attribute__(($1("resolve_foo"))); 160 ], 161 [leaf], [ 162 __attribute__(($1)) int foo( void ) { return 0; } 163 ], 164 [malloc], [ 165 void *foo( void ) __attribute__(($1)); 166 ], 167 [noclone], [ 168 int foo( void ) __attribute__(($1)); 169 ], 170 [noinline], [ 171 __attribute__(($1)) int foo( void ) { return 0; } 172 ], 173 [nonnull], [ 174 int foo(char *p) __attribute__(($1(1))); 175 ], 176 [noreturn], [ 177 void foo( void ) __attribute__(($1)); 178 ], 179 [nothrow], [ 180 int foo( void ) __attribute__(($1)); 181 ], 182 [optimize], [ 183 __attribute__(($1(3))) int foo( void ) { return 0; } 184 ], 185 [pure], [ 186 int foo( void ) __attribute__(($1)); 187 ], 188 [sentinel], [ 189 int foo(void *p, ...) __attribute__(($1)); 190 ], 191 [sentinel_position], [ 192 int foo(void *p, ...) __attribute__(($1(1))); 193 ], 194 [returns_nonnull], [ 195 void *foo( void ) __attribute__(($1)); 196 ], 197 [unused], [ 198 int foo( void ) __attribute__(($1)); 199 ], 200 [used], [ 201 int foo( void ) __attribute__(($1)); 202 ], 203 [visibility], [ 204 int foo_def( void ) __attribute__(($1("default"))); 205 int foo_hid( void ) __attribute__(($1("hidden"))); 206 int foo_int( void ) __attribute__(($1("internal"))); 207 int foo_pro( void ) __attribute__(($1("protected"))); 208 ], 209 [warning], [ 210 int foo( void ) __attribute__(($1(""))); 211 ], 212 [warn_unused_result], [ 213 int foo( void ) __attribute__(($1)); 214 ], 215 [weak], [ 216 int foo( void ) __attribute__(($1)); 217 ], 218 [weakref], [ 219 static int foo( void ) { return 0; } 220 static int bar( void ) __attribute__(($1("foo"))); 221 ], 222 [ 223 m4_warn([syntax], [Unsupported attribute $1, the test may fail]) 224 int foo( void ) __attribute__(($1)); 225 ] 226 )], []) 227 ], 228 dnl GCC doesn't exit with an error if an unknown attribute is 229 dnl provided but only outputs a warning, so accept the attribute 230 dnl only if no warning were issued. 231 [AS_IF([grep -- -Wattributes conftest.err], 232 [AS_VAR_SET([ac_var], [no])], 233 [AS_VAR_SET([ac_var], [yes])])], 234 [AS_VAR_SET([ac_var], [no])]) 235 ]) 236 237 AS_IF([test yes = AS_VAR_GET([ac_var])], 238 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1, 239 [Define to 1 if the system has the `$1' function attribute])], []) 240 241 AS_VAR_POPDEF([ac_var]) 242]) 243