1
0
mirror of https://frontier.innolan.net/rainlance/c-ares.git synced 2025-11-21 23:10:23 +00:00

Initial step towards the ability to reduce c-ares exported symbols

based on the 'visibility' attribute for GNUC and __global for Sun
compilers, taking also in account __declspec function decoration
for Win32 and Symbian DLL's.

Introducing configure options --enable-hidden-symbols and
--disable-hidden-symbols following libcurl's naming.
This commit is contained in:
Yang Tse
2009-10-28 19:45:26 +00:00
parent a732ace461
commit 9cac6a4625
5 changed files with 370 additions and 72 deletions

View File

@ -16,7 +16,7 @@
#***************************************************************************
# File version for 'aclocal' use. Keep it a single number.
# serial 56
# serial 59
dnl CARES_CHECK_COMPILER
@ -1249,6 +1249,100 @@ AC_DEFUN([CARES_CHECK_COMPILER_ARRAY_SIZE_NEGATIVE], [
])
dnl CARES_CHECK_COMPILER_HIDDEN_SYMBOLS
dnl -------------------------------------------------
dnl Verify if compiler supports hiding library internal symbols, setting
dnl shell variable hidden_symbols_supported value as appropriate, as well
dnl as variable hidden_symbols_CFLAGS when supported.
AC_DEFUN([CARES_CHECK_COMPILER_HIDDEN_SYMBOLS], [
AC_REQUIRE([CARES_CHECK_COMPILER])dnl
AC_BEFORE([$0],[CARES_CONFIGURE_HIDDEN_SYMBOLS])dnl
AC_MSG_CHECKING([if compiler supports hiding library internal symbols])
hidden_symbols_supported="no"
hidden_symbols_CFLAGS=""
tmp_CFLAGS=""
tmp_extern=""
case "$compiler_id" in
GNU_C)
dnl Only gcc 3.4 or later
if test "$compiler_num" -ge "304"; then
if $CC --help --verbose 2>&1 | grep fvisibility= > /dev/null ; then
tmp_extern="__attribute__ ((visibility (\"default\")))"
tmp_CFLAGS="-fvisibility=hidden"
hidden_symbols_supported="yes"
echo " " >&6
echo "debug: should work with this compiler and version" >&6
echo " " >&6
fi
fi
;;
INTEL_UNIX_C)
dnl Only icc 9.0 or later
if test "$compiler_num" -ge "900"; then
if $CC --help --verbose 2>&1 | grep fvisibility= > /dev/null ; then
tmp_extern="__attribute__ ((visibility (\"default\")))"
tmp_CFLAGS="-fvisibility=hidden"
hidden_symbols_supported="yes"
echo " " >&6
echo "debug: should work with this compiler and version" >&6
echo " " >&6
fi
fi
;;
SUNPRO_C)
if $CC 2>&1 | grep flags >/dev/null && $CC -flags | grep xldscope= >/dev/null ; then
tmp_extern="__global"
tmp_CFLAGS="-xldscope=hidden"
hidden_symbols_supported="yes"
echo " " >&6
echo "debug: should work with this compiler and version" >&6
echo " " >&6
fi
;;
esac
if test "$hidden_symbols_supported" = "yes"; then
tmp_save_CFLAGS="$CFLAGS"
CFLAGS="$tmp_save_CFLAGS $tmp_CFLAGS"
squeeze CFLAGS
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[
$tmp_extern char *dummy(char *buff);
char *dummy(char *buff)
{
if(buff)
return ++buff;
else
return buff;
}
]],[[
char b[16];
char *r = dummy(&b);
if(r)
return (int)*r;
]])
],[
hidden_symbols_supported="yes"
],[
hidden_symbols_supported="no"
sed 's/^/cc-src: /' conftest.$ac_ext >&6
sed 's/^/cc-err: /' conftest.err >&6
])
CFLAGS="$tmp_save_CFLAGS"
fi
if test "$hidden_symbols_supported" = "yes"; then
AC_MSG_RESULT([yes])
AC_DEFINE_UNQUOTED(CARES_HIDDEN_SYMBOLS, 1,
[Define to 1 to enable hiding of library internal symbols.])
AC_DEFINE_UNQUOTED(CARES_EXTERN_SYMBOL, $tmp_extern,
[Definition to make a library symbol externally visible.])
hidden_symbols_CFLAGS="$tmp_CFLAGS"
else
AC_MSG_RESULT([no])
fi
])
dnl CARES_CHECK_COMPILER_STRUCT_MEMBER_SIZE
dnl -------------------------------------------------
dnl Verifies if the compiler is capable of handling the

