From cb3e71747b5977c1fec2f120dba7a7eeaa026991 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Fri, 31 May 2019 17:32:08 +0200
Subject: [PATCH 2/6] Remove symorder(1). It's no longer useful.

---
 Makefile_upgrade.inc        |   2 +
 usr.bin/Makefile            |   1 -
 usr.bin/symorder/Makefile   |   6 -
 usr.bin/symorder/symorder.1 |  92 ----------
 usr.bin/symorder/symorder.c | 336 ------------------------------------
 5 files changed, 2 insertions(+), 435 deletions(-)
 delete mode 100644 usr.bin/symorder/Makefile
 delete mode 100644 usr.bin/symorder/symorder.1
 delete mode 100644 usr.bin/symorder/symorder.c

diff --git a/Makefile_upgrade.inc b/Makefile_upgrade.inc
index b0700ec390..6b2b3237b1 100644
--- a/Makefile_upgrade.inc
+++ b/Makefile_upgrade.inc
@@ -3654,6 +3654,8 @@ TO_REMOVE+=/usr/include/sys/fd_set.h
 TO_REMOVE+=/usr/include/net/netmap.h
 TO_REMOVE+=/usr/include/net/netmap_user.h
 TO_REMOVE+=/boot/kernel/radeonkms.ko
+TO_REMOVE+=/usr/bin/symorder
+TO_REMOVE+=/usr/share/man/man1/symorder.1.gz
 
 .if !defined(WANT_INSTALLER)
 TO_REMOVE+=/usr/sbin/dfuibe_installer
diff --git a/usr.bin/Makefile b/usr.bin/Makefile
index bd435325d2..777f223147 100644
--- a/usr.bin/Makefile
+++ b/usr.bin/Makefile
@@ -189,7 +189,6 @@ SUBDIR=	alias \
 	stat \
 	strfile \
 	su \
-	symorder \
 	systat \
 	tabs \
 	tail \
