diff options
author | 2013-07-05 21:38:35 +0000 | |
---|---|---|
committer | 2013-07-05 21:38:35 +0000 | |
commit | 6b7db23a9feb98094fce04d2f216aa9e002662cc (patch) | |
tree | 661d421be6298042954ba3d79e1dbea0c2539e43 | |
parent | Remove usr.bin/ar and usr.bin/ranlib, no longer building anything. Move their (diff) | |
download | wireguard-openbsd-6b7db23a9feb98094fce04d2f216aa9e002662cc.tar.xz wireguard-openbsd-6b7db23a9feb98094fce04d2f216aa9e002662cc.zip |
Remove usr.bin/strip and usr.bin/strings, no longer built.
-rw-r--r-- | usr.bin/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/strings/Makefile | 8 | ||||
-rw-r--r-- | usr.bin/strings/strings.1 | 124 | ||||
-rw-r--r-- | usr.bin/strings/strings.c | 254 | ||||
-rw-r--r-- | usr.bin/strip/Makefile | 54 | ||||
-rw-r--r-- | usr.bin/strip/strip.1 | 89 | ||||
-rw-r--r-- | usr.bin/strip/strip.c | 440 |
7 files changed, 2 insertions, 971 deletions
diff --git a/usr.bin/Makefile b/usr.bin/Makefile index 5a680a2fe33..05104174eb1 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.132 2013/07/05 21:37:19 miod Exp $ +# $OpenBSD: Makefile,v 1.133 2013/07/05 21:38:35 miod Exp $ .include <bsd.own.mk> @@ -22,7 +22,7 @@ SUBDIR= apply apropos arch asa at aucat audioctl awk banner \ readlink renice rev rpcgen rpcinfo rs rsh rup ruptime rusers rwall \ rwho sdiff script sed sendbug shar showmount skey \ skeyaudit skeyinfo skeyinit sndiod \ - sort spell split sqlite3 ssh stat strip strings su systat \ + sort spell split sqlite3 ssh stat su systat \ sudo tail talk tcopy tcpbench tee telnet tftp tic tip time \ tmux top touch tput tr true tset tsort tty usbhidaction usbhidctl \ ul uname unexpand unifdef uniq units \ diff --git a/usr.bin/strings/Makefile b/usr.bin/strings/Makefile deleted file mode 100644 index fb058588f94..00000000000 --- a/usr.bin/strings/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $OpenBSD: Makefile,v 1.4 2013/03/15 06:01:42 deraadt Exp $ - -.include <bsd.own.mk> -.if (${ELF_TOOLCHAIN:L} == "no") -PROG= strings -.endif - -.include <bsd.prog.mk> diff --git a/usr.bin/strings/strings.1 b/usr.bin/strings/strings.1 deleted file mode 100644 index d84ff65e507..00000000000 --- a/usr.bin/strings/strings.1 +++ /dev/null @@ -1,124 +0,0 @@ -.\" $OpenBSD: strings.1,v 1.16 2010/09/03 11:09:29 jmc Exp $ -.\" $NetBSD: strings.1,v 1.4 1994/12/10 11:54:28 jtc Exp $ -.\" -.\" Copyright (c) 1980, 1990, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY 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. -.\" -.\" @(#)strings.1 8.1 (Berkeley) 6/6/93 -.\" -.Dd $Mdocdate: September 3 2010 $ -.Dt STRINGS 1 -.Os -.Sh NAME -.Nm strings -.Nd find printable strings in a file -.Sh SYNOPSIS -.Nm strings -.Op Fl afo -.Op Fl m Ar number -.Op Fl n Ar number -.Op Fl t Ar radix -.Op Ar -.Sh DESCRIPTION -.Nm -displays the sequences of printable characters in each of the specified -files, or in the standard input, by default. -By default, a sequence must be at least four characters in length -before being displayed. -.Pp -The options are as follows: -.Bl -tag -width Ds -.It Fl a -By default, -.Nm -only searches the text and data segments of object files. -The -.Fl a -option causes -.Nm -to search the entire object file. -.It Fl f -Each string is preceded by the name of the file -in which it was found. -.It Fl m Ar number -Specifies the maximum number of characters in a sequence to be -.Ar number , -instead of unlimited. -.It Fl n Ar number -Specifies the minimum number of characters in a sequence to be -.Ar number , -instead of four. -.It Fl o -Each string is preceded by its octal offset in the file. -.It Fl t Ar radix -Each string is preceded by its offset in the file. -The first character of -.Ar radix -determines the radix of the offset: -.Sq o -for octal; -.Sq d -for decimal; or -.Sq x -for hexadecimal. -.El -.Pp -.Nm -is useful for identifying random binaries, among other things. -.Sh EXIT STATUS -.Ex -std strings -.Sh SEE ALSO -.Xr hexdump 1 , -.Xr od 1 -.Sh STANDARDS -The -.Nm -utility is compliant with the -.St -p1003.1-2008 -specification. -.Pp -The flags -.Op Fl fmo -are extensions to that specification. -.Pp -Historic implementations of -.Nm -only search the initialized data portion of the object file. -This was reasonable as strings were normally stored there. -Given new compiler technology which installs strings in the -text portion of the object file, the default behavior was -changed. -.Sh HISTORY -The -.Nm -utility appeared in -.Bx 3.0 . -.Sh BUGS -The algorithm for identifying strings is extremely primitive. -In particular, machine code instructions on certain architectures -can resemble sequences of ASCII bytes, which -will fool the algorithm. diff --git a/usr.bin/strings/strings.c b/usr.bin/strings/strings.c deleted file mode 100644 index 8b5b82026ab..00000000000 --- a/usr.bin/strings/strings.c +++ /dev/null @@ -1,254 +0,0 @@ -/* $OpenBSD: strings.c,v 1.15 2009/10/27 23:59:43 deraadt Exp $ */ -/* $NetBSD: strings.c,v 1.7 1995/02/15 15:49:19 jtc Exp $ */ - -/* - * Copyright (c) 1980, 1987, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY 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. - */ - -#include <sys/types.h> - -#include <a.out.h> -#include <ctype.h> -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <locale.h> -#include <unistd.h> -#include <err.h> - -#define FORMAT_DEC "%07ld " -#define FORMAT_OCT "%07lo " -#define FORMAT_HEX "%07lx " - -#define DEF_LEN 4 /* default minimum string length */ -#define ISSTR(ch) (isascii(ch) && (isprint(ch) || ch == '\t')) - -typedef struct exec EXEC; /* struct exec cast */ - -static long foff; /* offset in the file */ -static int hcnt, /* head count */ - head_len, /* length of header */ - read_len; /* length to read */ -static u_char hbfr[sizeof(EXEC)]; /* buffer for struct exec */ - -static void usage(void); -int getch(void); - -int -main(int argc, char *argv[]) -{ - extern char *optarg; - extern int optind; - int ch, cnt; - u_char *C; - EXEC *head; - int exitcode, minlen, maxlen, bfrlen; - short asdata, fflg; - u_char *bfr; - char *file, *p; - char *offset_format; - - setlocale(LC_ALL, ""); - - /* - * for backward compatibility, allow '-' to specify 'a' flag; no - * longer documented in the man page or usage string. - */ - asdata = exitcode = fflg = 0; - offset_format = NULL; - minlen = -1; - maxlen = -1; - while ((ch = getopt(argc, argv, "0123456789an:m:oft:-")) != -1) - switch((char)ch) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - /* - * kludge: strings was originally designed to take - * a number after a dash. - */ - if (minlen == -1) { - p = argv[optind - 1]; - if (p[0] == '-' && p[1] == ch && !p[2]) - minlen = atoi(++p); - else - minlen = atoi(argv[optind] + 1); - } - break; - case '-': - case 'a': - asdata = 1; - break; - case 'f': - fflg = 1; - break; - case 'n': - minlen = atoi(optarg); - break; - case 'm': - maxlen = atoi(optarg); - break; - case 'o': - offset_format = FORMAT_OCT; - break; - case 't': - switch (*optarg) { - case 'o': - offset_format = FORMAT_OCT; - break; - case 'd': - offset_format = FORMAT_DEC; - break; - case 'x': - offset_format = FORMAT_HEX; - break; - default: - usage(); - /* NOTREACHED */ - } - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (minlen == -1) - minlen = DEF_LEN; - else if (minlen < 1) - errx(1, "length less than 1"); - if (maxlen != -1 && maxlen < minlen) - errx(1, "max length less than min"); - bfrlen = maxlen == -1 ? minlen : maxlen; - bfr = malloc(bfrlen + 1); - if (!bfr) - err(1, "malloc"); - bfr[bfrlen] = '\0'; - file = "stdin"; - do { - if (*argv) { - file = *argv++; - if (!freopen(file, "r", stdin)) { - warn("%s", file); - exitcode = 1; - goto nextfile; - } - } - foff = 0; -#define DO_EVERYTHING() {read_len = -1; head_len = 0; goto start;} - read_len = -1; - if (asdata) - DO_EVERYTHING() - else { - head = (EXEC *)hbfr; - if ((head_len = - read(fileno(stdin), head, sizeof(EXEC))) == -1) - DO_EVERYTHING() - if (head_len == sizeof(EXEC) && !N_BADMAG(*head)) { - foff = N_TXTOFF(*head); - if (fseek(stdin, foff, SEEK_SET) == -1) - DO_EVERYTHING() - read_len = head->a_text + head->a_data; - head_len = 0; - } - else - hcnt = 0; - } -start: - for (cnt = 0, C = bfr; (ch = getch()) != EOF;) { - if (ISSTR(ch)) { - *C++ = ch; - if (++cnt < minlen) - continue; - if (maxlen != -1) { - while ((ch = getch()) != EOF && - ISSTR(ch) && cnt++ < maxlen) - *C++ = ch; - if (ch == EOF || - (ch != 0 && ch != '\n')) { - /* get all of too big string */ - while ((ch = getch()) != EOF && - ISSTR(ch)) - ; - ungetc(ch, stdin); - goto out; - } - *C = 0; - } - - if (fflg) - printf("%s:", file); - - if (offset_format) - printf(offset_format, foff - minlen); - - printf("%s", bfr); - - if (maxlen == -1) - while ((ch = getch()) != EOF && - ISSTR(ch)) - putchar((char)ch); - putchar('\n'); - out: - ; - } - cnt = 0; - C = bfr; - } -nextfile: ; - } while (*argv); - exit(exitcode); -} - -/* - * getch -- - * get next character from wherever - */ -int -getch(void) -{ - ++foff; - if (head_len) { - if (hcnt < head_len) - return((int)hbfr[hcnt++]); - head_len = 0; - } - if (read_len == -1 || read_len-- > 0) - return(getchar()); - return(EOF); -} - -static void -usage(void) -{ - (void)fprintf(stderr, - "usage: strings [-afo] [-m number] [-n number] [-t radix] [file ...]\n"); - exit(1); -} diff --git a/usr.bin/strip/Makefile b/usr.bin/strip/Makefile deleted file mode 100644 index 67f489ee51b..00000000000 --- a/usr.bin/strip/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -# $OpenBSD: Makefile,v 1.12 2013/03/15 06:01:42 deraadt Exp $ - -.include <bsd.own.mk> -.if (${ELF_TOOLCHAIN:L} == "no") - -TARGET_MACHINE_ARCH?= ${MACHINE_ARCH} - -PROG= strip - -CFLAGS+=-I${.CURDIR}/../nm -.if ${TARGET_MACHINE_ARCH} != ${MACHINE_ARCH} -# XXX should make this automatic -.if ${TARGET_MACHINE_ARCH} == "i386" -CFLAGS+= -DMID_MACHINE_OVERRIDE=MID_I386 -.elif ${TARGET_MACHINE_ARCH} == "m68k" -CFLAGS+= -DMID_MACHINE_OVERRIDE=MID_M68K -CPPFLAGS+=-I. -beforedepend: - ln -sf ${.CURDIR}/../../sys/arch/m68k/include m68k -.elif ${TARGET_MACHINE_ARCH} == "m88k" -CFLAGS+= -DMID_MACHINE_OVERRIDE=MID_M88K -CPPFLAGS+=-I. -beforedepend: - ln -sf ${.CURDIR}/../../sys/arch/m88k/include m88k -.elif ${TARGET_MACHINE_ARCH} == "ns32k" -CFLAGS+= -DMID_MACHINE_OVERRIDE=MID_NS32K -.elif ${TARGET_MACHINE_ARCH} == "sparc" -CFLAGS+= -DMID_MACHINE_OVERRIDE=MID_SPARC -.elif ${TARGET_MACHINE_ARCH} == "vax" -CFLAGS+= -DMID_MACHINE_OVERRIDE=MID_VAX -.endif -STRIP= /usr/bin/strip - -.elif ${HOSTCC} != ${CC} -STRIP=./hoststrip - -realinstall strip: hoststrip - -hoststrip: strip.c - ${HOSTCC} -I${.CURDIR}/../nm ${.CURDIR}/strip.c -o hoststrip -.else -STRIP=./strip -.endif - -realinstall: - ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 600 strip \ - ${DESTDIR}${BINDIR} - ${STRIP} ${DESTDIR}${BINDIR}/strip - chmod ${BINMODE} ${DESTDIR}${BINDIR}/strip - -if [ "${INSTALL_COPY}" = "" ]; then rm -f ${STRIP}; fi - -.endif - -.include <bsd.prog.mk> diff --git a/usr.bin/strip/strip.1 b/usr.bin/strip/strip.1 deleted file mode 100644 index 94ae043d084..00000000000 --- a/usr.bin/strip/strip.1 +++ /dev/null @@ -1,89 +0,0 @@ -.\" $OpenBSD: strip.1,v 1.15 2010/09/03 11:09:29 jmc Exp $ -.\" -.\" Copyright (c) 1989, 1990 The Regents of the University of California. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY 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. -.\" -.\" from: @(#)strip.1 6.6 (Berkeley) 5/26/91 -.\" -.Dd $Mdocdate: September 3 2010 $ -.Dt STRIP 1 -.Os -.Sh NAME -.Nm strip -.Nd remove unnecessary information from executable files -.Sh SYNOPSIS -.Nm strip -.Op Fl dgsx -.Op Fl o Ar outfile -.Ar -.Sh DESCRIPTION -The -.Nm -utility -deletes the relocation information and symbol table used by -assemblers, loaders and debuggers. -This significantly -decreases the size of the installed binaries and saves disk space. -.Pp -The options are as follows: -.Bl -tag -width Ds -.It Fl d | g -Delete only debugging and empty symbols. -.It Fl o Ar outfile -Place the stripped output into the specified file instead of modifying -the input file. -This option requires that only one input file be supplied. -.It Fl s -Delete all symbols. -This is the default. -.It Fl x -Delete only debugging, compiler identification, and local symbols. -.El -.Pp -When conflicting options are combined, the latter option wins. -.Sh EXIT STATUS -.Ex -std strip -.Sh SEE ALSO -.Xr cc 1 , -.Xr ld 1 , -.Xr stab 5 -.Sh STANDARDS -The -.Nm -utility is compliant with the -.St -p1003.1-2008 -specification, -though its presence is optional. -.Pp -The flags -.Op Fl dgosx -are extensions to that specification. -.Sh HISTORY -A -.Nm -command appeared in -.At v6 . diff --git a/usr.bin/strip/strip.c b/usr.bin/strip/strip.c deleted file mode 100644 index 980ed61dbf7..00000000000 --- a/usr.bin/strip/strip.c +++ /dev/null @@ -1,440 +0,0 @@ -/* $OpenBSD: strip.c,v 1.30 2013/03/21 19:53:32 deraadt Exp $ */ - -/* - * Copyright (c) 1988 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY 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. - */ - -#include <sys/param.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/mman.h> -#include <fcntl.h> -#include <errno.h> -#include <a.out.h> -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <err.h> -#include <ranlib.h> -#include "byte.c" - -#ifdef MID_MACHINE_OVERRIDE -#undef MID_MACHINE -#define MID_MACHINE MID_MACHINE_OVERRIDE -#if MID_MACHINE_OVERRIDE == MID_M68K -#undef __LDPGSZ -#undef ELF_TARG_DATA -#undef ELF_TARG_MACH -#include "m68k/exec.h" -#elif MID_MACHINE_OVERRIDE == MID_M88K -#undef __LDPGSZ -#undef ELF_TARG_DATA -#undef ELF_TARG_MACH -#include "m88k/exec.h" -#endif -#endif - -typedef struct exec EXEC; -typedef struct nlist NLIST; - -#define strx n_un.n_strx - -int s_stab(const char *, int, EXEC *, struct stat *, off_t *); -int s_sym(const char *, int, EXEC *, struct stat *, off_t *); -void usage(void); - -int xflag = 0; - -int -main(int argc, char *argv[]) -{ - int fd; - EXEC *ep; - struct stat sb; - int (*sfcn)(const char *, int, EXEC *, struct stat *, off_t *); - int ch, errors; - char *fn, *ofile = NULL; - off_t newsize; - - sfcn = s_sym; - while ((ch = getopt(argc, argv, "dgsxo:")) != -1) - switch(ch) { - case 'x': - xflag = 1; - /*FALLTHROUGH*/ - case 'g': - case 'd': - sfcn = s_stab; - break; - case 's': - /* reset back to the defaults */ - xflag = 0; - sfcn = s_sym; - break; - case 'o': - ofile = optarg; - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (ofile != NULL && argc > 1) - usage(); - errors = 0; -#define ERROR(x) errors |= 1; warnx("%s: %s", fn, strerror(x)); continue; - while ((fn = *argv++)) { - if (ofile) { - char buf[8192]; - ssize_t wn; - size_t rn; - off_t off; - int wfd; - - if ((fd = open(fn, O_RDONLY)) < 0) { - ERROR(errno); - break; - } - if ((wfd = open(ofile, O_RDWR|O_CREAT)) < 0) { - ERROR(errno); - break; - } - do { - rn = read(fd, buf, sizeof buf); - if (rn == (ssize_t)-1) { - int save_errno = errno; - - unlink(ofile); - ERROR(save_errno); - exit(errors); - } - if (rn == 0) - break; - - off = 0; - while (rn - off > 0) { - wn = write(wfd, buf + off, rn - off); - if (wn == (ssize_t)-1) { - int save_errno = errno; - - unlink(ofile); - ERROR(save_errno); - exit(errors); - } - off += wn; - } - } while (rn > 0); - - fn = ofile; - close(fd); - fd = wfd; - } else if ((fd = open(fn, O_RDWR)) < 0) { - ERROR(errno); - } - if (fstat(fd, &sb)) { - (void)close(fd); - ERROR(errno); - } - if (sb.st_size < sizeof(EXEC)) { - (void)close(fd); - ERROR(EFTYPE); - } - if ((ep = (EXEC *)mmap(NULL, sb.st_size, PROT_READ|PROT_WRITE, - MAP_SHARED, fd, (off_t)0)) == MAP_FAILED) { - (void)close(fd); - ERROR(errno); - } - if (BAD_OBJECT(*ep)) { - munmap((caddr_t)ep, sb.st_size); - (void)close(fd); - ERROR(EFTYPE); - } - /* - * Since we're dealing with an mmap there, we have to convert - * once for dealing with data in memory, and a second time - * for out. - */ - fix_header_order(ep); - newsize = 0; - errors |= sfcn(fn, fd, ep, &sb, &newsize); - fix_header_order(ep); - munmap((caddr_t)ep, sb.st_size); - if (newsize && ftruncate(fd, newsize)) { - warn("%s", fn); - errors = 1; - } - if (close(fd)) { - ERROR(errno); - } - } -#undef ERROR - exit(errors); -} - -int -s_sym(const char *fn, int fd, EXEC *ep, struct stat *sp, off_t *sz) -{ - char *neweof; -#if 0 - char *mineof; -#endif - int zmagic; - - zmagic = ep->a_data && - (N_GETMAGIC(*ep) == ZMAGIC || N_GETMAGIC(*ep) == QMAGIC); - - /* - * If no symbols or data/text relocation info and - * the file data segment size is already minimized, quit. - */ - if (!ep->a_syms && !ep->a_trsize && !ep->a_drsize) { -#if 0 - if (!zmagic) - return 0; - if (sp->st_size < N_TRELOFF(*ep)) -#endif - return 0; - } - - /* - * New file size is the header plus text and data segments; OMAGIC - * and NMAGIC formats have the text/data immediately following the - * header. ZMAGIC format wastes the rest of of header page. - */ - neweof = (char *)ep + N_TRELOFF(*ep); - -#if 0 - /* - * Unfortunately, this can't work correctly without changing the way - * the loader works. We could cap it at one page, or even fiddle with - * a_data and a_bss, but this only works for CLBYTES == PAGE_SIZE. If - * we are on a system where, e.g., CLBYTES is 8k and PAGE_SIZE is 4k, - * and we happen to remove 4.5k, we will lose. And we really don't want - * to fiddle with pages, because that breaks binary compatibility. Lose. - */ - - if (zmagic) { - /* - * Get rid of unneeded zeroes at the end of the data segment - * to reduce the file size even more. - */ - mineof = (char *)ep + N_DATOFF(*ep); - while (neweof > mineof && neweof[-1] == '\0') - neweof--; - } -#endif - - /* Set symbol size and relocation info values to 0. */ - ep->a_syms = ep->a_trsize = ep->a_drsize = 0; - - /* Truncate the file. */ - *sz = neweof - (char *)ep; - - return 0; -} - -int -s_stab(const char *fn, int fd, EXEC *ep, struct stat *sp, off_t *sz) -{ - int cnt, len; - char *nstr, *nstrbase=0, *used=0, *p, *strbase; - NLIST *sym, *nsym; - u_long allocsize; - int mid; - NLIST *symbase; - unsigned int *mapping=0; - int error=1; - unsigned int nsyms; - struct relocation_info *reloc_base; - unsigned int i, j; - - /* Quit if no symbols. */ - if (ep->a_syms == 0) - return 0; - - if (N_SYMOFF(*ep) >= sp->st_size) { - warnx("%s: bad symbol table", fn); - return 1; - } - - mid = N_GETMID(*ep); - - /* - * Initialize old and new symbol pointers. They both point to the - * beginning of the symbol table in memory, since we're deleting - * entries. - */ - sym = nsym = symbase = (NLIST *)((char *)ep + N_SYMOFF(*ep)); - - /* - * Allocate space for the new string table, initialize old and - * new string pointers. Handle the extra long at the beginning - * of the string table. - */ - strbase = (char *)ep + N_STROFF(*ep); - allocsize = fix_32_order(*(u_long *)strbase, mid); - if ((nstrbase = malloc((u_int) allocsize)) == NULL) { - warnx("%s", strerror(ENOMEM)); - goto end; - } - nstr = nstrbase + sizeof(u_long); - - /* okay, so we also need to keep symbol numbers for relocations. */ - nsyms = ep->a_syms/ sizeof(NLIST); - used = calloc(nsyms, 1); - if (!used) { - warnx("%s", strerror(ENOMEM)); - goto end; - } - mapping = calloc(nsyms, sizeof(unsigned int)); - if (!mapping) { - warnx("%s", strerror(ENOMEM)); - goto end; - } - - if ((ep->a_trsize || ep->a_drsize) && byte_sex(mid) != BYTE_ORDER) { - warnx("%s: cross-stripping not supported", fn); - goto end; - } - - /* first check the relocations for used symbols, and mark them */ - /* text */ - reloc_base = (struct relocation_info *) ((char *)ep + N_TRELOFF(*ep)); - if (N_TRELOFF(*ep) + ep->a_trsize > sp->st_size) { - warnx("%s: bad text relocation", fn); - goto end; - } - for (i = 0; i < ep->a_trsize / sizeof(struct relocation_info); i++) { - if (!reloc_base[i].r_extern) - continue; - if (reloc_base[i].r_symbolnum > nsyms) { - warnx("%s: bad symbol number in text relocation", fn); - goto end; - } - used[reloc_base[i].r_symbolnum] = 1; - } - /* data */ - reloc_base = (struct relocation_info *) ((char *)ep + N_DRELOFF(*ep)); - if (N_DRELOFF(*ep) + ep->a_drsize > sp->st_size) { - warnx("%s: bad data relocation", fn); - goto end; - } - for (i = 0; i < ep->a_drsize / sizeof(struct relocation_info); i++) { - if (!reloc_base[i].r_extern) - continue; - if (reloc_base[i].r_symbolnum > nsyms) { - warnx("%s: bad symbol number in data relocation", fn); - goto end; - } - used[reloc_base[i].r_symbolnum] = 1; - } - - /* - * Read through the symbol table. For each non-debugging symbol, - * copy it and save its string in the new string table. Keep - * track of the number of symbols. - */ - for (cnt = nsyms, i = 0, j = 0; cnt--; ++sym, ++i) { - fix_nlist_order(sym, mid); - if (!(sym->n_type & N_STAB) && sym->strx) { - *nsym = *sym; - nsym->strx = nstr - nstrbase; - p = strbase + sym->strx; - if (xflag && !used[i] && - (!(sym->n_type & N_EXT) || - (sym->n_type & ~N_EXT) == N_FN || - strcmp(p, "gcc_compiled.") == 0 || - strcmp(p, "gcc2_compiled.") == 0 || - strncmp(p, "___gnu_compiled_", 16) == 0)) { - continue; - } - len = strlen(p) + 1; - mapping[i] = j++; - if (N_STROFF(*ep) + sym->strx + len > sp->st_size) { - warnx("%s: bad symbol table", fn); - goto end; - } - bcopy(p, nstr, len); - nstr += len; - fix_nlist_order(nsym++, mid); - } - } - - /* renumber symbol relocations */ - /* text */ - reloc_base = (struct relocation_info *) ((char *)ep + N_TRELOFF(*ep)); - for (i = 0; i < ep->a_trsize / sizeof(struct relocation_info); i++) { - if (!reloc_base[i].r_extern) - continue; - reloc_base[i].r_symbolnum = mapping[reloc_base[i].r_symbolnum]; - } - /* data */ - reloc_base = (struct relocation_info *) ((char *)ep + N_DRELOFF(*ep)); - for (i = 0; i < ep->a_drsize / sizeof(struct relocation_info); i++) { - if (!reloc_base[i].r_extern) - continue; - reloc_base[i].r_symbolnum = mapping[reloc_base[i].r_symbolnum]; - } - - /* Fill in new symbol table size. */ - ep->a_syms = (nsym - symbase) * sizeof(NLIST); - - /* Fill in the new size of the string table. */ - len = nstr - nstrbase; - *(u_long *)nstrbase = fix_32_order(len, mid); - - /* - * Copy the new string table into place. Nsym should be pointing - * at the address past the last symbol entry. - */ - bcopy(nstrbase, (void *)nsym, len); - error = 0; -end: - free(nstrbase); - free(used); - free(mapping); - - /* Truncate to the current length. */ - *sz = (char *)nsym + len - (char *)ep; - - return error; -} - -void -usage(void) -{ - extern char *__progname; - - fprintf(stderr, "usage: %s [-dgsx] [-o outfile] file ...\n", - __progname); - exit(1); -} - |