Add -X flag, which strips only debugging and compiler identification

symbols. RCSid police and gcc -Wall cleanup.
This commit is contained in:
christos 1996-10-08 22:00:18 +00:00
parent edd633aef1
commit dc089e1ea1
3 changed files with 48 additions and 56 deletions

View File

@ -1,5 +1,5 @@
# from: @(#)Makefile 5.4 (Berkeley) 5/11/90 # $NetBSD: Makefile,v 1.11 1996/10/08 22:00:18 christos Exp $
# $Id: Makefile,v 1.10 1995/06/10 20:56:34 mycroft Exp $ # @(#)Makefile 5.4 (Berkeley) 5/11/90
PROG= strip PROG= strip

View File

@ -1,3 +1,4 @@
.\" $NetBSD: strip.1,v 1.4 1996/10/08 22:00:20 christos Exp $
.\" Copyright (c) 1989, 1990 The Regents of the University of California. .\" Copyright (c) 1989, 1990 The Regents of the University of California.
.\" All rights reserved. .\" All rights reserved.
.\" .\"
@ -29,8 +30,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" from: @(#)strip.1 6.6 (Berkeley) 5/26/91 .\" @(#)strip.1 6.6 (Berkeley) 5/26/91
.\" $Id: strip.1,v 1.3 1993/08/27 02:33:34 brezak Exp $
.\" .\"
.Dd May 26, 1991 .Dd May 26, 1991
.Dt STRIP 1 .Dt STRIP 1
@ -42,6 +42,7 @@
.Nm strip .Nm strip
.Op Fl d .Op Fl d
.Op Fl x .Op Fl x
.Op Fl X
.Ar file ... .Ar file ...
.Sh DESCRIPTION .Sh DESCRIPTION
The The
@ -56,8 +57,10 @@ The options are as follows:
.Bl -tag -width Ds .Bl -tag -width Ds
.It Fl d .It Fl d
Delete only debugging and empty symbols. Delete only debugging and empty symbols.
.It Fl X
Delete only debugging, empty, and compiler identification symbols.
.It Fl x .It Fl x
Delete only debugging, compiler identification, and local symbols. Delete only debugging, empty, compiler identification, and local symbols.
.El .El
.Pp .Pp
.Nm Strip .Nm Strip

View File

