aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/brandelf
diff options
context:
space:
mode:
authorDavid E. O'Brien <obrien@FreeBSD.org>2000-04-18 02:39:26 +0000
committerDavid E. O'Brien <obrien@FreeBSD.org>2000-04-18 02:39:26 +0000
commitc815a20cb23f53317c4d23d1884cd5e486dee876 (patch)
treef76576487158a5c7e15c4d35440dc09db280a7da /usr.bin/brandelf
parent8d396be510de9306b0efd32352a69860d7d195fc (diff)
downloadsrc-c815a20cb23f53317c4d23d1884cd5e486dee876.tar.gz
src-c815a20cb23f53317c4d23d1884cd5e486dee876.zip
Notes
Diffstat (limited to 'usr.bin/brandelf')
-rw-r--r--usr.bin/brandelf/Makefile4
-rw-r--r--usr.bin/brandelf/brandelf.122
-rw-r--r--usr.bin/brandelf/brandelf.c94
3 files changed, 79 insertions, 41 deletions
diff --git a/usr.bin/brandelf/Makefile b/usr.bin/brandelf/Makefile
index 81d0039e47df..87679131e8f2 100644
--- a/usr.bin/brandelf/Makefile
+++ b/usr.bin/brandelf/Makefile
@@ -1,4 +1,6 @@
+# $FreeBSD$
+
PROG= brandelf
-CFLAGS+=-Wall
+CFLAGS+= -Wall
.include <bsd.prog.mk>
diff --git a/usr.bin/brandelf/brandelf.1 b/usr.bin/brandelf/brandelf.1
index c7d69b378ab9..713b49124bd3 100644
--- a/usr.bin/brandelf/brandelf.1
+++ b/usr.bin/brandelf/brandelf.1
@@ -35,7 +35,7 @@
.Nd mark an ELF binary for a specific ABI
.Sh SYNOPSIS
.Nm brandelf
-.Op Fl f
+.Op Fl f Ar ELF ABI number
.Op Fl l
.Op Fl v
.Op Fl t Ar string
@@ -46,17 +46,18 @@ This command marks an ELF binary to be run under a certain ABI for
.Pp
The options are as follows:
.Bl -tag -width Fl
-.It Fl f
-forces branding even if the brand requested is unknown, and disables
-warnings for unknown brands.
+.It Fl f Ar ELF ABI number
+forces branding with the supplied ELF ABI number. In compatable with the
+.It Fl t
+option. These values are assigned by SCO/USL.
.It Fl l
lists all known ELF types on the standard error channel.
.It Fl v
turns on verbose reporting
.It Fl t Ar string
-Brands the given ELF binaries with
+Brands the given ELF binaries to be of the
.Ar string
-as the ABI type. Currently supported ABI's are
+ABI type. Currently supported ABI's are
.Dq Tn FreeBSD
and
.Dq Linux .
@@ -65,7 +66,7 @@ If
.Fl t Ar string
is given it will brand
.Ar file
-with
+to be of type
.Ar string ,
otherwise it will simply display the branding of
.Ar file .
@@ -84,6 +85,13 @@ fails if a file doesn't exist, is too short, fails to brand properly,
or the brand requested is not one of the known types and the
.Fl f
option is not set.
+.Sh SEE ALSO
+.Rs
+.%A The Scanta Cruz Operation, Inc.
+.%T System V Application Binary Interface
+.%D April 29, 1998 (DRAFT)
+.%O http://www.sco.com/developer/devspecs/
+.Re
.Sh HISTORY
The
.Nm
diff --git a/usr.bin/brandelf/brandelf.c b/usr.bin/brandelf/brandelf.c
index 65b473df5ebc..7993bf9fb67d 100644
--- a/usr.bin/brandelf/brandelf.c
+++ b/usr.bin/brandelf/brandelf.c
@@ -34,24 +34,46 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/errno.h>
#include <err.h>
-static int iselftype(const char *);
+static int elftype(const char *);
+static const char *iselftype(int);
static void printelftypes(void);
static void usage __P((void));
+struct ELFtypes {
+ const char *str;
+ int value;
+};
+/* XXX - any more types? */
+static struct ELFtypes elftypes[] = {
+ { "FreeBSD", ELFOSABI_FREEBSD },
+ { "SVR4", ELFOSABI_SYSV },
+ { "Linux", ELFOSABI_LINUX }
+};
+
int
main(int argc, char **argv)
{
- const char *type = "FreeBSD";
+ const char *strtype = "FreeBSD";
+ int type = ELFOSABI_FREEBSD;
int retval = 0;
int ch, change = 0, verbose = 0, force = 0, listed = 0;
- while ((ch = getopt(argc, argv, "flt:v")) != -1)
+ while ((ch = getopt(argc, argv, "f:lt:v")) != -1)
switch (ch) {
case 'f':
+ if (change)
+ errx(1, "f option incompatable with t option");
force = 1;
+ type = atoi(optarg);
+ if (errno == ERANGE || type < 0 || type > 255) {
+ warnx("invalid argument to option f: %s",
+ optarg);
+ usage();
+ }
break;
case 'l':
printelftypes();
@@ -61,8 +83,10 @@ main(int argc, char **argv)
verbose = 1;
break;
case 't':
+ if (force)
+ errx(1, "t option incompatable with f option");
change = 1;
- type = optarg;
+ strtype = optarg;
break;
default:
usage();
@@ -78,8 +102,8 @@ main(int argc, char **argv)
}
}
- if (!force && !iselftype(type)) {
- warnx("invalid ELF type '%s'", type);
+ if (!force && (type = elftype(strtype)) == -1) {
+ warnx("invalid ELF type '%s'", strtype);
printelftypes();
usage();
}
@@ -87,9 +111,8 @@ main(int argc, char **argv)
while (argc) {
int fd;
char buffer[EI_NIDENT];
- char string[(EI_NIDENT-EI_BRAND)+1];
- if ((fd = open(argv[0], change? O_RDWR: O_RDONLY, 0)) < 0) {
+ if ((fd = open(argv[0], change || force ? O_RDWR : O_RDONLY, 0)) < 0) {
warn("error opening file %s", argv[0]);
retval = 1;
goto fail;
@@ -105,28 +128,22 @@ main(int argc, char **argv)
retval = 1;
goto fail;
}
- if (!change) {
- bzero(string, sizeof(string));
- strncpy(string, &buffer[EI_BRAND], EI_NIDENT-EI_BRAND);
- if (strlen(string)) {
- fprintf(stdout,
- "File '%s' is of brand '%s'.\n",
- argv[0], string);
- if (!force && !iselftype(string)) {
- warnx("Brand '%s' is unknown",
- string);
- printelftypes();
- }
+ if (!change && !force) {
+ fprintf(stdout,
+ "File '%s' is of brand '%s' (%u).\n",
+ argv[0], iselftype(buffer[EI_OSABI]),
+ buffer[EI_OSABI]);
+ if (!iselftype(type)) {
+ warnx("ELF ABI Brand '%u' is unknown",
+ type);
+ printelftypes();
}
- else
- fprintf(stdout, "File '%s' has no branding.\n",
- argv[0]);
}
else {
- strncpy(&buffer[EI_BRAND], type, EI_NIDENT-EI_BRAND);
+ buffer[EI_OSABI] = type;
lseek(fd, 0, SEEK_SET);
if (write(fd, buffer, EI_NIDENT) != EI_NIDENT) {
- warnx("error writing %s", argv[0]);
+ warn("error writing %s %d", argv[0], fd);
retval = 1;
goto fail;
}
@@ -142,24 +159,34 @@ fail:
static void
usage()
{
- fprintf(stderr, "usage: brandelf [-f] [-v] [-l] [-t string] file ...\n");
+fprintf(stderr, "usage: brandelf [-f ELF ABI number] [-v] [-l] [-t string] file ...\n");
exit(1);
}
-/* XXX - any more types? */
-static const char *elftypes[] = { "FreeBSD", "Linux", "SVR4" };
+static const char *
+iselftype(int elftype)
+{
+ int elfwalk;
+
+ for (elfwalk = 0;
+ elfwalk < sizeof(elftypes)/sizeof(elftypes[0]);
+ elfwalk++)
+ if (elftype == elftypes[elfwalk].value)
+ return elftypes[elfwalk].str;
+ return 0;
+}
static int
-iselftype(const char *elftype)
+elftype(const char *elfstrtype)
{
int elfwalk;
for (elfwalk = 0;
elfwalk < sizeof(elftypes)/sizeof(elftypes[0]);
elfwalk++)
- if (strcmp(elftype, elftypes[elfwalk]) == 0)
- return 1;
- return 0;
+ if (strcmp(elfstrtype, elftypes[elfwalk].str) == 0)
+ return elftypes[elfwalk].value;
+ return -1;
}
static void
@@ -171,6 +198,7 @@ printelftypes()
for (elfwalk = 0;
elfwalk < sizeof(elftypes)/sizeof(elftypes[0]);
elfwalk++)
- fprintf(stderr, "%s ", elftypes[elfwalk]);
+ fprintf(stderr, "%s(%u) ", elftypes[elfwalk].str,
+ elftypes[elfwalk].value);
fprintf(stderr, "\n");
}