configury: detect dlsym underscore prefix without dlopen self.

* m4/ltdl.m4 (LT_FUNC_DLSYM_USCORE): Compile, load and get the
address of a symbol from a separate loadable module, rather than
assuming dlopen self works.
* NEWS: Update.
Reported by KO Myung-Hun

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
This commit is contained in:
Gary V. Vaughan 2014-11-28 15:12:03 +00:00
parent 1acee63da4
commit 81ab62f903
2 changed files with 98 additions and 13 deletions

3
NEWS
View File

@ -17,6 +17,9 @@ NEWS - list of user-visible changes between releases of GNU Libtool
including old versions of the snippet directory, and gnulib's
version of the argz module and supporting files.
- LT_FUNC_DLYSM_USCORE now works correctly on systems that don't
support self dlopen()ing.
** Important incompatible changes:
- LT_LIB_DLLOAD no longer prepends -ldl or -ldld to LIBS, causing

View File

@ -793,20 +793,102 @@ dnl AC_DEFUN([AC_LTDL_SYMBOL_USCORE], [])
# LT_FUNC_DLSYM_USCORE
# --------------------
AC_DEFUN([LT_FUNC_DLSYM_USCORE],
[AC_REQUIRE([LT_SYS_SYMBOL_USCORE])dnl
[AC_REQUIRE([_LT_COMPILER_PIC])dnl for lt_prog_compiler_wl
AC_REQUIRE([LT_SYS_SYMBOL_USCORE])dnl for lt_cv_sys_symbol_underscore
AC_REQUIRE([LT_SYS_MODULE_EXT])dnl for libltdl_cv_shlibext
if test yes = "$lt_cv_sys_symbol_underscore"; then
if test yes = "$libltdl_cv_func_dlopen" ||
test yes = "$libltdl_cv_lib_dl_dlopen"; then
AC_CACHE_CHECK([whether we have to add an underscore for dlsym],
[libltdl_cv_need_uscore],
[libltdl_cv_need_uscore=unknown
save_LIBS=$LIBS
LIBS="$LIBS $LIBADD_DLOPEN"
_LT_TRY_DLOPEN_SELF(
[libltdl_cv_need_uscore=no], [libltdl_cv_need_uscore=yes],
[], [libltdl_cv_need_uscore=cross])
LIBS=$save_LIBS
])
if test yes = "$libltdl_cv_func_dlopen" || test yes = "$libltdl_cv_lib_dl_dlopen"; then
AC_CACHE_CHECK([whether we have to add an underscore for dlsym],
[libltdl_cv_need_uscore],
[libltdl_cv_need_uscore=unknown
dlsym_uscore_save_LIBS=$LIBS
LIBS="$LIBS $LIBADD_DLOPEN"
libname=conftmod # stay within 8.3 filename limits!
cat >$libname.$ac_ext <<_LT_EOF
[#line $LINENO "configure"
#include "confdefs.h"
/* When -fvisibility=hidden is used, assume the code has been annotated
correspondingly for the symbols needed. */
#if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3))
int fnord () __attribute__((visibility("default")));
#endif
int fnord () { return 42; }]
_LT_EOF
# ltfn_module_cmds module_cmds
# Execute tilde-delimited MODULE_CMDS with environment primed for
# ${module_cmds} or ${archive_cmds} type content.
ltfn_module_cmds ()
{( # subshell avoids polluting parent global environment
module_cmds_save_ifs=$IFS; IFS='~'
for cmd in @S|@1; do
IFS=$module_cmds_save_ifs
libobjs=$libname.$ac_objext; lib=$libname$libltdl_cv_shlibext
rpath=/not-exists; soname=$libname$libltdl_cv_shlibext; output_objdir=.
major=; versuffix=; verstring=; deplibs=
ECHO=echo; wl=$lt_prog_compiler_wl; allow_undefined_flag=
eval $cmd
done
IFS=$module_cmds_save_ifs
)}
# Compile a loadable module using libtool macro expansion results.
$CC $pic_flag -c $libname.$ac_ext
ltfn_module_cmds "${module_cmds:-$archive_cmds}"
# Try to fetch fnord with dlsym().
libltdl_dlunknown=0; libltdl_dlnouscore=1; libltdl_dluscore=2
cat >conftest.$ac_ext <<_LT_EOF
[#line $LINENO "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
#include <dlfcn.h>
#endif
#include <stdio.h>
#ifndef RTLD_GLOBAL
# ifdef DL_GLOBAL
# define RTLD_GLOBAL DL_GLOBAL
# else
# define RTLD_GLOBAL 0
# endif
#endif
#ifndef RTLD_NOW
# ifdef DL_NOW
# define RTLD_NOW DL_NOW
# else
# define RTLD_NOW 0
# endif
#endif
int main () {
void *handle = dlopen ("`pwd`/$libname$libltdl_cv_shlibext", RTLD_GLOBAL|RTLD_NOW);
int status = $libltdl_dlunknown;
if (handle) {
if (dlsym (handle, "fnord"))
status = $libltdl_dlnouscore;
else {
if (dlsym (handle, "_fnord"))
status = $libltdl_dluscore;
else
puts (dlerror ());
}
dlclose (handle);
} else
puts (dlerror ());
return status;
}]
_LT_EOF
if AC_TRY_EVAL(ac_link) && test -s "conftest$ac_exeext" 2>/dev/null; then
(./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null
libltdl_status=$?
case x$libltdl_status in
x$libltdl_dlnouscore) libltdl_cv_need_uscore=no ;;
x$libltdl_dluscore) libltdl_cv_need_uscore=yes ;;
x*) libltdl_cv_need_uscore=unknown ;;
esac
fi
rm -rf conftest* $libname*
LIBS=$dlsym_uscore_save_LIBS
])
fi
fi