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 need
> > > 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 can't
> > > find rtld if rtld is missing?  (Think about /rescue if your rtld is hosed
> > > 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).
> 
> One workaround for this case would be to have two crunches, one for the 
> pure-static stuff and one for the dynamic-using stuff.  Alternatively, if you 
> had a way to statically link the rtld functions into the crunch you could 
> still use just one crunch.  I just want to make sure we don't go turning this 
> on for /rescue since that needs to work if rtld is hosed (unless we go the 
> 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
-- 
Only two things are infinite, the universe and human stupidity, and I'm
not sure about the former.                        -- Einstein (attrib.)
? crunchgen/fixit.conf
Index: crunchgen/crunchgen.1
===================================================================
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.M.
 .\" BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION, ARISING OUT OF 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 
+.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 
+.Ic libs_so
+keyword was added in 2005 by
+.An Adrian Steinmann Aq [EMAIL PROTECTED]
+and
+.An Ceri Davies Aq [EMAIL PROTECTED] .
Index: crunchgen/crunchgen.c
===================================================================
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;
 
@@ -83,6 +84,7 @@
 strlst_t *buildopts = NULL;
 strlst_t *srcdirs   = NULL;
 strlst_t *libs      = NULL;
+strlst_t *libs_so   = NULL;
 prog_t   *progs     = NULL;
 
 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);
 
 /* helper routines for main() */
 
@@ -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);
 
@@ -292,6 +297,8 @@
                        f = add_link;
                else if(!strcmp(fieldv[0], "libs"))
                        f = add_libs;
+               else if(!strcmp(fieldv[0], "libs_so"))
+                       f = add_libs_so;
                else if(!strcmp(fieldv[0], "buildopts"))
                        f = add_buildopts;
                else if(!strcmp(fieldv[0], "special"))
@@ -408,6 +415,7 @@
        p2->objdir = NULL;
        p2->links = NULL;
        p2->libs = NULL;
+       p2->libs_so = NULL;
        p2->objs = NULL;
        p2->keeplist = NULL;
        p2->buildopts = NULL;
@@ -443,8 +451,27 @@
 {
        int i;
 
-       for(i = 1; i < argc; i++)
+       for(i = 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 = 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]);
+       }
 }
 
 
@@ -922,9 +949,15 @@
 {
        prog_t *p;
 
+       if ( subtract_strlst(&libs, &libs_so) )
+               fprintf(outmk, "# NOTE: Some LIBS declarations below overridden 
by LIBS_SO\n");
+
        fprintf(outmk, "LIBS+=");
        output_strlst(outmk, libs);
 
+       fprintf(outmk, "LIBS_SO+=");
+       output_strlst(outmk, libs_so);
+
        if (makeobj) {
                fprintf(outmk, "MAKEOBJDIRPREFIX?=%s\n", objprefix);
                fprintf(outmk, "MAKEENV=env 
MAKEOBJDIRPREFIX=$(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 != NULL; lst = lst->next)
-               fprintf(outf, " %s", lst->str);
+               if ( strlen(lst->str) )
+                       fprintf(outf, " %s", lst->str);
        fprintf(outf, "\n");
 }
 
@@ -1106,6 +1149,27 @@
                p1->next = p2;
 }
 
+int subtract_strlst(strlst_t **lista, strlst_t **listb)
+{
+       int subtract_count = 0;
+       strlst_t *p1;
+       for (p1 = *listb; p1 != NULL; p1 = 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 = *listp; p1 != NULL; p1 = p1->next)
+               if (!strcmp(p1->str, str))
+                       return 1;
+       return 0;
+}
 
 int is_dir(char *pathname)
 {

Attachment: pgp5CnSkbzlql.pgp
Description: PGP signature

Reply via email to