mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-03 11:25:35 +00:00
optional_api: Fix linking problems between modules that export global symbols
With the new work in Asterisk 12, there are some uses of the optional_api that are prone to failure. The details are rather involved, and captured on [the wiki][1]. This patch addresses the issue by removing almost all of the magic from the optional API implementation. Instead of relying on weak symbol resolution, a new optional_api.c module was added to Asterisk core. For modules providing an optional API, the pointer to the implementation function is registered with the core. For modules that use an optional API, a pointer to a stub function, along with a optional_ref function pointer are registered with the core. The optional_ref function pointers is set to the implementation function when it's provided, or the stub function when it's now. Since the implementation no longer relies on magic, it is now supported on all platforms. In the spirit of choice, an OPTIONAL_API flag was added, so we can disable the optional_api if needed (maybe it's buggy on some bizarre platform I haven't tested on) The AST_OPTIONAL_API*() macros themselves remained unchanged, so existing code could remain unchanged. But to help with debugging the optional_api, the patch limits the #include of optional API's to just the modules using the API. This also reduces resource waste maintaining optional_ref pointers that aren't used. Other changes made as a part of this patch: * The stubs for http_websocket that wrap system calls set errno to ENOSYS. * res_http_websocket now properly increments module use count. * In loader.c, the while() wrappers around dlclose() were removed. The while(!dlclose()) is actually an anti-pattern, which can lead to infinite loops if the module you're attempting to unload exports a symbol that was directly linked to. * The special handling of nonoptreq on systems without weak symbol support was removed, since we no longer rely on weak symbols for optional_api. [1]: https://wiki.asterisk.org/wiki/x/wACUAQ (closes issue ASTERISK-22296) Reported by: Matt Jordan Review: https://reviewboard.asterisk.org/r/2797/ ........ Merged revisions 397989 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@397990 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
198
configure
vendored
198
configure
vendored
@@ -1,5 +1,5 @@
|
||||
#! /bin/sh
|
||||
# From configure.ac Revision: 395985 .
|
||||
# From configure.ac Revision: 397868 .
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.69 for asterisk trunk.
|
||||
#
|
||||
@@ -684,6 +684,7 @@ PKG_CONFIG_PATH
|
||||
PKG_CONFIG
|
||||
PBX_DLADDR
|
||||
PBX_IP_MTU_DISCOVER
|
||||
PBX_RTLD_NOLOAD
|
||||
PBX_GLOB_BRACE
|
||||
PBX_GLOB_NOMAGIC
|
||||
AST_RPATH
|
||||
@@ -696,7 +697,6 @@ AST_TRAMPOLINES
|
||||
AST_DECLARATION_AFTER_STATEMENT
|
||||
GC_LDFLAGS
|
||||
GC_CFLAGS
|
||||
PBX_WEAKREF
|
||||
PBX_PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
|
||||
PBX_PTHREAD_RWLOCK_INITIALIZER
|
||||
AST_ASTERISKSSL
|
||||
@@ -16564,28 +16564,17 @@ CFLAGS="$saved_CFLAGS"
|
||||
|
||||
|
||||
|
||||
# Support weak symbols on a platform specific basis. The Mac OS X
|
||||
# (Darwin) support must be isolated from the other platforms because
|
||||
# it has caused other platforms to fail.
|
||||
#
|
||||
case "${OSARCH}" in
|
||||
darwin*)
|
||||
# Allow weak symbol support on Darwin platforms only because there
|
||||
# is active community support for it.
|
||||
# However, Darwin seems to break weak symbols for each new version.
|
||||
#
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler 'attribute weak_import' support" >&5
|
||||
$as_echo_n "checking for compiler 'attribute weak_import' support... " >&6; }
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler 'attribute may_alias' support" >&5
|
||||
$as_echo_n "checking for compiler 'attribute may_alias' support... " >&6; }
|
||||
saved_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS -Wall -Wno-unused -Werror"
|
||||
PBX_WEAKREF=0
|
||||
|
||||
|
||||
if test "x" = "x"
|
||||
then
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
void __attribute__((weak_import)) *test(void *muffin, ...) {return (void *) 0;}
|
||||
void __attribute__((may_alias)) *test(void *muffin, ...) {return (void *) 0;}
|
||||
int
|
||||
main ()
|
||||
{
|
||||
@@ -16597,10 +16586,10 @@ _ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
PBX_WEAKREF=1
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_ATTRIBUTE_weak_import 1
|
||||
#define HAVE_ATTRIBUTE_may_alias 1
|
||||
_ACEOF
|
||||
|
||||
else
|
||||
@@ -16624,10 +16613,10 @@ _ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
PBX_WEAKREF=1
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_ATTRIBUTE_weak_import 1
|
||||
#define HAVE_ATTRIBUTE_may_alias 1
|
||||
_ACEOF
|
||||
|
||||
else
|
||||
@@ -16643,21 +16632,17 @@ CFLAGS="$saved_CFLAGS"
|
||||
|
||||
|
||||
|
||||
# Several other platforms including Linux have GCC versions that
|
||||
# define the weak attribute. However, this attribute is only
|
||||
# setup for use in the code by Darwin.
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler 'attribute weak' support" >&5
|
||||
$as_echo_n "checking for compiler 'attribute weak' support... " >&6; }
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler 'attribute constructor' support" >&5
|
||||
$as_echo_n "checking for compiler 'attribute constructor' support... " >&6; }
|
||||
saved_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS -Wall -Wno-unused -Werror"
|
||||
PBX_WEAKREF=0
|
||||
|
||||
|
||||
if test "x" = "x"
|
||||
then
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
void __attribute__((weak)) *test(void *muffin, ...) {return (void *) 0;}
|
||||
void __attribute__((constructor)) *test(void *muffin, ...) {return (void *) 0;}
|
||||
int
|
||||
main ()
|
||||
{
|
||||
@@ -16669,10 +16654,10 @@ _ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
PBX_WEAKREF=1
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_ATTRIBUTE_weak 1
|
||||
#define HAVE_ATTRIBUTE_constructor 1
|
||||
_ACEOF
|
||||
|
||||
else
|
||||
@@ -16696,10 +16681,10 @@ _ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
PBX_WEAKREF=1
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_ATTRIBUTE_weak 1
|
||||
#define HAVE_ATTRIBUTE_constructor 1
|
||||
_ACEOF
|
||||
|
||||
else
|
||||
@@ -16714,22 +16699,18 @@ fi
|
||||
CFLAGS="$saved_CFLAGS"
|
||||
|
||||
|
||||
;;
|
||||
linux-gnu)
|
||||
# Primarily support weak symbols on Linux platforms.
|
||||
#
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler 'attribute weakref' support" >&5
|
||||
$as_echo_n "checking for compiler 'attribute weakref' support... " >&6; }
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler 'attribute destructor' support" >&5
|
||||
$as_echo_n "checking for compiler 'attribute destructor' support... " >&6; }
|
||||
saved_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS -Wall -Wno-unused -Werror"
|
||||
PBX_WEAKREF=0
|
||||
|
||||
if test "xweakref("foo")" = "x"
|
||||
|
||||
if test "x" = "x"
|
||||
then
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
static void __attribute__((weakref)) *test(void *muffin, ...) {return (void *) 0;}
|
||||
void __attribute__((destructor)) *test(void *muffin, ...) {return (void *) 0;}
|
||||
int
|
||||
main ()
|
||||
{
|
||||
@@ -16741,10 +16722,10 @@ _ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
PBX_WEAKREF=1
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_ATTRIBUTE_weakref 1
|
||||
#define HAVE_ATTRIBUTE_destructor 1
|
||||
_ACEOF
|
||||
|
||||
else
|
||||
@@ -16756,7 +16737,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
else
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
static void __attribute__((weakref("foo"))) *test(void *muffin, ...) {return (void *) 0;}
|
||||
void __attribute__(()) *test(void *muffin, ...) {return (void *) 0;}
|
||||
int
|
||||
main ()
|
||||
{
|
||||
@@ -16768,10 +16749,10 @@ _ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
PBX_WEAKREF=1
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_ATTRIBUTE_weakref 1
|
||||
#define HAVE_ATTRIBUTE_destructor 1
|
||||
_ACEOF
|
||||
|
||||
else
|
||||
@@ -16786,82 +16767,6 @@ fi
|
||||
CFLAGS="$saved_CFLAGS"
|
||||
|
||||
|
||||
;;
|
||||
*)
|
||||
# Allow weak symbols on other platforms. However, any problems
|
||||
# with this feature on other platforms must be fixed by the
|
||||
# community.
|
||||
#
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler 'attribute weakref' support" >&5
|
||||
$as_echo_n "checking for compiler 'attribute weakref' support... " >&6; }
|
||||
saved_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS -Wall -Wno-unused -Werror"
|
||||
PBX_WEAKREF=0
|
||||
|
||||
if test "xweakref("foo")" = "x"
|
||||
then
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
static void __attribute__((weakref)) *test(void *muffin, ...) {return (void *) 0;}
|
||||
int
|
||||
main ()
|
||||
{
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
PBX_WEAKREF=1
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_ATTRIBUTE_weakref 1
|
||||
_ACEOF
|
||||
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
else
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
static void __attribute__((weakref("foo"))) *test(void *muffin, ...) {return (void *) 0;}
|
||||
int
|
||||
main ()
|
||||
{
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
PBX_WEAKREF=1
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_ATTRIBUTE_weakref 1
|
||||
_ACEOF
|
||||
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
fi
|
||||
|
||||
|
||||
CFLAGS="$saved_CFLAGS"
|
||||
|
||||
|
||||
;;
|
||||
esac
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -ffunction-sections support" >&5
|
||||
$as_echo_n "checking for -ffunction-sections support... " >&6; }
|
||||
@@ -17454,6 +17359,53 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
|
||||
|
||||
|
||||
if test "x${PBX_RTLD_NOLOAD}" != "x1"; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for RTLD_NOLOAD in dlfcn.h" >&5
|
||||
$as_echo_n "checking for RTLD_NOLOAD in dlfcn.h... " >&6; }
|
||||
saved_cppflags="${CPPFLAGS}"
|
||||
if test "x${RTLD_NOLOAD_DIR}" != "x"; then
|
||||
RTLD_NOLOAD_INCLUDE="-I${RTLD_NOLOAD_DIR}/include"
|
||||
fi
|
||||
CPPFLAGS="${CPPFLAGS} ${RTLD_NOLOAD_INCLUDE}"
|
||||
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <dlfcn.h>
|
||||
int
|
||||
main ()
|
||||
{
|
||||
#if defined(RTLD_NOLOAD)
|
||||
int foo = 0;
|
||||
#else
|
||||
int foo = bar;
|
||||
#endif
|
||||
0
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
PBX_RTLD_NOLOAD=1
|
||||
|
||||
$as_echo "#define HAVE_RTLD_NOLOAD 1" >>confdefs.h
|
||||
|
||||
|
||||
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
CPPFLAGS="${saved_cppflags}"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
if test "x${PBX_IP_MTU_DISCOVER}" != "x1"; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for IP_MTU_DISCOVER in netinet/in.h" >&5
|
||||
$as_echo_n "checking for IP_MTU_DISCOVER in netinet/in.h... " >&6; }
|
||||
|
Reference in New Issue
Block a user