Subject: Re: dynamic linker
To: NetBSD User's Discussion List <netbsd-users@NetBSD.ORG>
From: Greg A. Woods <woods@weird.com>
List: netbsd-users
Date: 03/20/2002 23:06:01
[ On Wednesday, March 20, 2002 at 19:06:23 (-0600), Richard Rauch wrote: ]
> Subject: Re: dynamic linker
>
> Of course, if one could link statically and break the library
> dependancies, one's problems would go away.

One can, and indeed they do!

I've had to modify a number of DEPENDS lines into BUILD_DEPENDS, but I
do it dynamically so that I can share this customised pkgsrc with other
machines that still use dynamic libraries.

In mk/bsd.prefs.mk I've added stuff like:

	LDSTATIC?=		# defined, but empty, by default
	
	.if !empty(LDSTATIC)
	LDSTATIC_DEPENDS=	BUILD_DEPENDS
	CHECK_SHLIBS?=		NO	# don't bother with check-shlibs after install
	SHLIB_HANDLING?=	NO	# do not do automatic shared lib handling
	MKPIC=			no	# don't build or install shared libraries
	NOPIC=			1	# disable stuff that requires PIC support
	.else
	LDSTATIC_DEPENDS=	DEPENDS
	CHECK_SHLIBS?=		YES	# run check-shlibs after install
	SHLIB_HANDLING?=	YES	# do automatic shared lib handling
	MKPIC?=			yes	# do build asd install shared libraries
	.endif

There are quite a few more related changes in mk/bsd.pkg.mk, though most
of the rest are quite obvious, such as adding LDSTATIC to LDFLAGS and
not adding any -Wl,-R flags if LDSTATIC is set, etc.

	.if !empty(LDSTATIC) && empty(LDFLAGS:M*${LDSTATIC}*)
	LDFLAGS+=	${LDSTATIC}
	.endif

	.if !empty(LDSTATIC)
	PLIST_SUBST+= SHARED_ONLY="@comment "
	.else
	PLIST_SUBST+= SHARED_ONLY=""
	.endif

and of course using LDSTATIC_DEPENDS as necessary, such as:

	200,201c200,201
	< # this is a DEPENDS not BUILD_DEPENDS because of the
	< # shared Fortran libs
	---
	> # this is an LDSTATIC_DEPENDS not just BUILD_DEPENDS because of the
	> # shared Fortran run-time libs
	205c205
	< DEPENDS+=	f2c>=20001205nb3:../../lang/f2c
	---
	> ${LDSTATIC_DEPENDS}+=		f2c>=20001205nb3:../../lang/f2c

and of course this is enabled in /etc/mk.conf with the appropriate
setting of LDSTATIC, which is (or at least was) compatibile with the
system build procedure:

	# set LDSTATIC=-static in order to build a static-only system
	#
	# (note you need a *LOT* of disk for '-g' and '-static'
	#
	LDSTATIC=       -static

>  I'm not sure how easy that is
> to do, though.

It's not too hard to do for the very few things I've built that way so
far:

digest-20010807
gtexinfo-4.0
m4-1.4
perl-5.6.1nb6
autoconf-2.52
automake-1.4.5nb1
xpm-3.4k
ctwm-3.5.2
gmake-3.79.1
links-0.96
mawk-1.3.3
gawk-3.0.4
nas-1.5
x11-links-0.5
mpg123-nas-0.59r
ssh2-3.1.0
lynx-2.8.4.1.2
expat-1.95.2
swisswatch-0.06
xearth-1.1nb1
ucd-snmp-4.2.3
intlfonts-1.2
bison-1.28


Currently I have to make the hinted-to changes to the PLIST of all
packages which install shared libraries because I currently don't build
shared libraries and thus there are not files to install.  Ideally I'd
like to build shared libraries but not necessarily use them....  :-)


I have some hope that once the few remaining wrinkles are worked out
(mostly in the "new" buildlink related stuff which all needs to use
LDSTATIC_DEPENDS) the changes I've made can be incorporated into the
official NetBSD pkgsrc so that pkgsrc will work on those architectures
which currently don't have dynamic library support.  Of course this will
require some buy-in from the pkgsrc maintainers who, to date anyway,
have been adamantly going strongly in the reverse direction, even when
packages initially come with no inherent support for building shared
libraries of their components.  Two perfect examples of this have been
rrdtool and ucd-snmp which have been "brutally" forced to be built with
shared libraries (though now net-snmp finally comes with some inherent
support for building shared libraries).


>  I also don't know how big things like KDE or GNOME would
> be if they didn't have shared libraries...(^&

At this point I'm still afraid to try anything really big like that, the
build system of which I don't understand fairly deeply in the first
place, and which doesn't already have inherent static-link support
supplied by the author/maintainer.

X11 itself, i.e. what's in /usr/xsrc, builds statically fairly well, and
it's not really that much bigger than what I remember it being back in
the X11R3 days, at least not after taking into account GCC and sparc
instead of a really good compiler on a good CISC machine....  :-)

Megabyte programs for sure, but only the servers are multi-megabyte.

-- 
								Greg A. Woods

+1 416 218-0098;  <gwoods@acm.org>;  <g.a.woods@ieee.org>;  <woods@robohack.ca>
Planix, Inc. <woods@planix.com>; VE3TCP; Secrets of the Weird <woods@weird.com>