]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
configury: detect dlsym underscore prefix without dlopen self.
authorGary V. Vaughan <gary@gnu.org>
Fri, 28 Nov 2014 15:12:03 +0000 (15:12 +0000)
committerGary V. Vaughan <gary@gnu.org>
Fri, 28 Nov 2014 15:14:54 +0000 (15:14 +0000)
* 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>
NEWS
m4/ltdl.m4

diff --git a/NEWS b/NEWS
index 2782511ccf265a37dfa76778427d7fae900f57ff..963c8a24661d690b7ec7ba338384c3f3a31b802b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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
index 41198441675c5a00e0fb4844503260c33249d396..5dc1e80f97ee10a59e0fea757c0a36e5d334e039 100644 (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