Skip to content

Commit f36a40f

Browse files
committed
build: check visibility attributes
1 parent 811a765 commit f36a40f

File tree

2 files changed

+223
-0
lines changed

2 files changed

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

configure.ac

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ fi
346346

347347
AX_CHECK_LINK_FLAG([[-Wl,--large-address-aware]], [LDFLAGS="$LDFLAGS -Wl,--large-address-aware"])
348348

349+
AX_GCC_FUNC_ATTRIBUTE([visibility])
350+
AX_GCC_FUNC_ATTRIBUTE([dllexport])
351+
AX_GCC_FUNC_ATTRIBUTE([dllimport])
352+
349353
if test x$use_glibc_compat != xno; then
350354

351355
#__fdelt_chk's params and return type have changed from long unsigned int to long int.

0 commit comments

Comments
 (0)