WARNSify, fix .Nm usage

This commit is contained in:
lukem 1997-10-18 13:54:51 +00:00
parent 7397398466
commit 0fbfce3460
4 changed files with 182 additions and 186 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: elfstrip.1,v 1.2 1997/01/09 20:18:39 tls Exp $
.\" $NetBSD: elfstrip.1,v 1.3 1997/10/18 13:54:51 lukem Exp $
.\"
.\" Copyright (c) 1989, 1990 The Regents of the University of California.
.\" All rights reserved.
@ -32,7 +32,7 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)strip.1 6.6 (Berkeley) 5/26/91
.\" $NetBSD: elfstrip.1,v 1.2 1997/01/09 20:18:39 tls Exp $
.\" $NetBSD: elfstrip.1,v 1.3 1997/10/18 13:54:51 lukem Exp $
.\"
.Dd September 30, 1996
.Dt ELFSTRIP 1
@ -41,18 +41,18 @@
.Nm elfstrip
.Nd remove unnecessary information from ELF executable files
.Sh SYNOPSIS
.Nm elfstrip
.Nm
.Ar file ...
.Sh DESCRIPTION
The
.Nm elfstrip
.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
.Nm Elfstrip
.Nm
is more aggressive about stripping unecessary information
than the GNU equivalent. The
GNU binutils
@ -61,7 +61,7 @@ utility uses the "unecessary" information and may not be able to
find the size of executable segments of stripped files.
The strippped files are still correctly executed.
.Pp
.Nm Strip
.Nm
exits 0 on success and 1 if an error occurred.
.Sh SEE ALSO
.Xr cc 1 ,
@ -83,6 +83,6 @@ A
command appeared in
.At v6 .
This
.Nm elfstrip
.Nm
command first appeared in
.Nx 1.1 .

View File