View File

@ -16,7 +16,7 @@
#***************************************************************************
# File version for 'aclocal' use. Keep it a single number.
# serial 5
# serial 6
dnl CARES_CHECK_OPTION_CURLDEBUG
@ -92,6 +92,46 @@ AC_HELP_STRING([--disable-debug],[Disable debug build options]),
])
dnl CARES_CHECK_OPTION_HIDDEN_SYMBOLS
dnl -------------------------------------------------
dnl Verify if configure has been invoked with option
dnl --enable-hidden-symbols or --disable-hidden-symbols,
dnl setting shell variable want_hidden_symbols value.
AC_DEFUN([CARES_CHECK_OPTION_HIDDEN_SYMBOLS], [
AC_BEFORE([$0],[CARES_CHECK_COMPILER_HIDDEN_SYMBOLS])dnl
AC_MSG_CHECKING([whether to enable hiding symbols])
OPT_HIDDEN_SYMBOLS="default"
AC_ARG_ENABLE(hidden-symbols,
AC_HELP_STRING([--enable-hidden-symbols],[Enable hiding of library internal symbols])
AC_HELP_STRING([--disable-hidden-symbols],[Disable hiding of library internal symbols]),
OPT_HIDDEN_SYMBOLS=$enableval)
case "$OPT_HIDDEN_SYMBOLS" in
no)
dnl --disable-hidden-symbols option used.
dnl This is an indication to not attempt hiding of library internal
dnl symbols. Default symbol visibility will be used, which normally
dnl exposes all library internal symbols.
want_hidden_symbols="no"
AC_MSG_RESULT([no])
;;
default)
dnl configure's hidden-symbols option not specified.
dnl Handle this as if --enable-hidden-symbols option was given.
want_hidden_symbols="yes"
AC_MSG_RESULT([not specified (assuming yes)])
;;
*)
dnl --enable-hidden-symbols option used.
dnl This is an indication to attempt hiding of library internal
dnl symbols. This is only supported on some compilers/linkers.
want_hidden_symbols="yes"
AC_MSG_RESULT([yes])
;;
esac
])
dnl CARES_CHECK_OPTION_NONBLOCKING
dnl -------------------------------------------------
dnl Verify if configure has been invoked with option
@ -252,3 +292,24 @@ AC_DEFUN([CARES_CHECK_NONBLOCKING_SOCKET], [
fi
])
dnl CARES_CONFIGURE_HIDDEN_SYMBOLS
dnl -------------------------------------------------
dnl Depending on --enable-hidden-symbols or --disable-hidden-symbols
dnl configure option, and compiler capability to actually honor such
dnl option, compiler flags will be modified as appropriate.
dnl This macro should not be used until all compilation tests have
dnl been done to prevent interferences on other tests.
AC_DEFUN([CARES_CONFIGURE_HIDDEN_SYMBOLS], [
AC_MSG_CHECKING([whether to actually hide library internal symbols])
if test "$want_hidden_symbols" = "yes" &&
test "$hidden_symbols_supported" = "yes"; then
tmp_save_CFLAGS="$CFLAGS"
CFLAGS="$tmp_save_CFLAGS $hidden_symbols_CFLAGS"
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi
])