summaryrefslogtreecommitdiffstats
path: root/usr.sbin/crunchgen
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2008-08-22 15:38:37 +0000
committerderaadt <deraadt@openbsd.org>2008-08-22 15:38:37 +0000
commit90d4c299af1711c55f37c1259f7fd10ed362355d (patch)
treed073dd5f306d2d6542ce6fb14c08ba10c88d2fff /usr.sbin/crunchgen
parentMerge crunchgen & crunchhide (using name checking), and move to usr.sbin (diff)
downloadwireguard-openbsd-90d4c299af1711c55f37c1259f7fd10ed362355d.tar.xz
wireguard-openbsd-90d4c299af1711c55f37c1259f7fd10ed362355d.zip
merge crunchide into crunchgen as the -h flag. this is not yet done the
nicest way since there is lot of code that has to churn, but it works.
Diffstat (limited to 'usr.sbin/crunchgen')
-rw-r--r--usr.sbin/crunchgen/Makefile6
-rw-r--r--usr.sbin/crunchgen/crunchgen.138
-rw-r--r--usr.sbin/crunchgen/crunchgen.c35
-rw-r--r--usr.sbin/crunchgen/crunchide.180
-rw-r--r--usr.sbin/crunchgen/crunchide.c22
5 files changed, 57 insertions, 124 deletions
diff --git a/usr.sbin/crunchgen/Makefile b/usr.sbin/crunchgen/Makefile
index 314174f33ba..36fbba3f358 100644
--- a/usr.sbin/crunchgen/Makefile
+++ b/usr.sbin/crunchgen/Makefile
@@ -1,7 +1,7 @@
-# $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
@@ -10,6 +10,4 @@ CLEANFILES+= crunched_skel.c
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>
diff --git a/usr.sbin/crunchgen/crunchgen.1 b/usr.sbin/crunchgen/crunchgen.1
index 11237841ffc..685b319e990 100644
--- a/usr.sbin/crunchgen/crunchgen.1
+++ b/usr.sbin/crunchgen/crunchgen.1
@@ -1,4 +1,4 @@
-.\" $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
@@ -42,6 +42,11 @@
.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
@@ -64,11 +69,34 @@ the program from its source directory Makefile.
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
@@ -265,8 +293,6 @@ At this point the binary
.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
diff --git a/usr.sbin/crunchgen/crunchgen.c b/usr.sbin/crunchgen/crunchgen.c
index 7a4c6983b21..60105ff079f 100644
--- a/usr.sbin/crunchgen/crunchgen.c
+++ b/usr.sbin/crunchgen/crunchgen.c
@@ -1,4 +1,4 @@
-/* $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
@@ -94,9 +94,9 @@ char topdir[MAXPATHLEN], execfname[MAXPATHLEN];
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);
@@ -116,20 +116,14 @@ main(int argc, char *argv[])
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;
@@ -218,9 +212,10 @@ void
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);
}
@@ -241,7 +236,7 @@ parse_conf_file(void)
{
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);
@@ -938,7 +933,7 @@ prog_makefile_rules(FILE * outmk, prog_t * p)
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);
}
diff --git a/usr.sbin/crunchgen/crunchide.1 b/usr.sbin/crunchgen/crunchide.1
deleted file mode 100644
index 2f9b4082dc7..00000000000
--- a/usr.sbin/crunchgen/crunchide.1
+++ /dev/null
@@ -1,80 +0,0 @@
-.\" $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.
diff --git a/usr.sbin/crunchgen/crunchide.c b/usr.sbin/crunchgen/crunchide.c
index 3c74a0da7bb..c6f4e72ad30 100644
--- a/usr.sbin/crunchgen/crunchide.c
+++ b/usr.sbin/crunchgen/crunchide.c
@@ -1,4 +1,4 @@
-/* $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
@@ -79,7 +79,7 @@
#define DO_AOUT
#endif
-void crunchide_usage(void);
+void usage(void);
void add_to_keep_list(char *);
void add_file_to_keep_list(char *);
@@ -99,8 +99,10 @@ crunchide_main(int argc, char *argv[])
{
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;
@@ -108,14 +110,14 @@ crunchide_main(int argc, char *argv[])
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);
@@ -126,14 +128,6 @@ crunchide_main(int argc, char *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;
@@ -188,7 +182,7 @@ add_file_to_keep_list(char *filename)
if ((keepf = fopen(filename, "r")) == NULL) {
perror(filename);
- crunchide_usage();
+ usage();
}
while (fgets(symbol, sizeof(symbol), keepf)) {
len = strlen(symbol);