@ -1,4 +1,4 @@
/* $NetBSD: elfstrip.c,v 1.4 1997/01/09 20:18:40 tls Exp $ */
/* $NetBSD: elfstrip.c,v 1.5 1997/10/18 13:54:55 lukem Exp $ */
/*
* Copyright (c) 1995
@ -44,35 +44,34 @@
#include <a.out.h>
struct sect {
unsigned long vaddr;
unsigned long len;
unsigned long vaddr;
unsigned long len;
};
int phcmp ();
void usage __P((void));
int main __P((int argc, char *argv[]));
int elf32_strip __P((const char *));
int main __P((int argc, char *argv[]));
int phcmp __P((const void *, const void *));
void usage __P((void));
void *saveRead (int file, off_t offset, int len, char *name);
void placeWrite(int file, off_t offset, int len, char *name, void *data);
void *saveRead(int file, off_t offset, int len, char *name);
void placeWrite(int file, off_t offset, int len, char *name, void *data);
extern int errno;
int xflag = 0;
int xflag = 0;
int
main(argc, argv)
int argc;
char *argv[];
int argc;
char *argv[];
{
int i;
int ch;
int ch;
while ((ch = getopt(argc, argv, "dx")) != EOF)
switch(ch) {
case 'x':
xflag = 1;
/*FALLTHROUGH*/
while ((ch = getopt(argc, argv, "dx")) != -1)
switch (ch) {
case 'x':
xflag = 1;
/* FALLTHROUGH */
case 'd':
#ifdef notyet
sfcn = s_stab;
@ -90,183 +89,179 @@ main(argc, argv)
usage();
}
while (argc > 0) {
elf32_strip(argv [0]);
argc--; argv++;
elf32_strip(argv[0]);
argc--;
argv++;
}
return (0);
}
int
elf32_strip(filename)
const char *filename;
const char *filename;
{
Elf32_Ehdr ex;
Elf32_Phdr *ph;
int i;
int infile;
int i;
int infile;
unsigned long lastp;
Elf32_Phdr **indt;
void *segment;
void *segment;
if ((infile = open (filename, O_RDWR)) < 0)
{
fprintf (stderr, "Can't open %s for read/write: %s\n",
filename, strerror (errno));
exit (1);
}
/* Read the header, which is at the beginning of the file... */
/*
** printf("elf header from file 0 size %x\n", sizeof ex);
*/
i = read (infile, &ex, sizeof ex);
if (i != sizeof ex)
{
fprintf (stderr, "ex: %s: %s.\n",
filename, i ? strerror (errno) : "End of file reached");
exit (1);
}
if (strncmp(ex.e_ident, Elf32_e_ident, sizeof(ex.e_ident)) != 0) {
fprintf (stderr, "strip: %s not ELF format\n", filename);
return(0);
}
/* Devalidate section headers */
ex.e_shoff = 0;
ex.e_shnum = 0;
ex.e_shentsize = 0;
ex.e_shstrndx = 0;
placeWrite (infile, 0, sizeof ex, "ex", &ex);
/* Read the program headers... */
/*
** printf("program headers from file %x size %x\n",
** ex.phoff, ex.phcount * sizeof (Elf32_Phdr));
*/
lastp = ex.e_phoff + ex.e_phnum * sizeof (Elf32_Phdr);
ph = (Elf32_Phdr *)saveRead (infile, ex.e_phoff,
ex.e_phnum * sizeof(Elf32_Phdr), "ph");
indt = (Elf32_Phdr **)malloc(ex.e_phnum * sizeof(Elf32_Phdr **));
for (i=0; i<ex.e_phnum; i++) {
indt[i] = ph+i;
}
qsort (indt, ex.e_phnum, sizeof (Elf32_Phdr **), phcmp);
for (i = 0; i < ex.e_phnum; i++)
{
Elf32_Phdr *php = indt[i];
/* Section types we can ignore... */
if (php->p_type == Elf_pt_null || php->p_type == Elf_pt_note ||
php->p_type == Elf_pt_phdr || php->p_type == Elf_pt_mips_reginfo)
{
printf("segment type %ld ignored file %lx size %lx\n",
php->p_type, php->p_offset, php->p_filesz);
continue;
}
/* Section types we can't handle... */
else if (php->p_type != Elf_pt_load)
{
fprintf (stderr, "Program header %d type %ld can't be converted.\n",
php-ph, php->p_type);
exit (1);
if ((infile = open(filename, O_RDWR)) < 0) {
fprintf(stderr, "Can't open %s for read/write: %s\n",
filename, strerror(errno));
exit(1);
}
/* Read the header, which is at the beginning of the file... */
/*
** printf("segment %d load file %x size %x end %x\n",
** php-ph,
** php->p_offset, php->p_filesz, php->p_offset + php->p_filesz);
*/
if ((php->p_offset - lastp) > 0x2000) {
int pg;
** printf("elf header from file 0 size %x\n", sizeof ex);
*/
pg = ((php->p_offset - lastp) / 0x2000);
pg *= 0x2000;
segment = saveRead (infile, php->p_offset,
php->p_filesz, "segment");
php->p_offset -= pg;
placeWrite (infile, php->p_offset,
php->p_filesz, "segment", segment);
/*
** printf("Move segment %d shift %x to %x\n",
** php-ph, pg, php->p_offset);
*/
i = read(infile, &ex, sizeof ex);
if (i != sizeof ex) {
fprintf(stderr, "ex: %s: %s.\n",
filename, i ? strerror(errno) : "End of file reached");
exit(1);
}
lastp = php->p_offset + php->p_filesz;
}
placeWrite (infile, ex.e_phoff, ex.e_phnum * sizeof (Elf32_Phdr), "ph", ph);
ftruncate(infile, lastp);
if (strncmp(ex.e_ident, Elf32_e_ident, sizeof(ex.e_ident)) != 0) {
fprintf(stderr, "strip: %s not ELF format\n", filename);
return (0);
}
/* Devalidate section headers */
ex.e_shoff = 0;
ex.e_shnum = 0;
ex.e_shentsize = 0;
ex.e_shstrndx = 0;
placeWrite(infile, 0, sizeof ex, "ex", &ex);
/* Looks like we won... */
exit (0);
/* Read the program headers... */
/*
** printf("program headers from file %x size %x\n",
** ex.phoff, ex.phcount * sizeof (Elf32_Phdr));
*/
lastp = ex.e_phoff + ex.e_phnum * sizeof(Elf32_Phdr);
ph = (Elf32_Phdr *) saveRead(infile, ex.e_phoff,
ex.e_phnum * sizeof(Elf32_Phdr), "ph");
indt = (Elf32_Phdr **) malloc(ex.e_phnum * sizeof(Elf32_Phdr **));
for (i = 0; i < ex.e_phnum; i++) {
indt[i] = ph + i;
}
qsort(indt, ex.e_phnum, sizeof(Elf32_Phdr **), phcmp);
for (i = 0; i < ex.e_phnum; i++) {
Elf32_Phdr *php = indt[i];
/* Section types we can ignore... */
if (php->p_type == Elf_pt_null || php->p_type == Elf_pt_note ||
php->p_type == Elf_pt_phdr || php->p_type == Elf_pt_mips_reginfo) {
printf("segment type %ld ignored file %lx size %lx\n",
(long)php->p_type, (long)php->p_offset,
(long)php->p_filesz);
continue;
}
/* Section types we can't handle... */
else
if (php->p_type != Elf_pt_load) {
fprintf(stderr,
"Program header %d type %ld can't be converted.\n",
php - ph, (long)php->p_type);
exit(1);
}
/*
** printf("segment %d load file %x size %x end %x\n",
** php-ph,
** php->p_offset, php->p_filesz, php->p_offset + php->p_filesz);
*/
if ((php->p_offset - lastp) > 0x2000) {
int pg;
pg = ((php->p_offset - lastp) / 0x2000);
pg *= 0x2000;
segment = saveRead(infile, php->p_offset,
php->p_filesz, "segment");
php->p_offset -= pg;
placeWrite(infile, php->p_offset,
php->p_filesz, "segment", segment);
/*
** printf("Move segment %d shift %x to %x\n",
** php-ph, pg, php->p_offset);
*/
}
lastp = php->p_offset + php->p_filesz;
}
placeWrite(infile, ex.e_phoff, ex.e_phnum * sizeof(Elf32_Phdr), "ph", ph);
ftruncate(infile, lastp);
/* Looks like we won... */
exit(0);
}
int
phcmp (h1, h2)
Elf32_Phdr **h1, **h2;
phcmp(vh1, vh2)
const void *vh1, *vh2;
{
if ((*h1) -> p_offset > (*h2) -> p_offset)
return 1;
else if ((*h1) -> p_offset < (*h2) -> p_offset)
return -1;
else
return 0;
Elf32_Phdr **h1, **h2;
h1 = (Elf32_Phdr **) vh1;
h2 = (Elf32_Phdr **) vh2;
if ((*h1)->p_offset > (*h2)->p_offset)
return 1;
else
if ((*h1)->p_offset < (*h2)->p_offset)
return -1;
else
return 0;
}
void *
saveRead (int file, off_t offset, int len, char *name)
void *
saveRead(int file, off_t offset, int len, char *name)
{
void *tmp;
int count;
off_t off;
if ((off = lseek (file, offset, SEEK_SET)) < 0)
{
fprintf (stderr, "%s: fseek: %s\n", name, strerror (errno));
exit (1);
}
if (!(tmp = malloc (len)))
{
fprintf (stderr, "%s: Can't allocate %d bytes.\n", name, len);
exit (1);
}
count = read (file, tmp, len);
if (count != len)
{
fprintf (stderr, "%s: read: %s.\n",
name, count ? strerror (errno) : "End of file reached");
exit (1);
}
return tmp;
void *tmp;
int count;
off_t off;
if ((off = lseek(file, offset, SEEK_SET)) < 0) {
fprintf(stderr, "%s: fseek: %s\n", name, strerror(errno));
exit(1);
}
if (!(tmp = malloc(len))) {
fprintf(stderr, "%s: Can't allocate %d bytes.\n", name, len);
exit(1);
}
count = read(file, tmp, len);
if (count != len) {
fprintf(stderr, "%s: read: %s.\n",
name, count ? strerror(errno) : "End of file reached");
exit(1);
}
return tmp;
}
void
placeWrite (int file, off_t offset, int len, char *name, void *data)
placeWrite(int file, off_t offset, int len, char *name, void *data)
{
int count;
off_t off;
if ((off = lseek (file, offset, SEEK_SET)) < 0)
{
fprintf (stderr, "%s: lseek: %s\n", name, strerror (errno));
exit (1);
}
count = write (file, data, len);
if (count != len)
{
fprintf (stderr, "%s: write: %s.\n", name, strerror (errno));
exit (1);
}
int count;
off_t off;
if ((off = lseek(file, offset, SEEK_SET)) < 0) {
fprintf(stderr, "%s: lseek: %s\n", name, strerror(errno));
exit(1);
}
count = write(file, data, len);
if (count != len) {
fprintf(stderr, "%s: write: %s.\n", name, strerror(errno));
exit(1);
}
}
void
usage()
{
(void)fprintf(stderr, "usage: strip [-dx] file ...\n");
(void) fprintf(stderr, "usage: strip [-dx] file ...\n");
exit(1);
}

24
usr.bin/env/env.1 vendored
View File

@ -1,4 +1,4 @@
.\" $NetBSD: env.1,v 1.5 1997/01/09 20:18:41 tls Exp $
.\" $NetBSD: env.1,v 1.6 1997/10/18 13:55:22 lukem Exp $
.\"
.\" Copyright (c) 1980, 1990 The Regents of the University of California.
.\" All rights reserved.
@ -34,7 +34,7 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)printenv.1 6.7 (Berkeley) 7/28/91
.\" $NetBSD: env.1,v 1.5 1997/01/09 20:18:41 tls Exp $
.\" $NetBSD: env.1,v 1.6 1997/10/18 13:55:22 lukem Exp $
.\"
.Dd August 27, 1993
.Dt ENV 1
@ -43,7 +43,7 @@
.Nm env
.Nd set and print environment
.Sh SYNOPSIS
.Nm env
.Nm
.Op Fl i
.Op Ar name=value ...
.Oo
@ -51,7 +51,7 @@
.Op argument ...
.Oc
.Sh DESCRIPTION
.Nm env
.Nm
executes
.Ar utility
after modifying the environment as
@ -65,14 +65,14 @@ with a value of
The option
.Sq Fl i
causes
.Nm env
.Nm
to completely ignore the environment
it inherits.
.Pp
If no
.Ar utility
is specified,
.Nm env
.Nm
prints out the names and values
of the variables in the environment, with one
.Ar name=value
@ -81,20 +81,20 @@ pair per line.
If the
.Ar utility
is invoked, the exit status of
.Nm env
.Nm
shall be the exit status of
.Ar utility;
otherwise, the
.Nm env
.Nm
utility exits with one of the following values:
.Bl -tag -width Ds
.It 0
The
.Nm env
.Nm
utility completed successfully
.It 1-125
An error occurred in the
.Nm env
.Nm
utility.
.It 126
The utility specified by
@ -114,11 +114,11 @@ option has been deprecated but is still supported in this implementation.
.Xr environ 7
.Sh STANDARDS
The
.Nm env
.Nm
utility conforms to
.St -p1003.2-92 .
.Sh BUGS
.Nm Env
.Nm
doesn't handle commands with equal
.Pq Dq =
signs in their

9
usr.bin/env/env.c vendored
View File

@ -31,15 +31,15 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1988, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#ifndef lint
/*static char sccsid[] = "@(#)env.c 8.3 (Berkeley) 4/2/94";*/
static char rcsid[] = "$NetBSD: env.c,v 1.9 1996/05/07 18:32:22 jtc Exp $";
__RCSID("$NetBSD: env.c,v 1.10 1997/10/18 13:55:28 lukem Exp $");
#endif /* not lint */
#include <err.h>
@ -50,6 +50,7 @@ static char rcsid[] = "$NetBSD: env.c,v 1.9 1996/05/07 18:32:22 jtc Exp $";
#include <locale.h>
#include <errno.h>
int main __P((int, char **));
static void usage __P((void));
int