changeset 29588:b4cb9d04f3cf

build: Use dynamic symbol lookup for functions in libraries on macOS (bug #53627). * configure.ac: Use "-no-undefined" linking by default only on platforms that need it. Don't link all dependencies on macOS by default. Consider changes of AMCOND_LINK_ALL_DEPS by other functions. * m4/acinclude.m4: Use "-bundle -undefined dynamic_lookup -bind_at_load" for linking shared libraries on macOS. * src/mkoctfile.in.cc (make_vars_map): Add path to octinterp and octave libraries to linker flags if linking with all dependencies.
author Andrew Janke <andrew@apjanke.net>
date Wed, 18 Jul 2018 22:34:08 -0400
parents d10027532f0a
children c3d463a3c472
files configure.ac m4/acinclude.m4 src/mkoctfile.in.cc
diffstat 3 files changed, 20 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Sat May 01 21:18:50 2021 +0200
+++ b/configure.ac	Wed Jul 18 22:34:08 2018 -0400
@@ -641,15 +641,23 @@
 
 ### More configure argument checking related to linking
 
+case $host_os in
+  msdosmsvc | mingw* | AIX | BeOS | OS/2 )
+    DEFAULT_NO_UNDEFINED_LDFLAG="-no-undefined"
+  ;;
+  *)
+    DEFAULT_NO_UNDEFINED_LDFLAG=""
+  ;;
+esac
 AC_ARG_ENABLE([no-undefined],
-  [AS_HELP_STRING([--disable-no-undefined],
-    [don't pass -no-undefined to libtool when linking Octave and its shared libraries])],
+  [AS_HELP_STRING([--enable-no-undefined],
+    [pass -no-undefined to libtool when linking Octave and its shared libraries. This is done by default for msdosmsvc, mingw*, AIX, BeOS, or OS/2 hosts.])],
   [case $enableval in
      yes) NO_UNDEFINED_LDFLAG="-no-undefined" ;;
      no)  NO_UNDEFINED_LDFLAG="" ;;
-     *) AC_MSG_ERROR([bad value $enableval for --disable-no-undefined]) ;;
+     *) AC_MSG_ERROR([bad value $enableval for --enable-no-undefined]) ;;
    esac],
-  [NO_UNDEFINED_LDFLAG="-no-undefined"])
+  [NO_UNDEFINED_LDFLAG="$DEFAULT_NO_UNDEFINED_LDFLAG"])
 AC_SUBST(NO_UNDEFINED_LDFLAG)
 
 AC_ARG_ENABLE([link-all-dependencies],
@@ -658,17 +666,10 @@
   [case $enableval in
      yes) link_all_deps=yes ;;
      no)  link_all_deps=no ;;
-     *) AC_MSG_ERROR([bad value $enableval for --enable-link-all-depenencies])
+     *) AC_MSG_ERROR([bad value $enableval for --enable-link-all-dependencies])
      ;;
    esac],
-  [case $host_os in
-    darwin*)
-      link_all_deps=yes
-    ;;
-    *)
-      link_all_deps=no
-    ;;
-  esac])
+  [link_all_deps=no])
 AM_CONDITIONAL([AMCOND_LINK_ALL_DEPS], [test $link_all_deps = yes])
 
 ### Check for BLAS and LAPACK libraries:
@@ -2922,7 +2923,9 @@
 OCT_LINK_OPTS="$LDFLAGS"
 OCT_GUI_LINK_OPTS="$LDFLAGS"
 
-if test $link_all_deps = yes; then
+if test $AMCOND_LINK_ALL_DEPS = yes; then
+  AC_DEFINE(OCTAVE_LINK_ALL_DEPS, 1, [Link with all dependencies.])
+
   OCT_LINK_DEPS="libinterp/liboctinterp.la liboctave/liboctave.la"
   OCT_GUI_LINK_DEPS="libgui/liboctgui.la libinterp/liboctinterp.la liboctave/liboctave.la"
 
--- a/m4/acinclude.m4	Sat May 01 21:18:50 2021 +0200
+++ b/m4/acinclude.m4	Wed Jul 18 22:34:08 2018 -0400
@@ -2613,10 +2613,10 @@
       SH_LDFLAGS="-shared -Wl,-expect_unresolved -Wl,'*'"
     ;;
     *-*-darwin*)
-      DL_LDFLAGS="-bundle -bundle_loader ${ac_top_build_prefix}libinterp/octave ${LDFLAGS}"
+      DL_LDFLAGS="-bundle -undefined dynamic_lookup -bind_at_load -bundle_loader ${ac_top_build_prefix}libinterp/octave ${LDFLAGS}"
       dnl Contains variables that are defined and undefined at this point, so use
       dnl appropriate quoting to defer expansion of ${bindir} and ${version}.
-      MKOCTFILE_DL_LDFLAGS='-bundle -bundle_loader ${bindir}/octave-${version}'"${EXEEXT}"
+      MKOCTFILE_DL_LDFLAGS='-bundle -undefined dynamic_lookup -bind_at_load -bundle_loader ${bindir}/octave-${version}'"${EXEEXT}"
       SH_LDFLAGS="-dynamiclib -single_module ${LDFLAGS}"
       case $canonical_host_type in
         powerpc-*)
--- a/src/mkoctfile.in.cc	Sat May 01 21:18:50 2021 +0200
+++ b/src/mkoctfile.in.cc	Wed Jul 18 22:34:08 2018 -0400
@@ -246,8 +246,7 @@
 
   std::string DEFAULT_LDFLAGS;
 
-#if (defined (OCTAVE_USE_WINDOWS_API) || defined (CROSS)) || (defined __APPLE__ && defined __MACH__)
-
+#if (defined (OCTAVE_USE_WINDOWS_API) || defined (CROSS) || defined (OCTAVE_LINK_ALL_DEPS))
   // We'll be linking the files we compile with -loctinterp and -loctave,
   // so we need to know where to find them.
   DEFAULT_LDFLAGS += "-L" + quote_path (vars["OCTLIBDIR"]);