As mentioned in passing in PR d/87864, libgphobos.so currently fails to
link before Solaris 11.4.  Until then, you needed to link with -lsocket
-lnsl for the networking functions, in S11.4 they were merged into libc.

To fix this, I've adapted the check from libgo/configure.ac, for the
moment just moving it into an autoconf macro, reindenting it, renaming
the variables for the new location, and removing the check for sendfile
which isn't used in libphobos.

With that patch (and the one from PR d/87864 to provide
__start_minfo/__stop_minfo when ld does not), I could bootstrap with
--enable-libphobos on i386-pc-solaris2.11 with gas and
sparc-sun-solaris2.11 with as on both S11.3 and S11.4.  On the former,
libsocket and libnsl were properly detected and linked into
libgdruntime.so and libgphobos.so, leaving no undefined symbols, while
on the latter nothing more than libc is needed.

Ok for mainline?

        Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2018-11-25  Rainer Orth  <r...@cebitec.uni-bielefeld.de>

        * m4/druntime/libraries.m4 (DRUNTIME_LIBRARIES_NET): New macro.
        * configure.ac: Invoke it.
        * configure: Regenerate.

# HG changeset patch
# Parent  8068f906d5f73ddb769b1241419ed3a330243e2b
Fix libphobos linking on Solaris 11

diff --git a/libphobos/configure.ac b/libphobos/configure.ac
--- a/libphobos/configure.ac
+++ b/libphobos/configure.ac
@@ -140,6 +140,7 @@ WITH_LOCAL_DRUNTIME([
 DRUNTIME_LIBRARIES_ATOMIC
 DRUNTIME_LIBRARIES_BACKTRACE
 DRUNTIME_LIBRARIES_DLOPEN
+DRUNTIME_LIBRARIES_NET
 DRUNTIME_LIBRARIES_ZLIB
 DRUNTIME_INSTALL_DIRECTORIES
 
diff --git a/libphobos/m4/druntime/libraries.m4 b/libphobos/m4/druntime/libraries.m4
--- a/libphobos/m4/druntime/libraries.m4
+++ b/libphobos/m4/druntime/libraries.m4
@@ -42,6 +42,40 @@ AC_DEFUN([DRUNTIME_LIBRARIES_DLOPEN],
 ])
 
 
+# DRUNTIME_LIBRARIES_NET
+# -----------------------
+# Autodetect and add networking library to LIBS if necessary.
+AC_DEFUN([DRUNTIME_LIBRARIES_NET],
+[
+  dnl Test for -lsocket and -lnsl.  Copied from libjava/configure.ac.
+  AC_CACHE_CHECK([for socket libraries], druntime_cv_lib_sockets,
+    [druntime_cv_lib_sockets=
+     druntime_check_both=no
+     AC_CHECK_FUNC(connect, druntime_check_socket=no, druntime_check_socket=yes)
+     if test "$druntime_check_socket" = "yes"; then
+       unset ac_cv_func_connect
+       AC_CHECK_LIB(socket, main, druntime_cv_lib_sockets="-lsocket",
+		    druntime_check_both=yes)
+     fi
+     if test "$druntime_check_both" = "yes"; then
+       druntime_old_libs=$LIBS
+       LIBS="$LIBS -lsocket -lnsl"
+       unset ac_cv_func_accept
+       AC_CHECK_FUNC(accept,
+		     [druntime_check_nsl=no
+		      druntime_cv_lib_sockets="-lsocket -lnsl"])
+       unset ac_cv_func_accept
+       LIBS=$druntime_old_libs
+     fi
+     unset ac_cv_func_gethostbyname
+     druntime_old_libs="$LIBS"
+     AC_CHECK_FUNC(gethostbyname, ,
+		   [AC_CHECK_LIB(nsl, main,
+		    [druntime_cv_lib_sockets="$druntime_cv_lib_sockets -lnsl"])])
+  ])
+  LIBS="$LIBS $druntime_cv_lib_sockets"
+])
+
 # DRUNTIME_LIBRARIES_ZLIB
 # -----------------------
 # Allow specifying whether to use the system zlib or

Reply via email to