Add a '-c' option for cleaning namelists of various things.

This commit is contained in:
phk 1995-10-15 14:31:10 +00:00
parent ad11483a50
commit 1852092e18
2 changed files with 30 additions and 4 deletions

View File

@ -39,6 +39,7 @@
.Nd rearrange name list
.Sh SYNOPSIS
.Nm symorder
.Fl c
.Fl m
.Fl t
.Fl x
@ -58,6 +59,10 @@ symbols read from
.Ar symlist
are relocated to the beginning of the table and in the order given.
.Bl -tag -width flag
.It Fl c
Makes all any symbols not in
.Ar symlist
local to this file.
.It Fl t
Restrict the symbol table to the symbols listed in
.Ar symlist .

View File

@ -68,7 +68,7 @@ struct exec exec;
struct stat stb;
struct nlist *newtab, *symtab;
off_t sa;
int nexclude, nsym, strtabsize, symfound, symkept, small, missing;
int nexclude, nsym, strtabsize, symfound, symkept, small, missing, clean;
char *kfile, *newstrings, *strings, asym[BUFSIZ];
main(argc, argv)
@ -84,8 +84,11 @@ main(argc, argv)
int ch, n, o;
xfilename = NULL;
while ((ch = getopt(argc, argv, "mtx:")) != EOF)
while ((ch = getopt(argc, argv, "cmtx:")) != EOF)
switch(ch) {
case 'c':
clean = 1;
break;
case 'm':
missing = 1;
break;
@ -199,8 +202,12 @@ main(argc, argv)
for (symp = symtab; --i >= 0; symp++) {
if (symp->n_un.n_strx == 0)
continue;
if (small && inlist(symp) < 0)
continue;
if (inlist(symp) < 0) {
if (small)
continue;
if (clean && !savesymb(symp))
symp->n_type &= ~N_EXT;
}
symp->n_un.n_strx -= sizeof(int);
(void)strcpy(t, &strings[symp->n_un.n_strx]);
symp->n_un.n_strx = (t - newstrings) + sizeof(int);
@ -240,6 +247,20 @@ main(argc, argv)
exit(OKEXIT);
}
savesymb(s)
register struct nlist *s;
{
if ((s->n_type & N_EXT) != N_EXT)
return 0;
switch (s->n_type & N_TYPE) {
case N_TEXT:
case N_DATA:
return 0;
default:
return 1;
}
}
reorder(st1, st2, entries)
register struct nlist *st1, *st2;
int entries;