Index: stable/4/usr.bin/brandelf/brandelf.1 =================================================================== --- stable/4/usr.bin/brandelf/brandelf.1 (revision 62761) +++ stable/4/usr.bin/brandelf/brandelf.1 (revision 62762) @@ -1,94 +1,105 @@ .\" Copyright (c) 1997 .\" John-Mark Gurney. 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 author nor the names of any co-contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY John-Mark Gurney 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 AUTHOR 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. .\" .\" $FreeBSD$ .\" .Dd February 6, 1997 .Dt BRANDELF 1 .Os FreeBSD .Sh NAME .Nm brandelf .Nd mark an ELF binary for a specific ABI .Sh SYNOPSIS -.Nm brandelf -.Op Fl f -.Op Fl l -.Op Fl v +.Nm +.Op Fl lv +.Op Fl f Ar ELF_ABI_number .Op Fl t Ar string -.Ar file ... +.Ar .Sh DESCRIPTION This command marks an ELF binary to be run under a certain ABI for .Tn FreeBSD . .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. +Incompatible with the +.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 +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 -.Dq Tn FreeBSD +ABI type. +Currently supported ABIs are +.Dq Tn FreeBSD , +.Dq Tn Linux , and -.Dq Linux . +.Dq Tn SVR4 . .It Ar file 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 +otherwise it will simply display the branding of .Ar file . .El .Sh EXAMPLES The following is an example of a typical usage of the .Nm command: .Pp .Dl % brandelf file .Dl % brandelf -t Linux file .Sh DIAGNOSTICS Exit status is 0 on success, and 1 if the command -fails if a file doesn't exist, is too short, fails to brand properly, +fails if a file does not 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 Santa 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 manual page first appeared in .Fx 2.2 . .Sh AUTHORS This manual page was written by .An John-Mark Gurney Aq gurney_j@efn.org . Index: stable/4/usr.bin/brandelf/brandelf.c =================================================================== --- stable/4/usr.bin/brandelf/brandelf.c (revision 62761) +++ stable/4/usr.bin/brandelf/brandelf.c (revision 62762) @@ -1,176 +1,206 @@ /*- * Copyright (c) 1996 Søren Schmidt * 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 * in this position and unchanged. * 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. The name of the author may not be used to endorse or promote products * derived from this software withough specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. * * $FreeBSD$ */ #include #include #include #include #include #include +#include #include -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 }, + { "Linux", ELFOSABI_LINUX }, + { "Solaris", ELFOSABI_SOLARIS }, + { "SVR4", ELFOSABI_SYSV } +}; + 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(); listed = 1; break; case 'v': verbose = 1; break; case 't': + if (force) + errx(1, "t option incompatable with f option"); change = 1; - type = optarg; + strtype = optarg; break; default: usage(); } argc -= optind; argv += optind; if (!argc) { if (listed) exit(0); else { warnx("no file(s) specified"); usage(); } } - if (!force && !iselftype(type)) { - warnx("invalid ELF type '%s'", type); + if (!force && (type = elftype(strtype)) == -1) { + warnx("invalid ELF type '%s'", strtype); printelftypes(); usage(); } 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; } if (read(fd, buffer, EI_NIDENT) < EI_NIDENT) { warnx("file '%s' too short", argv[0]); retval = 1; goto fail; } if (buffer[0] != ELFMAG0 || buffer[1] != ELFMAG1 || buffer[2] != ELFMAG2 || buffer[3] != ELFMAG3) { warnx("file '%s' is not ELF format", argv[0]); 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; } } fail: + close(fd); argc--; argv++; } return retval; } 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 printelftypes() { int elfwalk; fprintf(stderr, "known ELF types are: "); 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"); }