With the introduction of C++20 modules and libcody, cc1plus and cc1objplus gained a dependency on the socket functions. Before those were merged into libc in Solaris 11.4, one needed to link with -lsocket -lnsl on Solaris, so that merge broke the Solaris 11.3 build.
While we already have 4 different checks for those libraries in the tree, I decided to import autoconf-archive's AX_LIB_SOCKET_NSL macro instead. At the same time, the patch only links libcody and the networking libs where needed (cc1plus, cc1objplus). Bootstrapped without regressions on i386-pc-solaris2.11 (Solaris 11.3 and 11.4), sparc-sun-solaris2.11, and x86_64-pc-linux-gnu. Ok for master? As I'd mentioned, there are 4 checks for -lsocket -lnsl already: gotools/configure.ac libcc1/configure.ac libgo/configure.ac libphobos/m4/druntime/libraries.m4 While it seems sensible to replace those as well, I don't belive this is exactly stage 3 material. Rainer -- ----------------------------------------------------------------------------- Rainer Orth, Center for Biotechnology, Bielefeld University 2020-12-16 Rainer Orth <r...@cebitec.uni-bielefeld.de> c++tools: PR c++/98316 * configure.ac: Include ../config/ax_lib_socket_nsl.m4. (NETLIBS): Determine using AX_LIB_SOCKET_NSL. * Makefile.in (NETLIBS): Define. (g++-mapper-server$(exeext)): Add $(NETLIBS). gcc/objcp: PR c++/98316 * Make-lang.in (cc1objplus$(exeext)): Add $(CODYLIB), $(NETLIBS). gcc/cp: PR c++/98316 * Make-lang.in (cc1plus$(exeext)): Add $(CODYLIB), $(NETLIBS). gcc: PR c++/98316 * configure.ac (NETLIBS): Determine using AX_LIB_SOCKET_NSL. * aclocal.m4, configure: Regenerate. * Makefile.in (NETLIBS): Define. (BACKEND): Remove $(CODYLIB). config: PR c++/98316 * ax_lib_socket_nsl.m4: Import from autoconf-archive.
# HG changeset patch # Parent a5506d38f92e7a2d1627faa0d3a3b8f1d3d392f2 libcody: Link with -lsocket -lnsl if necessary [PR98316] diff --git a/c++tools/Makefile.in b/c++tools/Makefile.in --- a/c++tools/Makefile.in +++ b/c++tools/Makefile.in @@ -30,6 +30,7 @@ CXXFLAGS := @CXXFLAGS@ CXXOPTS := $(CXXFLAGS) -fno-exceptions -fno-rtti EXEEXT := @EXEEXT@ LIBIBERTY := ../libiberty/libiberty.a +NETLIBS := @NETLIBS@ VERSION.O := ../gcc/version.o all:: @@ -80,7 +81,7 @@ MAPPER.O := server.o resolver.o CODYLIB = ../libcody/libcody.a CXXINC += -I$(srcdir)/../libcody -I$(srcdir)/../include -I$(srcdir)/../gcc -I. g++-mapper-server$(exeext): $(MAPPER.O) $(CODYLIB) - +$(CXX) $(LDFLAGS) -o $@ $^ $(VERSION.O) $(LIBIBERTY) + +$(CXX) $(LDFLAGS) -o $@ $^ $(VERSION.O) $(LIBIBERTY) $(NETLIBS) # copy to gcc dir so tests there can run all::../gcc/g++-mapper-server$(exeext) diff --git a/c++tools/configure.ac b/c++tools/configure.ac --- a/c++tools/configure.ac +++ b/c++tools/configure.ac @@ -22,6 +22,7 @@ # By default g++ uses an in-process mapper. sinclude(../config/acx.m4) +sinclude(../config/ax_lib_socket_nsl.m4) AC_INIT(c++tools) @@ -204,6 +205,15 @@ if test $ac_cv_inet_ntop = yes; then [Define if inet_ntop provided.]) fi +# Solaris needs libsocket and libnsl for socket functions before 11.4. +# libcody uses those. +save_LIBS="$LIBS" +LIBS= +AX_LIB_SOCKET_NSL +NETLIBS="$LIBS" +LIBS="$save_LIBS" +AC_SUBST(NETLIBS) + AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile]) diff --git a/config/ax_lib_socket_nsl.m4 b/config/ax_lib_socket_nsl.m4 new file mode 100644 --- /dev/null +++ b/config/ax_lib_socket_nsl.m4 @@ -0,0 +1,40 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_lib_socket_nsl.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_LIB_SOCKET_NSL +# +# DESCRIPTION +# +# This macro figures out what libraries are required on this platform to +# link sockets programs. +# +# The common cases are not to need any extra libraries, or to need +# -lsocket and -lnsl. We need to avoid linking with libnsl unless we need +# it, though, since on some OSes where it isn't necessary it will totally +# break networking. Unisys also includes gethostbyname() in libsocket but +# needs libnsl for socket(). +# +# LICENSE +# +# Copyright (c) 2008 Russ Allbery <r...@stanford.edu> +# Copyright (c) 2008 Stepan Kasal <ka...@ucw.cz> +# Copyright (c) 2008 Warren Young <war...@etr-usa.com> +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 7 + +AU_ALIAS([LIB_SOCKET_NSL], [AX_LIB_SOCKET_NSL]) +AC_DEFUN([AX_LIB_SOCKET_NSL], +[ + AC_SEARCH_LIBS([gethostbyname], [nsl]) + AC_SEARCH_LIBS([socket], [socket], [], [ + AC_CHECK_LIB([socket], [socket], [LIBS="-lsocket -lnsl $LIBS"], + [], [-lnsl])]) +]) diff --git a/gcc/Makefile.in b/gcc/Makefile.in --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -414,6 +414,7 @@ CPPINC = -I$(srcdir)/../libcpp/include CODYLIB = ../libcody/libcody.a CODYINC = -I$(srcdir)/../libcody +NETLIBS = @NETLIBS@ # Where to find decNumber enable_decimal_float = @enable_decimal_float@ @@ -1718,7 +1719,7 @@ endif ALL_HOST_OBJS = $(ALL_HOST_FRONTEND_OBJS) $(ALL_HOST_BACKEND_OBJS) BACKEND = libbackend.a main.o libcommon-target.a libcommon.a \ - $(CPPLIB) $(CODYLIB) $(LIBDECNUMBER) + $(CPPLIB) $(LIBDECNUMBER) # This is defined to "yes" if Tree checking is enabled, which roughly means # front-end checking. diff --git a/gcc/configure.ac b/gcc/configure.ac --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -1291,6 +1291,15 @@ EXTRA_GCC_LIBS="$LIBS" LIBS="$save_LIBS" AC_SUBST(EXTRA_GCC_LIBS) +# Solaris needs libsocket and libnsl for socket functions before 11.4. +# C++ needs those for libcody. +save_LIBS="$LIBS" +LIBS= +AX_LIB_SOCKET_NSL +NETLIBS="$LIBS" +LIBS="$save_LIBS" +AC_SUBST(NETLIBS) + # Some systems put ldexp and frexp in libm instead of libc; assume # they're both in the same place. jcf-dump needs them. save_LIBS="$LIBS" diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in --- a/gcc/cp/Make-lang.in +++ b/gcc/cp/Make-lang.in @@ -134,7 +134,8 @@ cc1plus-checksum.c : build/genchecksum$( cc1plus$(exeext): $(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(LIBDEPS) $(c++.prev) @$(call LINK_PROGRESS,$(INDEX.c++),start) +$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \ - $(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(LIBS) $(BACKENDLIBS) + $(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(CODYLIB) $(NETLIBS) \ + $(LIBS) $(BACKENDLIBS) @$(call LINK_PROGRESS,$(INDEX.c++),end) ifeq ($(ENABLE_MAINTAINER_RULES), true) diff --git a/gcc/objcp/Make-lang.in b/gcc/objcp/Make-lang.in --- a/gcc/objcp/Make-lang.in +++ b/gcc/objcp/Make-lang.in @@ -71,7 +71,8 @@ cc1objplus$(exeext): $(OBJCXX_OBJS) cc1o $(LIBDEPS) $(obj-c++.prev) @$(call LINK_PROGRESS,$(INDEX.obj-c++),start) +$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \ - $(OBJCXX_OBJS) cc1objplus-checksum.o $(BACKEND) $(LIBS) $(BACKENDLIBS) + $(OBJCXX_OBJS) cc1objplus-checksum.o $(BACKEND) \ + $(CODYLIB) $(NETLIBS) $(LIBS) $(BACKENDLIBS) @$(call LINK_PROGRESS,$(INDEX.obj-c++),end) # Objective C++ language specific files.