@ -1,3 +1,5 @@
/* $NetBSD: strip.c,v 1.14 1996/10/08 22:00:22 christos Exp $ */
/* /*
* Copyright (c) 1988 Regents of the University of California. * Copyright (c) 1988 Regents of the University of California.
* All rights reserved. * All rights reserved.
@ -38,8 +40,11 @@ char copyright[] =
#endif /* not lint */ #endif /* not lint */
#ifndef lint #ifndef lint
/*static char sccsid[] = "from: @(#)strip.c 5.8 (Berkeley) 11/6/91";*/ #if 0
static char rcsid[] = "$Id: strip.c,v 1.13 1994/03/28 02:17:50 cgd Exp $"; static char sccsid[] = "@(#)strip.c 5.8 (Berkeley) 11/6/91";*/
#else
static char rcsid[] = "$NetBSD: strip.c,v 1.14 1996/10/08 22:00:22 christos Exp $";
#endif
#endif /* not lint */ #endif /* not lint */
#include <sys/types.h> #include <sys/types.h>
@ -52,24 +57,28 @@ static char rcsid[] = "$Id: strip.c,v 1.13 1994/03/28 02:17:50 cgd Exp $";
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <err.h>
typedef struct exec EXEC; typedef struct exec EXEC;
typedef struct nlist NLIST; typedef struct nlist NLIST;
#define strx n_un.n_strx #define strx n_un.n_strx
void err __P((const char *fmt, ...)); int main __P((int, char *[]));
int s_stab __P((const char *, int, EXEC *, struct stat *));
int s_sym __P((const char *, int, EXEC *, struct stat *));
void usage __P((void));
int xflag = 0; static int s_stab __P((const char *, int, EXEC *, struct stat *));
static int s_sym __P((const char *, int, EXEC *, struct stat *));
static void usage __P((void));
static int xflag = 0;
static int Xflag = 0;
int
main(argc, argv) main(argc, argv)
int argc; int argc;
char *argv[]; char *argv[];
{ {
register int fd, nb; int fd, nb;
EXEC *ep; EXEC *ep;
struct stat sb; struct stat sb;
int (*sfcn)__P((const char *, int, EXEC *, struct stat *)); int (*sfcn)__P((const char *, int, EXEC *, struct stat *));
@ -77,11 +86,14 @@ main(argc, argv)
char *fn; char *fn;
sfcn = s_sym; sfcn = s_sym;
while ((ch = getopt(argc, argv, "dx")) != EOF) while ((ch = getopt(argc, argv, "dxX")) != EOF)
switch(ch) { switch(ch) {
case 'x': case 'x':
xflag = 1; xflag = 1;
/*FALLTHROUGH*/ /*FALLTHROUGH*/
case 'X':
Xflag = 1;
/*FALLTHROUGH*/
case 'd': case 'd':
sfcn = s_stab; sfcn = s_stab;
break; break;
@ -93,8 +105,8 @@ main(argc, argv)
argv += optind; argv += optind;
errors = 0; errors = 0;
#define ERROR(x) errors |= 1; err("%s: %s", fn, strerror(x)); continue; #define ERROR(e) errno = e; errors |= 1; warn("%s:", fn); continue;
while (fn = *argv++) { while ((fn = *argv++) != NULL) {
if ((fd = open(fn, O_RDWR)) < 0) { if ((fd = open(fn, O_RDWR)) < 0) {
ERROR(errno); ERROR(errno);
} }
@ -126,14 +138,14 @@ main(argc, argv)
exit(errors); exit(errors);
} }
int static int
s_sym(fn, fd, ep, sp) s_sym(fn, fd, ep, sp)
const char *fn; const char *fn;
int fd; int fd;
register EXEC *ep; register EXEC *ep;
struct stat *sp; struct stat *sp;
{ {
register char *neweof, *mineof; char *neweof, *mineof;
int zmagic; int zmagic;
zmagic = ep->a_data && zmagic = ep->a_data &&
@ -185,14 +197,14 @@ s_sym(fn, fd, ep, sp)
/* Truncate the file. */ /* Truncate the file. */
if (ftruncate(fd, neweof - (char *)ep)) { if (ftruncate(fd, neweof - (char *)ep)) {
err("%s: %s", fn, strerror(errno)); warn("%s:", fn);
return 1; return 1;
} }
return 0; return 0;
} }
int static int
s_stab(fn, fd, ep, sp) s_stab(fn, fd, ep, sp)
const char *fn; const char *fn;
int fd; int fd;
@ -209,7 +221,7 @@ s_stab(fn, fd, ep, sp)
return 0; return 0;
if (N_SYMOFF(*ep) >= sp->st_size) { if (N_SYMOFF(*ep) >= sp->st_size) {
err("%s: bad symbol table", fn); warnx("%s: bad symbol table", fn);
return 1; return 1;
} }
@ -227,7 +239,7 @@ s_stab(fn, fd, ep, sp)
*/ */
strbase = (char *)ep + N_STROFF(*ep); strbase = (char *)ep + N_STROFF(*ep);
if ((nstrbase = malloc((u_int)*(u_long *)strbase)) == NULL) { if ((nstrbase = malloc((u_int)*(u_long *)strbase)) == NULL) {
err("%s", strerror(ENOMEM)); warn("%s", "");
return 1; return 1;
} }
nstr = nstrbase + sizeof(u_long); nstr = nstrbase + sizeof(u_long);
@ -242,12 +254,15 @@ s_stab(fn, fd, ep, sp)
*nsym = *sym; *nsym = *sym;
nsym->strx = nstr - nstrbase; nsym->strx = nstr - nstrbase;
p = strbase + sym->strx; p = strbase + sym->strx;
if (xflag && if (Xflag &&
(!(sym->n_type & N_EXT) || (strcmp(p, "gcc_compiled.") == 0 ||
(sym->n_type & ~N_EXT) == N_FN ||
strcmp(p, "gcc_compiled.") == 0 ||
strcmp(p, "gcc2_compiled.") == 0 || strcmp(p, "gcc2_compiled.") == 0 ||
strncmp(p, "___gnu_compiled_", 16) == 0)) { strncmp(p, "___gnu_compiled_", 16) == 0)) {
continue;
}
if (xflag &&
(!(sym->n_type & N_EXT) ||
(sym->n_type & ~N_EXT) == N_FN)) {
continue; continue;
} }
len = strlen(p) + 1; len = strlen(p) + 1;
@ -271,43 +286,17 @@ s_stab(fn, fd, ep, sp)
/* Truncate to the current length. */ /* Truncate to the current length. */
if (ftruncate(fd, (char *)nsym + len - (char *)ep)) { if (ftruncate(fd, (char *)nsym + len - (char *)ep)) {
err("%s: %s", fn, strerror(errno)); warn("%s", fn);
return 1; return 1;
} }
return 0; return 0;
} }
void static void
usage() usage()
{ {
(void)fprintf(stderr, "usage: strip [-dx] file ...\n"); extern char *__progname;
(void)fprintf(stderr, "Usage: %s [-dxX] file ...\n", __progname);
exit(1); exit(1);
} }
#if __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
void
#if __STDC__
err(const char *fmt, ...)
#else
err(fmt, va_alist)
char *fmt;
va_dcl
#endif
{
va_list ap;
#if __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
(void)fprintf(stderr, "strip: ");
(void)vfprintf(stderr, fmt, ap);
va_end(ap);
(void)fprintf(stderr, "\n");
}