]> git.pld-linux.org Git - packages/sudo.git/blob - ax_sys_weak_alias.m4
Version: sudo-1.8.13
[packages/sudo.git] / ax_sys_weak_alias.m4
1 # ===========================================================================
2 #     http://www.gnu.org/software/autoconf-archive/ax_sys_weak_alias.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 #   AX_SYS_WEAK_ALIAS
8 #
9 # DESCRIPTION
10 #
11 #   Determines whether weak aliases are supported on the system, and if so,
12 #   what scheme is used to declare them. Also checks to see if aliases can
13 #   cross object file boundaries, as some systems don't permit them to.
14 #
15 #   Most systems permit something called a "weak alias" or "weak symbol."
16 #   These aliases permit a library to provide a stub form of a routine
17 #   defined in another library, thus allowing the first library to operate
18 #   even if the other library is not linked. This macro will check for
19 #   support of weak aliases, figure out what schemes are available, and
20 #   determine some characteristics of the weak alias support -- primarily,
21 #   whether a weak alias declared in one object file may be referenced from
22 #   another object file.
23 #
24 #   There are four known schemes of declaring weak symbols; each scheme is
25 #   checked in turn, and the first one found is prefered. Note that only one
26 #   of the mentioned preprocessor macros will be defined!
27 #
28 #   1. #pragma weak
29 #
30 #   This scheme is in use by many compilers other than the GNU C compiler.
31 #   It is also particularly easy to use, and fairly portable -- well, as
32 #   portable as these things get. If this scheme is detected first, the
33 #   preprocessor macro HAVE_SYS_WEAK_ALIAS_PRAGMA will be defined to 1. This
34 #   scheme is used as in the following code fragment:
35 #
36 #     extern void weakf(int c);
37 #     #pragma weak weakf = __weakf
38 #     void __weakf(int c)
39 #     {
40 #       /* Function definition... */
41 #     }
42 #
43 #   2. #pragma _HP_SECONDARY_DEF
44 #
45 #   This scheme appears to be in use by the HP compiler. As it is rather
46 #   specialized, this is one of the last schemes checked. If it is the first
47 #   one detected, the preprocessor macro HAVE_SYS_WEAK_ALIAS_HPSECONDARY
48 #   will be defined to 1. This scheme is used as in the following code
49 #   fragment:
50 #
51 #     extern void weakf(int c);
52 #     #pragma _HP_SECONDARY_DEF __weakf weakf
53 #     void __weakf(int c)
54 #     {
55 #       /* Function definition... */
56 #     }
57 #
58 #   3. #pragma _CRI duplicate
59 #
60 #   This scheme appears to be in use by the Cray compiler. As it is rather
61 #   specialized, it too is one of the last schemes checked. If it is the
62 #   first one detected, the preprocessor macro
63 #   HAVE_SYS_WEAK_ALIAS_CRIDUPLICATE will be defined to 1. This scheme is
64 #   used as in the following code fragment:
65 #
66 #     extern void weakf(int c);
67 #     #pragma _CRI duplicate weakf as __weakf
68 #     void __weakf(int c)
69 #     {
70 #       /* Function definition... */
71 #     }
72 #
73 #   4. Function attributes
74 #
75 #   This scheme was first introduced by the GNU C compiler, and attaches
76 #   attributes to particular functions. However, since some compilers
77 #   simply ignore unsupported attributes, this scheme is tried last.
78 #   If this scheme is detected, the preprocessor macro
79 #   HAVE_SYS_WEAK_ALIAS_ATTRIBUTE will be defined to 1.
80 #   This scheme is used as in the following code fragment:
81 #
82 #     void __weakf(int c)
83 #     {
84 #       /* Function definition... */
85 #     }
86 #
87 #     void weakf(int c) __attribute__((weak, alias("__weakf")));
88 #
89 #   In addition to the preprocessor macros listed above, if any scheme is
90 #   found, the preprocessor macro HAVE_SYS_WEAK_ALIAS will also be defined
91 #   to 1.
92 #
93 #   Once a weak aliasing scheme has been found, a check will be performed to
94 #   see if weak aliases are honored across object file boundaries. If they
95 #   are, the HAVE_SYS_WEAK_ALIAS_CROSSFILE preprocessor macro is defined to
96 #   1.
97 #
98 #   This Autoconf macro also makes two substitutions. The first, WEAK_ALIAS,
99 #   contains the name of the scheme found (one of "attribute", "pragma",
100 #   "hpsecondary", or "criduplicate"), or "no" if no weak aliasing scheme
101 #   was found. The second, WEAK_ALIAS_CROSSFILE, is set to "yes" or "no"
102 #   depending on whether or not weak aliases may cross object file
103 #   boundaries.
104 #
105 # LICENSE
106 #
107 #   Copyright (c) 2008 Kevin L. Mitchell <klmitch@mit.edu>
108 #
109 #   Copying and distribution of this file, with or without modification, are
110 #   permitted in any medium without royalty provided the copyright notice
111 #   and this notice are preserved. This file is offered as-is, without any
112 #   warranty.
113
114 #serial 6
115
116 AU_ALIAS([KLM_SYS_WEAK_ALIAS], [AX_SYS_WEAK_ALIAS])
117 AC_DEFUN([AX_SYS_WEAK_ALIAS], [
118   # starting point: no aliasing scheme yet...
119   ax_sys_weak_alias=no
120
121   # Figure out what kind of aliasing may be supported...
122   _AX_SYS_WEAK_ALIAS_PRAGMA
123   _AX_SYS_WEAK_ALIAS_HPSECONDARY
124   _AX_SYS_WEAK_ALIAS_CRIDUPLICATE
125   _AX_SYS_WEAK_ALIAS_ATTRIBUTE
126
127   # Do we actually support aliasing?
128   AC_CACHE_CHECK([how to create weak aliases with $CC],
129                  [ax_cv_sys_weak_alias],
130                  [ax_cv_sys_weak_alias=$ax_sys_weak_alias])
131
132   # OK, set a #define
133   AS_IF([test $ax_cv_sys_weak_alias != no], [
134     AC_DEFINE([HAVE_SYS_WEAK_ALIAS], 1,
135               [Define this if your system can create weak aliases])
136   ])
137
138   # Can aliases cross object file boundaries?
139   _AX_SYS_WEAK_ALIAS_CROSSFILE
140
141   # OK, remember the results
142   AC_SUBST([WEAK_ALIAS], [$ax_cv_sys_weak_alias])
143   AC_SUBST([WEAK_ALIAS_CROSSFILE], [$ax_cv_sys_weak_alias_crossfile])
144 ])
145
146 AC_DEFUN([_AX_SYS_WEAK_ALIAS_ATTRIBUTE],
147 [ # Test whether compiler accepts __attribute__ form of weak aliasing
148   AC_CACHE_CHECK([whether $CC accepts function __attribute__((weak,alias()))],
149   [ax_cv_sys_weak_alias_attribute], [
150     # We add -Werror if it's gcc to force an error exit if the weak attribute
151     # isn't understood
152     AS_IF([test $GCC = yes], [
153       save_CFLAGS=$CFLAGS
154       CFLAGS=-Werror])
155
156     # Try linking with a weak alias...
157     AC_LINK_IFELSE([
158       AC_LANG_PROGRAM([
159 void __weakf(int c) {}
160 void weakf(int c) __attribute__((weak, alias("__weakf")));],
161         [weakf(0)])],
162       [ax_cv_sys_weak_alias_attribute=yes],
163       [ax_cv_sys_weak_alias_attribute=no])
164
165     # Restore original CFLAGS
166     AS_IF([test $GCC = yes], [
167       CFLAGS=$save_CFLAGS])
168   ])
169
170   # What was the result of the test?
171   AS_IF([test $ax_sys_weak_alias = no &&
172          test $ax_cv_sys_weak_alias_attribute = yes], [
173     ax_sys_weak_alias=attribute
174     AC_DEFINE([HAVE_SYS_WEAK_ALIAS_ATTRIBUTE], 1,
175               [Define this if weak aliases may be created with __attribute__])
176   ])
177 ])
178
179 AC_DEFUN([_AX_SYS_WEAK_ALIAS_PRAGMA],
180 [ # Test whether compiler accepts #pragma form of weak aliasing
181   AC_CACHE_CHECK([whether $CC supports @%:@pragma weak],
182   [ax_cv_sys_weak_alias_pragma], [
183
184     # Try linking with a weak alias...
185     AC_LINK_IFELSE([
186       AC_LANG_PROGRAM([
187 extern void weakf(int c);
188 @%:@pragma weak weakf = __weakf
189 void __weakf(int c) {}],
190         [weakf(0)])],
191       [ax_cv_sys_weak_alias_pragma=yes],
192       [ax_cv_sys_weak_alias_pragma=no])
193   ])
194
195   # What was the result of the test?
196   AS_IF([test $ax_sys_weak_alias = no &&
197          test $ax_cv_sys_weak_alias_pragma = yes], [
198     ax_sys_weak_alias=pragma
199     AC_DEFINE([HAVE_SYS_WEAK_ALIAS_PRAGMA], 1,
200               [Define this if weak aliases may be created with @%:@pragma weak])
201   ])
202 ])
203
204 AC_DEFUN([_AX_SYS_WEAK_ALIAS_HPSECONDARY],
205 [ # Test whether compiler accepts _HP_SECONDARY_DEF pragma from HP...
206   AC_CACHE_CHECK([whether $CC supports @%:@pragma _HP_SECONDARY_DEF],
207   [ax_cv_sys_weak_alias_hpsecondary], [
208
209     # Try linking with a weak alias...
210     AC_LINK_IFELSE([
211       AC_LANG_PROGRAM([
212 extern void weakf(int c);
213 @%:@pragma _HP_SECONDARY_DEF __weakf weakf
214 void __weakf(int c) {}],
215         [weakf(0)])],
216       [ax_cv_sys_weak_alias_hpsecondary=yes],
217       [ax_cv_sys_weak_alias_hpsecondary=no])
218   ])
219
220   # What was the result of the test?
221   AS_IF([test $ax_sys_weak_alias = no &&
222          test $ax_cv_sys_weak_alias_hpsecondary = yes], [
223     ax_sys_weak_alias=hpsecondary
224     AC_DEFINE([HAVE_SYS_WEAK_ALIAS_HPSECONDARY], 1,
225               [Define this if weak aliases may be created with @%:@pragma _HP_SECONDARY_DEF])
226   ])
227 ])
228
229 AC_DEFUN([_AX_SYS_WEAK_ALIAS_CRIDUPLICATE],
230 [ # Test whether compiler accepts "_CRI duplicate" pragma from Cray
231   AC_CACHE_CHECK([whether $CC supports @%:@pragma _CRI duplicate],
232   [ax_cv_sys_weak_alias_criduplicate], [
233
234     # Try linking with a weak alias...
235     AC_LINK_IFELSE([
236       AC_LANG_PROGRAM([
237 extern void weakf(int c);
238 @%:@pragma _CRI duplicate weakf as __weakf
239 void __weakf(int c) {}],
240         [weakf(0)])],
241       [ax_cv_sys_weak_alias_criduplicate=yes],
242       [ax_cv_sys_weak_alias_criduplicate=no])
243   ])
244
245   # What was the result of the test?
246   AS_IF([test $ax_sys_weak_alias = no &&
247          test $ax_cv_sys_weak_alias_criduplicate = yes], [
248     ax_sys_weak_alias=criduplicate
249     AC_DEFINE([HAVE_SYS_WEAK_ALIAS_CRIDUPLICATE], 1,
250               [Define this if weak aliases may be created with @%:@pragma _CRI duplicate])
251   ])
252 ])
253
254 dnl Note: This macro is modeled closely on AC_LINK_IFELSE, and in fact
255 dnl depends on some implementation details of that macro, particularly
256 dnl its use of _AC_MSG_LOG_CONFTEST to log the failed test program and
257 dnl its use of ac_link for running the linker.
258 AC_DEFUN([_AX_SYS_WEAK_ALIAS_CROSSFILE],
259 [ # Check to see if weak aliases can cross object file boundaries
260   AC_CACHE_CHECK([whether $CC supports weak aliases across object file boundaries],
261   [ax_cv_sys_weak_alias_crossfile], [
262     AS_IF([test $ax_cv_sys_weak_alias = no],
263           [ax_cv_sys_weak_alias_crossfile=no], [
264 dnl Must build our own test files...
265       # conftest1 contains our weak alias definition...
266       cat >conftest1.$ac_ext <<_ACEOF
267 /* confdefs.h.  */
268 _ACEOF
269       cat confdefs.h >>conftest1.$ac_ext
270       cat >>conftest1.$ac_ext <<_ACEOF
271 /* end confdefs.h.  */
272
273 @%:@ifndef HAVE_SYS_WEAK_ALIAS_ATTRIBUTE
274 extern void weakf(int c);
275 @%:@endif
276 @%:@if defined(HAVE_SYS_WEAK_ALIAS_PRAGMA)
277 @%:@pragma weak weakf = __weakf
278 @%:@elif defined(HAVE_SYS_WEAK_ALIAS_HPSECONDARY)
279 @%:@pragma _HP_SECONDARY_DEF __weakf weakf
280 @%:@elif defined(HAVE_SYS_WEAK_ALIAS_CRIDUPLICATE)
281 @%:@pragma _CRI duplicate weakf as __weakf
282 @%:@endif
283 void __weakf(int c) {}
284 @%:@ifdef HAVE_SYS_WEAK_ALIAS_ATTRIBUTE
285 void weakf(int c) __attribute((weak, alias("__weakf")));
286 @%:@endif
287 _ACEOF
288       # And conftest2 contains our main routine that calls it
289       cat >conftest2.$ac_ext <<_ACEOF
290 /* confdefs.h.  */
291 _ACEOF
292       cat confdefs.h >> conftest2.$ac_ext
293       cat >>conftest2.$ac_ext <<_ACEOF
294 /* end confdefs.h.  */
295
296 extern void weakf(int c);
297 int
298 main ()
299 {
300   weakf(0);
301   return 0;
302 }
303 _ACEOF
304       # We must remove the object files (if any) ourselves...
305       rm -f conftest2.$ac_objext conftest$ac_exeext
306
307       # Change ac_link to compile *2* files together
308       save_aclink=$ac_link
309       ac_link=`echo "$ac_link" | \
310                sed -e 's/conftest\(\.\$ac_ext\)/conftest1\1 conftest2\1/'`
311 dnl Substitute our own routine for logging the conftest
312 m4_pushdef([_AC_MSG_LOG_CONFTEST],
313 [echo "$as_me: failed program was:" >&AS_MESSAGE_LOG_FD
314 echo ">>> conftest1.$ac_ext" >&AS_MESSAGE_LOG_FD
315 sed "s/^/| /" conftest1.$ac_ext >&AS_MESSAGE_LOG_FD
316 echo ">>> conftest2.$ac_ext" >&AS_MESSAGE_LOG_FD
317 sed "s/^/| /" conftest2.$ac_ext >&AS_MESSAGE_LOG_FD
318 ])dnl
319       # Since we created the files ourselves, don't use SOURCE argument
320       AC_LINK_IFELSE(, [ax_cv_sys_weak_alias_crossfile=yes],
321                      [ax_cv_sys_weak_alias_crossfile=no])
322 dnl Restore _AC_MSG_LOG_CONFTEST
323 m4_popdef([_AC_MSG_LOG_CONFTEST])dnl
324       # Restore ac_link
325       ac_link=$save_aclink
326
327       # We must remove the object files (if any) and C files ourselves...
328       rm -f conftest1.$ac_ext conftest2.$ac_ext \
329             conftest1.$ac_objext conftest2.$ac_objext
330     ])
331   ])
332
333   # What were the results of the test?
334   AS_IF([test $ax_cv_sys_weak_alias_crossfile = yes], [
335     AC_DEFINE([HAVE_SYS_WEAK_ALIAS_CROSSFILE], 1,
336               [Define this if weak aliases in other files are honored])
337   ])
338 ])
This page took 0.062277 seconds and 3 git commands to generate.