summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--contrib/binutils/bfd/elf.c29
-rw-r--r--lib/csu/amd64/crti.S14
-rw-r--r--lib/csu/i386-elf/crti.S14
-rw-r--r--sys/alpha/linux/linux_sysvec.c4
-rw-r--r--sys/compat/svr4/svr4_sysvec.c10
-rw-r--r--sys/i386/linux/linux_sysvec.c4
-rw-r--r--sys/kern/imgact_elf.c55
-rw-r--r--sys/svr4/svr4_sysvec.c10
-rw-r--r--sys/sys/elf_common.h24
-rw-r--r--sys/sys/imgact_elf.h6
-rw-r--r--usr.bin/brandelf/Makefile4
-rw-r--r--usr.bin/brandelf/brandelf.122
-rw-r--r--usr.bin/brandelf/brandelf.c94
-rw-r--r--usr.bin/gcore/elfcore.c4
14 files changed, 189 insertions, 105 deletions
diff --git a/contrib/binutils/bfd/elf.c b/contrib/binutils/bfd/elf.c
index 90c27d5..44d1e91 100644
--- a/contrib/binutils/bfd/elf.c
+++ b/contrib/binutils/bfd/elf.c
@@ -40,13 +40,6 @@ SECTION
#define ARCH_SIZE 0
#include "elf-bfd.h"
-#define EI_BRAND_OFFSET 8 /* should be in binutils/include/elf/common.h */
-#if defined(__FreeBSD__)
-#define BRANDING "FreeBSD"
-#else
-#define BRANDING ""
-#endif
-
static INLINE struct elf_segment_map *make_mapping
PARAMS ((bfd *, asection **, unsigned int, unsigned int, boolean));
static boolean map_sections_to_segments PARAMS ((bfd *));
@@ -2932,9 +2925,24 @@ prep_headers (abfd)
bfd_big_endian (abfd) ? ELFDATA2MSB : ELFDATA2LSB;
i_ehdrp->e_ident[EI_VERSION] = bed->s->ev_current;
+#ifdef __FreeBSD__
+ /* Quick and dirty hack to brand the file as a FreeBSD ELF file. */
+ i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
+ i_ehdrp->e_ident[EI_ABIVERSION] = 0;
+#endif
+
for (count = EI_PAD; count < EI_NIDENT; count++)
i_ehdrp->e_ident[count] = 0;
+#ifdef __FreeBSD__
+/* #ifdef BRANDELF_CHANGE_BOOTSTRAP */
+#define _OLD_EI_BRAND_OFFSET 8
+#define _OLD_BRANDING "FreeBSD"
+ strncpy((char *) &i_ehdrp->e_ident[_OLD_EI_BRAND_OFFSET], _OLD_BRANDING,
+ EI_NIDENT-_OLD_EI_BRAND_OFFSET);
+/* #endif */
+#endif
+
if ((abfd->flags & DYNAMIC) != 0)
i_ehdrp->e_type = ET_DYN;
else if ((abfd->flags & EXEC_P) != 0)
@@ -2949,7 +2957,7 @@ prep_headers (abfd)
break;
case bfd_arch_sparc:
if (bed->s->arch_size == 64)
- i_ehdrp->e_machine = EM_SPARC64;
+ i_ehdrp->e_machine = EM_SPARCV9;
else
i_ehdrp->e_machine = EM_SPARC;
break;
@@ -3009,11 +3017,6 @@ prep_headers (abfd)
i_ehdrp->e_version = bed->s->ev_current;
i_ehdrp->e_ehsize = bed->s->sizeof_ehdr;
- /* Some OS's brands all ELF binaries so the image loader knows what system
- call set, etc. to use. */
- strncpy((char *) &i_ehdrp->e_ident[EI_BRAND_OFFSET], BRANDING,
- EI_NIDENT-EI_BRAND_OFFSET);
-
/* no program header, for now. */
i_ehdrp->e_phoff = 0;
i_ehdrp->e_phentsize = 0;
diff --git a/lib/csu/amd64/crti.S b/lib/csu/amd64/crti.S
index 0038497..a4df32e 100644
--- a/lib/csu/amd64/crti.S
+++ b/lib/csu/amd64/crti.S
@@ -25,6 +25,20 @@
* $FreeBSD$
*/
+ /* See http://www.netbsd.org/Documentation/kernel/elf-notes.html for
+ details on the ELF .note section as we are using it. */
+ .section .note.ABI-tag, "a"
+ .align 4
+ .long 1f - 0f # name length
+ .long 3f - 2f # data length
+ .long 1 # note type
+0: .asciz "FreeBSD" # vendor name
+1: .align 4
+2: .long 500000 # data - ABI tag
+ # (from __FreeBSD_version (param.h))
+3: .align 4 # pad out section
+
+
.section .init,"ax",@progbits
.align 4
.globl _init
diff --git a/lib/csu/i386-elf/crti.S b/lib/csu/i386-elf/crti.S
index 0038497..a4df32e 100644
--- a/lib/csu/i386-elf/crti.S
+++ b/lib/csu/i386-elf/crti.S
@@ -25,6 +25,20 @@
* $FreeBSD$
*/
+ /* See http://www.netbsd.org/Documentation/kernel/elf-notes.html for
+ details on the ELF .note section as we are using it. */
+ .section .note.ABI-tag, "a"
+ .align 4
+ .long 1f - 0f # name length
+ .long 3f - 2f # data length
+ .long 1 # note type
+0: .asciz "FreeBSD" # vendor name
+1: .align 4
+2: .long 500000 # data - ABI tag
+ # (from __FreeBSD_version (param.h))
+3: .align 4 # pad out section
+
+
.section .init,"ax",@progbits
.align 4
.globl _init
diff --git a/sys/alpha/linux/linux_sysvec.c b/sys/alpha/linux/linux_sysvec.c
index 39f3000..a92cd8ad 100644
--- a/sys/alpha/linux/linux_sysvec.c
+++ b/sys/alpha/linux/linux_sysvec.c
@@ -439,14 +439,14 @@ struct sysentvec elf_linux_sysvec = {
};
static Elf32_Brandinfo linux_brand = {
- "Linux",
+ ELFOSABI_LINUX,
"/compat/linux",
"/lib/ld-linux.so.1",
&elf_linux_sysvec
};
static Elf32_Brandinfo linux_glibc2brand = {
- "Linux",
+ ELFOSABI_LINUX,
"/compat/linux",
"/lib/ld-linux.so.2",
&elf_linux_sysvec
diff --git a/sys/compat/svr4/svr4_sysvec.c b/sys/compat/svr4/svr4_sysvec.c
index b470157..c66e61b 100644
--- a/sys/compat/svr4/svr4_sysvec.c
+++ b/sys/compat/svr4/svr4_sysvec.c
@@ -155,7 +155,7 @@ int bsd_to_svr4_errno[ELAST+1] = {
};
-static int svr4_fixup(long **stack_base, struct image_params *imgp);
+static int svr4_fixup(register_t **stack_base, struct image_params *imgp);
extern struct sysent svr4_sysent[];
#undef szsigcode
@@ -183,8 +183,8 @@ struct sysentvec svr4_sysvec = {
};
Elf32_Brandinfo svr4_brand = {
- "SVR4",
- "/compat/svr4",
+ ELFOSABI_SOLARIS, /* XXX Or should we use ELFOSABI_SYSV here? */
+ svr4_emul_path,
"/lib/libc.so.1",
&svr4_sysvec
};
@@ -192,10 +192,10 @@ Elf32_Brandinfo svr4_brand = {
const char svr4_emul_path[] = "/compat/svr4";
static int
-svr4_fixup(long **stack_base, struct image_params *imgp)
+svr4_fixup(register_t **stack_base, struct image_params *imgp)
{
Elf32_Auxargs *args = (Elf32_Auxargs *)imgp->auxargs;
- long *pos;
+ register_t *pos;
pos = *stack_base + (imgp->argc + imgp->envc + 2);
diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c
index 39f3000..a92cd8ad 100644
--- a/sys/i386/linux/linux_sysvec.c
+++ b/sys/i386/linux/linux_sysvec.c
@@ -439,14 +439,14 @@ struct sysentvec elf_linux_sysvec = {
};
static Elf32_Brandinfo linux_brand = {
- "Linux",
+ ELFOSABI_LINUX,
"/compat/linux",
"/lib/ld-linux.so.1",
&elf_linux_sysvec
};
static Elf32_Brandinfo linux_glibc2brand = {
- "Linux",
+ ELFOSABI_LINUX,
"/compat/linux",
"/lib/ld-linux.so.2",
&elf_linux_sysvec
diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index 6a0e0ef..8fe3362 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -65,6 +65,8 @@
#include <machine/elf.h>
#include <machine/md_var.h>
+#define OLD_EI_BRAND 8
+
__ElfType(Brandinfo);
__ElfType(Auxargs);
@@ -82,12 +84,6 @@ static int exec_elf_imgact __P((struct image_params *imgp));
static int elf_trace = 0;
SYSCTL_INT(_debug, OID_AUTO, elf_trace, CTLFLAG_RW, &elf_trace, 0, "");
-/*
- * XXX Maximum length of an ELF brand (sysctl wants a statically-allocated
- * buffer).
- */
-#define MAXBRANDLEN 16
-
static struct sysentvec elf_freebsd_sysvec = {
SYS_MAXSYSCALL,
sysent,
@@ -107,7 +103,7 @@ static struct sysentvec elf_freebsd_sysvec = {
};
static Elf_Brandinfo freebsd_brand_info = {
- "FreeBSD",
+ ELFOSABI_FREEBSD,
"",
"/usr/libexec/ld-elf.so.1",
&elf_freebsd_sysvec
@@ -412,9 +408,9 @@ fail:
return error;
}
-static char fallback_elf_brand[MAXBRANDLEN+1] = { "none" };
-SYSCTL_STRING(_kern, OID_AUTO, fallback_elf_brand, CTLFLAG_RW,
- fallback_elf_brand, sizeof(fallback_elf_brand),
+static int fallback_elf_brand = ELFOSABI_FREEBSD;
+SYSCTL_INT(_kern, OID_AUTO, fallback_elf_brand, CTLFLAG_RW,
+ &fallback_elf_brand, ELFOSABI_FREEBSD,
"ELF brand of last resort");
static int
@@ -431,7 +427,6 @@ exec_elf_imgact(struct image_params *imgp)
int error, i;
const char *interp = NULL;
Elf_Brandinfo *brand_info;
- const char *brand;
char path[MAXPATHLEN];
/*
@@ -526,14 +521,23 @@ exec_elf_imgact(struct image_params *imgp)
imgp->entry_addr = entry;
- /* If the executable has a brand, search for it in the brand list. */
brand_info = NULL;
- brand = (const char *)&hdr->e_ident[EI_BRAND];
- if (brand[0] != '\0') {
+
+ /* XXX For now we look for the magic "FreeBSD" that we used to put
+ * into the ELF header at the EI_ABIVERSION location. If found use
+ * that information rather than figuring out the ABI from proper
+ * branding. This should be removed for 5.0-RELEASE. The Linux caes
+ * can be figured out from the `interp_path' field.
+ */
+ if (strcmp("FreeBSD", (const char *)&hdr->e_ident[OLD_EI_BRAND]) == 0)
+ brand_info = &freebsd_brand_info;
+
+ /* If the executable has a brand, search for it in the brand list. */
+ if (brand_info == NULL) {
for (i = 0; i < MAX_BRANDS; i++) {
Elf_Brandinfo *bi = elf_brand_list[i];
- if (bi != NULL && strcmp(brand, bi->brand) == 0) {
+ if (bi != NULL && hdr->e_ident[EI_OSABI] == bi->brand) {
brand_info = bi;
break;
}
@@ -554,31 +558,24 @@ exec_elf_imgact(struct image_params *imgp)
}
/* Lacking a recognized interpreter, try the default brand */
- if (brand_info == NULL && fallback_elf_brand[0] != '\0') {
+ if (brand_info == NULL) {
for (i = 0; i < MAX_BRANDS; i++) {
Elf_Brandinfo *bi = elf_brand_list[i];
- if (bi != NULL
- && strcmp(fallback_elf_brand, bi->brand) == 0) {
+ if (bi != NULL && fallback_elf_brand == bi->brand) {
brand_info = bi;
break;
}
}
}
-#ifdef __alpha__
- /* XXX - Assume FreeBSD on the alpha. */
+ /* XXX - Assume FreeBSD after the branding method change. */
if (brand_info == NULL)
brand_info = &freebsd_brand_info;
-#endif
if (brand_info == NULL) {
- if (brand[0] == 0)
- uprintf("ELF binary type not known."
- " Use \"brandelf\" to brand it.\n");
- else
- uprintf("ELF binary type \"%.*s\" not known.\n",
- EI_NIDENT - EI_BRAND, brand);
+ uprintf("ELF binary type \"%u\" not known.\n",
+ hdr->e_ident[EI_OSABI]);
error = ENOEXEC;
goto fail;
}
@@ -932,9 +929,9 @@ elf_puthdr(struct proc *p, void *dst, size_t *off, const prstatus_t *status,
ehdr->e_ident[EI_CLASS] = ELF_CLASS;
ehdr->e_ident[EI_DATA] = ELF_DATA;
ehdr->e_ident[EI_VERSION] = EV_CURRENT;
+ ehdr->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
+ ehdr->e_ident[EI_ABIVERSION] = 0;
ehdr->e_ident[EI_PAD] = 0;
- strncpy(ehdr->e_ident + EI_BRAND, "FreeBSD",
- EI_NIDENT - EI_BRAND);
ehdr->e_type = ET_CORE;
ehdr->e_machine = ELF_ARCH;
ehdr->e_version = EV_CURRENT;
diff --git a/sys/svr4/svr4_sysvec.c b/sys/svr4/svr4_sysvec.c
index b470157..c66e61b 100644
--- a/sys/svr4/svr4_sysvec.c
+++ b/sys/svr4/svr4_sysvec.c
@@ -155,7 +155,7 @@ int bsd_to_svr4_errno[ELAST+1] = {
};
-static int svr4_fixup(long **stack_base, struct image_params *imgp);
+static int svr4_fixup(register_t **stack_base, struct image_params *imgp);
extern struct sysent svr4_sysent[];
#undef szsigcode
@@ -183,8 +183,8 @@ struct sysentvec svr4_sysvec = {
};
Elf32_Brandinfo svr4_brand = {
- "SVR4",
- "/compat/svr4",
+ ELFOSABI_SOLARIS, /* XXX Or should we use ELFOSABI_SYSV here? */
+ svr4_emul_path,
"/lib/libc.so.1",
&svr4_sysvec
};
@@ -192,10 +192,10 @@ Elf32_Brandinfo svr4_brand = {
const char svr4_emul_path[] = "/compat/svr4";
static int
-svr4_fixup(long **stack_base, struct image_params *imgp)
+svr4_fixup(register_t **stack_base, struct image_params *imgp)
{
Elf32_Auxargs *args = (Elf32_Auxargs *)imgp->auxargs;
- long *pos;
+ register_t *pos;
pos = *stack_base + (imgp->argc + imgp->envc + 2);
diff --git a/sys/sys/elf_common.h b/sys/sys/elf_common.h
index 207050d..f63f384 100644
--- a/sys/sys/elf_common.h
+++ b/sys/sys/elf_common.h
@@ -48,7 +48,8 @@ typedef struct {
u_int32_t n_type; /* Type of this note. */
} Elf_Note;
-/* Indexes into the e_ident array. */
+/* Indexes into the e_ident array. Keep synced with
+ http://www.sco.com/developer/gabi/ch4.eheader.html */
#define EI_MAG0 0 /* Magic number, byte 0. */
#define EI_MAG1 1 /* Magic number, byte 1. */
#define EI_MAG2 2 /* Magic number, byte 2. */
@@ -56,8 +57,10 @@ typedef struct {
#define EI_CLASS 4 /* Class of machine. */
#define EI_DATA 5 /* Data format. */
#define EI_VERSION 6 /* ELF format version. */
-#define EI_PAD 7 /* Start of padding (per SVR4 ABI). */
-#define EI_BRAND 8 /* Start of architecture identification. */
+#define EI_OSABI 7 /* Operating system / ABI identification */
+#define EI_ABIVERSION 8 /* ABI version */
+#define OLD_EI_BRAND 8 /* Start of architecture identification. */
+#define EI_PAD 9 /* Start of padding (per SVR4 ABI). */
#define EI_NIDENT 16 /* Size of e_ident array. */
/* Values for the magic number bytes. */
@@ -80,6 +83,21 @@ typedef struct {
#define ELFDATA2LSB 1 /* 2's complement little-endian. */
#define ELFDATA2MSB 2 /* 2's complement big-endian. */
+/* Values for e_ident[EI_OSABI]. */
+#define ELFOSABI_SYSV 0 /* UNIX System V ABI */
+#define ELFOSABI_HPUX 1 /* HP-UX operating system */
+#define ELFOSABI_NETBSD 2 /* NetBSD */
+#define ELFOSABI_LINUX 3 /* GNU/Linux */
+#define ELFOSABI_HURD 4 /* GNU/Hurd */
+#define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */
+#define ELFOSABI_SOLARIS 6 /* Solaris */
+#define ELFOSABI_MONTEREY 7 /* Monterey */
+#define ELFOSABI_IRIX 8 /* IRIX */
+#define ELFOSABI_FREEBSD 9 /* FreeBSD */
+#define ELFOSABI_TRU64 10 /* TRU64 UNIX */
+#define ELFOSABI_ARM 97 /* ARM */
+#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
+
/* e_ident */
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
(ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
diff --git a/sys/sys/imgact_elf.h b/sys/sys/imgact_elf.h
index 065d5b5..b781552 100644
--- a/sys/sys/imgact_elf.h
+++ b/sys/sys/imgact_elf.h
@@ -56,9 +56,9 @@ typedef struct {
} Elf32_Auxargs;
typedef struct {
- char *brand;
- char *emul_path;
- char *interp_path;
+ int brand;
+ const char *emul_path;
+ const char *interp_path;
struct sysentvec *sysvec;
} Elf32_Brandinfo;
diff --git a/usr.bin/brandelf/Makefile b/usr.bin/brandelf/Makefile
index 81d0039..8767913 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 c7d69b3..713b491 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 65b473d..7993bf9 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");
}
diff --git a/usr.bin/gcore/elfcore.c b/usr.bin/gcore/elfcore.c
index c05dad6..775fd3b 100644
--- a/usr.bin/gcore/elfcore.c
+++ b/usr.bin/gcore/elfcore.c
@@ -287,9 +287,9 @@ elf_puthdr(vm_map_entry_t map, void *dst, size_t *off, const prstatus_t *status,
ehdr->e_ident[EI_CLASS] = ELF_CLASS;
ehdr->e_ident[EI_DATA] = ELF_DATA;
ehdr->e_ident[EI_VERSION] = EV_CURRENT;
+ ehdr->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
+ ehdr->e_ident[EI_ABIVERSION] = 0;
ehdr->e_ident[EI_PAD] = 0;
- strncpy(ehdr->e_ident + EI_BRAND, "FreeBSD",
- EI_NIDENT - EI_BRAND);
ehdr->e_type = ET_CORE;
ehdr->e_machine = ELF_ARCH;
ehdr->e_version = EV_CURRENT;
OpenPOWER on IntegriCloud