diff --git a/usr.bin/symorder/Makefile b/usr.bin/symorder/Makefile
deleted file mode 100644
index 2d0a0beb3f..0000000000
--- a/usr.bin/symorder/Makefile
+++ /dev/null
@@ -1,6 +0,0 @@
-#	@(#)Makefile	5.3 (Berkeley) 5/11/90
-
-PROG=	symorder
-WARNS?=	2
-
-.include <bsd.prog.mk>
diff --git a/usr.bin/symorder/symorder.1 b/usr.bin/symorder/symorder.1
deleted file mode 100644
index c17ffdfd0a..0000000000
--- a/usr.bin/symorder/symorder.1
+++ /dev/null
@@ -1,92 +0,0 @@
-.\" Copyright (c) 1980, 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.
-.\"
-.\"     @(#)symorder.1	6.5 (Berkeley) 4/22/91
-.\" $FreeBSD: src/usr.bin/symorder/symorder.1,v 1.9.2.3 2001/08/16 13:17:05 ru Exp $
-.\"
-.Dd September 2, 2008
-.Dt SYMORDER 1
-.Os
-.Sh NAME
-.Nm symorder
-.Nd rearrange name list
-.Sh SYNOPSIS
-.Nm
-.Op Fl c
-.Op Fl m
-.Op Fl t
-.Op Fl x Ar excludelist
-.Ar symlist file
-.Sh DESCRIPTION
-The file
-.Ar symlist
-contains a list of symbols to be found in
-.Ar file ,
-one symbol per line.
-.Pp
-The symbol table of
-.Ar file
-is updated in place;
-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 .
-.It Fl x Ar excludelist
-Exclude the symbols listed in
-.Ar excludelist
-from the symbol table.
-.It Fl m
-Exit with status zero, even if some symbols are missing.
-.El
-.Pp
-This program was specifically designed to cut down on the
-overhead of getting symbols from
-.Pa /boot/kernel .
-.Sh EXIT STATUS
-The
-.Nm
-utility exits 0 on success, 1 if a symbol
-listed in the
-.Ar symlist
-file was not found in the symbol
-table, and >1 if an error occurs.
-.Sh SEE ALSO
-.Xr nm 1 ,
-.Xr strip 1 ,
-.Xr nlist 3
-.Sh HISTORY
-The
-.Nm
-command appeared in
-.Bx 3.0 .
diff --git a/usr.bin/symorder/symorder.c b/usr.bin/symorder/symorder.c
deleted file mode 100644
index b9d0ee9f59..0000000000
--- a/usr.bin/symorder/symorder.c
+++ /dev/null
@@ -1,336 +0,0 @@
-/*
- * Copyright (c) 1980 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.
- *
- * @(#) Copyright (c) 1980 The Regents of the University of California. All rights reserved.
- * @(#)symorder.c	5.8 (Berkeley) 4/1/91
- * $FreeBSD: src/usr.bin/symorder/symorder.c,v 1.15 1999/08/28 01:05:57 peter Exp $
- */
-
-/*
- * symorder - reorder symbol table
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <a.out.h>
-#include <ctype.h>
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <netinet/in.h>
-
-#define SPACE		500
-
-#define	OKEXIT		0
-#define	NOTFOUNDEXIT	1
-#define	ERREXIT		2
-
-static char	*exclude[SPACE];
-static struct	nlist order[SPACE];
-
-static struct	exec exec;
-static struct	stat stb;
-static struct	nlist *newtab, *symtab;
-static off_t	sa;
-static int	nexclude, nsym, strtabsize, symfound, symkept, small, missing, clean;
-static char	*kfile, *newstrings, *strings, asym[BUFSIZ];
-
-static void badfmt(char *) __dead2;
-static int excluded(struct nlist *);
-static int inlist(struct nlist *);
-static void reorder(struct nlist *, struct nlist *, int);
-static int savesymb(struct nlist *);
-static void usage(void) __dead2;
-
-int
-main(int argc, char **argv)
-{
-	struct nlist *p, *symp;
-	FILE *f, *xfile;
-	int i;
-	char *start, *t, *xfilename;
-	int ch, n, o;
-
-	xfilename = NULL;
-	while ((ch = getopt(argc, argv, "cmtx:")) != -1)
-		switch(ch) {
-		case 'c':
-			clean = 1;
-			break;
-		case 'm':
-			missing = 1;
-			break;
-		case 't':
-			small = 1;
-			break;
-		case 'x':
-			if (xfilename != NULL)
-				usage();
-			xfilename = optarg;
-			break;
-		case '?':
-		default:
-			usage();
-		}
-	argc -= optind;
-	argv += optind;
-
-	if (argc != 2)
-		usage();
-
-	if ((f = fopen(argv[0], "r")) == NULL)
-		err(ERREXIT, "%s", argv[0]);
-
-	for (p = order; fgets(asym, sizeof(asym), f) != NULL;) {
-		for (t = asym; isspace(*t); ++t);
-		if (!*(start = t))
-			continue;
-		while (*++t);
-		if (*--t == '\n')
-			*t = '\0';
-		p->n_un.n_name = strdup(start);
-		++p;
-		if (++nsym >= sizeof order / sizeof order[0])
-			break;
-	}
-	(void)fclose(f);
-
-	if (xfilename != NULL) {
-		if ((xfile = fopen(xfilename, "r")) == NULL)
-			err(ERREXIT, "%s", xfilename);
-		for (; fgets(asym, sizeof(asym), xfile) != NULL;) {
-			for (t = asym; isspace(*t); ++t);
-			if (!*(start = t))
-				continue;
-			while (*++t);
-			if (*--t == '\n')
-				*t = '\0';
-			exclude[nexclude] = strdup(start);
-			if (++nexclude >= sizeof exclude / sizeof exclude[0])
-				break;
-		}
-		(void)fclose(xfile);
-	}
-
-	kfile = argv[1];
-	if ((f = fopen(kfile, "r")) == NULL)
-		err(ERREXIT, "%s", kfile);
-	if ((o = open(kfile, O_WRONLY)) < 0)
-		err(ERREXIT, "%s", kfile);
-
-	/* read exec header */
-	if ((fread(&exec, sizeof(exec), 1, f)) != 1)
-		badfmt("no exec header");
-	if (N_BADMAG(exec))
-		badfmt("bad magic number");
-	if (exec.a_syms == 0)
-		badfmt("stripped");
-	(void)fstat(fileno(f), &stb);
-	if (stb.st_size < N_STROFF(exec) + sizeof(off_t))
-		badfmt("no string table");
-
-	/* seek to and read the symbol table */
-	sa = N_SYMOFF(exec);
-	(void)fseek(f, sa, SEEK_SET);
-	n = exec.a_syms;
-	if (!(symtab = (struct nlist *)malloc(n)))
-		err(ERREXIT, NULL);
-	if (fread((void *)symtab, 1, n, f) != n)
-		badfmt("corrupted symbol table");
-
-	/* read string table size and string table */
-	if (fread((void *)&strtabsize, sizeof(int), 1, f) != 1 ||
-	    strtabsize <= 0)
-		badfmt("corrupted string table");
-	strings = malloc(strtabsize);
-	if (strings == NULL)
-		err(ERREXIT, NULL);
-	/*
-	 * Subtract four from strtabsize since strtabsize includes itself,
-	 * and we've already read it.
-	 */
-	if (fread(strings, 1, strtabsize - sizeof(int), f) !=
-	    strtabsize - sizeof(int))
-		badfmt("corrupted string table");
-
-	i = n / sizeof(struct nlist);
-	if (!clean) {
-		newtab = (struct nlist *)malloc(n);
-		if (newtab == NULL)
-			err(ERREXIT, NULL);
-		memset(newtab, 0, n);
-
-		reorder(symtab, newtab, i);
-		free((void *)symtab);
-		symtab = newtab;
-	} else {
-		symkept = i;
-	}
-
-	newstrings = malloc(strtabsize);
-	if (newstrings == NULL)
-		err(ERREXIT, NULL);
-	t = newstrings;
-	for (symp = symtab; --i >= 0; symp++) {
-		if (symp->n_un.n_strx == 0)
-			continue;
-		if (inlist(symp) < 0) {
-			if (small)
-				continue;
-			if (clean && !savesymb(symp))
-				symp->n_type &= ~N_EXT;
-		} else if (clean)
-			symfound++;
-		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);
-		t += strlen(t) + 1;
-	}
-
-	/* update shrunk sizes */
-	strtabsize = t - newstrings + sizeof(int);
-	n = symkept * sizeof(struct nlist);
-
-	/* fix exec sym size */
-	(void)lseek(o, (off_t)0, SEEK_SET);
-	exec.a_syms = n;
-	if (write(o, (void *)&exec, sizeof(exec)) != sizeof(exec))
-		err(ERREXIT, "%s", kfile);
-
-	(void)lseek(o, sa, SEEK_SET);
-	if (write(o, (void *)symtab, n) != n)
-		err(ERREXIT, "%s", kfile);
-	if (write(o, (void *)&strtabsize, sizeof(int)) != sizeof(int))
-		err(ERREXIT, "%s", kfile);
-	if (write(o, newstrings, strtabsize - sizeof(int)) !=
-	    strtabsize - sizeof(int))
-		err(ERREXIT, "%s", kfile);
-
-	ftruncate(o, lseek(o, (off_t)0, SEEK_CUR));
-
-	if ((i = nsym - symfound) > 0) {
-		(void)printf("symorder: %d symbol%s not found:\n",
-		    i, i == 1 ? "" : "s");
-		for (i = 0; i < nsym; i++)
-			if (order[i].n_value == 0)
-				printf("%s\n", order[i].n_un.n_name);
-		if (!missing)
-			exit(NOTFOUNDEXIT);
-	}
-	exit(OKEXIT);
-}
-
-static int
-savesymb(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;
-	}
-}
-
-static void
-reorder(struct nlist *st1, struct nlist *st2, int entries)
-{
-	struct nlist *p;
-	int i, n;
-
-	for (p = st1, n = entries; --n >= 0; ++p)
-		if (inlist(p) != -1)
-			++symfound;
-	for (p = st2 + symfound, n = entries; --n >= 0; ++st1) {
-		if (excluded(st1))
-			continue;
-		i = inlist(st1);
-		if (i == -1)
-			*p++ = *st1;
-		else
-			st2[i] = *st1;
-		++symkept;
-	}
-}
-
-static int
-inlist(struct nlist *p)
-{
-	char *nam;
-	struct nlist *op;
-
-	if (p->n_type & N_STAB || p->n_un.n_strx == 0)
-		return (-1);
-	if (p->n_un.n_strx < sizeof(int) || p->n_un.n_strx >= strtabsize)
-		badfmt("corrupted symbol table");
-	nam = &strings[p->n_un.n_strx - sizeof(int)];
-	for (op = &order[nsym]; --op >= order; ) {
-		if (strcmp(op->n_un.n_name, nam) != 0)
-			continue;
-		op->n_value = 1;
-		return (op - order);
-	}
-	return (-1);
-}
-
-static int
-excluded(struct nlist *p)
-{
-	char *nam;
-	int x;
-
-	if (p->n_type & N_STAB || p->n_un.n_strx == 0)
-		return (0);
-	if (p->n_un.n_strx < sizeof(int) || p->n_un.n_strx >= strtabsize)
-		badfmt("corrupted symbol table");
-	nam = &strings[p->n_un.n_strx - sizeof(int)];
-	for (x = nexclude; --x >= 0; )
-		if (strcmp(nam, exclude[x]) == 0)
-			return (1);
-	return (0);
-}
-
-static void
-badfmt(char *why)
-{
-	errx(ERREXIT, "%s: %s: %s", kfile, why, strerror(EFTYPE));
-}
-
-static void
-usage(void)
-{
-	(void)fprintf(stderr,
-	    "usage: symorder [-c] [-m] [-t] [-x excludelist] symlist file\n");
-	exit(ERREXIT);
-}
-- 
2.21.0

