nicest way since there is lot of code that has to churn, but it works.
-# $OpenBSD: Makefile,v 1.1 2008/08/22 15:18:55 deraadt Exp $
+# $OpenBSD: Makefile,v 1.2 2008/08/22 15:38:37 deraadt Exp $
PROG= crunchgen
-MAN= crunchgen.1 crunchide.1
+MAN= crunchgen.1
SRCS= crunchgen.c crunched_skel.c \
crunchide.c elf_hide.c ecoff_hide.c
CFLAGS+= -g -Wall
crunched_skel.c: crunched_main.c
sh ${.CURDIR}/mkskel.sh ${.CURDIR}/crunched_main.c > crunched_skel.c
-LINKS= ${BINDIR}/crunchgen ${BINDIR}/crunchide
-
.include <bsd.prog.mk>
-.\" $OpenBSD: crunchgen.1,v 1.1 2008/08/22 15:18:55 deraadt Exp $
+.\" $OpenBSD: crunchgen.1,v 1.2 2008/08/22 15:38:37 deraadt Exp $
.\"
.\"
.\" Copyright (c) 1994 University of Maryland
.Op Fl m Ar makefile-name
.Op Fl O Ar objdir-name
.Ar conf-file
+.Nm crunchgen
+.Fl h
+.Op Fl f Ar keep-list-file
+.Op Fl k Ar keep-symbol
+.Ar object-file ...
.Ek
.Sh DESCRIPTION
A crunched binary is a program made up of many other programs linked
This information is cached in a file named
.Pa <conf-name>.cache
between runs.
+.Pp
.Nm
-uses the companion program
-.Xr crunchide 1
-to eliminate link-time conflicts between the component programs by
+is later run again with the
+.Fl h
+flag to eliminate link-time conflicts between the component programs by
hiding all unnecessary symbols.
+Some symbols may be left visible via the
+.Fl k Ar keep-symbol
+and
+.Fl f Ar keep-list-file
+options.
+The
+.Ar keep-list-file
+must contain a list of symbols to keep visible, one symbol per line.
+Note that the C compiler prepends an underscore in front of
+symbols, so to keep the C function ``foo'' visible, the option
+.Dq -k _foo
+must be used.
+.Pp
+.Sh NOTES
+The ELF version of
+.Fl h
+mangles the symbol table beyond recognition.
+It is therefore not advisable to try to run
+.Xr nm 1
+on a crunched object file.
+This is due to the nature of the ELF symbol table
+and how some arches uses the symbol attributes for their GOT build.
.Pp
After
.Nm
.Dq kcopy
can be copied onto an install floppy
and hard-linked to the names of the component programs.
-.Sh SEE ALSO
-.Xr crunchide 1
.Sh AUTHORS
.Nm
was written by James da Silva
-/* $OpenBSD: crunchgen.c,v 1.1 2008/08/22 15:18:55 deraadt Exp $ */
+/* $OpenBSD: crunchgen.c,v 1.2 2008/08/22 15:38:37 deraadt Exp $ */
/*
* Copyright (c) 1994 University of Maryland
int linenum = -1;
int goterror = 0;
-char *progname = "crunchgen";
+extern char *__progname;
-int verbose, readcache, elf_names; /* options */
+int verbose = 1, readcache = 1, elf_names; /* options */
int reading_cache;
void status(char *str);
char *p;
int optc;
extern int optind;
- extern char *optarg, *__progname;
+ extern char *optarg;
- verbose = 1;
- readcache = 1;
- *outmkname = *outcfname = *execfname = '\0';
-
- if (argc > 0)
- progname = argv[0];
-
- if (strcmp(__progname, "crunchide") == 0)
- return (crunchide_main(argc, argv));
-
- while ((optc = getopt(argc, argv, "m:c:e:fqD:EL:O:")) != -1) {
+ while ((optc = getopt(argc, argv, "hm:c:e:fqD:EL:O:")) != -1) {
switch (optc) {
+ case 'h':
+ optreset = 1;
+ return (crunchide_main(argc, argv));
+ break;
case 'f':
readcache = 0;
break;
usage(void)
{
fprintf(stderr,
- "usage: %s [-Efq] [-c c-file-name] [-D src-root] [-e exec-file-name]\n"
- "\t[-L lib-dir] [-m makefile-name] [-O objdir-name] conf-file\n",
- progname);
+ "usage: crunchgen [-Efq] [-c c-file-name] [-D src-root] [-e exec-file-name]\n"
+ "\t[-L lib-dir] [-m makefile-name] [-O objdir-name] conf-file\n");
+ fprintf(stderr,
+ "usage: crunchgen -h [-f keep-list-file] [-k keep-symbol] object-file ...\n");
exit(1);
}
{
if (!is_nonempty_file(infilename)) {
fprintf(stderr, "%s: fatal: input file \"%s\" not found.\n",
- progname, infilename);
+ __progname, infilename);
exit(1);
}
parse_one_file(infilename);
p->name, p->name, p->ident);
fprintf(outmk, "\t$(LINK) -o $@ %s_stub.o $(%s_OBJPATHS)\n",
p->name, p->ident);
- fprintf(outmk, "\tcrunchide -k %s_crunched_%s_stub $@\n",
+ fprintf(outmk, "\tcrunchgen -h -k %s_crunched_%s_stub $@\n",
elf_names ? "" : "_", p->ident);
}
+++ /dev/null
-.\" $OpenBSD: crunchide.1,v 1.1 2008/08/22 15:18:55 deraadt Exp $
-.\"
-.\"
-.\" 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
-.\"
-.Dd $Mdocdate: August 22 2008 $
-.Dt CRUNCHIDE 1
-.Os
-.Sh NAME
-.Nm crunchide
-.Nd hides symbol names from ld, for crunching programs together
-.Sh SYNOPSIS
-.Nm crunchide
-.Op Fl f Ar keep-list-file
-.Op Fl k Ar keep-symbol
-.Ar object-file ...
-.Sh DESCRIPTION
-.Nm
-hides the global symbols of
-.Ar object-file
-such that they are ignored by subsequent runs of the linker,
-.Xr ld 1 .
-Some symbols may be left visible via the
-.Fl k Ar keep-symbol
-and
-.Fl f Ar keep-list-file
-options.
-The
-.Ar keep-list-file
-must contain a list of symbols to keep visible, one symbol per line.
-Note that the C compiler prepends an underscore in front of
-symbols, so to keep the C function ``foo'' visible, the option
-.Dq -k _foo
-must be used.
-.Pp
-.Nm
-is designed as a companion program for
-.Xr crunchgen 1 ,
-which automates the process of creating crunched binaries from
-multiple component programs.
-.Sh NOTES
-The ELF version of
-.Nm crunchide
-mangles the symbol table beyond recognition.
-It is therefore not advisable to try to run
-.Xr nm 1
-on a crunched object file.
-This is due to the nature of the ELF symbol table
-and how some arches uses the symbol attributes for their GOT build.
-.Sh SEE ALSO
-.Xr crunchgen 1 ,
-.Xr ld 1
-.Sh AUTHORS
-.Nm
-was written by James da Silva
-.Aq jds@cs.umd.edu .
-.Pp
-Copyright (c) 1994 University of Maryland. All Rights Reserved.
-/* $OpenBSD: crunchide.c,v 1.1 2008/08/22 15:18:55 deraadt Exp $ */
+/* $OpenBSD: crunchide.c,v 1.2 2008/08/22 15:38:37 deraadt Exp $ */
/*
* Copyright (c) 1994 University of Maryland
#define DO_AOUT
#endif
-void crunchide_usage(void);
+void usage(void);
void add_to_keep_list(char *);
void add_file_to_keep_list(char *);
{
int ch;
- while ((ch = getopt(argc, argv, "k:f:")) != -1)
+ while ((ch = getopt(argc, argv, "hk:f:")) != -1)
switch (ch) {
+ case 'h':
+ break;
case 'k':
add_to_keep_list(optarg);
break;
add_file_to_keep_list(optarg);
break;
default:
- crunchide_usage();
+ usage();
}
argc -= optind;
argv += optind;
if (argc == 0)
- crunchide_usage();
+ usage();
while (argc) {
hide_syms(*argv);
return 0;
}
-void
-crunchide_usage(void)
-{
- fprintf(stderr,
- "usage: crunchide [-f keep-list-file] [-k keep-symbol] object-file ...\n");
- exit(1);
-}
-
struct keep {
struct keep *next;
char *sym;
if ((keepf = fopen(filename, "r")) == NULL) {
perror(filename);
- crunchide_usage();
+ usage();
}
while (fgets(symbol, sizeof(symbol), keepf)) {
len = strlen(symbol);