summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2008-06-04 21:12:51 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2008-06-04 21:12:51 +0000
commit27c67008ddea42303263824c8d145cb52ac76acb (patch)
tree0587195c442101efe5ca5d09279d74fdef466e8a
parent8e4b93b0d63335923d0a9a19013170d078bcbd43 (diff)
olf support starts to die (easy stuff first); ok miod
-rw-r--r--include/Makefile4
-rw-r--r--include/olf_abi.h33
-rw-r--r--lib/libc/gen/nlist.c5
-rw-r--r--sys/arch/amd64/stand/installboot/nlist.c5
-rw-r--r--sys/kern/exec_elf.c66
-rw-r--r--sys/sys/exec_olf.h52
-rw-r--r--usr.bin/Makefile4
-rw-r--r--usr.bin/elf2olf/Makefile8
-rw-r--r--usr.bin/elf2olf/elf2olf.1113
-rw-r--r--usr.bin/elf2olf/elf2olf.c262
10 files changed, 12 insertions, 540 deletions
diff --git a/include/Makefile b/include/Makefile
index ab167372a0f..605e1f9e56c 100644
--- a/include/Makefile
+++ b/include/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.143 2008/04/23 10:58:34 norby Exp $
+# $OpenBSD: Makefile,v 1.144 2008/06/04 21:12:50 deraadt Exp $
# $NetBSD: Makefile,v 1.59 1996/05/15 21:36:43 jtc Exp $
# @(#)Makefile 5.45.1.1 (Berkeley) 5/6/91
@@ -17,7 +17,7 @@ FILES= a.out.h ar.h assert.h bitstring.h blf.h bm.h bsd_auth.h cast.h \
glob.h grp.h ifaddrs.h inttypes.h iso646.h kvm.h langinfo.h \
libgen.h limits.h locale.h login_cap.h malloc.h math.h md4.h \
md5.h memory.h mpool.h ndbm.h netdb.h netgroup.h nlist.h nl_types.h \
- ohash.h olf_abi.h paths.h poll.h pwd.h ranlib.h re_comp.h \
+ ohash.h paths.h poll.h pwd.h ranlib.h re_comp.h \
readpassphrase.h regex.h resolv.h rmd160.h search.h setjmp.h \
sgtty.h sha1.h sha2.h skipjack.h signal.h stab.h stdbool.h stddef.h \
stdio.h stdlib.h string.h strings.h struct.h sysexits.h tar.h \
diff --git a/include/olf_abi.h b/include/olf_abi.h
deleted file mode 100644
index 781d89cdf0d..00000000000
--- a/include/olf_abi.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* $OpenBSD: olf_abi.h,v 1.1 1996/10/27 20:22:45 etheisen Exp $ */
-/*
- * Copyright (c) 1996 Erik Theisen
- * 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. The name of the author may not be used to endorse or promote products
- * derived from this software without 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.
- */
-#ifndef _OLF_ABI_H_
-#define _OLF_ABI_H_
-
-#include <sys/exec_olf.h>
-
-#endif /* _OLF_ABI_H_ */
diff --git a/lib/libc/gen/nlist.c b/lib/libc/gen/nlist.c
index 669856a42f2..5dd365be8c8 100644
--- a/lib/libc/gen/nlist.c
+++ b/lib/libc/gen/nlist.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nlist.c,v 1.52 2005/11/28 17:50:32 deraadt Exp $ */
+/* $OpenBSD: nlist.c,v 1.53 2008/06/04 21:12:50 deraadt Exp $ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -43,7 +43,6 @@
#ifdef _NLIST_DO_ELF
#include <elf_abi.h>
-#include <olf_abi.h>
#endif
#ifdef _NLIST_DO_ECOFF
@@ -282,7 +281,7 @@ __elf_is_okay__(Elf_Ehdr *ehdr)
* Elf_Ehdr structure. These few elements are
* represented in a machine independent fashion.
*/
- if ((IS_ELF(*ehdr) || IS_OLF(*ehdr)) &&
+ if (IS_ELF(*ehdr) &&
ehdr->e_ident[EI_CLASS] == ELF_TARG_CLASS &&
ehdr->e_ident[EI_DATA] == ELF_TARG_DATA &&
ehdr->e_ident[EI_VERSION] == ELF_TARG_VER) {
diff --git a/sys/arch/amd64/stand/installboot/nlist.c b/sys/arch/amd64/stand/installboot/nlist.c
index f23600dc9d1..39600a141f2 100644
--- a/sys/arch/amd64/stand/installboot/nlist.c
+++ b/sys/arch/amd64/stand/installboot/nlist.c
@@ -28,7 +28,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: nlist.c,v 1.3 2007/04/10 17:47:54 miod Exp $";
+static char rcsid[] = "$OpenBSD: nlist.c,v 1.4 2008/06/04 21:12:50 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -46,7 +46,6 @@ static char rcsid[] = "$OpenBSD: nlist.c,v 1.3 2007/04/10 17:47:54 miod Exp $";
#ifdef _NLIST_DO_ELF
#include <elf_abi.h>
-#include <olf_abi.h>
#endif
#ifdef _NLIST_DO_ECOFF
@@ -290,7 +289,7 @@ __elf_is_okay__(ehdr)
* Elf_Ehdr structure. These few elements are
* represented in a machine independent fashion.
*/
- if ((IS_ELF(*ehdr) || IS_OLF(*ehdr)) &&
+ if (IS_ELF(*ehdr) &&
ehdr->e_ident[EI_CLASS] == ELF_TARG_CLASS &&
ehdr->e_ident[EI_DATA] == ELF_TARG_DATA &&
ehdr->e_ident[EI_VERSION] == ELF_TARG_VER) {
diff --git a/sys/kern/exec_elf.c b/sys/kern/exec_elf.c
index cca52a150f4..f386cf5ebd6 100644
--- a/sys/kern/exec_elf.c
+++ b/sys/kern/exec_elf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec_elf.c,v 1.61 2007/05/28 23:10:10 beck Exp $ */
+/* $OpenBSD: exec_elf.c,v 1.62 2008/06/04 21:12:50 deraadt Exp $ */
/*
* Copyright (c) 1996 Per Fogelstrom
@@ -90,7 +90,6 @@ struct ELFNAME(probe_entry) {
int ELFNAME(load_file)(struct proc *, char *, struct exec_package *,
struct elf_args *, Elf_Addr *);
int ELFNAME(check_header)(Elf_Ehdr *, int);
-int ELFNAME(olf_check_header)(Elf_Ehdr *, int, u_int8_t *);
int ELFNAME(read_from)(struct proc *, struct vnode *, u_long, caddr_t, int);
void ELFNAME(load_psection)(struct exec_vmcmd_set *, struct vnode *,
Elf_Phdr *, Elf_Addr *, Elf_Addr *, int *, int);
@@ -190,54 +189,6 @@ ELFNAME(check_header)(Elf_Ehdr *ehdr, int type)
return (0);
}
-#ifndef SMALL_KERNEL
-/*
- * Check header for validity; return 0 for ok, ENOEXEC if error.
- * Remember OS tag for callers sake.
- */
-int
-ELFNAME(olf_check_header)(Elf_Ehdr *ehdr, int type, u_int8_t *os)
-{
- int i;
-
- /*
- * We need to check magic, class size, endianess, version, and OS
- * before we look at the rest of the Elf_Ehdr structure. These few
- * elements are represented in a machine independant fashion.
- */
- if (!IS_OLF(*ehdr) ||
- ehdr->e_ident[OI_CLASS] != ELF_TARG_CLASS ||
- ehdr->e_ident[OI_DATA] != ELF_TARG_DATA ||
- ehdr->e_ident[OI_VERSION] != ELF_TARG_VER)
- return (ENOEXEC);
-
- for (i = 0;
- i < sizeof(ELFNAME(probes)) / sizeof(ELFNAME(probes)[0]);
- i++) {
- if ((1 << ehdr->e_ident[OI_OS]) & ELFNAME(probes)[i].os_mask)
- goto os_ok;
- }
- return (ENOEXEC);
-
-os_ok:
- /* Now check the machine dependant header */
- if (ehdr->e_machine != ELF_TARG_MACH ||
- ehdr->e_version != ELF_TARG_VER)
- return (ENOEXEC);
-
- /* Check the type */
- if (ehdr->e_type != type)
- return (ENOEXEC);
-
- /* Don't allow an insane amount of sections. */
- if (ehdr->e_phnum > ELF_MAX_VALID_PHDR)
- return (ENOEXEC);
-
- *os = ehdr->e_ident[OI_OS];
- return (0);
-}
-#endif /* !SMALL_KERNEL */
-
/*
* Load a psection at the appropriate address
*/
@@ -349,9 +300,6 @@ ELFNAME(load_file)(struct proc *p, char *path, struct exec_package *epp,
u_long phsize;
Elf_Addr addr;
struct vnode *vp;
-#ifndef SMALL_KERNEL
- u_int8_t os; /* Just a dummy in this routine */
-#endif
Elf_Phdr *base_ph = NULL;
struct interp_ld_sec {
Elf_Addr vaddr;
@@ -382,11 +330,7 @@ ELFNAME(load_file)(struct proc *p, char *path, struct exec_package *epp,
(caddr_t)&eh, sizeof(eh))) != 0)
goto bad1;
- if (ELFNAME(check_header)(&eh, ET_DYN)
-#ifndef SMALL_KERNEL
- && ELFNAME(olf_check_header)(&eh, ET_DYN, &os)
-#endif
- ) {
+ if (ELFNAME(check_header)(&eh, ET_DYN)) {
error = ENOEXEC;
goto bad1;
}
@@ -543,11 +487,7 @@ ELFNAME2(exec,makecmds)(struct proc *p, struct exec_package *epp)
if (epp->ep_hdrvalid < sizeof(Elf_Ehdr))
return (ENOEXEC);
- if (ELFNAME(check_header)(eh, ET_EXEC)
-#ifndef SMALL_KERNEL
- && ELFNAME(olf_check_header)(eh, ET_EXEC, &os)
-#endif
- )
+ if (ELFNAME(check_header)(eh, ET_EXEC))
return (ENOEXEC);
/*
diff --git a/sys/sys/exec_olf.h b/sys/sys/exec_olf.h
index 8ea75801bae..59572ebc758 100644
--- a/sys/sys/exec_olf.h
+++ b/sys/sys/exec_olf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec_olf.h,v 1.8 2001/06/22 14:11:00 deraadt Exp $ */
+/* $OpenBSD: exec_olf.h,v 1.9 2008/06/04 21:12:50 deraadt Exp $ */
/*
* Copyright (c) 1996 Erik Theisen. All rights reserved.
*
@@ -35,41 +35,6 @@
#include <sys/exec_elf.h>
-/* e_ident[] identification indexes */
-#define OI_MAG0 EI_MAG0 /* file ID */
-#define OI_MAG1 EI_MAG1 /* file ID */
-#define OI_MAG2 EI_MAG2 /* file ID */
-#define OI_MAG3 EI_MAG3 /* file ID */
-#define OI_CLASS EI_CLASS /* file class */
-#define OI_DATA EI_DATA /* data encoding */
-#define OI_VERSION EI_VERSION /* OLF header version */
-#define OI_OS 7 /* Operating system tag */
-#define OI_DYNAMIC 8 /* Dynamic tag */
-#define OI_STRIP 9 /* Strip tag */
-#define OI_PAD 10 /* start of pad bytes */
-#define OI_NIDENT EI_NIDENT /* Size of e_ident[] */
-
-/* e_ident[] magic number */
-#define OLFMAG0 ELFMAG0 /* e_ident[OI_MAG0] */
-#define OLFMAG1 'O' /* e_ident[OI_MAG1] */
-#define OLFMAG2 ELFMAG2 /* e_ident[OI_MAG2] */
-#define OLFMAG3 ELFMAG3 /* e_ident[OI_MAG3] */
-#define OLFMAG "\177OLF" /* magic */
-#define SOLFMAG SELFMAG /* size of magic */
-
-/* e_ident[] file class */
-#define OLFCLASSNONE ELFCLASSNONE /* invalid */
-#define OLFCLASS32 ELFCLASS32 /* 32-bit objs */
-#define OLFCLASS64 ELFCLASS64 /* 64-bit objs */
-#define OLFCLASSNUM ELFCLASSNUM /* number of classes */
-
-/* e_ident[] data encoding */
-#define OLFDATANONE ELFDATANONE /* invalid */
-#define OLFDATA2LSB ELFDATA2LSB /* Little-Endian */
-#define OLFDATA2MSB ELFDATA2MSB /* Big-Endian */
-#define OLFDATANUM ELFDATANUM /* number of data encode defines */
-
-
/*
* Please help make this list definative.
*/
@@ -112,20 +77,5 @@
OOSN_NCR, \
0 }
-/* e_ident[] dynamic */
-#define ODYNAMIC_N 0 /* Statically linked */
-#define ODYNAMIC 1 /* Dynamically linked */
-
-/* e_ident[] strip */
-#define OSTRIP 0 /* Stripped */
-#define OSTRIP_N 1 /* Not Stripped */
-
-/* e_ident */
-#define IS_OLF(ehdr) \
- ((ehdr).e_ident[OI_MAG0] == OLFMAG0 && \
- (ehdr).e_ident[OI_MAG1] == OLFMAG1 && \
- (ehdr).e_ident[OI_MAG2] == OLFMAG2 && \
- (ehdr).e_ident[OI_MAG3] == OLFMAG3)
-
/* The rest of the types and defines come from the ELF header file */
#endif /* _SYS_EXEC_OLF_H_ */
diff --git a/usr.bin/Makefile b/usr.bin/Makefile
index 3f52b83db26..dc46cc66dec 100644
--- a/usr.bin/Makefile
+++ b/usr.bin/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.108 2008/05/21 19:48:50 miod Exp $
+# $OpenBSD: Makefile,v 1.109 2008/06/04 21:12:49 deraadt Exp $
.include <bsd.own.mk>
@@ -6,7 +6,7 @@ SUBDIR= apply apropos ar arch asa asn1_compile at aucat audioctl awk banner \
basename bc bdes bgplg \
biff cal calendar cap_mkdb cdio checknr chpass cmp col colcrt colrm \
column comm compile_et compress cpp crontab csplit ctags cut \
- dc deroff diff diff3 dirname du elf2olf encrypt env expand false file \
+ dc deroff diff diff3 dirname du encrypt env expand false file \
file2c find fgen finger fmt fold from fsplit fstat ftp gencat getcap \
getconf getent getopt gprof grep gzsig head hexdump id indent \
infocmp ipcrm ipcs \
diff --git a/usr.bin/elf2olf/Makefile b/usr.bin/elf2olf/Makefile
deleted file mode 100644
index 8b17f488d42..00000000000
--- a/usr.bin/elf2olf/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
-# $OpenBSD: Makefile,v 1.5 1996/12/08 20:59:20 tholo Exp $
-
-PROG= elf2olf
-CPPFLAGS+= -DOS_ID=OOS_OPENBSD
-LINKS= ${BINDIR}/elf2olf ${BINDIR}/olf2elf
-MLINKS= elf2olf.1 olf2elf.1
-
-.include <bsd.prog.mk>
diff --git a/usr.bin/elf2olf/elf2olf.1 b/usr.bin/elf2olf/elf2olf.1
deleted file mode 100644
index 4e4919c675b..00000000000
--- a/usr.bin/elf2olf/elf2olf.1
+++ /dev/null
@@ -1,113 +0,0 @@
-.\" $OpenBSD: elf2olf.1,v 1.15 2007/05/31 19:20:09 jmc Exp $
-.\"
-.\" Copyright (c) 1996, 1997 Erik Theisen.
-.\" 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. The name of the author may not be used to endorse or promote products
-.\" derived from this software without 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.
-.\"
-.\" @(#)$Id: elf2olf.1,v 1.15 2007/05/31 19:20:09 jmc Exp $
-.\"
-.Dd $Mdocdate: May 31 2007 $
-.Dt ELF2OLF 1
-.Os
-.Sh NAME
-.Nm elf2olf ,
-.Nm olf2elf
-.Nd convert between ELF and OLF object module format
-.Sh SYNOPSIS
-.Nm elf2olf
-.Op Fl v
-.Op Fl o Ar opsys
-.Ar module ...
-.Nm olf2elf
-.Op Fl v
-.Ar
-.Sh DESCRIPTION
-The
-.Nm elf2olf
-utility reads the specified
-.Em ELF
-version 1 module operands and converts them to the default operating system's
-.Em OLF
-object module format.
-.Pp
-The
-.Nm olf2elf
-utility reverses the process.
-The
-.Ar module
-operands are processed in command line order.
-.Pp
-The options are as follows:
-.Bl -tag -width Ds
-.It Fl o Ar opsys
-Specifies the operating system
-.Em OLF
-tag
-.Em "opsys"
-as follows:
-.Pp
-.Bl -tag -width Ds -compact
-.It Ta Pa "openbsd" Ta "OpenBSD"
-.It Ta Pa "netbsd" Ta "NetBSD"
-.It Ta Pa "freebsd" Ta "FreeBSD"
-.It Ta Pa "44bsd" Ta "4.4BSD"
-.It Ta Pa "linux" Ta "Linux"
-.It Ta Pa "svr4" Ta "AT&T System V Release 4"
-.It Ta Pa "esix" Ta "esix UNIX"
-.It Ta Pa "solaris" Ta "SunSoft Solaris"
-.It Ta Pa "irix" Ta "SGI IRIX"
-.It Ta Pa "sco " Ta "SCO UNIX"
-.It Ta Pa "dell" Ta "Dell SVR4"
-.It Ta Pa "ncr " Ta "NCR SVR4"
-.El
-.It Fl v
-Operate in verbose mode.
-.El
-.Pp
-The
-.Nm elf2olf
-and
-.Nm olf2elf
-utilities exit 0 on success or >0 if an error occurred.
-.Sh HISTORY
-The
-.Nm elf2olf
-and
-.Nm olf2elf
-utilities first appeared in
-.Ox 2.1 .
-.Sh AUTHORS
-Erik Theisen
-.Sh BUGS
-The
-.Em ELF
-version 1 object module format lacks any real method to determine the native
-operating system for any given binary thus mandating the existence of these
-tools.
-The converted binaries created by
-.Nm elf2olf
-will no longer execute on their native operating system, only on OLF
-enabled platforms, although
-.Nm olf2elf
-will undo the damage.
diff --git a/usr.bin/elf2olf/elf2olf.c b/usr.bin/elf2olf/elf2olf.c
deleted file mode 100644
index b2a0cad4a6e..00000000000
--- a/usr.bin/elf2olf/elf2olf.c
+++ /dev/null
@@ -1,262 +0,0 @@
-/* $OpenBSD: elf2olf.c,v 1.9 2007/03/15 23:06:01 jmc Exp $ */
-/*
- * Copyright (c) 1996 Erik Theisen. 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. The name of the author may not be used to endorse or promote products
- * derived from this software without 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.
- */
-#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1996 Erik Theisen. All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char rcsid[] = "@(#) $Id: elf2olf.c,v 1.9 2007/03/15 23:06:01 jmc Exp $";
-#endif
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <sys/stat.h>
-#include <sys/param.h>
-
-#include <olf_abi.h>
-
-int retval = 0;
-int olf2elf;
-char *progname;
-int verbose;
-int opsys = OS_ID;
-
-char *os_namev[] = ONAMEV;
-
-/* Handle endianess */
-#define word(x,y)((y == ELFDATA2LSB) ? ntohl(htonl(x)) : ntohl(x))
-#define half(x,y)((y == ELFDATA2LSB) ? ntohs(htons(x)) : ntohs(x))
-
-void usage(void);
-void pwarn(char *, char *, int);
-
-int
-main(int argc, char*argv[])
-{
- extern char *optarg;
- extern int optind;
- int ch, i, okay;
- char *opstring;
-
- int fd;
- struct stat st;
- Elf32_Ehdr ehdr;
- Elf32_Shdr shdr;
- int e;
-
- if ((progname = strrchr(*argv, '/')))
- ++progname;
- else
- progname = *argv;
-
- if (strstr(progname, "olf2elf"))
- olf2elf = 1;
-
- /*
- * Process cmdline
- */
- opstring = olf2elf ? "v" : "vo:";
- while((ch = getopt(argc, argv, opstring)) != -1)
- switch(ch) {
- case 'v':
- verbose = 1;
- break;
- case 'o':
- for (i = 1; i <= OOS_NUM; i++) {
- if (os_namev[i] == NULL) {
- fprintf(stderr,
- "%s: illegal -o argument -- %s\n",
- progname, optarg);
- usage();
- }
- else if (strcmp(optarg, os_namev[i]) == 0) {
- opsys = i;
- break;
- }
- }
- break;
- default:
- usage();
- }
- argc -= optind;
- argv += optind;
-
- if (argc == 0)
- usage();
-
- /*
- * Process file(s)
- */
- do {
- okay = 0;
-
- if ((fd = open(*argv, O_RDWR | O_EXLOCK, 0)) != -1 &&
- lseek(fd, (off_t)0, SEEK_SET) == 0 &&
- fstat(fd, &st) == 0) {
-
- /* Make sure this is a 32bit ELF or OLF version 1 file */
- if (read(fd, &ehdr, sizeof(Elf32_Ehdr)) == sizeof(Elf32_Ehdr)&&
- (IS_ELF(ehdr) || IS_OLF(ehdr)) &&
- ehdr.e_ident[EI_CLASS] == ELFCLASS32 &&
- ehdr.e_ident[EI_VERSION] == 1) {
-
- /* Is this elf2olf? */
- if(!olf2elf) {
-
- /* Tag, your it... */
- ehdr.e_ident[OI_MAG0] = OLFMAG0;
- ehdr.e_ident[OI_MAG1] = OLFMAG1;
- ehdr.e_ident[OI_MAG2] = OLFMAG2;
- ehdr.e_ident[OI_MAG3] = OLFMAG3;
- ehdr.e_ident[OI_OS] = opsys;
- ehdr.e_ident[OI_DYNAMIC] = ODYNAMIC_N;
- ehdr.e_ident[OI_STRIP] = OSTRIP;
-
- /* We'll need this endian */
- e = ehdr.e_ident[EI_DATA];
-
- /* Now we need to figure out wether or */
- /* not we're really stripped. */
- if (lseek(fd, (off_t)word(ehdr.e_shoff, e),
- SEEK_SET) == word(ehdr.e_shoff, e)) {
-
- /*
- * search through section header table
- * looking for a section header of type
- * SHT_SYMTAB and SHT_DYNAMIC. If there is
- * one present we're NOT stripped and/or
- * dynamic.
- */
- for (i = 0; i < half(ehdr.e_shnum, e); i++) {
- if (read(fd, &shdr, sizeof(Elf32_Shdr)) == sizeof(Elf32_Shdr)){
- if (word(shdr.sh_type, e) == SHT_SYMTAB)
- ehdr.e_ident[OI_STRIP] = OSTRIP_N;
- else if (word(shdr.sh_type, e) == SHT_DYNAMIC)
- ehdr.e_ident[OI_DYNAMIC] = ODYNAMIC;
- } else
- pwarn(progname, *argv, errno);
- } /* while less than number of section headers */
-
- /* We're ready to modify */
- okay = 1;
-
- } else /* Bogus section header table seek */
- pwarn(progname, *argv, errno);
-
- } else { /* olf2elf */
- ehdr.e_ident[EI_MAG0] = ELFMAG0;
- ehdr.e_ident[EI_MAG1] = ELFMAG1;
- ehdr.e_ident[EI_MAG2] = ELFMAG2;
- ehdr.e_ident[EI_MAG3] = ELFMAG3;
- ehdr.e_ident[OI_OS] = 0;
- ehdr.e_ident[OI_DYNAMIC] = 0;
- ehdr.e_ident[OI_STRIP] = 0;
-
- okay = 1;
- } /* olf2elf */
- } else /* Bogus non-ELF file encountered */
- pwarn(progname, *argv, ENOEXEC);
-
- /*
- * Do It.
- */
- if (okay) {
- if (lseek(fd, (off_t)0, SEEK_SET) == 0) {
- if (write(fd, &ehdr, sizeof(Elf32_Ehdr)) == sizeof(Elf32_Ehdr)) {
- if (verbose) {
- if (!olf2elf) {
- printf("ELF %s => OLF %d-bit %s %s linked %s OLF.\n",
- *argv,
- (ehdr.e_ident[OI_CLASS] == OLFCLASS32)?\
- 32 : 64,
- os_namev[ehdr.e_ident[OI_OS]],
- ehdr.e_ident[OI_DYNAMIC] ? \
- "dynamically" : "statically",
- !ehdr.e_ident[OI_STRIP] ?
- "stripped" : "unstripped");
- } else
- printf("OLF %s => ELF.\n", *argv);
- }
- } else /* bad write */
- pwarn(progname, *argv, errno);
- } else /* bad seek */
- pwarn(progname, *argv, errno);
- } /* okay? */
- fsync(fd);
- close(fd);
-
- } else /* couldn't handle file */
- pwarn(progname, *argv, errno);
- } while (*(++argv) != NULL);
-
-
- return (retval);
-}
-
-void
-pwarn(name, fname, errval)
- char *name;
- char *fname;
- int errval;
-{
- fprintf(stderr, "%s: %s: %s.\n", name, fname, strerror(errval));
- retval = 1;
-}
-
-void
-usage(void)
-{
- int i;
- int col = 8;
-
- if (olf2elf) {
- fprintf(stderr, "usage: %s [-v] file ...\n", progname);
- } else {
- fprintf(stderr, "usage: %s [-v] [-o opsys] module ...\n", progname);
- fprintf(stderr, "where opsys is:\n\t");
- for (i = 1; os_namev[i] != NULL; i++) {
- col = col + strlen(os_namev[i]) + 2;
- if (col > 78) {
- fprintf(stderr, "\n\t");
- col = 8;
- }
- fprintf(stderr, "%s%s", os_namev[i],
- os_namev[i+1] ? ", " : "\n");
- }
- }
- exit(1);
-}
-
-