From owner-freebsd-hackers@FreeBSD.ORG Tue Dec 20 11:41:25 2005 Return-Path: X-Original-To: hackers@FreeBSD.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EFFF216A41F for ; Tue, 20 Dec 2005 11:41:24 +0000 (GMT) (envelope-from ceri@submonkey.net) Received: from shrike.submonkey.net (cpc2-cdif2-3-1-cust208.cdif.cable.ntl.com [82.31.78.208]) by mx1.FreeBSD.org (Postfix) with ESMTP id B9D3D43D4C for ; Tue, 20 Dec 2005 11:41:22 +0000 (GMT) (envelope-from ceri@submonkey.net) Received: from ceri by shrike.submonkey.net with local (Exim 4.60 (FreeBSD)) (envelope-from ) id 1Eofrt-000C5a-UQ for hackers@FreeBSD.org; Tue, 20 Dec 2005 11:41:21 +0000 Date: Tue, 20 Dec 2005 11:41:21 +0000 From: Ceri Davies To: hackers@FreeBSD.org Message-ID: <20051220114121.GA58620@submonkey.net> Mail-Followup-To: Ceri Davies , hackers@FreeBSD.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ADZbWkCsHQ7r3kzd" Content-Disposition: inline X-PGP: finger ceri@FreeBSD.org User-Agent: Mutt/1.5.11 Sender: Ceri Davies Cc: Subject: Mostly static binaries with crunchgen X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Dec 2005 11:41:25 -0000 --ADZbWkCsHQ7r3kzd Content-Type: multipart/mixed; boundary="Kj7319i9nmIyA2yE" Content-Disposition: inline --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Adrian Steinmann's talk at EuroBSDcon regarding a single user SSH daemon for rescue purposes highlighted an interesting point regarding some binaries. The GEOM userland binaries such as gmirror, gstripe, etc. use dlopen() to load classes from /lib/geom and therefore cannot be statically linked and, by extension, cannot be crunched with crunchgen. Adrian mentioned that it would be useful if crunchgen(1) supported "mostly static" binaries; i.e., a libs_so extension to crunchgen which would allow these binaries to be crunched, simply requiring then that rtld and the libraries be made available on the memory disk. This allows those of us who use GEOM classes to make a small rescue disk. I started to add this to crunchgen on the way home, and have worked with Adrian to finish it off. The patch is attached. It simply adds a "libs_so" keyword which specifies libraries that will be linked statically; all current config files continue to produce the same code as they did before. I'd like to commit this with a 6 week MFC period or so, but my mentor is currently busy. Could someone else please take this up? Ceri --=20 Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. -- Einstein (attrib.) --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="crunchgen.so.diff" Content-Transfer-Encoding: quoted-printable Index: crunchgen.1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/ncvs/src/usr.sbin/crunch/crunchgen/crunchgen.1,v retrieving revision 1.28 diff -u -r1.28 crunchgen.1 --- crunchgen.1 30 May 2002 07:51:22 -0000 1.28 +++ crunchgen.1 14 Dec 2005 21:11:30 -0000 @@ -16,7 +16,7 @@ .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U= =2EM. .\" BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DA= MAGES .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT O= F OR +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION, ARISING OUT O= F OR .\" IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" .\" Author: James da Silva, Systems Design and Analysis Group @@ -139,7 +139,7 @@ .Nm . This is useful to define some make variables such as .Va RELEASE_CRUNCH -or similar, which might affect the behaviour of +or similar, which might affect the behavior of .Xr make 1 and are annoying to pass through environment variables. .It Fl m Ar makefile-name @@ -210,6 +210,21 @@ Multiple .Ic libs lines can be specified. +.It Ic libs_so Ar libspec ... +A list of library specifications to be dynamically linked in the +crunched binary. +These libraries will need to be made available via the run-time link-editor +.Xr rtld 1 +when the component program that requires them is executed from +the crunched binary. +Multiple +.Ic libs_so +lines can be specified. +The +.Ic libs_so +directive overrides a library specified gratuitously on a +.Ic libs +line. .It Ic buildopts Ar buildopts ... A list of build options to be added to every make target. .It Ic ln Ar progname linkname @@ -417,9 +432,15 @@ .Dq Pa kcopy can be copied onto an install floppy and hard-linked to the names of the component programs. +.Pp +Note that if the=20 +.Ic libs_so +command had been used, copies of the libraries so named +would also need to be copied to the install floppy. .Sh SEE ALSO .Xr crunchide 1 , -.Xr make 1 +.Xr make 1 , +.Xr rtld 1 .Sh CAVEATS While .Nm @@ -446,3 +467,10 @@ .Pp Copyright (c) 1994 University of Maryland. All Rights Reserved. +.Pp +The=20 +.Ic libs_so +keyword was added in 2005 by +.An Adrian Steinmann Aq ast@marabu.ch +and +.An Ceri Davies Aq ceri@FreeBSD.org . Index: crunchgen.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/ncvs/src/usr.sbin/crunch/crunchgen/crunchgen.c,v retrieving revision 1.35 diff -u -r1.35 crunchgen.c --- crunchgen.c 20 Jan 2005 10:49:03 -0000 1.35 +++ crunchgen.c 14 Dec 2005 21:11:30 -0000 @@ -74,6 +74,7 @@ strlst_t *keeplist; strlst_t *links; strlst_t *libs; + strlst_t *libs_so; int goterror; } prog_t; =20 @@ -83,6 +84,7 @@ strlst_t *buildopts =3D NULL; strlst_t *srcdirs =3D NULL; strlst_t *libs =3D NULL; +strlst_t *libs_so =3D NULL; prog_t *progs =3D NULL; =20 char confname[MAXPATHLEN], infilename[MAXPATHLEN]; @@ -106,6 +108,8 @@ void add_string(strlst_t **listp, char *str); int is_dir(char *pathname); int is_nonempty_file(char *pathname); +int subtract_strlst(strlst_t **lista, strlst_t **listb); +int in_list(strlst_t **listp, char *str); =20 /* helper routines for main() */ =20 @@ -238,6 +242,7 @@ void add_progs(int argc, char **argv); void add_link(int argc, char **argv); void add_libs(int argc, char **argv); +void add_libs_so(int argc, char **argv); void add_buildopts(int argc, char **argv); void add_special(int argc, char **argv); =20 @@ -292,6 +297,8 @@ f =3D add_link; else if(!strcmp(fieldv[0], "libs")) f =3D add_libs; + else if(!strcmp(fieldv[0], "libs_so")) + f =3D add_libs_so; else if(!strcmp(fieldv[0], "buildopts")) f =3D add_buildopts; else if(!strcmp(fieldv[0], "special")) @@ -408,6 +415,7 @@ p2->objdir =3D NULL; p2->links =3D NULL; p2->libs =3D NULL; + p2->libs_so =3D NULL; p2->objs =3D NULL; p2->keeplist =3D NULL; p2->buildopts =3D NULL; @@ -443,8 +451,27 @@ { int i; =20 - for(i =3D 1; i < argc; i++) + for(i =3D 1; i < argc; i++) { add_string(&libs, argv[i]); + if ( in_list(&libs_so, argv[i]) ) + warnx("%s:%d: " + "library `%s' specified as dynamic earlier", + curfilename, linenum, argv[i]); + } +} + + +void add_libs_so(int argc, char **argv) +{ + int i; + + for(i =3D 1; i < argc; i++) { + add_string(&libs_so, argv[i]); + if ( in_list(&libs, argv[i]) ) + warnx("%s:%d: " + "library `%s' specified as static earlier", + curfilename, linenum, argv[i]); + } } =20 =20 @@ -922,9 +949,15 @@ { prog_t *p; =20 + if ( subtract_strlst(&libs, &libs_so) ) + fprintf(outmk, "# NOTE: Some LIBS declarations below overridden by LIBS_= SO\n"); + fprintf(outmk, "LIBS+=3D"); output_strlst(outmk, libs); =20 + fprintf(outmk, "LIBS_SO+=3D"); + output_strlst(outmk, libs_so); + if (makeobj) { fprintf(outmk, "MAKEOBJDIRPREFIX?=3D%s\n", objprefix); fprintf(outmk, "MAKEENV=3Denv MAKEOBJDIRPREFIX=3D$(MAKEOBJDIRPREFIX)\n"); @@ -954,8 +987,10 @@ fprintf(outmk, "all: objs exe\nobjs: $(SUBMAKE_TARGETS)\n"); fprintf(outmk, "exe: %s\n", execfname); fprintf(outmk, "%s: %s.o $(CRUNCHED_OBJS)\n", execfname, execfname); - fprintf(outmk, "\t$(CC) -static -o %s %s.o $(CRUNCHED_OBJS) $(LIBS)\n", + fprintf(outmk, "\t$(CC) -o %s %s.o $(CRUNCHED_OBJS) \\\n", execfname, execfname); + fprintf(outmk, "\t\t-Xlinker -Bstatic $(LIBS) \\\n"); + fprintf(outmk, "\t\t-Xlinker -Bdynamic $(LIBS_SO)\n"); fprintf(outmk, "\tstrip %s\n", execfname); fprintf(outmk, "realclean: clean subclean\n"); fprintf(outmk, "clean:\n\trm -f %s *.lo *.o *_stub.c\n", execfname); @@ -1031,6 +1066,7 @@ p->name, p->name, p->ident); if (p->libs) fprintf(outmk, " $(%s_LIBS)", p->ident); + fprintf(outmk, "\n"); fprintf(outmk, "\tld -dc -r -o %s.lo %s_stub.o $(%s_OBJPATHS)", p->name, p->name, p->ident); @@ -1046,7 +1082,8 @@ void output_strlst(FILE *outf, strlst_t *lst) { for (; lst !=3D NULL; lst =3D lst->next) - fprintf(outf, " %s", lst->str); + if ( strlen(lst->str) ) + fprintf(outf, " %s", lst->str); fprintf(outf, "\n"); } =20 @@ -1106,6 +1143,27 @@ p1->next =3D p2; } =20 +int subtract_strlst(strlst_t **lista, strlst_t **listb) +{ + int subtract_count =3D 0; + strlst_t *p1; + for (p1 =3D *listb; p1 !=3D NULL; p1 =3D p1->next) + if ( in_list(lista, p1->str) ) { + warnx("Will compile library `%s' dynamically", p1->str); + strcat(p1->str, ""); + subtract_count++; + } + return subtract_count; +} + +int in_list(strlst_t **listp, char *str) +{ + strlst_t *p1; + for (p1 =3D *listp; p1 !=3D NULL; p1 =3D p1->next) + if (!strcmp(p1->str, str)) + return 1; + return 0; +} =20 int is_dir(char *pathname) { --Kj7319i9nmIyA2yE-- --ADZbWkCsHQ7r3kzd Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (FreeBSD) iD8DBQFDp+3hocfcwTS3JF8RAuCOAJ4g5wUcbJXheJoyHwZfAxupGL/eqACeLUrf frmiXndfTbYcUs5T+e8wPcs= =1vJf -----END PGP SIGNATURE----- --ADZbWkCsHQ7r3kzd--