1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>
Autoconf Macro: klm_sys_weak_alias
</title>
<link rel="stylesheet" type="text/css" href="autoconf-archive.css">
</head>
<body>
<table summary="web navigation" style="width:100%;">
<tbody>
<tr>
<td style="width:25%;" align="center" valign="top">
<a href="http://autoconf-archive.cryp.to/klm_sys_weak_alias.m4">Download
M4 Source</a>
</td>
<td style="width:25%;" align="center" valign="top">
<a href=
"http://git.cryp.to/?p=autoconf-archive;a=history;f=klm_sys_weak_alias.m4">
Macro History</a>
</td>
<td style="width:25%;" align="center" valign="top">
<a href="macros-by-category.html">Category Index</a>
</td>
<td style="width:25%;" align="center" valign="top">
<form method="get" action="http://www.google.com/search">
<div>
<input name="sitesearch" value="autoconf-archive.cryp.to" type=
"hidden"><a href="http://www.google.com/">Search</a>: <input name="q"
size="10" maxlength="255" type="text">
</div>
</form>
</td>
</tr>
</tbody>
</table>
<hr>
<h1>
klm_sys_weak_alias
</h1>
<h2>
Synopsis
</h2>
<p class="indent" style="white-space:nowrap;">
<code>KLM_SYS_WEAK_ALIAS</code>
</p>
<h2>
Description
</h2>
<div class="indent">
<p>
Determines whether weak aliases are supported on the system, and if so,
what scheme is used to declare them. Also checks to see if aliases can
cross object file boundaries, as some systems don't permit them to.
</p>
<p>
Most systems permit something called a "weak alias" or "weak symbol." These
aliases permit a library to provide a stub form of a routine defined in
another library, thus allowing the first library to operate even if the
other library is not linked. This macro will check for support of weak
aliases, figure out what schemes are available, and determine some
characteristics of the weak alias support -- primarily, whether a weak
alias declared in one object file may be referenced from another object
file.
</p>
<p>
There are four known schemes of declaring weak symbols; each scheme is
checked in turn, and the first one found is prefered. Note that only one of
the mentioned preprocessor macros will be defined!
</p>
<p>
1. Function attributes
</p>
<p>
This scheme was first introduced by the GNU C compiler, and attaches
attributes to particular functions. It is among the easiest to use, and so
is the first one checked. If this scheme is detected, the preprocessor
macro HAVE_SYS_WEAK_ALIAS_ATTRIBUTE will be defined to 1. This scheme is
used as in the following code fragment:
</p>
<pre>
void __weakf(int c)
{
/* Function definition... */
}
void weakf(int c) __attribute__((weak, alias("__weakf")));
</pre>
<p>
2. #pragma weak
</p>
<p>
This scheme is in use by many compilers other than the GNU C compiler. It
is also particularly easy to use, and fairly portable -- well, as portable
as these things get. If this scheme is detected first, the preprocessor
macro HAVE_SYS_WEAK_ALIAS_PRAGMA will be defined to 1. This scheme is used
as in the following code fragment:
</p>
<pre>
extern void weakf(int c);
#pragma weak weakf = __weakf
void __weakf(int c)
{
/* Function definition... */
}
</pre>
<p>
3. #pragma _HP_SECONDARY_DEF
</p>
<p>
This scheme appears to be in use by the HP compiler. As it is rather
specialized, this is one of the last schemes checked. If it is the first
one detected, the preprocessor macro HAVE_SYS_WEAK_ALIAS_HPSECONDARY will
be defined to 1. This scheme is used as in the following code fragment:
</p>
<pre>
extern void weakf(int c);
#pragma _HP_SECONDARY_DEF __weakf weakf
void __weakf(int c)
{
/* Function definition... */
}
</pre>
<p>
4. #pragma _CRI duplicate
</p>
<p>
This scheme appears to be in use by the Cray compiler. As it is rather
specialized, it too is one of the last schemes checked. If it is the first
one detected, the preprocessor macro HAVE_SYS_WEAK_ALIAS_CRIDUPLICATE will
be defined to 1. This scheme is used as in the following code fragment:
</p>
<pre>
extern void weakf(int c);
#pragma _CRI duplicate weakf as __weakf
void __weakf(int c)
{
/* Function definition... */
}
</pre>
<p>
In addition to the preprocessor macros listed above, if any scheme is
found, the preprocessor macro HAVE_SYS_WEAK_ALIAS will also be defined to
1.
</p>
<p>
Once a weak aliasing scheme has been found, a check will be performed to
see if weak aliases are honored across object file boundaries. If they are,
the HAVE_SYS_WEAK_ALIAS_CROSSFILE preprocessor macro is defined to 1.
</p>
<p>
This Autoconf macro also makes two substitutions. The first, WEAK_ALIAS,
contains the name of the scheme found (one of "attribute", "pragma",
"hpsecondary", or "criduplicate"), or "no" if no weak aliasing scheme was
found. The second, WEAK_ALIAS_CROSSFILE, is set to "yes" or "no" depending
on whether or not weak aliases may cross object file boundaries.
</p>
</div>
<h2>
Author
</h2>
<p class="indent">
Kevin L. Mitchell <klmitch@mit.edu>
</p>
<h2>
Last Modified
</h2>
<p class="indent">
2005-05-02
</p>
<h2>
M4 Source Code
</h2>
<div class="indent">
<pre class="m4source">
AC_DEFUN([KLM_SYS_WEAK_ALIAS], [
# starting point: no aliasing scheme yet...
klm_sys_weak_alias=no
# Figure out what kind of aliasing may be supported...
_KLM_SYS_WEAK_ALIAS_ATTRIBUTE
_KLM_SYS_WEAK_ALIAS_PRAGMA
_KLM_SYS_WEAK_ALIAS_HPSECONDARY
_KLM_SYS_WEAK_ALIAS_CRIDUPLICATE
# Do we actually support aliasing?
AC_CACHE_CHECK([how to create weak aliases with $CC],
[klm_cv_sys_weak_alias],
[klm_cv_sys_weak_alias=$klm_sys_weak_alias])
# OK, set a #define
AS_IF([test $klm_cv_sys_weak_alias != no], [
AC_DEFINE([HAVE_SYS_WEAK_ALIAS], 1,
[Define this if your system can create weak aliases])
])
# Can aliases cross object file boundaries?
_KLM_SYS_WEAK_ALIAS_CROSSFILE
# OK, remember the results
AC_SUBST([WEAK_ALIAS], [$klm_cv_sys_weak_alias])
AC_SUBST([WEAK_ALIAS_CROSSFILE], [$klm_cv_sys_weak_alias_crossfile])
])
AC_DEFUN([_KLM_SYS_WEAK_ALIAS_ATTRIBUTE],
[ # Test whether compiler accepts __attribute__ form of weak aliasing
AC_CACHE_CHECK([whether $CC accepts function __attribute__((weak,alias()))],
[klm_cv_sys_weak_alias_attribute], [
# We add -Werror if it's gcc to force an error exit if the weak attribute
# isn't understood
AS_IF([test $GCC = yes], [
save_CFLAGS=$CFLAGS
CFLAGS=-Werror])
# Try linking with a weak alias...
AC_LINK_IFELSE([
AC_LANG_PROGRAM([
void __weakf(int c) {}
void weakf(int c) __attribute__((weak, alias("__weakf")));],
[weakf(0)])],
[klm_cv_sys_weak_alias_attribute=yes],
[klm_cv_sys_weak_alias_attribute=no])
# Restore original CFLAGS
AS_IF([test $GCC = yes], [
CFLAGS=$save_CFLAGS])
])
# What was the result of the test?
AS_IF([test $klm_sys_weak_alias = no &&
test $klm_cv_sys_weak_alias_attribute = yes], [
klm_sys_weak_alias=attribute
AC_DEFINE([HAVE_SYS_WEAK_ALIAS_ATTRIBUTE], 1,
[Define this if weak aliases may be created with __attribute__])
])
])
AC_DEFUN([_KLM_SYS_WEAK_ALIAS_PRAGMA],
[ # Test whether compiler accepts #pragma form of weak aliasing
AC_CACHE_CHECK([whether $CC supports @%:@pragma weak],
[klm_cv_sys_weak_alias_pragma], [
# Try linking with a weak alias...
AC_LINK_IFELSE([
AC_LANG_PROGRAM([
extern void weakf(int c);
@%:@pragma weak weakf = __weakf
void __weakf(int c) {}],
[weakf(0)])],
[klm_cv_sys_weak_alias_pragma=yes],
[klm_cv_sys_weak_alias_pragma=no])
])
# What was the result of the test?
AS_IF([test $klm_sys_weak_alias = no &&
test $klm_cv_sys_weak_alias_pragma = yes], [
klm_sys_weak_alias=pragma
AC_DEFINE([HAVE_SYS_WEAK_ALIAS_PRAGMA], 1,
[Define this if weak aliases may be created with @%:@pragma weak])
])
])
AC_DEFUN([_KLM_SYS_WEAK_ALIAS_HPSECONDARY],
[ # Test whether compiler accepts _HP_SECONDARY_DEF pragma from HP...
AC_CACHE_CHECK([whether $CC supports @%:@pragma _HP_SECONDARY_DEF],
[klm_cv_sys_weak_alias_hpsecondary], [
# Try linking with a weak alias...
AC_LINK_IFELSE([
AC_LANG_PROGRAM([
extern void weakf(int c);
@%:@pragma _HP_SECONDARY_DEF __weakf weakf
void __weakf(int c) {}],
[weakf(0)])],
[klm_cv_sys_weak_alias_hpsecondary=yes],
[klm_cv_sys_weak_alias_hpsecondary=no])
])
# What was the result of the test?
AS_IF([test $klm_sys_weak_alias = no &&
test $klm_cv_sys_weak_alias_hpsecondary = yes], [
klm_sys_weak_alias=hpsecondary
AC_DEFINE([HAVE_SYS_WEAK_ALIAS_HPSECONDARY], 1,
[Define this if weak aliases may be created with @%:@pragma _HP_SECONDARY_DEF])
])
])
AC_DEFUN([_KLM_SYS_WEAK_ALIAS_CRIDUPLICATE],
[ # Test whether compiler accepts "_CRI duplicate" pragma from Cray
AC_CACHE_CHECK([whether $CC supports @%:@pragma _CRI duplicate],
[klm_cv_sys_weak_alias_criduplicate], [
# Try linking with a weak alias...
AC_LINK_IFELSE([
AC_LANG_PROGRAM([
extern void weakf(int c);
@%:@pragma _CRI duplicate weakf as __weakf
void __weakf(int c) {}],
[weakf(0)])],
[klm_cv_sys_weak_alias_criduplicate=yes],
[klm_cv_sys_weak_alias_criduplicate=no])
])
# What was the result of the test?
AS_IF([test $klm_sys_weak_alias = no &&
test $klm_cv_sys_weak_alias_criduplicate = yes], [
klm_sys_weak_alias=criduplicate
AC_DEFINE([HAVE_SYS_WEAK_ALIAS_CRIDUPLICATE], 1,
[Define this if weak aliases may be created with @%:@pragma _CRI duplicate])
])
])
dnl Note: This macro is modeled closely on AC_LINK_IFELSE, and in fact
dnl depends on some implementation details of that macro, particularly
dnl its use of _AC_MSG_LOG_CONFTEST to log the failed test program and
dnl its use of ac_link for running the linker.
AC_DEFUN([_KLM_SYS_WEAK_ALIAS_CROSSFILE],
[ # Check to see if weak aliases can cross object file boundaries
AC_CACHE_CHECK([whether $CC supports weak aliases across object file boundaries],
[klm_cv_sys_weak_alias_crossfile], [
AS_IF([test $klm_cv_sys_weak_alias = no],
[klm_cv_sys_weak_alias_crossfile=no], [
dnl Must build our own test files...
# conftest1 contains our weak alias definition...
cat >conftest1.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest1.$ac_ext
cat >>conftest1.$ac_ext <<_ACEOF
/* end confdefs.h. */
@%:@ifndef HAVE_SYS_WEAK_ALIAS_ATTRIBUTE
extern void weakf(int c);
@%:@endif
@%:@if defined(HAVE_SYS_WEAK_ALIAS_PRAGMA)
@%:@pragma weak weakf = __weakf
@%:@elif defined(HAVE_SYS_WEAK_ALIAS_HPSECONDARY)
@%:@pragma _HP_SECONDARY_DEF __weakf weakf
@%:@elif defined(HAVE_SYS_WEAK_ALIAS_CRIDUPLICATE)
@%:@pragma _CRI duplicate weakf as __weakf
@%:@endif
void __weakf(int c) {}
@%:@ifdef HAVE_SYS_WEAK_ALIAS_ATTRIBUTE
void weakf(int c) __attribute((weak, alias("__weakf")));
@%:@endif
_ACEOF
# And conftest2 contains our main routine that calls it
cat >conftest2.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >> conftest2.$ac_ext
cat >>conftest2.$ac_ext <<_ACEOF
/* end confdefs.h. */
extern void weakf(int c);
int
main ()
{
weakf(0);
return 0;
}
_ACEOF
# We must remove the object files (if any) ourselves...
rm -f conftest2.$ac_objext conftest$ac_exeext
# Change ac_link to compile *2* files together
save_aclink=$ac_link
ac_link=`echo "$ac_link" | \
sed -e 's/conftest\(\.\$ac_ext\)/conftest1\1 conftest2\1/'`
dnl Substitute our own routine for logging the conftest
m4_pushdef([_AC_MSG_LOG_CONFTEST],
[echo "$as_me: failed program was:" >&AS_MESSAGE_LOG_FD
echo ">>> conftest1.$ac_ext" >&AS_MESSAGE_LOG_FD
sed "s/^/| /" conftest1.$ac_ext >&AS_MESSAGE_LOG_FD
echo ">>> conftest2.$ac_ext" >&AS_MESSAGE_LOG_FD
sed "s/^/| /" conftest2.$ac_ext >&AS_MESSAGE_LOG_FD
])dnl
# Since we created the files ourselves, don't use SOURCE argument
AC_LINK_IFELSE(, [klm_cv_sys_weak_alias_crossfile=yes],
[klm_cv_sys_weak_alias_crossfile=no])
dnl Restore _AC_MSG_LOG_CONFTEST
m4_popdef([_AC_MSG_LOG_CONFTEST])dnl
# Restore ac_link
ac_link=$save_aclink
# We must remove the object files (if any) and C files ourselves...
rm -f conftest1.$ac_ext conftest2.$ac_ext \
conftest1.$ac_objext conftest2.$ac_objext
])
])
# What were the results of the test?
AS_IF([test $klm_cv_sys_weak_alias_crossfile = yes], [
AC_DEFINE([HAVE_SYS_WEAK_ALIAS_CROSSFILE], 1,
[Define this if weak aliases in other files are honored])
])
])
</pre>
</div>
<h2>
License
</h2>
<div class="indent">
<span style="white-space:nowrap;">Copyright © 2005 Kevin L. Mitchell
<klmitch@mit.edu></span>
<p>
Copying and distribution of this file, with or without modification, are
permitted in any medium without royalty provided the copyright notice and
this notice are preserved.
</p>
</div>
</body>
</html>
|