ax_gcc_func_attribute.m4 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. # ===========================================================================
  2. # http://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. # flatten
  42. # format
  43. # format_arg
  44. # gnu_inline
  45. # hot
  46. # ifunc
  47. # leaf
  48. # malloc
  49. # noclone
  50. # noinline
  51. # nonnull
  52. # noreturn
  53. # nothrow
  54. # optimize
  55. # pure
  56. # unused
  57. # used
  58. # visibility
  59. # warning
  60. # warn_unused_result
  61. # weak
  62. # weakref
  63. #
  64. # Unsupported function attributes will be tested with a prototype returning
  65. # an int and not accepting any arguments and the result of the check might
  66. # be wrong or meaningless so use with care.
  67. #
  68. # LICENSE
  69. #
  70. # Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com>
  71. #
  72. # SPDX-License-Identifier: FSFAP
  73. #serial 4
  74. AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [
  75. AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1])
  76. AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [
  77. AC_LINK_IFELSE([AC_LANG_PROGRAM([
  78. m4_case([$1],
  79. [alias], [
  80. int foo( void ) { return 0; }
  81. int bar( void ) __attribute__(($1("foo")));
  82. ],
  83. [aligned], [
  84. int foo( void ) __attribute__(($1(32)));
  85. ],
  86. [alloc_size], [
  87. void *foo(int a) __attribute__(($1(1)));
  88. ],
  89. [always_inline], [
  90. inline __attribute__(($1)) int foo( void ) { return 0; }
  91. ],
  92. [artificial], [
  93. inline __attribute__(($1)) int foo( void ) { return 0; }
  94. ],
  95. [cold], [
  96. int foo( void ) __attribute__(($1));
  97. ],
  98. [const], [
  99. int foo( void ) __attribute__(($1));
  100. ],
  101. [constructor_priority], [
  102. int foo( void ) __attribute__((__constructor__(65535/2)));
  103. ],
  104. [constructor], [
  105. int foo( void ) __attribute__(($1));
  106. ],
  107. [deprecated], [
  108. int foo( void ) __attribute__(($1("")));
  109. ],
  110. [destructor], [
  111. int foo( void ) __attribute__(($1));
  112. ],
  113. [dllexport], [
  114. __attribute__(($1)) int foo( void ) { return 0; }
  115. ],
  116. [dllimport], [
  117. int foo( void ) __attribute__(($1));
  118. ],
  119. [error], [
  120. int foo( void ) __attribute__(($1("")));
  121. ],
  122. [externally_visible], [
  123. int foo( void ) __attribute__(($1));
  124. ],
  125. [flatten], [
  126. int foo( void ) __attribute__(($1));
  127. ],
  128. [format], [
  129. int foo(const char *p, ...) __attribute__(($1(printf, 1, 2)));
  130. ],
  131. [format_arg], [
  132. char *foo(const char *p) __attribute__(($1(1)));
  133. ],
  134. [gnu_inline], [
  135. inline __attribute__(($1)) int foo( void ) { return 0; }
  136. ],
  137. [hot], [
  138. int foo( void ) __attribute__(($1));
  139. ],
  140. [ifunc], [
  141. int my_foo( void ) { return 0; }
  142. static int (*resolve_foo(void))(void) { return my_foo; }
  143. int foo( void ) __attribute__(($1("resolve_foo")));
  144. ],
  145. [leaf], [
  146. __attribute__(($1)) int foo( void ) { return 0; }
  147. ],
  148. [malloc], [
  149. void *foo( void ) __attribute__(($1));
  150. ],
  151. [noclone], [
  152. int foo( void ) __attribute__(($1));
  153. ],
  154. [noinline], [
  155. __attribute__(($1)) int foo( void ) { return 0; }
  156. ],
  157. [nonnull], [
  158. int foo(char *p) __attribute__(($1(1)));
  159. ],
  160. [noreturn], [
  161. void foo( void ) __attribute__(($1));
  162. ],
  163. [nothrow], [
  164. int foo( void ) __attribute__(($1));
  165. ],
  166. [optimize], [
  167. __attribute__(($1(3))) int foo( void ) { return 0; }
  168. ],
  169. [pure], [
  170. int foo( void ) __attribute__(($1));
  171. ],
  172. [returns_nonnull], [
  173. void *foo( void ) __attribute__(($1));
  174. ],
  175. [unused], [
  176. int foo( void ) __attribute__(($1));
  177. ],
  178. [used], [
  179. int foo( void ) __attribute__(($1));
  180. ],
  181. [visibility], [
  182. int foo_def( void ) __attribute__(($1("default")));
  183. int foo_hid( void ) __attribute__(($1("hidden")));
  184. int foo_int( void ) __attribute__(($1("internal")));
  185. int foo_pro( void ) __attribute__(($1("protected")));
  186. ],
  187. [warning], [
  188. int foo( void ) __attribute__(($1("")));
  189. ],
  190. [warn_unused_result], [
  191. int foo( void ) __attribute__(($1));
  192. ],
  193. [weak], [
  194. int foo( void ) __attribute__(($1));
  195. ],
  196. [weakref], [
  197. static int foo( void ) { return 0; }
  198. static int bar( void ) __attribute__(($1("foo")));
  199. ],
  200. [
  201. m4_warn([syntax], [Unsupported attribute $1, the test may fail])
  202. int foo( void ) __attribute__(($1));
  203. ]
  204. )], [])
  205. ],
  206. dnl GCC doesn't exit with an error if an unknown attribute is
  207. dnl provided but only outputs a warning, so accept the attribute
  208. dnl only if no warning were issued.
  209. [AS_IF([test -s conftest.err],
  210. [AS_VAR_SET([ac_var], [no])],
  211. [AS_VAR_SET([ac_var], [yes])])],
  212. [AS_VAR_SET([ac_var], [no])])
  213. ])
  214. AS_IF([test yes = AS_VAR_GET([ac_var])],
  215. [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1,
  216. [Define to 1 if the system has the `$1' function attribute])], [])
  217. AS_VAR_POPDEF([ac_var])
  218. ])