zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: reduce unnecessary linking
@ 2001-04-19 14:41 Clint Adams
  2001-04-19 14:53 ` Andrej Borsenkow
  0 siblings, 1 reply; 6+ messages in thread
From: Clint Adams @ 2001-04-19 14:41 UTC (permalink / raw)
  To: zsh-workers

This could probably use some tidying.

Index: acconfig.h
===================================================================
RCS file: /cvsroot/zsh/zsh/acconfig.h,v
retrieving revision 1.6
diff -u -r1.6 acconfig.h
--- acconfig.h	2001/04/12 04:08:36	1.6
+++ acconfig.h	2001/04/19 14:38:12
@@ -317,3 +317,9 @@
 
 /* Define if you have the terminfo strnames symbol.  */
 #undef HAVE_STRNAMES
+
+/* Define if you have the cap library.  */
+#undef HAVE_LIBCAP
+
+/* Define if you have the socket library.  */
+#undef HAVE_LIBSOCKET
Index: aczsh.m4
===================================================================
RCS file: /cvsroot/zsh/zsh/aczsh.m4,v
retrieving revision 1.8
diff -u -r1.8 aczsh.m4
--- aczsh.m4	2001/03/07 11:40:48	1.8
+++ aczsh.m4	2001/04/19 14:38:12
@@ -683,3 +683,27 @@
 	then LIBS="$4"
 	else LIBS="$enable_libs"
 	fi)])
+
+dnl zsh_SEARCH_LIBS(FUNCTION, SEARCH-LIBS [, ACTION-IF-FOUND
+dnl            [, ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
+dnl Search for a library defining FUNC, if it's not already available.
+
+AC_DEFUN(zsh_SEARCH_LIBS,
+[AC_PREREQ([2.13])
+AC_CACHE_CHECK([for library containing $1], [ac_cv_search_$1],
+[ac_func_search_save_LIBS="$LIBS"
+ac_cv_search_$1="no"
+AC_TRY_LINK_FUNC([$1], [ac_cv_search_$1="none required"])
+test "$ac_cv_search_$1" = "no" && for i in $2; do
+LIBS="-l$i $5 $ac_func_search_save_LIBS"
+AC_TRY_LINK_FUNC([$1],
+[ac_cv_search_$1="-l$i"
+break])
+done
+LIBS="$ac_func_search_save_LIBS"])
+if test "$ac_cv_search_$1" != "no"; then
+  test "$ac_cv_search_$1" = "none required" || ZS_LIBS="$ac_cv_search_$1"
+  $3
+else :
+  $4
+fi])
Index: configure.in
===================================================================
RCS file: /cvsroot/zsh/zsh/configure.in,v
retrieving revision 1.43
diff -u -r1.43 configure.in
--- configure.in	2001/04/12 04:08:36	1.43
+++ configure.in	2001/04/19 14:38:12
@@ -504,7 +504,7 @@
 dnl may happen.
 AC_CHECK_LIB(c, printf, [LIBS="$LIBS -lc"])
 
-AC_CHECK_LIB(m, pow)
+AC_CHECK_LIB(m, pow, [LIBS_M="-lm"])
 
 dnl Prefer BSD termcap library to SysV curses library, except on certain
 dnl SYSV-derived systems.
@@ -514,7 +514,12 @@
   *)             termcap_curses_order="termcap curses ncurses" ;;
 esac
 
-AC_SEARCH_LIBS(tgetent, [$termcap_curses_order])
+zsh_SEARCH_LIBS(tgetent, [$termcap_curses_order])
+LIBS_TERMCAP=$ZS_LIBS
+
+zsh_SEARCH_LIBS(tigetstr, [$termcap_curses_order])
+LIBS_TERMINFO=$ZS_LIBS
+
 AC_MSG_CHECKING(if boolcodes is available)
 AC_TRY_COMPILE([#include <curses.h>
 #include <term.h>], [char **test = boolcodes;],
@@ -549,7 +554,8 @@
 dnl Some systems (Solaris 2.x, Linux Redhat 5.x) require
 dnl libnsl (Network Services Library) to find yp_all
 
-AC_SEARCH_LIBS(yp_all, nsl)
+zsh_SEARCH_LIBS(yp_all, nsl)
+LIBS_YP=$ZS_LIBS
 
 dnl I am told that told that unicos reqire these for nis_list
 if test `echo $host_os | sed 's/^\(unicos\).*/\1/'` = unicos; then
@@ -560,9 +566,11 @@
   AC_CHECK_LIB(dl, dlopen)
 fi
 
-AC_CHECK_LIB(cap, cap_get_proc)
+AC_CHECK_LIB(cap, cap_get_proc, [LIBS_CAP="-lcap"
+AC_DEFINE(HAVE_LIBCAP)])
 
-AC_CHECK_LIB(socket, socket)
+AC_CHECK_LIB(socket, socket, [LIBS_SOCKET="-lsocket"
+AC_DEFINE(HAVE_LIBSOCKET)])
 
 dnl ---------------------
 dnl CHECK TERMCAP LIBRARY
@@ -831,6 +839,9 @@
 dnl need to integrate this function
 dnl AC_FUNC_STRFTIME
 
+SAVELIBS=$LIBS
+LIBS="$LIBS_TERMCAP $LIBS_TERMINFO $LIBS"
+
 AC_CHECK_FUNCS(strftime difftime gettimeofday \
 	       select poll \
 	       readlink lstat lchown faccessx fchdir ftruncate \
@@ -887,6 +898,8 @@
   AC_DEFINE(TGETENT_ACCEPTS_NULL)
 fi
 
+LIBS=$SAVELIBS
+
 AC_FUNC_MMAP
 if test x$ac_cv_func_mmap_fixed_mapped = xyes; then
   AC_CHECK_FUNCS(munmap msync)
@@ -1675,10 +1688,16 @@
   test "$zsh_cv_shared_environ" = yes || dynamic=no
 dnl  test "$zsh_cv_sys_dynamic_broken" = no || dynamic=no
   if test "$ac_cv_func_tgetent" = yes; then
+    SAVELIBS=$LIBS
+    LIBS="$LIBS_TERMCAP $LIBS"
     zsh_SHARED_FUNCTION([tgetent])
+    LIBS=$SAVELIBS
   fi
   if test "$ac_cv_func_tigetstr" = yes; then
+    SAVELIBS=$LIBS
+    LIBS="$LIBS_TERMINFO $LIBS"
     zsh_SHARED_FUNCTION([tigetstr])
+    LIBS=$SAVELIBS
   fi
 fi
 
@@ -1752,6 +1771,12 @@
 AC_SUBST(MOD_IMPORT_VARIABLE)dnl
 AC_SUBST(MOD_IMPORT_FUNCTION)dnl
 AC_SUBST(EXTRAZSHOBJS)dnl
+AC_SUBST(LIBS_M)dnl
+AC_SUBST(LIBS_CAP)dnl
+AC_SUBST(LIBS_SOCKET)dnl
+AC_SUBST(LIBS_TERMCAP)dnl
+AC_SUBST(LIBS_TERMINFO)dnl
+AC_SUBST(LIBS_YP)dnl
 
 # Generate config.modules.  We look for *.mdd files in first and second
 # level subdirectories.  Any existing line not containing 'auto=y' will be
Index: Config/defs.mk.in
===================================================================
RCS file: /cvsroot/zsh/zsh/Config/defs.mk.in,v
retrieving revision 1.4
diff -u -r1.4 defs.mk.in
--- Config/defs.mk.in	2000/12/04 19:21:07	1.4
+++ Config/defs.mk.in	2001/04/19 14:38:12
@@ -63,6 +63,14 @@
 EXPOPT          = @EXPOPT@
 IMPOPT          = @IMPOPT@
 
+# extra libraries
+LIBS_M          = @LIBS_M@
+LIBS_CAP        = @LIBS_CAP@
+LIBS_SOCKET     = @LIBS_SOCKET@
+LIBS_TERMCAP    = @LIBS_TERMCAP@
+LIBS_TERMINFO   = @LIBS_TERMINFO@
+LIBS_YP         = @LIBS_YP@
+
 # utilities
 AWK             = @AWK@
 YODL            = @YODL@
Index: Src/Makefile.in
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Makefile.in,v
retrieving revision 1.7
diff -u -r1.7 Makefile.in
--- Src/Makefile.in	2000/11/26 20:01:03	1.7
+++ Src/Makefile.in	2001/04/19 14:38:12
@@ -82,11 +82,11 @@
 
 zsh$(EXEEXT): $(@L@IBZSH) $(@L@STMP) $(MAIN_OBJS) zsh.export $(EXTRAZSHOBJS)
 	rm -f $@
-	$(@L@DRUNPATH) $(LINK) $(MAIN_OBJS) $(EXTRAZSHOBJS) $(@L@LIST) $(ZSH_@E@XPORT) $(@L@IBZSH) $(LIBS)
+	$(@L@DRUNPATH) $(LINK) $(MAIN_OBJS) $(EXTRAZSHOBJS) $(@L@LIST) $(ZSH_@E@XPORT) $(@L@IBZSH) $(LIBS_M) $(LIBS_TERMCAP) $(LIBS_YP) $(LIBS)
 
 $(LIBZSH): $(LIBOBJS) $(NSTMP)
 	rm -f $@
-	$(DLLINK) $(LIBOBJS) $(NLIST) $(LIBS)
+	$(DLLINK) $(LIBOBJS) $(NLIST) $(LIBS_M) $(LIBS_TERMCAP) $(LIBS)
 
 zsh.res.o: $(sdir)/zsh.rc $(sdir)/zsh.ico
 	windres -O coff --include-dir $(sdir) -i $(sdir)/zsh.rc -o zsh.res.o
Index: Src/mkmakemod.sh
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/mkmakemod.sh,v
retrieving revision 1.8
diff -u -r1.8 mkmakemod.sh
--- Src/mkmakemod.sh	2001/04/19 01:44:30	1.8
+++ Src/mkmakemod.sh	2001/04/19 14:38:12
@@ -27,6 +27,7 @@
 #   autoprefixconds like autoinfixconds, but for prefix condition codes
 #   autoparams      parameters defined by the module, for autoloading
 #   automathfuncs   math functions defined by the module, for autoloading
+#   extralibs       libraries specific to this module (default none)
 #   objects         .o files making up this module (*must* be defined)
 #   proto           .syms files for this module (default generated from $objects)
 #   headers         extra headers for this module (default none)
@@ -190,7 +191,8 @@
 
 	unset name moddeps nozshdep alwayslink hasexport
 	unset autobins autoinfixconds autoprefixconds autoparams automathfuncs
-	unset objects proto headers hdrdeps otherincs
+	unset extralibs objects proto headers hdrdeps otherincs
+	unset EXTRALIBS
 	. $top_srcdir/$the_subdir/${mddname}.mdd
 	q_name=`echo $name | sed 's,Q,Qq,g;s,_,Qu,g;s,/,Qs,g'`
 	test -n "${moddeps+set}" || moddeps=
@@ -199,6 +201,24 @@
 	    proto=`echo $objects '' | sed 's,\.o ,.syms ,g'`
 
 	dobjects=`echo $objects '' | sed 's,\.o ,..o ,g'`
+
+	for lib in $extralibs; do
+	case $lib in
+	m) EXTRALIBS="$EXTRALIBS \$(LIBS_M)"
+	;;
+	cap) EXTRALIBS="$EXTRALIBS \$(LIBS_CAP)"
+	;;
+	socket) EXTRALIBS="$EXTRALIBS \$(LIBS_SOCKET)"
+	;;
+	termcap) EXTRALIBS="$EXTRALIBS \$(LIBS_TERMCAP)"
+	;;
+	terminfo) EXTRALIBS="$EXTRALIBS \$(LIBS_TERMINFO)"
+	;;
+	yp) EXTRALIBS="$EXTRALIBS \$(LIBS_YP)"
+	;;
+	esac
+	done
+
 	modhdeps=
 	mododeps=
 	exportdeps=
@@ -302,6 +322,7 @@
 	echo "NXPIMP_${mddname} ="
 	echo "LINKMODS_${mddname} = $mododeps"
 	echo "NOLINKMODS_${mddname} = "
+	echo "EXTRALIBS_${mddname} = $EXTRALIBS"
 	echo
 	echo "proto.${mddname}: \$(EPRO_${mddname})"
 	echo "\$(SYMS_${mddname}): \$(PROTODEPS)"
@@ -328,7 +349,7 @@
 	    echo
 	    echo "${mddname}.\$(DL_EXT): \$(MODDOBJS_${mddname}) ${mddname}.export $exportdeps \$(@LINKMODS@_${mddname})"
 	    echo '	rm -f $@'
-	    echo "	\$(DLLINK) \$(@E@XPIMP_$mddname) \$(@E@NTRYOPT) \$(MODDOBJS_${mddname}) \$(@LINKMODS@_${mddname}) \$(LIBS) "
+	    echo "	\$(DLLINK) \$(@E@XPIMP_$mddname) \$(@E@NTRYOPT) \$(MODDOBJS_${mddname}) \$(@LINKMODS@_${mddname}) $EXTRALIBS \$(LIBS)"
 	    echo
 	fi
 	echo "${mddname}.mdhi: ${mddname}.mdhs \$(INCS_${mddname})"
Index: Src/zsh.mdd
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.mdd,v
retrieving revision 1.7
diff -u -r1.7 zsh.mdd
--- Src/zsh.mdd	2001/04/02 14:36:38	1.7
+++ Src/zsh.mdd	2001/04/19 14:38:12
@@ -17,6 +17,8 @@
 headers="../config.h system.h zsh.h sigcount.h signals.h \
 prototypes.h hashtable.h ztype.h"
 
+extralibs="m termcap yp"
+
 :<<\Make
 @CONFIG_MK@
 
Index: Src/Modules/cap.mdd
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/cap.mdd,v
retrieving revision 1.2
diff -u -r1.2 cap.mdd
--- Src/Modules/cap.mdd	2000/11/26 20:01:03	1.2
+++ Src/Modules/cap.mdd	2001/04/19 14:38:12
@@ -5,3 +5,5 @@
 autobins="cap getcap setcap"
 
 objects="cap.o"
+
+extralibs="cap"
Index: Src/Modules/termcap.mdd
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/termcap.mdd,v
retrieving revision 1.4
diff -u -r1.4 termcap.mdd
--- Src/Modules/termcap.mdd	2001/04/09 17:26:59	1.4
+++ Src/Modules/termcap.mdd	2001/04/19 14:38:12
@@ -15,3 +15,5 @@
 autobins="echotc"
 
 objects="termcap.o"
+
+extralibs="termcap"
Index: Src/Modules/terminfo.mdd
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/terminfo.mdd,v
retrieving revision 1.6
diff -u -r1.6 terminfo.mdd
--- Src/Modules/terminfo.mdd	2001/04/09 17:26:59	1.6
+++ Src/Modules/terminfo.mdd	2001/04/19 14:38:12
@@ -16,3 +16,5 @@
 autoparams="terminfo"
 
 objects="terminfo.o"
+
+extralibs="terminfo"


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: reduce unnecessary linking
  2001-04-19 14:41 PATCH: reduce unnecessary linking Clint Adams
@ 2001-04-19 14:53 ` Andrej Borsenkow
  2001-04-19 15:55   ` Andrej Borsenkow
  2001-04-19 15:59   ` Clint Adams
  0 siblings, 2 replies; 6+ messages in thread
