summaryrefslogtreecommitdiffstats
path: root/usr.sbin/crunchgen
diff options
context:
space:
mode:
authordrahn <drahn@openbsd.org>2008-11-24 17:23:26 +0000
committerdrahn <drahn@openbsd.org>2008-11-24 17:23:26 +0000
commit03ab18c25136433c58be73760b38cda4c2a64bb7 (patch)
treeed1f9b3a5979d47da17c57fe12edc9499a0a437d /usr.sbin/crunchgen
parentsome whitespace fixes in em_rxeof (diff)
downloadwireguard-openbsd-03ab18c25136433c58be73760b38cda4c2a64bb7.tar.xz
wireguard-openbsd-03ab18c25136433c58be73760b38cda4c2a64bb7.zip
Change mips detection in crunchgen from ifdef to command line flag
ok deraadt@, fkr@, rainer@. manpage cleanup thanks to jmc@
Diffstat (limited to 'usr.sbin/crunchgen')
-rw-r--r--usr.sbin/crunchgen/crunchgen.820
-rw-r--r--usr.sbin/crunchgen/crunchgen.c14
-rw-r--r--usr.sbin/crunchgen/elf_hide.c46
3 files changed, 42 insertions, 38 deletions
diff --git a/usr.sbin/crunchgen/crunchgen.8 b/usr.sbin/crunchgen/crunchgen.8
index 3c37ebf0e88..1abfe9b0f31 100644
--- a/usr.sbin/crunchgen/crunchgen.8
+++ b/usr.sbin/crunchgen/crunchgen.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: crunchgen.8,v 1.2 2008/08/23 07:24:06 jmc Exp $
+.\" $OpenBSD: crunchgen.8,v 1.3 2008/11/24 17:23:26 drahn Exp $
.\"
.\"
.\" Copyright (c) 1994 University of Maryland
@@ -25,7 +25,7 @@
.\" Computer Science Department
.\" University of Maryland at College Park
.\"
-.Dd $Mdocdate: August 23 2008 $
+.Dd $Mdocdate: November 24 2008 $
.Dt CRUNCHGEN 8
.Os
.Sh NAME
@@ -34,7 +34,7 @@
.Sh SYNOPSIS
.Nm crunchgen
.Bk -words
-.Op Fl Efq
+.Op Fl EfMq
.Op Fl c Ar c-file-name
.Op Fl D Ar src-root
.Op Fl e Ar exec-file-name
@@ -113,8 +113,8 @@ Assume that relative source directory specifications begin with
.Ar src-root .
.It Fl E
Don't prepend stub names with an underscore.
-Used for architectures that don't have underscore prepended to symbol names.
-Example mips ELF.
+Used for architectures that don't have underscore prepended to symbol names,
+such as ELF architectures.
.It Fl e Ar exec-file-name
Set crunched binary executable file name to
.Ar exec-file-name .
@@ -125,9 +125,10 @@ Flush cache.
Forces the recalculation of cached parameters.
.It Fl h
Hide all unnecessary symbols.
-Note that the ELF version of
-.Fl h
-mangles the symbol table beyond recognition.
+Note that this is done on some ELF architectures by marking the symbol
+local, while the
+.Fl M
+option causes it to mangle the symbol name to hide the symbol.
It is therefore not advisable to try to run
.Xr nm 1
on a crunched object file.
@@ -136,6 +137,9 @@ and how some architectures use the symbol attributes for their GOT build.
.It Fl L Ar lib-dir
Try to obtain libraries from
.Ar lib-dir .
+.It Fl M
+On ELF architectures mangle the symbol instead of marking it global;
+necessary for some architectures due to GOT usage.
.It Fl m Ar makefile-name
Set output Makefile name to
.Ar makefile-name .
diff --git a/usr.sbin/crunchgen/crunchgen.c b/usr.sbin/crunchgen/crunchgen.c
index 88a82d59f12..4d53a05b7f8 100644
--- a/usr.sbin/crunchgen/crunchgen.c
+++ b/usr.sbin/crunchgen/crunchgen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crunchgen.c,v 1.3 2008/08/23 07:24:06 jmc Exp $ */
+/* $OpenBSD: crunchgen.c,v 1.4 2008/11/24 17:23:26 drahn Exp $ */
/*
* Copyright (c) 1994 University of Maryland
@@ -96,7 +96,7 @@ int goterror = 0;
extern char *__progname;
-int verbose = 1, readcache = 1, elf_names; /* options */
+int verbose = 1, readcache = 1, elf_names, elf_mangle; /* options */
int reading_cache;
void status(char *str);
@@ -118,7 +118,7 @@ main(int argc, char *argv[])
extern int optind;
extern char *optarg;
- while ((optc = getopt(argc, argv, "hm:c:e:fqD:EL:O:")) != -1) {
+ while ((optc = getopt(argc, argv, "hm:c:e:fqD:EL:O:M")) != -1) {
switch (optc) {
case 'h':
optreset = 1;
@@ -164,6 +164,9 @@ main(int argc, char *argv[])
sizeof(objdir))
usage();
break;
+ case 'M':
+ elf_mangle = 1;
+ break;
default:
usage();
}
@@ -212,7 +215,7 @@ void
usage(void)
{
fprintf(stderr,
- "usage: crunchgen [-Efq] [-c c-file-name] [-D src-root] [-e exec-file-name]\n"
+ "usage: crunchgen [-EfMq] [-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,
" crunchgen -h [-f keep-list-file] [-k keep-symbol] object-file ...\n");
@@ -933,7 +936,8 @@ 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, "\tcrunchgen -h -k %s_crunched_%s_stub $@\n",
+ fprintf(outmk, "\tcrunchgen %s -h -k %s_crunched_%s_stub $@\n",
+ elf_mangle ? "-M" : "",
elf_names ? "" : "_", p->ident);
}
diff --git a/usr.sbin/crunchgen/elf_hide.c b/usr.sbin/crunchgen/elf_hide.c
index 148a3946ff1..3d084aa6c99 100644
--- a/usr.sbin/crunchgen/elf_hide.c
+++ b/usr.sbin/crunchgen/elf_hide.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: elf_hide.c,v 1.2 2008/09/08 20:42:24 deraadt Exp $ */
+/* $OpenBSD: elf_hide.c,v 1.3 2008/11/24 17:23:26 drahn Exp $ */
/*
* Copyright (c) 1997 Dale Rahn.
@@ -40,6 +40,8 @@
#ifdef _NLIST_DO_ELF
#include <sys/exec_elf.h>
+extern int elf_mangle;
+
void load_strtab(Elf_Ehdr * pehdr, char *pexe);
void dump_strtab();
char *get_str(int indx);
@@ -304,15 +306,9 @@ hide_sym(Elf_Ehdr * ehdr, Elf_Shdr * symsect,
Elf_Sym * symtab, int symtabsize, int symtabsecnum)
{
int i;
-#ifndef __mips__
unsigned char info;
-#endif
Elf_Sym *psymtab;
-#ifdef __mips__
- u_int32_t f = arc4random();
-#endif
-
for (i = 0; i < (symtabsize / sizeof(Elf_Sym)); i++) {
psymtab = &(symtab[i]);
if ((psymtab->st_info & 0xf0) == 0x10 &&
@@ -325,24 +321,26 @@ hide_sym(Elf_Ehdr * ehdr, Elf_Shdr * symsect,
get_str(psymtab->st_name));
printf("st_info %x\n", psymtab->st_info);
#endif
-#ifndef __mips__
- info = psymtab->st_info;
- info = info & 0xf;
- psymtab->st_info = info;
-#else
- /*
- * XXX This is a small ugly hack to be able to use
- * XXX chrunchide with MIPS.
- * XXX Because MIPS needs global symbols to stay
- * XXX global (has to do with GOT), we mess around
- * XXX with the symbol names instead. For most uses
- * XXX this will be no problem, symbols are stripped
- * XXX anyway. However, if many one character
- * XXX symbols exist, names may clash.
- */
- {
+ if (!elf_mangle) {
+ info = psymtab->st_info;
+ info = info & 0xf;
+ psymtab->st_info = info;
+ } else {
+ /*
+ * XXX This is a small ugly hack to be able to
+ * XXX use chrunchide with MIPS.
+ * XXX Because MIPS needs global symbols to stay
+ * XXX global (has to do with GOT), we mess
+ * XXX around with the symbol names instead.
+ * XXX For most uses this will be no problem,
+ * XXX symbols are stripped anyway.
+ * XXX However, if many one character
+ * XXX symbols exist, names may clash.
+ */
char *p;
u_int32_t n, z;
+ u_int32_t f;
+ f = arc4random();
z = f++;
p = get_str(psymtab->st_name);
@@ -356,8 +354,6 @@ hide_sym(Elf_Ehdr * ehdr, Elf_Shdr * symsect,
p[n] += arc4random();
}
}
-
-#endif
#ifdef DEBUG
printf("st_info %x\n", psymtab->st_info);
#endif