Date: Wed, 21 Dec 2005 09:41:30 +0000 From: Ceri Davies <ceri@submonkey.net> To: John Baldwin <jhb@freebsd.org> Cc: freebsd-hackers@freebsd.org Subject: Re: Mostly static binaries with crunchgen Message-ID: <20051221094130.GB20540@submonkey.net> In-Reply-To: <200512201641.02898.jhb@freebsd.org> References: <20051220114121.GA58620@submonkey.net> <200512201343.59668.jhb@freebsd.org> <20051220213131.GA20540@submonkey.net> <200512201641.02898.jhb@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--NKoe5XOeduwbEQHU Content-Type: multipart/mixed; boundary="VrqPEDrXMn8OVzN4" Content-Disposition: inline --VrqPEDrXMn8OVzN4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Dec 20, 2005 at 04:41:01PM -0500, John Baldwin wrote: > On Tuesday 20 December 2005 04:31 pm, Ceri Davies wrote: > > On Tue, Dec 20, 2005 at 01:43:58PM -0500, John Baldwin wrote: > > > On Tuesday 20 December 2005 10:58 am, Ceri Davies wrote: > > > > On Tue, Dec 20, 2005 at 10:29:27AM -0500, John Baldwin wrote: > > > > > The other concern is does this force the entire crunch to require= a > > > > > working rtld now? If so, that would mean that this wouldn't be > > > > > appropriate for something such as /rescue. If there were a way to > > > > > statically link rtld into the crunch itself that would probably be > > > > > ideal, but I'm not sure that is possible. > > > > > > > > No, just the dynamic bits require rtld. > > > > > > So you can still run /foo without rtld being present if foo doesn't n= eed > > > dlopen, etc.? It looks like you link the crunch with -o dynamic, so > > > isn't the kernel going to complain when you try to exec it that it ca= n't > > > find rtld if rtld is missing? (Think about /rescue if your rtld is h= osed > > > and/or missing.) > > > > Sorry, you're correct of course. It's still useful in Adrian's > > environment at least (because he puts rtld on an MFS). >=20 > One workaround for this case would be to have two crunches, one for the= =20 > pure-static stuff and one for the dynamic-using stuff. Alternatively, if= you=20 > had a way to statically link the rtld functions into the crunch you could= =20 > still use just one crunch. I just want to make sure we don't go turning = this=20 > on for /rescue since that needs to work if rtld is hosed (unless we go th= e=20 > route of two crunches). Ah, OK. The new version attached ensures that if you don't use the libs_so declaration, you get an identical binary to that produced without the patch. Ceri --=20 Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. -- Einstein (attrib.) --VrqPEDrXMn8OVzN4 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="crunchgen.so.diff" Content-Transfer-Encoding: quoted-printable ? crunchgen/fixit.conf Index: crunchgen/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/crunchgen.1 30 May 2002 07:51:22 -0000 1.28 +++ crunchgen/crunchgen.1 21 Dec 2005 09:39:33 -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/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/crunchgen.c 20 Jan 2005 10:49:03 -0000 1.35 +++ crunchgen/crunchgen.c 21 Dec 2005 09:39:33 -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,16 @@ 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, ".if defined(LIBS_SO) && !empty(LIBS_SO)\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, ".else\n"); + fprintf(outmk, "\t$(CC) -o %s %s.o $(CRUNCHED_OBJS) \\\n", execfname, execfname); + fprintf(outmk, "\t\t-Xlinker -Bstatic $(LIBS)\n"); + fprintf(outmk, ".endif\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 +1072,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 +1088,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 +1149,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) { --VrqPEDrXMn8OVzN4-- --NKoe5XOeduwbEQHU Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (FreeBSD) iD8DBQFDqSNKocfcwTS3JF8RAgE/AJ0afUQlmC33E1TCwkwfucjI/2pxGwCgoufa ZMe4u5T6zgSvGPdv2/9DxqY= =brHQ -----END PGP SIGNATURE----- --NKoe5XOeduwbEQHU--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051221094130.GB20540>