From: Andrej Borsenkow @ 2001-04-19 14:53 UTC (permalink / raw)
  To: zsh-workers

On Thu, 19 Apr 2001, Clint Adams wrote:


> +dnl zsh_SEARCH_LIBS(FUNCTION, SEARCH-LIBS [, ACTION-IF-FOUND


What was wrong with AC_SEARCH_LIBS?

>
> -AC_CHECK_LIB(socket, socket)
> +AC_CHECK_LIB(socket, socket, [LIBS_SOCKET="-lsocket"
> +AC_DEFINE(HAVE_LIBSOCKET)])
>

No, that won't do. I (being on SVR4) need '-lsocket -lnsl' for any
networking code (what our Solaris fellas say?) Moreover, I *do* need them
both in *main* module and not in any DSO (else some funny effects may
happen).

I really suggest that this patch should be hold off till 4.0.1 release. It
is just too dangerous and can break too much.

Not everybody is using Linux ... yet :-)

-andrej


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: reduce unnecessary linking
  2001-04-19 14:53 ` Andrej Borsenkow
@ 2001-04-19 15:55   ` Andrej Borsenkow
  2001-04-19 16:02     ` Clint Adams
  2001-04-19 15:59   ` Clint Adams
  1 sibling, 1 reply; 6+ messages in thread
From: Andrej Borsenkow @ 2001-04-19 15:55 UTC (permalink / raw)
  To: zsh-workers

On Thu, 19 Apr 2001, Andrej Borsenkow wrote:

> >
> > -AC_CHECK_LIB(socket, socket)
> > +AC_CHECK_LIB(socket, socket, [LIBS_SOCKET="-lsocket"
> > +AC_DEFINE(HAVE_LIBSOCKET)])
> >
>
> No, that won't do. I (being on SVR4) need '-lsocket -lnsl' for any
> networking code (what our Solaris fellas say?) Moreover, I *do* need them
> both in *main* module and not in any DSO (else some funny effects may
> happen).
>

And actually on my system it is very hard (near to impossible) to link
shared module with (dynamic) library. Basically, in

cc -G -o foo.so ... -lbar

any -lbar is simply ignored. So, you cannot link zftp with -lsocket while
omitting -lsocket for main module.


> I really suggest that this patch should be hold off till 4.0.1 release. It
> is just too dangerous and can break too much.
>

And in any case - this optimisation should be used only for systems that
are known to support it.

-andrej


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: reduce unnecessary linking
  2001-04-19 14:53 ` Andrej Borsenkow
  2001-04-19 15:55   ` Andrej Borsenkow
@ 2001-04-19 15:59   ` Clint Adams
  2001-04-19 18:15     ` Andrej Borsenkow
  1 sibling, 1 reply; 6+ messages in thread
From: Clint Adams @ 2001-04-19 15:59 UTC (permalink / raw)
  To: Andrej Borsenkow; +Cc: zsh-workers

> What was wrong with AC_SEARCH_LIBS?

It adds the library to LIBS, which would be counterproductive.

> No, that won't do. I (being on SVR4) need '-lsocket -lnsl' for any
> networking code (what our Solaris fellas say?) Moreover, I *do* need them
> both in *main* module and not in any DSO (else some funny effects may
> happen).

I can't compile current CVS on Solaris 8, or I'd check.  -lnsl should
already be in the main module, because that's where yp_all is called.
I'll add -lsocket to zftp.mdd.

Are you saying that all the libraries that any DSO's are linked against
need to be linked to the main binary?

configure:2623: gcc -E -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 conftest.c >/d
ev/null 2>conftest.out
In file included from /usr/include/curses.h:23,
                 from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2/include
/curses.h:5,
                 from configure:2619:
/usr/include/widec.h:38: warning: `getwc' redefined
/usr/include/iso/wchar_iso.h:337: warning: this is the location of the previous 
definition
/usr/include/widec.h:39: warning: `putwc' redefined
/usr/include/iso/wchar_iso.h:340: warning: this is the location of the previous 
definition
/usr/include/widec.h:40: warning: `getwchar' redefined
/usr/include/iso/wchar_iso.h:338: warning: this is the location of the previous 
definition
/usr/include/widec.h:41: warning: `putwchar' redefined
/usr/include/iso/wchar_iso.h:341: warning: this is the location of the previous 
definition
configure: failed program was:
#line 2618 "configure"
#include "confdefs.h"
#include <curses.h>

> I really suggest that this patch should be hold off till 4.0.1 release. It
> is just too dangerous and can break too much.

We should probably start branching in CVS.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: reduce unnecessary linking
  2001-04-19 15:55   ` Andrej Borsenkow
@ 2001-04-19 16:02     ` Clint Adams
  0 siblings, 0 replies; 6+ messages in thread
From: Clint Adams @ 2001-04-19 16:02 UTC (permalink / raw)
  To: Andrej Borsenkow; +Cc: zsh-workers

> And actually on my system it is very hard (near to impossible) to link
> shared module with (dynamic) library. Basically, in
> 
> cc -G -o foo.so ... -lbar
> 
> any -lbar is simply ignored. So, you cannot link zftp with -lsocket while
> omitting -lsocket for main module.

Is there a good way to test for that?

> And in any case - this optimisation should be used only for systems that
> are known to support it.

That's fair.  I'll simulate the old behavior for now.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: reduce unnecessary linking
  2001-04-19 15:59   ` Clint Adams
@ 2001-04-19 18:15     ` Andrej Borsenkow
  0 siblings, 0 replies; 6+ messages in thread
From: Andrej Borsenkow @ 2001-04-19 18:15 UTC (permalink / raw)
  To: zsh-workers

On Thu, 19 Apr 2001, Clint Adams wrote:

>
> Are you saying that all the libraries that any DSO's are linked against
> need to be linked to the main binary?
>

Sort of. And in particular order (due to ugly interdependencies) :( It is
actually a bit more complicated - but in default linkage mode (binding
happens at runtime) - yes, that's correct. Anything else needs real
testing and lacks good documentation.

-andrej


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-04-19 18:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-19 14:41 PATCH: reduce unnecessary linking Clint Adams
2001-04-19 14:53 ` Andrej Borsenkow
2001-04-19 15:55   ` Andrej Borsenkow
2001-04-19 16:02     ` Clint Adams
2001-04-19 15:59   ` Clint Adams
2001-04-19 18:15     ` Andrej Borsenkow

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).