From 6fc6ffe875a65c7dd78db11628a8430879f6c4b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Tigeot?= Date: Sun, 30 Mar 2014 21:55:54 +0200 Subject: [PATCH] Update crunched binaries tools from FreeBSD * Fix amd64/x86_64 confusion * Remove a.out support --- Makefile.inc1 | 3 +- share/mk/bsd.crunchgen.mk | 167 ++++++++ sys/boot/dloader/dloader.menu | 15 + usr.bin/crunch/Makefile | 3 +- usr.bin/crunch/Makefile.inc | 7 +- usr.bin/crunch/crunchgen/Makefile | 3 +- usr.bin/crunch/crunchgen/crunched_main.c | 15 +- usr.bin/crunch/crunchgen/crunchgen.1 | 54 ++- usr.bin/crunch/crunchgen/crunchgen.c | 188 ++++++--- usr.bin/crunch/crunchide/Makefile | 18 +- usr.bin/crunch/crunchide/crunchide.1 | 17 +- usr.bin/crunch/crunchide/crunchide.c | 19 +- usr.bin/crunch/crunchide/exec_aout.c | 207 ---------- usr.bin/crunch/crunchide/exec_elf32.c | 473 ++++++++++++++--------- usr.bin/crunch/crunchide/exec_elf64.c | 7 +- usr.bin/crunch/crunchide/extern.h | 21 +- usr.bin/crunch/examples/Makefile | 17 +- usr.bin/crunch/examples/filesystem.conf | 3 +- usr.bin/crunch/examples/fixit.conf | 2 +- usr.bin/crunch/examples/kcopy.conf | 3 +- usr.bin/crunch/examples/really-big.conf | 33 +- 21 files changed, 735 insertions(+), 540 deletions(-) create mode 100644 share/mk/bsd.crunchgen.mk delete mode 100644 usr.bin/crunch/crunchide/exec_aout.c diff --git a/Makefile.inc1 b/Makefile.inc1 index 0b994bc477..ea46e3d7bb 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -805,7 +805,8 @@ BSTRAPDIRS2= \ usr.sbin/chown usr.sbin/mtree usr.sbin/config \ usr.sbin/btxld usr.sbin/zic usr.sbin/makewhatis \ gnu/usr.bin/texinfo gnu/usr.bin/grep usr.bin/sort \ - usr.bin/gzip usr.bin/bzip2 usr.bin/mkcsmapper usr.bin/mkesdb + usr.bin/gzip usr.bin/bzip2 usr.bin/mkcsmapper usr.bin/mkesdb \ + usr.bin/crunch bootstrap-tools: bootstrap-tools-before bootstrap-tools-targets1 bootstrap-tools-targets2 touch ${BTOOLSDEST}/.bootstrap_done diff --git a/share/mk/bsd.crunchgen.mk b/share/mk/bsd.crunchgen.mk new file mode 100644 index 0000000000..9832881ca0 --- /dev/null +++ b/share/mk/bsd.crunchgen.mk @@ -0,0 +1,167 @@ +################################################################# +# +# General notes: +# +# A number of Make variables are used to generate the crunchgen config file. +# +# CRUNCH_SRCDIRS: lists directories to search for included programs +# CRUNCH_PROGS: lists programs to be included +# CRUNCH_LIBS: libraries to statically link with +# CRUNCH_SHLIBS: libraries to dynamically link with +# CRUNCH_BUILDOPTS: generic build options to be added to every program +# CRUNCH_BUILDTOOLS: lists programs that need build tools built in the +# local architecture. +# +# Special options can be specified for individual programs +# CRUNCH_SRCDIR_$(P): base source directory for program $(P) +# CRUNCH_BUILDOPTS_$(P): additional build options for $(P) +# CRUNCH_ALIAS_$(P): additional names to be used for $(P) +# +# By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P} +# will be used to generate a hard link to the resulting binary. +# Specific links can be suppressed by setting +# CRUNCH_SUPPRESS_LINK_$(NAME) to 1. +# +# If CRUNCH_GENERATE_LINKS is set to no, no links will be generated. +# + +# $FreeBSD: head/share/mk/bsd.crunchgen.mk 251512 2013-06-07 21:40:02Z emaste $ + +################################################################## +# The following is pretty nearly a generic crunchgen-handling makefile +# + +CONF= $(PROG).conf +OUTMK= $(PROG).mk +OUTC= $(PROG).c +OUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache +CRUNCHOBJS= ${.OBJDIR} +.if defined(MAKEOBJDIRPREFIX) +CANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR} +.elif defined(MAKEOBJDIR) && ${MAKEOBJDIR:M/*} != "" +CANONICALOBJDIR:=${MAKEOBJDIR} +.else +CANONICALOBJDIR:= /usr/obj${.CURDIR} +.endif +CRUNCH_GENERATE_LINKS?= yes + +CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h + +# Don't try to extract debug info from ${PROG}. +NO_DEBUG_FILES= + +# Program names and their aliases contribute hardlinks to 'rescue' executable, +# except for those that get suppressed. +.for D in $(CRUNCH_SRCDIRS) +.for P in $(CRUNCH_PROGS_$(D)) +.ifdef CRUNCH_SRCDIR_${P} +$(OUTPUTS): $(CRUNCH_SRCDIR_${P})/Makefile +.else +$(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile +.endif +.if ${CRUNCH_GENERATE_LINKS} == "yes" +.ifndef CRUNCH_SUPPRESS_LINK_${P} +LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P) +.endif +.for A in $(CRUNCH_ALIAS_$(P)) +.ifndef CRUNCH_SUPPRESS_LINK_${A} +LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A) +.endif +.endfor +.endif +.endfor +.endfor + +all: $(PROG) +exe: $(PROG) + +$(CONF): Makefile + echo \# Auto-generated, do not edit >$(.TARGET) +.ifdef CRUNCH_BUILDOPTS + echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET) +.endif +.ifdef CRUNCH_LIBS + echo libs $(CRUNCH_LIBS) >>$(.TARGET) +.endif +.ifdef CRUNCH_SHLIBS + echo libs_so $(CRUNCH_SHLIBS) >>$(.TARGET) +.endif +.for D in $(CRUNCH_SRCDIRS) +.for P in $(CRUNCH_PROGS_$(D)) + echo progs $(P) >>$(.TARGET) +.ifdef CRUNCH_SRCDIR_${P} + echo special $(P) srcdir $(CRUNCH_SRCDIR_${P}) >>$(.TARGET) +.else + echo special $(P) srcdir $(.CURDIR)/../../$(D)/$(P) >>$(.TARGET) +.endif +.ifdef CRUNCH_BUILDOPTS_${P} + echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ \ + $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET) +.else + echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ >>$(.TARGET) +.endif +.for A in $(CRUNCH_ALIAS_$(P)) + echo ln $(P) $(A) >>$(.TARGET) +.endfor +.endfor +.endfor + +# XXX Make sure we don't pass -P to crunchgen(1). +.MAKEFLAGS:= ${.MAKEFLAGS:N-P} +.ORDER: $(OUTPUTS) objs +$(OUTPUTS): $(CONF) + MAKE=${MAKE} MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -fq -m $(OUTMK) \ + -c $(OUTC) $(CONF) + +$(PROG): $(OUTPUTS) objs + MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) exe + +objs: $(OUTMK) + MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) objs + +# Someone should replace the bin/csh and bin/sh build-tools with +# shell scripts so we can remove this nonsense. +build-tools: +.for _tool in $(CRUNCH_BUILDTOOLS) + cd $(.CURDIR)/../../${_tool}; \ + MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \ + MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools +.endfor + +# Use a separate build tree to hold files compiled for this crunchgen binary +# Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't +# get that to cooperate with bsd.prog.mk. Besides, many of the standard +# targets should NOT be propagated into the components. +cleandepend cleandir obj objlink: +.for D in $(CRUNCH_SRCDIRS) +.for P in $(CRUNCH_PROGS_$(D)) +.ifdef CRUNCH_SRCDIR_${P} + cd ${CRUNCH_SRCDIR_$(P)} && \ + MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ + DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} +.else + cd $(.CURDIR)/../../${D}/${P} && \ + MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ + DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} +.endif +.endfor +.endfor + +clean: + rm -f ${CLEANFILES} + if [ -e ${.OBJDIR}/$(OUTMK) ]; then \ + MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) clean; \ + fi +.for D in $(CRUNCH_SRCDIRS) +.for P in $(CRUNCH_PROGS_$(D)) +.ifdef CRUNCH_SRCDIR_${P} + cd ${CRUNCH_SRCDIR_$(P)} && \ + MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ + DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} +.else + cd $(.CURDIR)/../../${D}/${P} && \ + MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ + DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} +.endif +.endfor +.endfor diff --git a/sys/boot/dloader/dloader.menu b/sys/boot/dloader/dloader.menu index dab7df6cb4..016ba395e7 100644 --- a/sys/boot/dloader/dloader.menu +++ b/sys/boot/dloader/dloader.menu @@ -133,6 +133,21 @@ menuadd boot menuadd set autoboot_delay=NO endif +menuitem r "Boot DragonFly in a rescue ramdisk" +menuadd cd ${base}${default_kernel} +menuadd optinclude loader.conf +menuadd optinclude loader.conf.local +menuadd set boot_single="YES" +menuadd lunsetif acpi_load hint.acpi.0.disabled +menuadd lunsetif ehci_load hint.ehci.0.disabled +menuadd lunsetif ahci_load hint.ahci.disabled +menuadd initrd.img_load="YES" +menuadd initrd.img_type="md_image" +menuadd set vfs.root.mountfrom="ufs:md0s0" +menuadd loadall +menuadd boot +menuadd set autoboot_delay=NO + menuitem s "Boot DragonFly in single user mode" menuadd cd ${base}${default_kernel} menuadd optinclude loader.conf diff --git a/usr.bin/crunch/Makefile b/usr.bin/crunch/Makefile index a38e0b9061..67e5b71587 100644 --- a/usr.bin/crunch/Makefile +++ b/usr.bin/crunch/Makefile @@ -1,4 +1,5 @@ +# $FreeBSD: head/usr.sbin/crunch/Makefile 80029 2001-07-20 06:20:32Z obrien $ -SUBDIR=crunchgen crunchide +SUBDIR= crunchgen crunchide .include diff --git a/usr.bin/crunch/Makefile.inc b/usr.bin/crunch/Makefile.inc index ad6e982e6d..2ac565c2bc 100644 --- a/usr.bin/crunch/Makefile.inc +++ b/usr.bin/crunch/Makefile.inc @@ -1,3 +1,6 @@ -WARNS?= 1 +# $FreeBSD: head/usr.sbin/crunch/Makefile.inc 201390 2010-01-02 11:07:44Z ed $ -.include "../Makefile.inc" +# modify to taste +BINDIR?= /usr/bin + +WARNS?= 2 diff --git a/usr.bin/crunch/crunchgen/Makefile b/usr.bin/crunch/crunchgen/Makefile index ecf99d9820..3014db87b7 100644 --- a/usr.bin/crunch/crunchgen/Makefile +++ b/usr.bin/crunch/crunchgen/Makefile @@ -1,5 +1,4 @@ -# $FreeBSD: src/usr.sbin/crunch/crunchgen/Makefile,v 1.4.8.1 2002/04/11 19:41:39 murray Exp $ -# $DragonFly: src/usr.sbin/crunch/crunchgen/Makefile,v 1.2 2003/06/17 04:29:53 dillon Exp $ +# $FreeBSD: head/usr.sbin/crunch/crunchgen/Makefile 80029 2001-07-20 06:20:32Z obrien $ PROG= crunchgen SRCS= crunchgen.c crunched_skel.c diff --git a/usr.bin/crunch/crunchgen/crunched_main.c b/usr.bin/crunch/crunchgen/crunched_main.c index c3bfe07509..2c4ef07c82 100644 --- a/usr.bin/crunch/crunchgen/crunched_main.c +++ b/usr.bin/crunch/crunchgen/crunched_main.c @@ -22,9 +22,6 @@ * Author: James da Silva, Systems Design and Analysis Group * Computer Science Department * University of Maryland at College Park - * - * $FreeBSD: src/usr.sbin/crunch/crunchgen/crunched_main.c,v 1.6.6.2 2002/08/09 02:42:02 gshapiro Exp $ - * $DragonFly: src/usr.sbin/crunch/crunchgen/crunched_main.c,v 1.3 2003/11/16 14:10:44 eirikn Exp $ */ /* * crunched_main.c - main program for crunched binaries, it branches to a @@ -34,7 +31,12 @@ * or calls one of them based on argv[1]. This allows the testing of * the crunched binary without creating all the links. */ + +#include +__FBSDID("$FreeBSD: head/usr.sbin/crunch/crunchgen/crunched_main.c 237625 2012-06-27 04:39:30Z obrien $"); + #include +#include #include struct stub { @@ -42,6 +44,7 @@ struct stub { int (*f)(); }; +extern char *__progname; extern struct stub entry_points[]; int @@ -87,18 +90,22 @@ crunched_here(char *path) int crunched_main(int argc, char **argv, char **envp) { + char *slash; struct stub *ep; int columns, len; if(argc <= 1) crunched_usage(); + slash = strrchr(argv[1], '/'); + __progname = slash? slash+1 : argv[1]; + return main(--argc, ++argv, envp); } int -crunched_usage(void) +crunched_usage() { int columns, len; struct stub *ep; diff --git a/usr.bin/crunch/crunchgen/crunchgen.1 b/usr.bin/crunch/crunchgen/crunchgen.1 index de57b15759..a6a6595239 100644 --- a/usr.bin/crunch/crunchgen/crunchgen.1 +++ b/usr.bin/crunch/crunchgen/crunchgen.1 @@ -22,10 +22,9 @@ .\" Author: James da Silva, Systems Design and Analysis Group .\" Computer Science Department .\" University of Maryland at College Park -.\" $FreeBSD: src/usr.sbin/crunch/crunchgen/crunchgen.1,v 1.11.2.11 2003/03/12 22:08:13 trhodes Exp $ -.\" $DragonFly: src/usr.sbin/crunch/crunchgen/crunchgen.1,v 1.3 2008/05/02 02:05:07 swildner Exp $ +.\" $FreeBSD: head/usr.sbin/crunch/crunchgen/crunchgen.1 213573 2010-10-08 12:40:16Z uqs $ .\" -.Dd November 16, 2000 +.Dd December 23, 2005 .Dt CRUNCHGEN 1 .Os .Sh NAME @@ -140,7 +139,7 @@ generated by .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 @@ -211,6 +210,21 @@ A list of library specifications to be included in the crunched binary link. 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 @@ -416,9 +430,31 @@ At this point the binary .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 AUTHORS +.An -nosplit +The +.Nm +utility was written by +.An James da Silva Aq jds@cs.umd.edu . +.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 ast@marabu.ch +and +.An Ceri Davies Aq ceri@FreeBSD.org . .Sh CAVEATS While .Nm @@ -437,11 +473,3 @@ The .Dq Li make objs must then be used to get those object files built, or some other arrangements made. -.Sh AUTHORS -The -.Nm -utility was written by -.An James da Silva Aq jds@cs.umd.edu . -.Pp -Copyright (c) 1994 University of Maryland. -All Rights Reserved. diff --git a/usr.bin/crunch/crunchgen/crunchgen.c b/usr.bin/crunch/crunchgen/crunchgen.c index 3e20625a8e..1df14fb116 100644 --- a/usr.bin/crunch/crunchgen/crunchgen.c +++ b/usr.bin/crunch/crunchgen/crunchgen.c @@ -22,9 +22,6 @@ * Author: James da Silva, Systems Design and Analysis Group * Computer Science Department * University of Maryland at College Park - * - * $FreeBSD: src/usr.sbin/crunch/crunchgen/crunchgen.c,v 1.12.2.10 2002/04/14 20:55:21 luigi Exp $ - * $DragonFly: src/usr.sbin/crunch/crunchgen/crunchgen.c,v 1.4 2005/10/30 23:00:57 swildner Exp $ */ /* * ======================================================================== @@ -33,9 +30,12 @@ * Generates a Makefile and main C file for a crunched executable, * from specs given in a .conf file. */ -#include -#include + +#include +__FBSDID("$FreeBSD: head/usr.sbin/crunch/crunchgen/crunchgen.c 246346 2013-02-05 02:57:59Z pfg $"); + #include +#include #include #include @@ -48,7 +48,7 @@ #define CRUNCH_VERSION "0.2" #define MAXLINELEN 16384 -#define MAXFIELDS 2048 +#define MAXFIELDS 2048 /* internal representation of conf file: */ @@ -75,6 +75,7 @@ typedef struct prog { strlst_t *keeplist; strlst_t *links; strlst_t *libs; + strlst_t *libs_so; int goterror; } prog_t; @@ -84,6 +85,7 @@ typedef struct prog { 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]; @@ -91,6 +93,7 @@ char outmkname[MAXPATHLEN], outcfname[MAXPATHLEN], execfname[MAXPATHLEN]; char tempfname[MAXPATHLEN], cachename[MAXPATHLEN], curfilename[MAXPATHLEN]; char outhdrname[MAXPATHLEN] ; /* user-supplied header for *.mk */ char *objprefix; /* where are the objects ? */ +char *path_make; int linenum = -1; int goterror = 0; @@ -102,11 +105,13 @@ int list_mode; /* general library routines */ -void status(char *str); +void status(const char *str); void out_of_memory(void); void add_string(strlst_t **listp, char *str); -int is_dir(char *pathname); -int is_nonempty_file(char *pathname); +int is_dir(const char *pathname); +int is_nonempty_file(const char *pathname); +int subtract_strlst(strlst_t **lista, strlst_t **listb); +int in_list(strlst_t **listp, char *str); /* helper routines for main() */ @@ -114,6 +119,8 @@ void usage(void); void parse_conf_file(void); void gen_outputs(void); +extern char *crunched_skel[]; + int main(int argc, char **argv) @@ -125,6 +132,10 @@ main(int argc, char **argv) readcache = 1; *outmkname = *outcfname = *execfname = '\0'; + path_make = getenv("MAKE"); + if (path_make == NULL || *path_make == '\0') + path_make = "make"; + p = getenv("MAKEOBJDIRPREFIX"); if (p == NULL || *p == '\0') objprefix = "/usr/obj"; /* default */ @@ -236,11 +247,12 @@ usage(void) /* helper routines for parse_conf_file */ void parse_one_file(char *filename); -void parse_line(char *line, int *fc, char **fv, int nf); +void parse_line(char *pline, int *fc, char **fv, int nf); void add_srcdirs(int argc, char **argv); 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); @@ -297,6 +309,8 @@ parse_one_file(char *filename) 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")) @@ -328,15 +342,15 @@ parse_one_file(char *filename) void -parse_line(char *line, int *fc, char **fv, int nf) +parse_line(char *pline, int *fc, char **fv, int nf) { char *p; - p = line; + p = pline; *fc = 0; while (1) { - while (isspace(*p)) + while (isspace((unsigned char)*p)) p++; if (*p == '\0' || *p == '#') @@ -345,7 +359,7 @@ parse_line(char *line, int *fc, char **fv, int nf) if (*fc < nf) fv[(*fc)++] = p; - while (*p && !isspace(*p) && *p != '#') + while (*p && !isspace((unsigned char)*p) && *p != '#') p++; if (*p == '\0' || *p == '#') @@ -417,6 +431,7 @@ add_prog(char *progname) p2->objdir = NULL; p2->links = NULL; p2->libs = NULL; + p2->libs_so = NULL; p2->objs = NULL; p2->keeplist = NULL; p2->buildopts = NULL; @@ -454,8 +469,28 @@ add_libs(int argc, char **argv) { 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]); + } } @@ -538,8 +573,7 @@ add_special(int argc, char **argv) } -prog_t * -find_prog(char *str) +prog_t *find_prog(char *str) { prog_t *p; @@ -587,7 +621,8 @@ gen_outputs(void) gen_output_makefile(); status(""); fprintf(stderr, - "Run \"make -f %s\" to build crunched binary.\n", outmkname); + "Run \"%s -f %s\" to build crunched binary.\n", + path_make, outmkname); } /* @@ -699,24 +734,27 @@ fillin_program_objs(prog_t *p, char *path) if (outhdrname[0] != '\0') fprintf(f, ".include \"%s\"\n", outhdrname); fprintf(f, ".include \"%s\"\n", path); + fprintf(f, ".POSIX:\n"); if (buildopts) { fprintf(f, "BUILDOPTS+="); output_strlst(f, buildopts); } - fprintf(f, ".if defined(PROG) && !defined(%s)\n", objvar); - fprintf(f, "%s=${PROG}.o\n", objvar); + fprintf(f, ".if defined(PROG)\n"); + fprintf(f, "%s?=${PROG}.o\n", objvar); fprintf(f, ".endif\n"); fprintf(f, "loop:\n\t@echo 'OBJS= '${%s}\n", objvar); - fprintf(f, "crunchgen_objs:\n\t@make -f %s $(BUILDOPTS) $(%s_OPTS)", - tempfname, p->ident); + fprintf(f, "crunchgen_objs:\n" + "\t@cd %s && %s -f %s $(BUILDOPTS) $(%s_OPTS)", + p->srcdir, path_make, tempfname, p->ident); for (s = p->buildopts; s != NULL; s = s->next) fprintf(f, " %s", s->str); fprintf(f, " loop\n"); fclose(f); - snprintf(line, MAXLINELEN, "make -f %s crunchgen_objs 2>&1", tempfname); + snprintf(line, MAXLINELEN, "cd %s && %s -f %s -B crunchgen_objs", + p->srcdir, path_make, tempfname); if ((f = popen(line, "r")) == NULL) { warn("submake pipe"); goterror = 1; @@ -731,17 +769,17 @@ fillin_program_objs(prog_t *p, char *path) } cp = line + 6; - while (isspace(*cp)) + while (isspace((unsigned char)*cp)) cp++; while(*cp) { obj = cp; - while (*cp && !isspace(*cp)) + while (*cp && !isspace((unsigned char)*cp)) cp++; if (*cp) *cp++ = '\0'; add_string(&p->objs, obj); - while (isspace(*cp)) + while (isspace((unsigned char)*cp)) cp++; } } @@ -851,7 +889,6 @@ gen_output_makefile(void) void gen_output_cfile(void) { - extern char *crunched_skel[]; char **cp; FILE *outcf; prog_t *p; @@ -893,8 +930,7 @@ gen_output_cfile(void) } -char * -genident(char *str) +char *genident(char *str) { char *n, *s, *d; @@ -910,7 +946,7 @@ genident(char *str) for (d = s = n; *s != '\0'; s++) { if (*s == '-') *d++ = '_'; - else if (*s == '_' || isalnum(*s)) + else if (*s == '_' || isalnum((unsigned char)*s)) *d++ = *s; } *d = '\0'; @@ -918,8 +954,7 @@ genident(char *str) } -char * -dir_search(char *progname) +char *dir_search(char *progname) { char path[MAXPATHLEN]; strlst_t *dir; @@ -944,15 +979,22 @@ top_makefile_rules(FILE *outmk) { prog_t *p; + fprintf(outmk, "LD?= ld\n"); + 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, "MAKE=env MAKEOBJDIRPREFIX=$(MAKEOBJDIRPREFIX) " - "make\n"); + fprintf(outmk, "MAKEENV=env MAKEOBJDIRPREFIX=$(MAKEOBJDIRPREFIX)\n"); + fprintf(outmk, "CRUNCHMAKE=$(MAKEENV) $(MAKE)\n"); } else { - fprintf(outmk, "MAKE=make\n"); + fprintf(outmk, "CRUNCHMAKE=$(MAKE)\n"); } if (buildopts) { @@ -975,9 +1017,16 @@ top_makefile_rules(FILE *outmk) 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, "%s: %s.o $(CRUNCHED_OBJS) $(SUBMAKE_TARGETS)\n", execfname, execfname); + 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) -static -o %s %s.o $(CRUNCHED_OBJS) $(LIBS)\n", execfname, execfname); + 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); @@ -1000,6 +1049,16 @@ prog_makefile_rules(FILE *outmk, prog_t *p) p->ident); fprintf(outmk, "\n"); + fprintf(outmk, "%s_OBJPATHS=", p->ident); + if (p->objpaths) + output_strlst(outmk, p->objpaths); + else { + for (lst = p->objs; lst != NULL; lst = lst->next) { + fprintf(outmk, " $(%s_OBJDIR)/%s", p->ident, lst->str); + } + fprintf(outmk, "\n"); + } + if (p->srcdir && p->objs) { fprintf(outmk, "%s_SRCDIR=%s\n", p->ident, p->srcdir); fprintf(outmk, "%s_REALSRCDIR=%s\n", p->ident, p->realsrcdir); @@ -1010,20 +1069,23 @@ prog_makefile_rules(FILE *outmk, prog_t *p) fprintf(outmk, "%s_OPTS+=", p->ident); output_strlst(outmk, p->buildopts); } +#if 0 + fprintf(outmk, "$(%s_OBJPATHS): %s_make\n\n", p->ident, p->ident); +#endif fprintf(outmk, "%s_make:\n", p->ident); fprintf(outmk, "\t(cd $(%s_SRCDIR) && ", p->ident); if (makeobj) - fprintf(outmk, "$(MAKE) obj && "); + fprintf(outmk, "$(CRUNCHMAKE) obj && "); fprintf(outmk, "\\\n"); - fprintf(outmk, "\t\t$(MAKE) $(BUILDOPTS) $(%s_OPTS) depend &&", + fprintf(outmk, "\t\t$(CRUNCHMAKE) $(BUILDOPTS) $(%s_OPTS) depend &&", p->ident); fprintf(outmk, "\\\n"); - fprintf(outmk, "\t\t$(MAKE) $(BUILDOPTS) $(%s_OPTS) " + fprintf(outmk, "\t\t$(CRUNCHMAKE) $(BUILDOPTS) $(%s_OPTS) " "$(%s_OBJS))", p->ident, p->ident); fprintf(outmk, "\n"); fprintf(outmk, "%s_clean:\n", p->ident); - fprintf(outmk, "\t(cd $(%s_SRCDIR) && $(MAKE) $(BUILDOPTS) clean cleandepend)\n\n", + fprintf(outmk, "\t(cd $(%s_SRCDIR) && $(CRUNCHMAKE) $(BUILDOPTS) clean cleandepend)\n\n", p->ident); } else { fprintf(outmk, "%s_make:\n", p->ident); @@ -1031,15 +1093,6 @@ prog_makefile_rules(FILE *outmk, prog_t *p) p->name); } - fprintf(outmk, "%s_OBJPATHS=", p->ident); - if (p->objpaths) - output_strlst(outmk, p->objpaths); - else { - for (lst = p->objs; lst != NULL; lst = lst->next) { - fprintf(outmk, " $(%s_OBJDIR)/%s", p->ident, lst->str); - } - fprintf(outmk, "\n"); - } if (p->libs) { fprintf(outmk, "%s_LIBS=", p->ident); output_strlst(outmk, p->libs); @@ -1054,8 +1107,9 @@ prog_makefile_rules(FILE *outmk, prog_t *p) 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)", + fprintf(outmk, "\t$(LD) -dc -r -o %s.lo %s_stub.o $(%s_OBJPATHS)", p->name, p->name, p->ident); if (p->libs) fprintf(outmk, " $(%s_LIBS)", p->ident); @@ -1070,7 +1124,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"); } @@ -1082,7 +1137,7 @@ output_strlst(FILE *outf, strlst_t *lst) */ void -status(char *str) +status(const char *str) { static int lastlen = 0; int len, spaces; @@ -1123,7 +1178,7 @@ add_string(strlst_t **listp, char *str) if (p2) { p2->next = NULL; p2->str = strdup(str); - } + } if (!p2 || !p2->str) out_of_memory(); @@ -1133,9 +1188,32 @@ add_string(strlst_t **listp, char *str) 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) +is_dir(const char *pathname) { struct stat buf; @@ -1146,7 +1224,7 @@ is_dir(char *pathname) } int -is_nonempty_file(char *pathname) +is_nonempty_file(const char *pathname) { struct stat buf; diff --git a/usr.bin/crunch/crunchide/Makefile b/usr.bin/crunch/crunchide/Makefile index eb022f0c2b..de57326d46 100644 --- a/usr.bin/crunch/crunchide/Makefile +++ b/usr.bin/crunch/crunchide/Makefile @@ -1,13 +1,19 @@ -# $FreeBSD: src/usr.sbin/crunch/crunchide/Makefile,v 1.2.6.1 2002/07/25 09:33:17 ru Exp $ -# $DragonFly: src/usr.sbin/crunch/crunchide/Makefile,v 1.2 2003/06/17 04:29:53 dillon Exp $ +# $FreeBSD: head/usr.sbin/crunch/crunchide/Makefile 232911 2012-03-13 05:21:14Z jmallett $ PROG= crunchide -SRCS= crunchide.c exec_elf32.c exec_elf64.c +SRCS= crunchide.c TARGET_ARCH?= ${MACHINE_ARCH} -.if ${TARGET_ARCH} == i386 && ${MACHINE_ARCH} == i386 -SRCS+= exec_aout.c + +.if ${TARGET_ARCH} == ia64 || ${TARGET_ARCH} == powerpc64 || \ + ${TARGET_ARCH} == sparc64 || ${TARGET_ARCH} == x86_64 || \ + ${TARGET_ARCH:Mmips64*} +CFLAGS+=-DNLIST_ELF64 +SRCS+= exec_elf64.c +exec_elf64.o: exec_elf32.c +.else +CFLAGS+=-DNLIST_ELF32 +SRCS+= exec_elf32.c .endif -CFLAGS+=-Darch_${TARGET_ARCH} .include diff --git a/usr.bin/crunch/crunchide/crunchide.1 b/usr.bin/crunch/crunchide/crunchide.1 index 1327cc92f4..1625ef9e08 100644 --- a/usr.bin/crunch/crunchide/crunchide.1 +++ b/usr.bin/crunch/crunchide/crunchide.1 @@ -22,8 +22,7 @@ .\" Author: James da Silva, Systems Design and Analysis Group .\" Computer Science Department .\" University of Maryland at College Park -.\" $FreeBSD: src/usr.sbin/crunch/crunchide/crunchide.1,v 1.5.2.5 2003/03/12 22:08:14 trhodes Exp $ -.\" $DragonFly: src/usr.sbin/crunch/crunchide/crunchide.1,v 1.2 2003/06/17 04:29:53 dillon Exp $ +.\" $FreeBSD: head/usr.sbin/crunch/crunchide/crunchide.1 131500 2004-07-02 23:13:00Z ru $ .\" .Dd June 14, 1994 .Dt CRUNCHIDE 1 @@ -47,14 +46,16 @@ Some symbols may be left visible via the .Fl k Ar keep-symbol and .Fl f Ar keep-list-file -options. The +options. +The .Ar keep-list-file must contain a list of symbols to keep visible, one symbol per line. The names given by .Ar keep-symbol or in .Ar keep-list-file -should be C names. For example, +should be C names. +For example, to keep the C function .Dq foo visible, the option @@ -71,12 +72,14 @@ multiple component programs. .Xr crunchgen 1 , .Xr ld 1 .Sh AUTHORS +.An -nosplit The .Nm crunch utility was written by .An James da Silva Aq jds@cs.umd.edu . .Pp -Copyright (c) 1994 University of Maryland. All Rights Reserved. +Copyright (c) 1994 University of Maryland. +All Rights Reserved. .Pp .An Chris Demetriou Aq cgd@netbsd.org reorganized @@ -84,4 +87,6 @@ reorganized so that it supported multiple object formats, and added ELF object support and ECOFF object recognition. .Pp -Copyright (c) 1997 Christopher G. Demetriou. All Rights Reserved. +Copyright (c) 1997 +.An Christopher G. Demetriou . +All Rights Reserved. diff --git a/usr.bin/crunch/crunchide/crunchide.c b/usr.bin/crunch/crunchide/crunchide.c index d9a090251f..5fbba25f6c 100644 --- a/usr.bin/crunch/crunchide/crunchide.c +++ b/usr.bin/crunch/crunchide/crunchide.c @@ -1,6 +1,4 @@ /* $NetBSD: crunchide.c,v 1.8 1997/11/01 06:51:45 lukem Exp $ */ -/* $FreeBSD: src/usr.sbin/crunch/crunchide/crunchide.c,v 1.6.6.1 2002/07/25 09:33:17 ru Exp $ */ -/* $DragonFly: src/usr.sbin/crunch/crunchide/crunchide.c,v 1.4 2003/11/16 14:10:45 eirikn Exp $ */ /* * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved. * Copyright (c) 1994 University of Maryland @@ -26,8 +24,6 @@ * Author: James da Silva, Systems Design and Analysis Group * Computer Science Department * University of Maryland at College Park - * - * $NetBSD: crunchide.c,v 1.8 1997/11/01 06:51:45 lukem Exp $ */ /* * crunchide.c - tiptoes through an a.out symbol table, hiding all defined @@ -62,17 +58,22 @@ * that the final crunched binary BSS size is the max of all the * component programs' BSS sizes, rather than their sum. */ + #include +#ifndef lint +__RCSID("$NetBSD: crunchide.c,v 1.8 1997/11/01 06:51:45 lukem Exp $"); +#endif +__FBSDID("$FreeBSD: head/usr.sbin/crunch/crunchide/crunchide.c 237625 2012-06-27 04:39:30Z obrien $"); +#include +#include +#include #include #include #include #include #include #include -#include -#include -#include #include "extern.h" @@ -194,7 +195,7 @@ add_file_to_keep_list(char *filename) usage(); } - while(fgets(symbol, 1024, keepf)) { + while(fgets(symbol, sizeof(symbol), keepf)) { len = strlen(symbol); if(len && symbol[len-1] == '\n') symbol[len-1] = '\0'; @@ -211,11 +212,9 @@ struct { int (*check)(int, const char *); /* 1 if match, zero if not */ int (*hide)(int, const char *); /* non-zero if error */ } exec_formats[] = { -#if defined(__i386__) && defined(arch_i386) #ifdef NLIST_AOUT { "a.out", check_aout, hide_aout, }, #endif -#endif #ifdef NLIST_ECOFF { "ECOFF", check_elf64, hide_elf64, }, #endif diff --git a/usr.bin/crunch/crunchide/exec_aout.c b/usr.bin/crunch/crunchide/exec_aout.c deleted file mode 100644 index ab49da93d4..0000000000 --- a/usr.bin/crunch/crunchide/exec_aout.c +++ /dev/null @@ -1,207 +0,0 @@ -/* $NetBSD: exec_aout.c,v 1.6 1997/08/02 21:30:17 perry Exp $ */ -/* - * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved. - * Copyright (c) 1994 University of Maryland - * All Rights Reserved. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of U.M. not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. U.M. makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * 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 IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: James da Silva, Systems Design and Analysis Group - * Computer Science Department - * University of Maryland at College Park - * - * $NetBSD: exec_aout.c,v 1.6 1997/08/02 21:30:17 perry Exp $ - * $FreeBSD: src/usr.sbin/crunch/crunchide/exec_aout.c,v 1.1.6.1 2002/07/25 09:33:17 ru Exp $ - * $DragonFly: src/usr.sbin/crunch/crunchide/exec_aout.c,v 1.5 2004/02/08 10:48:30 rob Exp $ - */ -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "extern.h" - -#if defined(NLIST_AOUT) - -int nsyms, ntextrel, ndatarel; -struct exec *hdrp; -char *aoutdata, *strbase; -struct relocation_info *textrel, *datarel; -struct nlist *symbase; - - -#define SYMSTR(sp) (&strbase[(sp)->n_un.n_strx]) - -/* is the symbol a global symbol defined in the current file? */ -#define IS_GLOBAL_DEFINED(sp) \ - (((sp)->n_type & N_EXT) && ((sp)->n_type & N_TYPE) != N_UNDF) - -#ifdef arch_sparc -/* is the relocation entry dependent on a symbol? */ -#define IS_SYMBOL_RELOC(rp) \ - ((rp)->r_extern || \ - ((rp)->r_type >= RELOC_BASE10 && (rp)->r_type <= RELOC_BASE22) || \ - (rp)->r_type == RELOC_JMP_TBL) -#else -/* is the relocation entry dependent on a symbol? */ -#define IS_SYMBOL_RELOC(rp) \ - ((rp)->r_extern||(rp)->r_baserel||(rp)->r_jmptable) -#endif - -static void check_reloc(const char *filename, struct relocation_info *relp); - -int -check_aout(int inf, const char *filename) -{ - struct stat infstat; - struct exec eh; - - /* - * check the header to make sure it's an a.out-format file. - */ - - if(fstat(inf, &infstat) == -1) - return 0; - if(infstat.st_size < sizeof eh) - return 0; - if(read(inf, &eh, sizeof eh) != sizeof eh) - return 0; - - if(N_BADMAG(eh)) - return 0; - - return 1; -} - -int -hide_aout(int inf, const char *filename) -{ - struct stat infstat; - struct relocation_info *relp; - struct nlist *symp; - int rc; - - /* - * do some error checking. - */ - - if(fstat(inf, &infstat) == -1) { - perror(filename); - return 1; - } - - /* - * Read the entire file into memory. XXX - Really, we only need to - * read the header and from TRELOFF to the end of the file. - */ - - if((aoutdata = (char *) malloc(infstat.st_size)) == NULL) { - fprintf(stderr, "%s: too big to read into memory\n", filename); - return 1; - } - - if((rc = read(inf, aoutdata, infstat.st_size)) < infstat.st_size) { - fprintf(stderr, "%s: read error: %s\n", filename, - rc == -1? strerror(errno) : "short read"); - return 1; - } - - /* - * Calculate offsets and sizes from the header. - */ - - hdrp = (struct exec *) aoutdata; - -#if defined (__DragonFly__) || defined (__FreeBSD__) - textrel = (struct relocation_info *) (aoutdata + N_RELOFF(*hdrp)); - datarel = (struct relocation_info *) (aoutdata + N_RELOFF(*hdrp) + - hdrp->a_trsize); -#else - textrel = (struct relocation_info *) (aoutdata + N_TRELOFF(*hdrp)); - datarel = (struct relocation_info *) (aoutdata + N_DRELOFF(*hdrp)); -#endif - symbase = (struct nlist *) (aoutdata + N_SYMOFF(*hdrp)); - strbase = (char *) (aoutdata + N_STROFF(*hdrp)); - - ntextrel = hdrp->a_trsize / sizeof(struct relocation_info); - ndatarel = hdrp->a_drsize / sizeof(struct relocation_info); - nsyms = hdrp->a_syms / sizeof(struct nlist); - - /* - * Zap the type field of all globally-defined symbols. The linker will - * subsequently ignore these entries. Don't zap any symbols in the - * keep list. - */ - - for(symp = symbase; symp < symbase + nsyms; symp++) { - if(!IS_GLOBAL_DEFINED(symp)) /* keep undefined syms */ - continue; - - /* keep (C) symbols which are on the keep list */ - if(SYMSTR(symp)[0] == '_' && in_keep_list(SYMSTR(symp) + 1)) - continue; - - symp->n_type = 0; - } - - /* - * Check whether the relocation entries reference any symbols that we - * just zapped. I don't know whether ld can handle this case, but I - * haven't encountered it yet. These checks are here so that the program - * doesn't fail silently should such symbols be encountered. - */ - - for(relp = textrel; relp < textrel + ntextrel; relp++) - check_reloc(filename, relp); - for(relp = datarel; relp < datarel + ndatarel; relp++) - check_reloc(filename, relp); - - /* - * Write the .o file back out to disk. XXX - Really, we only need to - * write the symbol table entries back out. - */ - lseek(inf, 0, SEEK_SET); - if((rc = write(inf, aoutdata, infstat.st_size)) < infstat.st_size) { - fprintf(stderr, "%s: write error: %s\n", filename, - rc == -1? strerror(errno) : "short write"); - return 1; - } - - return 0; -} - - -static void -check_reloc(const char *filename, struct relocation_info *relp) -{ - /* bail out if we zapped a symbol that is needed */ - if(IS_SYMBOL_RELOC(relp) && symbase[relp->r_symbolnum].n_type == 0) { - fprintf(stderr, - "%s: oops, have hanging relocation for %s: bailing out!\n", - filename, SYMSTR(&symbase[relp->r_symbolnum])); - exit(1); - } -} - -#endif /* defined(NLIST_AOUT) */ diff --git a/usr.bin/crunch/crunchide/exec_elf32.c b/usr.bin/crunch/crunchide/exec_elf32.c index b0c3782962..6fe0e479da 100644 --- a/usr.bin/crunch/crunchide/exec_elf32.c +++ b/usr.bin/crunch/crunchide/exec_elf32.c @@ -26,22 +26,26 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $NetBSD: exec_elf32.c,v 1.4 1997/08/12 06:07:24 mikel Exp $ - * $FreeBSD: src/usr.sbin/crunch/crunchide/exec_elf32.c,v 1.1.6.2 2002/07/25 09:33:17 ru Exp $ - * $DragonFly: src/usr.sbin/crunch/crunchide/exec_elf32.c,v 1.2 2003/06/17 04:29:53 dillon Exp $ */ #include - +#ifndef lint +#if 0 +__RCSID("$NetBSD: exec_elf32.c,v 1.6 1999/09/20 04:12:16 christos Exp $"); +#endif +#endif +__FBSDID("$FreeBSD: head/usr.sbin/crunch/crunchide/exec_elf32.c 246298 2013-02-03 21:16:33Z pfg $"); + #ifndef ELFSIZE #define ELFSIZE 32 #endif #include +#include #include #include +#include #include #include #include @@ -55,8 +59,17 @@ #define __ELF_WORD_SIZE ELFSIZE #if (ELFSIZE == 32) #include +#define xewtoh(x) ((data == ELFDATA2MSB) ? be32toh(x) : le32toh(x)) +#define htoxew(x) ((data == ELFDATA2MSB) ? htobe32(x) : htole32(x)) +#define wewtoh(x) ((data == ELFDATA2MSB) ? be32toh(x) : le32toh(x)) +#define htowew(x) ((data == ELFDATA2MSB) ? htobe32(x) : htole32(x)) #elif (ELFSIZE == 64) #include +#define xewtoh(x) ((data == ELFDATA2MSB) ? be64toh(x) : le64toh(x)) +#define htoxew(x) ((data == ELFDATA2MSB) ? htobe64(x) : htole64(x)) +/* elf64 Elf64_Word are 32 bits */ +#define wewtoh(x) ((data == ELFDATA2MSB) ? be32toh(x) : le32toh(x)) +#define htowew(x) ((data == ELFDATA2MSB) ? htobe32(x) : htole32(x)) #endif #include @@ -66,11 +79,13 @@ #define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE)) #define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x))) -struct listelem { - struct listelem *next; - void *mem; - off_t file; - size_t size; +#define xe16toh(x) ((data == ELFDATA2MSB) ? be16toh(x) : le16toh(x)) +#define xe32toh(x) ((data == ELFDATA2MSB) ? be32toh(x) : le32toh(x)) +#define htoxe32(x) ((data == ELFDATA2MSB) ? htobe32(x) : htole32(x)) + +struct shlayout { + Elf_Shdr *shdr; + void *bufp; }; static ssize_t @@ -82,7 +97,7 @@ xreadatoff(int fd, void *buf, off_t off, size_t size, const char *fn) perror(fn); return -1; } - if ((rv = read(fd, buf, size)) != size) { + if ((size_t)(rv = read(fd, buf, size)) != size) { fprintf(stderr, "%s: read error: %s\n", fn, rv == -1 ? strerror(errno) : "short read"); return -1; @@ -99,7 +114,7 @@ xwriteatoff(int fd, void *buf, off_t off, size_t size, const char *fn) perror(fn); return -1; } - if ((rv = write(fd, buf, size)) != size) { + if ((size_t)(rv = write(fd, buf, size)) != size) { fprintf(stderr, "%s: write error: %s\n", fn, rv == -1 ? strerror(errno) : "short write"); return -1; @@ -119,11 +134,26 @@ xmalloc(size_t size, const char *fn, const char *use) return (rv); } +static void * +xrealloc(void *ptr, size_t size, const char *fn, const char *use) +{ + void *rv; + + rv = realloc(ptr, size); + if (rv == NULL) { + free(ptr); + fprintf(stderr, "%s: out of memory (reallocating for %s)\n", + fn, use); + } + return (rv); +} + int ELFNAMEEND(check)(int fd, const char *fn) { Elf_Ehdr eh; struct stat sb; + unsigned char data; /* * Check the header to maek sure it's an ELF file (of the @@ -131,7 +161,7 @@ ELFNAMEEND(check)(int fd, const char *fn) */ if (fstat(fd, &sb) == -1) return 0; - if (sb.st_size < sizeof eh) + if (sb.st_size < (off_t)(sizeof eh)) return 0; if (read(fd, &eh, sizeof eh) != sizeof eh) return 0; @@ -139,9 +169,43 @@ ELFNAMEEND(check)(int fd, const char *fn) if (IS_ELF(eh) == 0) return 0; - switch (eh.e_machine) { + data = eh.e_ident[EI_DATA]; + + switch (xe16toh(eh.e_machine)) { case EM_386: break; case EM_ALPHA: break; +#ifndef EM_ARM +#define EM_ARM 40 +#endif + case EM_ARM: break; +#ifndef EM_MIPS +#define EM_MIPS 8 +#endif +#ifndef EM_MIPS_RS4_BE /* same as EM_MIPS_RS3_LE */ +#define EM_MIPS_RS4_BE 10 +#endif + case EM_MIPS: break; + case /* EM_MIPS_RS3_LE */ EM_MIPS_RS4_BE: break; +#ifndef EM_IA_64 +#define EM_IA_64 50 +#endif + case EM_IA_64: break; +#ifndef EM_PPC +#define EM_PPC 20 +#endif + case EM_PPC: break; +#ifndef EM_PPC64 +#define EM_PPC64 21 +#endif + case EM_PPC64: break; +#ifndef EM_SPARCV9 +#define EM_SPARCV9 43 +#endif + case EM_SPARCV9: break; +#ifndef EM_X86_64 +#define EM_X86_64 62 +#endif + case EM_X86_64: break; /* ELFDEFNNAME(MACHDEP_ID_CASES) */ default: @@ -151,239 +215,278 @@ ELFNAMEEND(check)(int fd, const char *fn) return 1; } +/* + * This function 'hides' (some of) ELF executable file's symbols. + * It hides them by renaming them to "_$$hide$$ ". + * Symbols in the global keep list, or which are marked as being undefined, + * are left alone. + * + * An old version of this code shuffled various tables around, turning + * global symbols to be hidden into local symbols. That lost on the + * mips, because CALL16 relocs must reference global symbols, and, if + * those symbols were being hidden, they were no longer global. + * + * The new renaming behaviour doesn't take global symbols out of the + * namespace. However, it's ... unlikely that there will ever be + * any collisions in practice because of the new method. + */ int ELFNAMEEND(hide)(int fd, const char *fn) { Elf_Ehdr ehdr; - Elf_Shdr *shdrp = NULL, *symtabshdr, *strtabshdr; + struct shlayout *layoutp = NULL; + Elf_Shdr *shdrp = NULL, *symtabshdr, *strtabshdr, *shstrtabshdr; + Elf_Shdr shdrshdr; Elf_Sym *symtabp = NULL; - char *strtabp = NULL; - Elf_Word *symfwmap = NULL, *symrvmap = NULL, nsyms, nlocalsyms, ewi; - struct listelem *relalist = NULL, *rellist = NULL, *tmpl; + char *shstrtabp = NULL, *strtabp = NULL; + Elf_Size nsyms, ewi; + Elf_Off off; ssize_t shdrsize; - int rv, i, weird; + int rv, i, weird, l, m, r, strtabidx; + size_t nstrtab_size, nstrtab_nextoff, fn_size, size; + char *nstrtabp = NULL; + unsigned char data; + const char *weirdreason = NULL; + void *buf; + Elf_Half shnum; rv = 0; if (xreadatoff(fd, &ehdr, 0, sizeof ehdr, fn) != sizeof ehdr) goto bad; - shdrsize = ehdr.e_shnum * ehdr.e_shentsize; + data = ehdr.e_ident[EI_DATA]; + shnum = xe16toh(ehdr.e_shnum); + + shdrsize = shnum * xe16toh(ehdr.e_shentsize); if ((shdrp = xmalloc(shdrsize, fn, "section header table")) == NULL) goto bad; - if (xreadatoff(fd, shdrp, ehdr.e_shoff, shdrsize, fn) != shdrsize) + if (xreadatoff(fd, shdrp, xewtoh(ehdr.e_shoff), shdrsize, fn) != + shdrsize) goto bad; - symtabshdr = strtabshdr = NULL; + symtabshdr = strtabshdr = shstrtabshdr = NULL; weird = 0; - for (i = 0; i < ehdr.e_shnum; i++) { - switch (shdrp[i].sh_type) { + for (i = 0; i < shnum; i++) { + switch (xe32toh(shdrp[i].sh_type)) { case SHT_SYMTAB: - if (symtabshdr != NULL) + if (symtabshdr != NULL) { weird = 1; + weirdreason = "multiple symbol tables"; + } symtabshdr = &shdrp[i]; - strtabshdr = &shdrp[shdrp[i].sh_link]; + strtabshdr = &shdrp[xe32toh(shdrp[i].sh_link)]; break; - case SHT_RELA: - tmpl = xmalloc(sizeof *tmpl, fn, "rela list element"); - if (tmpl == NULL) - goto bad; - tmpl->mem = NULL; - tmpl->file = shdrp[i].sh_offset; - tmpl->size = shdrp[i].sh_size; - tmpl->next = relalist; - relalist = tmpl; - break; - case SHT_REL: - tmpl = xmalloc(sizeof *tmpl, fn, "rel list element"); - if (tmpl == NULL) - goto bad; - tmpl->mem = NULL; - tmpl->file = shdrp[i].sh_offset; - tmpl->size = shdrp[i].sh_size; - tmpl->next = rellist; - rellist = tmpl; + case SHT_STRTAB: + if (i == xe16toh(ehdr.e_shstrndx)) + shstrtabshdr = &shdrp[i]; break; } } if (symtabshdr == NULL) goto out; - if (strtabshdr == NULL) + if (strtabshdr == NULL) { weird = 1; + weirdreason = "string table does not exist"; + } + if (shstrtabshdr == NULL) { + weird = 1; + weirdreason = "section header string table does not exist"; + } + if (weirdreason == NULL) + weirdreason = "unsupported"; if (weird) { - fprintf(stderr, "%s: weird executable (unsupported)\n", fn); + fprintf(stderr, "%s: weird executable (%s)\n", fn, weirdreason); goto bad; } /* - * load up everything we need + * sort section layout table by offset */ - - /* symbol table */ - if ((symtabp = xmalloc(symtabshdr->sh_size, fn, "symbol table")) - == NULL) - goto bad; - if (xreadatoff(fd, symtabp, symtabshdr->sh_offset, symtabshdr->sh_size, - fn) != symtabshdr->sh_size) + layoutp = xmalloc((shnum + 1) * sizeof(struct shlayout), + fn, "layout table"); + if (layoutp == NULL) goto bad; - /* string table */ - if ((strtabp = xmalloc(strtabshdr->sh_size, fn, "string table")) - == NULL) - goto bad; - if (xreadatoff(fd, strtabp, strtabshdr->sh_offset, strtabshdr->sh_size, - fn) != strtabshdr->sh_size) - goto bad; + /* add a pseudo entry to represent the section header table */ + shdrshdr.sh_offset = ehdr.e_shoff; + shdrshdr.sh_size = htoxew(shdrsize); + shdrshdr.sh_addralign = htoxew(ELFSIZE / 8); + layoutp[shnum].shdr = &shdrshdr; + + /* insert and sort normal section headers */ + for (i = shnum; i-- != 0;) { + l = i + 1; + r = shnum; + while (l <= r) { + m = ( l + r) / 2; + if (xewtoh(shdrp[i].sh_offset) > + xewtoh(layoutp[m].shdr->sh_offset)) + l = m + 1; + else + r = m - 1; + } - /* any rela tables */ - for (tmpl = relalist; tmpl != NULL; tmpl = tmpl->next) { - if ((tmpl->mem = xmalloc(tmpl->size, fn, "rela table")) - == NULL) - goto bad; - if (xreadatoff(fd, tmpl->mem, tmpl->file, tmpl->size, fn) != - tmpl->size) - goto bad; - } + if (r != i) { + memmove(&layoutp[i], &layoutp[i + 1], + sizeof(struct shlayout) * (r - i)); + } - /* any rel tables */ - for (tmpl = rellist; tmpl != NULL; tmpl = tmpl->next) { - if ((tmpl->mem = xmalloc(tmpl->size, fn, "rel table")) - == NULL) - goto bad; - if (xreadatoff(fd, tmpl->mem, tmpl->file, tmpl->size, fn) != - tmpl->size) - goto bad; + layoutp[r].shdr = &shdrp[i]; + layoutp[r].bufp = NULL; } + ++shnum; - /* Prepare data structures for symbol movement. */ - nsyms = symtabshdr->sh_size / symtabshdr->sh_entsize; - nlocalsyms = symtabshdr->sh_info; - if ((symfwmap = xmalloc(nsyms * sizeof (Elf_Word), fn, - "symbol forward mapping table")) == NULL) + /* + * load up everything we need + */ + + /* load section string table for debug use */ + if ((shstrtabp = xmalloc(xewtoh(shstrtabshdr->sh_size), fn, + "section string table")) == NULL) goto bad; - if ((symrvmap = xmalloc(nsyms * sizeof (Elf_Word), fn, - "symbol reverse mapping table")) == NULL) + if ((size_t)xreadatoff(fd, shstrtabp, xewtoh(shstrtabshdr->sh_offset), + xewtoh(shstrtabshdr->sh_size), fn) != xewtoh(shstrtabshdr->sh_size)) goto bad; - /* init location -> symbol # table */ - for (ewi = 0; ewi < nsyms; ewi++) - symrvmap[ewi] = ewi; + /* we need symtab, strtab, and everything behind strtab */ + strtabidx = INT_MAX; + for (i = 0; i < shnum; i++) { + if (layoutp[i].shdr == &shdrshdr) { + /* not load section header again */ + layoutp[i].bufp = shdrp; + continue; + } + if (layoutp[i].shdr == shstrtabshdr) { + /* not load section string table again */ + layoutp[i].bufp = shstrtabp; + continue; + } - /* move symbols, making them local */ - for (ewi = nlocalsyms; ewi < nsyms; ewi++) { - Elf_Sym *sp, symswap; - Elf_Word mapswap; + if (layoutp[i].shdr == strtabshdr) + strtabidx = i; + if (layoutp[i].shdr == symtabshdr || i >= strtabidx) { + off = xewtoh(layoutp[i].shdr->sh_offset); + size = xewtoh(layoutp[i].shdr->sh_size); + layoutp[i].bufp = xmalloc(size, fn, + shstrtabp + xewtoh(layoutp[i].shdr->sh_name)); + if (layoutp[i].bufp == NULL) + goto bad; + if ((size_t)xreadatoff(fd, layoutp[i].bufp, off, size, fn) != + size) + goto bad; - sp = &symtabp[ewi]; + /* set symbol table and string table */ + if (layoutp[i].shdr == symtabshdr) + symtabp = layoutp[i].bufp; + else if (layoutp[i].shdr == strtabshdr) + strtabp = layoutp[i].bufp; + } + } - /* if it's on our keep list, don't move it */ - if (in_keep_list(strtabp + sp->st_name)) - continue; + nstrtab_size = 256; + nstrtabp = xmalloc(nstrtab_size, fn, "new string table"); + if (nstrtabp == NULL) + goto bad; + nstrtab_nextoff = 0; - /* if it's an undefined symbol, keep it */ - if (sp->st_shndx == SHN_UNDEF) - continue; + fn_size = strlen(fn); - /* adjust the symbol so that it's local */ - sp->st_info = - ELF_ST_INFO(STB_LOCAL, sp->st_info); -/* (STB_LOCAL << 4) | ELF_SYM_TYPE(sp->st_info); *//* XXX */ + /* Prepare data structures for symbol movement. */ + nsyms = xewtoh(symtabshdr->sh_size) / xewtoh(symtabshdr->sh_entsize); + /* move symbols, making them local */ + for (ewi = 0; ewi < nsyms; ewi++) { + Elf_Sym *sp = &symtabp[ewi]; + const char *symname = strtabp + xe32toh(sp->st_name); + size_t newent_len; /* - * move the symbol to its new location + * make sure there's size for the next entry, even if it's + * as large as it can be. + * + * "_$$hide$$ " -> + * 9 + 3 + sizes of fn and sym name */ + while ((nstrtab_size - nstrtab_nextoff) < + strlen(symname) + fn_size + 12) { + nstrtab_size *= 2; + nstrtabp = xrealloc(nstrtabp, nstrtab_size, fn, + "new string table"); + if (nstrtabp == NULL) + goto bad; + } - /* note that symbols in those locations have been swapped */ - mapswap = symrvmap[ewi]; - symrvmap[ewi] = symrvmap[nlocalsyms]; - symrvmap[nlocalsyms] = mapswap; - - /* and swap the symbols */ - symswap = *sp; - *sp = symtabp[nlocalsyms]; - symtabp[nlocalsyms] = symswap; + sp->st_name = htowew(nstrtab_nextoff); - nlocalsyms++; /* note new local sym */ - } - symtabshdr->sh_info = nlocalsyms; - - /* set up symbol # -> location mapping table */ - for (ewi = 0; ewi < nsyms; ewi++) - symfwmap[symrvmap[ewi]] = ewi; - - /* any rela tables */ - for (tmpl = relalist; tmpl != NULL; tmpl = tmpl->next) { - Elf_Rela *relap = tmpl->mem; - - for (ewi = 0; ewi < tmpl->size / sizeof(*relap); ewi++) { - relap[ewi].r_info = -#if (ELFSIZE == 32) /* XXX */ - symfwmap[ELF_R_SYM(relap[ewi].r_info)] << 8 | - ELF_R_TYPE(relap[ewi].r_info); -#elif (ELFSIZE == 64) /* XXX */ - symfwmap[ELF_R_SYM(relap[ewi].r_info)] << 32 | - ELF_R_TYPE(relap[ewi].r_info); -#endif /* XXX */ + /* if it's a keeper or is undefined, don't rename it. */ + if (in_keep_list(symname) || + (xe16toh(sp->st_shndx) == SHN_UNDEF)) { + newent_len = sprintf(nstrtabp + nstrtab_nextoff, + "%s", symname) + 1; + } else { + newent_len = sprintf(nstrtabp + nstrtab_nextoff, + "_$$hide$$ %s %s", fn, symname) + 1; } + nstrtab_nextoff += newent_len; } + strtabshdr->sh_size = htoxew(nstrtab_nextoff); - /* any rel tables */ - for (tmpl = rellist; tmpl != NULL; tmpl = tmpl->next) { - Elf_Rel *relp = tmpl->mem; - - for (ewi = 0; ewi < tmpl->size / sizeof *relp; ewi++) { - relp[ewi].r_info = -#if (ELFSIZE == 32) /* XXX */ - symfwmap[ELF_R_SYM(relp[ewi].r_info)] << 8 | - ELF_R_TYPE(relp[ewi].r_info); -#elif (ELFSIZE == 64) /* XXX */ - symfwmap[ELF_R_SYM(relp[ewi].r_info)] << 32 | - ELF_R_TYPE(relp[ewi].r_info); -#endif /* XXX */ - } + /* + * update section header table in ascending order of offset + */ + for (i = strtabidx + 1; i < shnum; i++) { + Elf_Off off, align; + off = xewtoh(layoutp[i - 1].shdr->sh_offset) + + xewtoh(layoutp[i - 1].shdr->sh_size); + align = xewtoh(layoutp[i].shdr->sh_addralign); + off = (off + (align - 1)) & ~(align - 1); + layoutp[i].shdr->sh_offset = htoxew(off); } /* - * write new tables to the file + * write data to the file in descending order of offset */ - if (xwriteatoff(fd, shdrp, ehdr.e_shoff, shdrsize, fn) != shdrsize) - goto bad; - if (xwriteatoff(fd, symtabp, symtabshdr->sh_offset, - symtabshdr->sh_size, fn) != symtabshdr->sh_size) - goto bad; - for (tmpl = relalist; tmpl != NULL; tmpl = tmpl->next) { - if (xwriteatoff(fd, tmpl->mem, tmpl->file, tmpl->size, fn) != - tmpl->size) - goto bad; - } - for (tmpl = rellist; tmpl != NULL; tmpl = tmpl->next) { - if (xwriteatoff(fd, tmpl->mem, tmpl->file, tmpl->size, fn) != - tmpl->size) - goto bad; + for (i = shnum; i-- != 0;) { + if (layoutp[i].shdr == strtabshdr) { + /* new string table */ + buf = nstrtabp; + } else + buf = layoutp[i].bufp; + + if (layoutp[i].shdr == &shdrshdr || + layoutp[i].shdr == symtabshdr || i >= strtabidx) { + if (buf == NULL) + goto bad; + + /* + * update the offset of section header table in elf + * header if needed. + */ + if (layoutp[i].shdr == &shdrshdr && + ehdr.e_shoff != shdrshdr.sh_offset) { + ehdr.e_shoff = shdrshdr.sh_offset; + off = (ELFSIZE == 32) ? 32 : 44; + size = sizeof(Elf_Off); + if ((size_t)xwriteatoff(fd, &ehdr.e_shoff, off, size, + fn) != size) + goto bad; + } + + off = xewtoh(layoutp[i].shdr->sh_offset); + size = xewtoh(layoutp[i].shdr->sh_size); + if ((size_t)xwriteatoff(fd, buf, off, size, fn) != size) + goto bad; + } } out: - if (shdrp != NULL) - free(shdrp); - if (symtabp != NULL) - free(symtabp); - if (strtabp != NULL) - free(strtabp); - if (symfwmap != NULL) - free(symfwmap); - if (symrvmap != NULL) - free(symrvmap); - while ((tmpl = relalist) != NULL) { - relalist = tmpl->next; - if (tmpl->mem != NULL) - free(tmpl->mem); - free(tmpl); - } - while ((tmpl = rellist) != NULL) { - rellist = tmpl->next; - if (tmpl->mem != NULL) - free(tmpl->mem); - free(tmpl); + if (layoutp != NULL) { + for (i = 0; i < shnum; i++) { + if (layoutp[i].bufp != NULL) + free(layoutp[i].bufp); + } + free(layoutp); } + free(nstrtabp); return (rv); bad: diff --git a/usr.bin/crunch/crunchide/exec_elf64.c b/usr.bin/crunch/crunchide/exec_elf64.c index a0c0329142..962cc07748 100644 --- a/usr.bin/crunch/crunchide/exec_elf64.c +++ b/usr.bin/crunch/crunchide/exec_elf64.c @@ -28,12 +28,13 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $NetBSD: exec_elf64.c,v 1.2 1997/08/02 21:30:19 perry Exp $ */ #include - +#ifndef lint +__IDSTRING(elf64rcsid, "$NetBSD: exec_elf64.c,v 1.2 1997/08/02 21:30:19 perry Exp $"); +#endif + #define ELFSIZE 64 #include "exec_elf32.c" diff --git a/usr.bin/crunch/crunchide/extern.h b/usr.bin/crunch/crunchide/extern.h index 4de25a863b..70e6b2e589 100644 --- a/usr.bin/crunch/crunchide/extern.h +++ b/usr.bin/crunch/crunchide/extern.h @@ -1,6 +1,5 @@ /* $NetBSD: extern.h,v 1.5 1998/05/06 13:16:57 mycroft Exp $ */ -/* $FreeBSD: src/usr.sbin/crunch/crunchide/extern.h,v 1.1.6.1 2002/07/25 09:33:17 ru Exp $ */ -/* $DragonFly: src/usr.sbin/crunch/crunchide/extern.h,v 1.2 2003/06/17 04:29:53 dillon Exp $ */ +/* $FreeBSD: head/usr.sbin/crunch/crunchide/extern.h 97280 2002-05-25 13:39:20Z ru $ */ /* * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved. @@ -32,24 +31,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifdef arch_alpha -#define NLIST_ECOFF -#define NLIST_ELF64 -#else -#ifdef arch_mips -#define NLIST_ELF32 -#else -#ifdef arch_powerpc -#define NLIST_ELF32 -#else -#define NLIST_AOUT -/* #define NLIST_ECOFF */ -#define NLIST_ELF32 -/* #define NLIST_ELF64 */ -#endif -#endif -#endif - #ifdef NLIST_AOUT int check_aout(int, const char *); int hide_aout(int, const char *); diff --git a/usr.bin/crunch/examples/Makefile b/usr.bin/crunch/examples/Makefile index 861e3028cb..46c8c94990 100644 --- a/usr.bin/crunch/examples/Makefile +++ b/usr.bin/crunch/examples/Makefile @@ -1,5 +1,6 @@ +# $FreeBSD: head/usr.sbin/crunch/examples/Makefile 241298 2012-10-06 20:01:05Z marcel $ -CRUNCHED= fixit +CRUNCHED= fixit # below is boiler-plate to make $(CRUNCHED) from $(CRUNCHED).conf # I'd use PROG instead of CRUNCHED, but the system makefiles REALLY want @@ -8,24 +9,24 @@ CRUNCHED= fixit CONF= $(CRUNCHED).conf OUTMK= $(CRUNCHED).mk -OUTPUTS= $(OUTMK) $(CRUNCHED).c $(CRUNCHED).cache +OUTPUTS= $(OUTMK) $(CRUNCHED).c $(CRUNCHED).cache -NOMAN= -CLEANFILES+=$(CRUNCHED) *.o *.lo *.c *.mk *.cache -CLEANDIRFILES+=$(OUTPUTS) +NO_MAN= +CLEANFILES+= $(CRUNCHED) *.o *.lo *.c *.mk *.cache +CLEANDIRFILES+= $(OUTPUTS) all: $(CRUNCHED) exe: $(CRUNCHED) $(OUTPUTS): $(CONF) - crunchgen ${.CURDIR}/$(CONF) + MAKE=${MAKE} crunchgen ${.CURDIR}/$(CONF) $(CRUNCHED): $(OUTPUTS) submake submake: - make -f $(OUTMK) + ${MAKE} -f $(OUTMK) objs: - make -f $(OUTMK) objs + ${MAKE} -f $(OUTMK) objs cleandir: rm -f $(CLEANDIRFILES) diff --git a/usr.bin/crunch/examples/filesystem.conf b/usr.bin/crunch/examples/filesystem.conf index d4315aa3aa..96d7342146 100644 --- a/usr.bin/crunch/examples/filesystem.conf +++ b/usr.bin/crunch/examples/filesystem.conf @@ -1,5 +1,4 @@ -# $FreeBSD: src/usr.sbin/crunch/examples/filesystem.conf,v 1.8 1999/08/28 01:15:57 peter Exp $ -# $DragonFly: src/usr.sbin/crunch/examples/filesystem.conf,v 1.2 2003/06/17 04:29:53 dillon Exp $ +# $FreeBSD: head/usr.sbin/crunch/examples/filesystem.conf 50479 1999-08-28 01:35:59Z peter $ srcdirs /usr/src/bin /usr/src/sbin /usr/src/gnu/usr.bin /usr/src/usr.sbin srcdirs /usr/src/sbin/i386 diff --git a/usr.bin/crunch/examples/fixit.conf b/usr.bin/crunch/examples/fixit.conf index 26543c3b65..80a2346e34 100644 --- a/usr.bin/crunch/examples/fixit.conf +++ b/usr.bin/crunch/examples/fixit.conf @@ -9,7 +9,7 @@ srcdirs /usr/src/sbin/i386 # second, we list all the programs we want to include in our crunched binary. # The order doesn't matter. Any program that needs hard links to it gets an -# `ln' directive. +# `ln' directive. # /bin stuff diff --git a/usr.bin/crunch/examples/kcopy.conf b/usr.bin/crunch/examples/kcopy.conf index a6c1bd1782..dd00608e0f 100644 --- a/usr.bin/crunch/examples/kcopy.conf +++ b/usr.bin/crunch/examples/kcopy.conf @@ -1,5 +1,4 @@ -# $FreeBSD: src/usr.sbin/crunch/examples/kcopy.conf,v 1.7 1999/08/28 01:15:57 peter Exp $ -# $DragonFly: src/usr.sbin/crunch/examples/kcopy.conf,v 1.2 2003/06/17 04:29:53 dillon Exp $ +# $FreeBSD: head/usr.sbin/crunch/examples/kcopy.conf 50479 1999-08-28 01:35:59Z peter $ srcdirs /usr/src/bin /usr/src/sbin diff --git a/usr.bin/crunch/examples/really-big.conf b/usr.bin/crunch/examples/really-big.conf index b9b543ae42..d666be99de 100644 --- a/usr.bin/crunch/examples/really-big.conf +++ b/usr.bin/crunch/examples/really-big.conf @@ -1,12 +1,12 @@ -# $FreeBSD: src/usr.sbin/crunch/examples/really-big.conf,v 1.2.6.1 2003/02/10 12:21:09 des Exp $ -# $DragonFly: src/usr.sbin/crunch/examples/really-big.conf,v 1.4 2008/02/17 19:51:54 swildner Exp $ -# # really-big.conf - just about everything, just for testing. # This ends up having some good examples of the use of specials for # those hard-to-reach programs. I stopped when I got tired, but we # could probably get even more stuff (like libexec stuff) in here. # # This produces a 4608000 byte binary. Pretty sick and twisted, eh? +# +# $FreeBSD: head/usr.sbin/crunch/examples/really-big.conf 246256 2013-02-02 21:51:14Z pfg $ +# # ========================================================================= @@ -24,10 +24,10 @@ ln sh -sh srcdirs /usr/src/sbin progs badsect bim clri disklabel dmesg dump dumpfs fdisk fsck halt -progs ifconfig init mknod modload modunload mount mount_fdesc mount_isofs -progs mount_lofs mount_msdos mount_portal mount_procfs mountd +progs ifconfig init mknod modload modunload mount mount_isofs +progs mount_lofs mount_msdosfs mountd progs newfs nfsd nfsiod ping quotacheck reboot restore route routed savecore -progs shutdown slattach swapon ttyflags tunefs umount +progs shutdown swapon ttyflags tunefs umount # shell scripts: fastboot ln dump rdump @@ -54,7 +54,7 @@ progs vacation vgrind vi vis vmstat w wall wc what whatis whereis who progs whois window write xargs xinstall xstr yacc yes ypcat ypmatch ypwhich # shell scripts: lorder mkdep shar which -# problems: rdist uses libcompat.a(regex.o), which conflicts with +# problems: rdist uses libcompat.a(regex.o), which conflicts with # libedit(readline.o) over regerror(). # special requirements @@ -68,11 +68,11 @@ special tn3270 srcdir /usr/src/usr.bin/tn3270/tn3270 srcdirs /usr/src/usr.sbin progs ac accton amd arp bad144 catman chown chroot config config.new cron -progs dev_mkdb edquota flcopy gettable grfinfo hilinfo htable inetd -progs iostat iteconfig kvm_mkdb mrouted mtree named portmap pppd +progs dev_mkdb diskpart edquota flcopy gettable grfinfo hilinfo htable inetd +progs iostat iteconfig kvm_mkdb mtree named portmap pppd progs pstat pwd_mkdb quot quotaon rarpd rbootd repquota rmt rpc.bootparamd -progs rwhod sa sliplogin slstats spray sysctl syslogd tcpdump -progs traceroute trpt trsp update vipw vnconfig ypbind yppoll ypset +progs rwhod sa spray sysctl syslogd tcpdump +progs traceroute trpt update vipw vnconfig ypbind yppoll ypset special amd srcdir /usr/src/usr.sbin/amd/amd special amd objs vers.amd.o afs_ops.o am_ops.o clock.o util.o xutil.o efs_ops.o mapc.o info_file.o info_hes.o info_ndbm.o info_passwd.o info_nis.o info_union.o map.o srvr_afs.o srvr_nfs.o mntfs.o misc_rpc.o mount_fs.o mtab.o mtab_bsd.o nfs_ops.o nfs_prot_svc.o nfs_start.o nfs_subr.o opts.o pfs_ops.o rpc_fwd.o sched.o sfs_ops.o amq_svc.o amq_subr.o umount_fs.o host_ops.o nfsx_ops.o ufs_ops.o ifs_ops.o amd.o get_args.o restart.o wire.o @@ -92,6 +92,15 @@ srcdirs /usr/src/usr.sbin/timed # timed & timedc progs timed timedc special timed srcdir /usr/src/usr.sbin/timed/timed +srcdirs /usr/src/usr.sbin/xntpd # NTP subsystem +# xntpd uses a gross hack to pass some information in the global +# variable `progname' between the actual program (ntpdate in this +# case), and the NTP library. Add `progname' to the keep list. +progs ntpdate +special ntpdate srcdir /usr/src/usr.sbin/xntpd/ntpdate +special ntpdate keep progname +libs -L/usr/src/usr.sbin/xntpd/lib -lntp + srcdirs /usr/src/usr.sbin/yp # yp subsystem progs ypbind ypwhich ypcat ypmatch ypset yppoll @@ -145,5 +154,5 @@ special cc1 objpaths /usr/src/gnu/usr.bin/gcc2/cc1/obj/c-parse.o /usr/src/gnu/us ln gzip gunzip ln gzip gzcat -libs -ledit -lgnumalloc -lc -lcrypt -ltermcap -lcurses -ltelnet -lutil -lkvm +libs -ledit -lgnumalloc -lc -lcrypt -ltermcap -lcurses -ltelnet -lutil -lkvm libs -ll -ly -lm -lresolv -lrpcsvc -lcompat -- 2.41.0