Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Use libelf from elftoolchain for the bundle version of libelf (it has the portability bits)
Baptiste Daroussin committed 13 years ago
commit 7283bfa91c6c9586da2f24b32c9e06c6e6f74b56
parent b16bde2
126 files changed +6517 -5178
modified external/libelf/Makefile
@@ -1,8 +1,7 @@
-
# $FreeBSD: head/lib/libelf/Makefile 238741 2012-07-24 16:03:28Z ache $
-

LIB=	elf

-
SRCS=	elf_begin.c						\
+
SRCS=	elf.c							\
+
	elf_begin.c						\
	elf_cntl.c						\
	elf_end.c elf_errmsg.c elf_errno.c			\
	elf_data.c						\
@@ -16,6 +15,7 @@ SRCS= elf_begin.c \
	elf_kind.c						\
	elf_memory.c						\
	elf_next.c						\
+
	elf_open.c						\
	elf_rand.c						\
	elf_rawfile.c						\
	elf_phnum.c						\
@@ -40,7 +40,6 @@ SRCS= elf_begin.c \
	gelf_syminfo.c						\
	gelf_symshndx.c						\
	gelf_xlate.c						\
-
	libelf.c						\
	libelf_align.c						\
	libelf_allocate.c					\
	libelf_ar.c						\
@@ -49,20 +48,24 @@ SRCS= elf_begin.c \
	libelf_data.c						\
	libelf_ehdr.c						\
	libelf_extended.c					\
+
	libelf_memory.c						\
+
	libelf_open.c						\
	libelf_phdr.c						\
	libelf_shdr.c						\
	libelf_xlate.c						\
	${GENSRCS}
-

-
INTERNALLIB=
INCS=	libelf.h gelf.h

GENSRCS=	libelf_fsize.c libelf_msize.c libelf_convert.c
CLEANFILES=	${GENSRCS}
-
CLEANDIRS=	sys
-
CFLAGS+=	-I${.CURDIR} -I.

+
CFLAGS+=	-I${.CURDIR}
+

+
INTERNALLI=
NO_MAN=	yes
+
NOMAN=	yes
+

+
WARNS?=	6

libelf_convert.c:	elf_types.m4 libelf_convert.m4
libelf_fsize.c:		elf_types.m4 libelf_fsize.m4
@@ -71,6 +74,7 @@ libelf_msize.c: elf_types.m4 libelf_msize.m4
.include <bsd.lib.mk>

# Keep the .SUFFIXES line after the include of bsd.lib.mk
-
.SUFFIXES:	.m4 .c
+
.SUFFIXES:     .m4 .c
.m4.c:
	m4 -D SRCDIR=${.CURDIR} ${.IMPSRC} > ${.TARGET}
+

deleted external/libelf/README
@@ -1,12 +0,0 @@
-
# $FreeBSD: releng/9.1/lib/libelf/README 186758 2009-01-05 05:14:26Z jkoshy $
-
# $NetBSD$
-

-
libelf: a BSD-licensed implementation of the ELF(3)/GELF(3) API.
-

-
Documentation:
-
 * Manual page elf.3 contains an overview of the library.  Other
-
   manual pages document individual APIs in the library.
-
 * A tutorial "libelf by Example" is available at:
-
   http://people.freebsd.org/~jkoshy/download/libelf/article.html
-
	
-
For ongoing development please see http://elftoolchain.sourceforge.net/
modified external/libelf/Version.map
@@ -1,7 +1,6 @@
-
/*
-
 * $FreeBSD: releng/9.1/lib/libelf/Version.map 210345 2010-07-21 12:14:50Z kaiw $
-
 */
-
FBSD_1.0 {
+
/* $Id: Version.map 2574 2012-09-11 15:11:59Z jkoshy $ */
+

+
R1.0 {
global:
	elf32_checksum;
	elf32_fsize;
@@ -27,6 +26,7 @@ global:
	elf_errmsg;
	elf_errno;
	elf_fill;
+
	elf_flagarhdr;
	elf_flagdata;
	elf_flagehdr;
	elf_flagelf;
@@ -38,12 +38,12 @@ global:
	elf_getbase;
	elf_getdata;
	elf_getident;
-
	elf_getscn;
	elf_getphdrnum;
	elf_getphnum;
+
	elf_getscn;
	elf_getshdrnum;
-
	elf_getshnum;
	elf_getshdrstrndx;
+
	elf_getshnum;
	elf_getshstrndx;
	elf_hash;
	elf_kind;
@@ -53,6 +53,8 @@ global:
	elf_newscn;
	elf_next;
	elf_nextscn;
+
	elf_open;
+
	elf_openmemory;
	elf_rand;
	elf_rawdata;
	elf_rawfile;
@@ -92,14 +94,3 @@ global:
local:
	*;
};
-

-
/*
-
 * Private symbols, mostly test hooks
-
 */
-
FBSDprivate_1.0 {
-
global:
-
	_libelf_set_error;
-
	_libelf_get_max_error;
-
	_libelf_get_no_error_message;
-
	_libelf_get_unknown_error_message;
-
};
added external/libelf/_elftc.h
@@ -0,0 +1,387 @@
+
/*-
+
 * Copyright (c) 2009 Joseph Koshy
+
 * 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.
+
 *
+
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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.
+
 *
+
 * $Id: _elftc.h 2495 2012-04-23 05:31:56Z jkoshy $
+
 */
+

+
/**
+
 ** Miscellanous definitions needed by multiple components.
+
 **/
+

+
#ifndef	_ELFTC_H
+
#define	_ELFTC_H
+

+
#ifndef	NULL
+
#define NULL 	((void *) 0)
+
#endif
+

+
#ifndef	offsetof
+
#define	offsetof(T, M)		((int) &((T*) 0) -> M)
+
#endif
+

+
/* --QUEUE-MACROS-- [[ */
+

+
/*
+
 * Supply macros missing from <sys/queue.h>
+
 */
+

+
/*
+
 * Copyright (c) 1991, 1993
+
 *	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.
+
 */
+

+
#ifndef	STAILQ_CONCAT
+
#define	STAILQ_CONCAT(head1, head2) do {			\
+
	if (!STAILQ_EMPTY((head2))) {				\
+
		*(head1)->stqh_last = (head2)->stqh_first;	\
+
		(head1)->stqh_last = (head2)->stqh_last;	\
+
		STAILQ_INIT((head2));				\
+
	}							\
+
} while (/*CONSTCOND*/0)
+
#endif
+

+
#ifndef	STAILQ_EMPTY
+
#define	STAILQ_EMPTY(head)	((head)->stqh_first == NULL)
+
#endif
+

+
#ifndef	STAILQ_ENTRY
+
#define	STAILQ_ENTRY(type)					\
+
struct {							\
+
	struct type *stqe_next;	/* next element */		\
+
}
+
#endif
+

+
#ifndef	STAILQ_FIRST
+
#define	STAILQ_FIRST(head)	((head)->stqh_first)
+
#endif
+

+
#ifndef	STAILQ_HEAD
+
#define	STAILQ_HEAD(name, type)					\
+
struct name {							\
+
	struct type *stqh_first; /* first element */		\
+
	struct type **stqh_last; /* addr of last next element */ \
+
}
+
#endif
+

+
#ifndef	STAILQ_HEAD_INITIALIZER
+
#define	STAILQ_HEAD_INITIALIZER(head)				\
+
	{ NULL, &(head).stqh_first }
+
#endif
+

+
#ifndef	STAILQ_FOREACH
+
#define	STAILQ_FOREACH(var, head, field)			\
+
	for ((var) = ((head)->stqh_first);			\
+
		(var);						\
+
		(var) = ((var)->field.stqe_next))
+
#endif
+

+
#ifndef	STAILQ_FOREACH_SAFE
+
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)		\
+
       for ((var) = STAILQ_FIRST((head));			\
+
	    (var) && ((tvar) = STAILQ_NEXT((var), field), 1);	\
+
	    (var) = (tvar))
+
#endif
+

+
#ifndef	STAILQ_INIT
+
#define	STAILQ_INIT(head) do {					\
+
	(head)->stqh_first = NULL;				\
+
	(head)->stqh_last = &(head)->stqh_first;		\
+
} while (/*CONSTCOND*/0)
+
#endif
+

+
#ifndef	STAILQ_INSERT_HEAD
+
#define	STAILQ_INSERT_HEAD(head, elm, field) do {			\
+
	if (((elm)->field.stqe_next = (head)->stqh_first) == NULL)	\
+
		(head)->stqh_last = &(elm)->field.stqe_next;		\
+
	(head)->stqh_first = (elm);					\
+
} while (/*CONSTCOND*/0)
+
#endif
+

+
#ifndef	STAILQ_INSERT_TAIL
+
#define	STAILQ_INSERT_TAIL(head, elm, field) do {			\
+
	(elm)->field.stqe_next = NULL;					\
+
	*(head)->stqh_last = (elm);					\
+
	(head)->stqh_last = &(elm)->field.stqe_next;			\
+
} while (/*CONSTCOND*/0)
+
#endif
+

+
#ifndef	STAILQ_INSERT_AFTER
+
#define	STAILQ_INSERT_AFTER(head, listelm, elm, field) do {		\
+
	if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\
+
		(head)->stqh_last = &(elm)->field.stqe_next;		\
+
	(listelm)->field.stqe_next = (elm);				\
+
} while (/*CONSTCOND*/0)
+
#endif
+

+
#ifndef	STAILQ_LAST
+
#define STAILQ_LAST(head, type, field)					\
+
	(STAILQ_EMPTY((head)) ?					\
+
	    NULL : ((struct type *)(void *)				\
+
	    ((char *)((head)->stqh_last) - offsetof(struct type, field))))
+
#endif
+

+
#ifndef	STAILQ_NEXT
+
#define	STAILQ_NEXT(elm, field)	((elm)->field.stqe_next)
+
#endif
+

+
#ifndef	STAILQ_REMOVE
+
#define	STAILQ_REMOVE(head, elm, type, field) do {			\
+
	if ((head)->stqh_first == (elm)) {				\
+
		STAILQ_REMOVE_HEAD((head), field);			\
+
	} else {							\
+
		struct type *curelm = (head)->stqh_first;		\
+
		while (curelm->field.stqe_next != (elm))		\
+
			curelm = curelm->field.stqe_next;		\
+
		if ((curelm->field.stqe_next =				\
+
			curelm->field.stqe_next->field.stqe_next) == NULL) \
+
			    (head)->stqh_last = &(curelm)->field.stqe_next; \
+
	}								\
+
} while (/*CONSTCOND*/0)
+
#endif
+

+
#ifndef	STAILQ_REMOVE_HEAD
+
#define	STAILQ_REMOVE_HEAD(head, field) do {				\
+
	if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == \
+
	    NULL)							\
+
		(head)->stqh_last = &(head)->stqh_first;		\
+
} while (/*CONSTCOND*/0)
+
#endif
+

+
#ifndef	TAILQ_FOREACH_SAFE
+
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)                      \
+
	for ((var) = TAILQ_FIRST((head));                               \
+
	    (var) && ((tvar) = TAILQ_NEXT((var), field), 1);            \
+
	    (var) = (tvar))
+
#endif
+

+
/* ]] --QUEUE-MACROS-- */
+

+
/*
+
 * VCS Ids.
+
 */
+

+
#ifndef	ELFTC_VCSID
+

+
#if defined(__DragonFly__)
+
#define	ELFTC_VCSID(ID)		__RCSID(ID)
+
#endif
+

+
#if defined(__FreeBSD__)
+
#define	ELFTC_VCSID(ID)		__FBSDID(ID)
+
#endif
+

+
#if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)
+
#if defined(__GNUC__)
+
#define	ELFTC_VCSID(ID)		__asm__(".ident\t\"" ID "\"")
+
#else
+
#define	ELFTC_VCSID(ID)		/**/
+
#endif
+
#endif
+

+
#if defined(__minix)
+
#if defined(__GNUC__)
+
#define	ELFTC_VCSID(ID)		__asm__(".ident\t\"" ID "\"")
+
#else
+
#define	ELFTC_VCSID(ID)		/**/
+
#endif	/* __GNU__ */
+
#endif
+

+
#if defined(__NetBSD__)
+
#define	ELFTC_VCSID(ID)		__RCSID(ID)
+
#endif
+

+
#if defined(__OpenBSD__)
+
#if defined(__GNUC__)
+
#define	ELFTC_VCSID(ID)		__asm__(".ident\t\"" ID "\"")
+
#else
+
#define	ELFTC_VCSID(ID)		/**/
+
#endif	/* __GNUC__ */
+
#endif
+

+
#endif	/* ELFTC_VCSID */
+

+
/*
+
 * Provide an equivalent for getprogname(3).
+
 */
+

+
#ifndef	ELFTC_GETPROGNAME
+

+
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__minix) || \
+
    defined(__NetBSD__)
+

+
#include <stdlib.h>
+

+
#define	ELFTC_GETPROGNAME()	getprogname()
+

+
#endif	/* __DragonFly__ || __FreeBSD__ || __minix || __NetBSD__ */
+

+

+
#if defined(__GLIBC__)
+

+
/*
+
 * GLIBC based systems have a global 'char *' pointer referencing
+
 * the executable's name.
+
 */
+
extern const char *program_invocation_short_name;
+

+
#define	ELFTC_GETPROGNAME()	program_invocation_short_name
+

+
#endif	/* __GLIBC__ */
+

+

+
#if defined(__OpenBSD__)
+

+
extern const char *__progname;
+

+
#define	ELFTC_GETPROGNAME()	__progname
+

+
#endif	/* __OpenBSD__ */
+

+
#endif	/* ELFTC_GETPROGNAME */
+

+

+
/**
+
 ** Per-OS configuration.
+
 **/
+

+
#if defined(__DragonFly__)
+

+
#include <osreldate.h>
+
#include <sys/endian.h>
+

+
#define	ELFTC_BYTE_ORDER			_BYTE_ORDER
+
#define	ELFTC_BYTE_ORDER_LITTLE_ENDIAN		_LITTLE_ENDIAN
+
#define	ELFTC_BYTE_ORDER_BIG_ENDIAN		_BIG_ENDIAN
+

+
#define	ELFTC_HAVE_MMAP				1
+

+
#endif
+

+
#if defined(__GLIBC__)
+

+
#include <endian.h>
+

+
#define	ELFTC_BYTE_ORDER			__BYTE_ORDER
+
#define	ELFTC_BYTE_ORDER_LITTLE_ENDIAN		__LITTLE_ENDIAN
+
#define	ELFTC_BYTE_ORDER_BIG_ENDIAN		__BIG_ENDIAN
+

+
#define	ELFTC_HAVE_MMAP				1
+

+
/*
+
 * Debian GNU/Linux and Debian GNU/kFreeBSD do not have strmode(3).
+
 */
+
#define	ELFTC_HAVE_STRMODE			0
+

+
/* Whether we need to supply {be,le}32dec. */
+
#define ELFTC_NEED_BYTEORDER_EXTENSIONS		1
+

+
#define	roundup2	roundup
+

+
#endif	/* __GLIBC__ */
+

+

+
#if defined(__FreeBSD__)
+

+
#include <osreldate.h>
+
#include <sys/endian.h>
+

+
#define	ELFTC_BYTE_ORDER			_BYTE_ORDER
+
#define	ELFTC_BYTE_ORDER_LITTLE_ENDIAN		_LITTLE_ENDIAN
+
#define	ELFTC_BYTE_ORDER_BIG_ENDIAN		_BIG_ENDIAN
+

+
#define	ELFTC_HAVE_MMAP				1
+
#define	ELFTC_HAVE_STRMODE			1
+
#if __FreeBSD_version <= 900000
+
#define	ELFTC_BROKEN_YY_NO_INPUT		1
+
#endif
+
#endif	/* __FreeBSD__ */
+

+

+
#if defined(__minix)
+
#define	ELFTC_HAVE_MMAP				0
+
#endif	/* __minix */
+

+

+
#if defined(__NetBSD__)
+

+
#include <sys/param.h>
+
#include <sys/endian.h>
+

+
#define	ELFTC_BYTE_ORDER			_BYTE_ORDER
+
#define	ELFTC_BYTE_ORDER_LITTLE_ENDIAN		_LITTLE_ENDIAN
+
#define	ELFTC_BYTE_ORDER_BIG_ENDIAN		_BIG_ENDIAN
+

+
#define	ELFTC_HAVE_MMAP				1
+
#define	ELFTC_HAVE_STRMODE			1
+
#if __NetBSD_Version__ <= 599002100
+
/* from src/doc/CHANGES: flex(1): Import flex-2.5.35 [christos 20091025] */
+
/* and 5.99.21 was from Wed Oct 21 21:28:36 2009 UTC */
+
#  define ELFTC_BROKEN_YY_NO_INPUT		1
+
#endif
+
#endif	/* __NetBSD __ */
+

+

+
#if defined(__OpenBSD__)
+

+
#include <sys/param.h>
+
#include <sys/endian.h>
+

+
#define	ELFTC_BYTE_ORDER			_BYTE_ORDER
+
#define	ELFTC_BYTE_ORDER_LITTLE_ENDIAN		_LITTLE_ENDIAN
+
#define	ELFTC_BYTE_ORDER_BIG_ENDIAN		_BIG_ENDIAN
+

+
#define	ELFTC_HAVE_MMAP				1
+
#define	ELFTC_HAVE_STRMODE			1
+

+
#define	ELFTC_NEED_BYTEORDER_EXTENSIONS		1
+
#define	roundup2	roundup
+

+
#endif	/* __OpenBSD__ */
+

+
#endif	/* _ELFTC_H */
modified external/libelf/_libelf.h
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008-2011 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -23,7 +23,7 @@
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
-
 * $FreeBSD: releng/9.1/lib/libelf/_libelf.h 210348 2010-07-21 12:54:34Z kaiw $
+
 * $Id: _libelf.h 2365 2011-12-29 04:36:44Z jkoshy $
 */

#ifndef	__LIBELF_H_
@@ -31,9 +31,9 @@

#include <sys/queue.h>

-
#ifndef	NULL
-
#define NULL 	((void *) 0)
-
#endif
+
#include "_libelf_config.h"
+

+
#include "_elftc.h"

/*
 * Library-private data structures.
@@ -55,38 +55,53 @@ extern struct _libelf_globals _libelf;

#define	LIBELF_PRIVATE(N)	(_libelf.libelf_##N)

-
#define	LIBELF_ELF_ERROR_MASK	0xFF
-
#define	LIBELF_OS_ERROR_SHIFT	8
+
#define	LIBELF_ELF_ERROR_MASK			0xFF
+
#define	LIBELF_OS_ERROR_SHIFT			8
+

+
#define	LIBELF_ERROR(E, O) (((E) & LIBELF_ELF_ERROR_MASK) |	\
+
	((O) << LIBELF_OS_ERROR_SHIFT))

#define	LIBELF_SET_ERROR(E, O) do {					\
-
	LIBELF_PRIVATE(error) = ((ELF_E_##E & LIBELF_ELF_ERROR_MASK)|	\
-
	    ((O) << LIBELF_OS_ERROR_SHIFT));				\
+
		LIBELF_PRIVATE(error) = LIBELF_ERROR(ELF_E_##E, (O));	\
	} while (0)

#define	LIBELF_ADJUST_AR_SIZE(S)	(((S) + 1U) & ~1U)

/*
-
 * Flags for library internal use.  These use the upper 16 bits of a
-
 * flags field.
+
 * Flags for library internal use.  These use the upper 16 bits of the
+
 * `e_flags' field.
 */
-
#define	LIBELF_F_MALLOCED	0x010000 /* whether data was malloc'ed */
-
#define	LIBELF_F_MMAP		0x020000 /* whether e_rawfile was mmap'ed */
-
#define	LIBELF_F_SHDRS_LOADED	0x040000 /* whether all shdrs were read in */
+
#define	LIBELF_F_API_MASK	0x00FFFF  /* Flags defined by the API. */
+
#define	LIBELF_F_AR_HEADER	0x010000  /* translated header available */
+
#define	LIBELF_F_AR_VARIANT_SVR4 0x020000 /* BSD style ar(1) archive */
+
#define	LIBELF_F_DATA_MALLOCED	0x040000 /* whether data was malloc'ed */
+
#define	LIBELF_F_RAWFILE_MALLOC	0x080000 /* whether e_rawfile was malloc'ed */
+
#define	LIBELF_F_RAWFILE_MMAP	0x100000 /* whether e_rawfile was mmap'ed */
+
#define	LIBELF_F_SHDRS_LOADED	0x200000 /* whether all shdrs were read in */
+
#define	LIBELF_F_SPECIAL_FILE	0x400000 /* non-regular file */

struct _Elf {
	int		e_activations;	/* activation count */
-
	Elf_Arhdr	*e_arhdr;	/* header for archive members */
	unsigned int	e_byteorder;	/* ELFDATA* */
	int		e_class;	/* ELFCLASS*  */
	Elf_Cmd		e_cmd;		/* ELF_C_* used at creation time */
	int		e_fd;		/* associated file descriptor */
-
	unsigned int	e_flags;	/* ELF_F_*, LIBELF_F_* flags */
+
	unsigned int	e_flags;	/* ELF_F_* & LIBELF_F_* flags */
	Elf_Kind	e_kind;		/* ELF_K_* */
	Elf		*e_parent; 	/* non-NULL for archive members */
-
	char	 	*e_rawfile;	/* uninterpreted bytes */
+
	char		*e_rawfile;	/* uninterpreted bytes */
	size_t		e_rawsize;	/* size of uninterpreted bytes */
	unsigned int	e_version;	/* file version */

+
	/*
+
	 * Header information for archive members.  See the
+
	 * LIBELF_F_AR_HEADER flag.
+
	 */
+
	union {
+
		Elf_Arhdr	*e_arhdr;	/* translated header */
+
		char		*e_rawhdr;	/* untranslated header */
+
	} e_hdr;
+

	union {
		struct {		/* ar(1) archives */
			off_t	e_next;	/* set by elf_rand()/elf_next() */
@@ -115,13 +130,23 @@ struct _Elf {
	} e_u;
};

+
/*
+
 * The internal descriptor wrapping the "Elf_Data" type.
+
 */
+
struct _Libelf_Data {
+
	Elf_Data	d_data;		/* The exported descriptor. */
+
	Elf_Scn		*d_scn;		/* The containing section */
+
	unsigned int	d_flags;
+
	STAILQ_ENTRY(_Libelf_Data) d_next;
+
};
+

struct _Elf_Scn {
	union {
		Elf32_Shdr	s_shdr32;
		Elf64_Shdr	s_shdr64;
	} s_shdr;
-
	STAILQ_HEAD(, _Elf_Data) s_data;	/* list of Elf_Data descriptors */
-
	STAILQ_HEAD(, _Elf_Data) s_rawdata;	/* raw data for this section */
+
	STAILQ_HEAD(, _Libelf_Data) s_data;	/* translated data */
+
	STAILQ_HEAD(, _Libelf_Data) s_rawdata;	/* raw data */
	STAILQ_ENTRY(_Elf_Scn) s_next;
	struct _Elf	*s_elf;		/* parent ELF descriptor */
	unsigned int	s_flags;	/* flags for the section as a whole */
@@ -156,20 +181,19 @@ enum {


/*
-
 * Prototypes
+
 * Function Prototypes.
 */

-
Elf_Data *_libelf_allocate_data(Elf_Scn *_s);
+
__BEGIN_DECLS
+
struct _Libelf_Data *_libelf_allocate_data(Elf_Scn *_s);
Elf	*_libelf_allocate_elf(void);
Elf_Scn	*_libelf_allocate_scn(Elf *_e, size_t _ndx);
Elf_Arhdr *_libelf_ar_gethdr(Elf *_e);
-
Elf	*_libelf_ar_open(Elf *_e);
+
Elf	*_libelf_ar_open(Elf *_e, int _reporterror);
Elf	*_libelf_ar_open_member(int _fd, Elf_Cmd _c, Elf *_ar);
int	_libelf_ar_get_member(char *_s, size_t _sz, int _base, size_t *_ret);
-
char	*_libelf_ar_get_string(const char *_buf, size_t _sz, int _rawname);
-
char	*_libelf_ar_get_name(char *_buf, size_t _sz, Elf *_e);
-
int	_libelf_ar_get_number(char *_buf, size_t _sz, int _base, size_t *_ret);
-
Elf_Arsym *_libelf_ar_process_symtab(Elf *_ar, size_t *_dst);
+
Elf_Arsym *_libelf_ar_process_bsd_symtab(Elf *_ar, size_t *_dst);
+
Elf_Arsym *_libelf_ar_process_svr4_symtab(Elf *_ar, size_t *_dst);
unsigned long _libelf_checksum(Elf *_e, int _elfclass);
void	*_libelf_ehdr(Elf *_e, int _elfclass, int _allocate);
int	_libelf_falign(Elf_Type _t, int _elfclass);
@@ -180,11 +204,13 @@ int (*_libelf_get_translator(Elf_Type _t, int _direction, int _elfclass))
void	*_libelf_getphdr(Elf *_e, int _elfclass);
void	*_libelf_getshdr(Elf_Scn *_scn, int _elfclass);
void	_libelf_init_elf(Elf *_e, Elf_Kind _kind);
-
int	_libelf_load_scn(Elf *e, void *ehdr);
+
int	_libelf_load_section_headers(Elf *e, void *ehdr);
int	_libelf_malign(Elf_Type _t, int _elfclass);
+
Elf	*_libelf_memory(char *_image, size_t _sz, int _reporterror);
size_t	_libelf_msize(Elf_Type _t, int _elfclass, unsigned int _version);
void	*_libelf_newphdr(Elf *_e, int _elfclass, size_t _count);
-
Elf_Data *_libelf_release_data(Elf_Data *_d);
+
Elf	*_libelf_open_object(int _fd, Elf_Cmd _c, int _reporterror);
+
struct _Libelf_Data *_libelf_release_data(struct _Libelf_Data *_d);
Elf	*_libelf_release_elf(Elf *_e);
Elf_Scn	*_libelf_release_scn(Elf_Scn *_s);
int	_libelf_setphnum(Elf *_e, void *_eh, int _elfclass, size_t _phnum);
@@ -194,5 +220,6 @@ int _libelf_setshstrndx(Elf *_e, void *_eh, int _elfclass,
Elf_Data *_libelf_xlate(Elf_Data *_d, const Elf_Data *_s,
    unsigned int _encoding, int _elfclass, int _direction);
int	_libelf_xlate_shtype(uint32_t _sht);
+
__END_DECLS

#endif	/* __LIBELF_H_ */
added external/libelf/_libelf_ar.h
@@ -0,0 +1,56 @@
+
/*-
+
 * Copyright (c) 2010 Joseph Koshy
+
 * 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.
+
 *
+
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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.
+
 *
+
 * $Id: _libelf_ar.h 2032 2011-10-23 09:07:00Z jkoshy $
+
 */
+

+
#ifndef	__LIBELF_AR_H_
+
#define	__LIBELF_AR_H_
+

+
/*
+
 * Prototypes and declarations needed by libelf's ar(1) archive
+
 * handling code.
+
 */
+

+
#include <ar.h>
+

+
#define	LIBELF_AR_BSD_EXTENDED_NAME_PREFIX	"#1/"
+
#define	LIBELF_AR_BSD_SYMTAB_NAME		"__.SYMDEF"
+
#define	LIBELF_AR_BSD_EXTENDED_NAME_PREFIX_SIZE	\
+
	(sizeof(LIBELF_AR_BSD_EXTENDED_NAME_PREFIX) - 1)
+

+
#define	IS_EXTENDED_BSD_NAME(NAME)				\
+
	(strncmp((NAME), LIBELF_AR_BSD_EXTENDED_NAME_PREFIX,	\
+
	 LIBELF_AR_BSD_EXTENDED_NAME_PREFIX_SIZE) == 0)
+

+

+
char	*_libelf_ar_get_string(const char *_buf, size_t _sz, int _rawname,
+
    int _svr4names);
+
char	*_libelf_ar_get_raw_name(const struct ar_hdr *_arh);
+
char	*_libelf_ar_get_translated_name(const struct ar_hdr *_arh, Elf *_ar);
+
int	_libelf_ar_get_number(const char *_buf, size_t _sz, int _base,
+
    size_t *_ret);
+

+
#endif	/* __LIBELF_AR_H_ */
added external/libelf/_libelf_config.h
@@ -0,0 +1,177 @@
+
/*-
+
 * Copyright (c) 2008-2011 Joseph Koshy
+
 * 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.
+
 *
+
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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.
+
 *
+
 * $Id: _libelf_config.h 2287 2011-12-04 06:45:47Z jkoshy $
+
 */
+

+
#ifdef	__DragonFly__
+

+
#if	defined(__amd64__)
+
#define	LIBELF_ARCH		EM_X86_64
+
#define	LIBELF_BYTEORDER	ELFDATA2LSB
+
#define	LIBELF_CLASS		ELFCLASS64
+
#elif	defined(__i386__)
+
#define	LIBELF_ARCH		EM_386
+
#define	LIBELF_BYTEORDER	ELFDATA2LSB
+
#define	LIBELF_CLASS		ELFCLASS32
+
#endif
+

+
#endif	/* __DragonFly__ */
+

+
#ifdef __FreeBSD__
+

+
/*
+
 * Define LIBELF_{ARCH,BYTEORDER,CLASS} based on the machine architecture.
+
 * See also: <machine/elf.h>.
+
 */
+

+
#if	defined(__amd64__)
+

+
#define	LIBELF_ARCH		EM_X86_64
+
#define	LIBELF_BYTEORDER	ELFDATA2LSB
+
#define	LIBELF_CLASS		ELFCLASS64
+

+
#elif	defined(__arm__)
+

+
#define	LIBELF_ARCH		EM_ARM
+
#if	defined(__ARMEB__)	/* Big-endian ARM. */
+
#define	LIBELF_BYTEORDER	ELFDATA2MSB
+
#else
+
#define	LIBELF_BYTEORDER	ELFDATA2LSB
+
#endif
+
#define	LIBELF_CLASS		ELFCLASS32
+

+
#elif	defined(__i386__)
+

+
#define	LIBELF_ARCH		EM_386
+
#define	LIBELF_BYTEORDER	ELFDATA2LSB
+
#define	LIBELF_CLASS		ELFCLASS32
+

+
#elif	defined(__ia64__)
+

+
#define	LIBELF_ARCH		EM_IA_64
+
#define	LIBELF_BYTEORDER	ELFDATA2LSB
+
#define	LIBELF_CLASS		ELFCLASS64
+

+
#elif	defined(__mips__)
+

+
#define	LIBELF_ARCH		EM_MIPS
+
#if	defined(__MIPSEB__)
+
#define	LIBELF_BYTEORDER	ELFDATA2MSB
+
#else
+
#define	LIBELF_BYTEORDER	ELFDATA2LSB
+
#endif
+
#define	LIBELF_CLASS		ELFCLASS32
+

+
#elif	defined(__powerpc__)
+

+
#define	LIBELF_ARCH		EM_PPC
+
#define	LIBELF_BYTEORDER	ELFDATA2MSB
+
#define	LIBELF_CLASS		ELFCLASS32
+

+
#elif	defined(__sparc__)
+

+
#define	LIBELF_ARCH		EM_SPARCV9
+
#define	LIBELF_BYTEORDER	ELFDATA2MSB
+
#define	LIBELF_CLASS		ELFCLASS64
+

+
#else
+
#error	Unknown FreeBSD architecture.
+
#endif
+
#endif  /* __FreeBSD__ */
+

+
/*
+
 * Definitions for Minix3.
+
 */
+
#ifdef __minix
+

+
#define	LIBELF_ARCH		EM_386
+
#define	LIBELF_BYTEORDER	ELFDATA2LSB
+
#define	LIBELF_CLASS		ELFCLASS32
+

+
#endif	/* __minix */
+

+
#ifdef __NetBSD__
+

+
#include <machine/elf_machdep.h>
+

+
#if	!defined(ARCH_ELFSIZE)
+
#error	ARCH_ELFSIZE is not defined.
+
#endif
+

+
#if	ARCH_ELFSIZE == 32
+
#define	LIBELF_ARCH		ELF32_MACHDEP_ID
+
#define	LIBELF_BYTEORDER	ELF32_MACHDEP_ENDIANNESS
+
#define	LIBELF_CLASS		ELFCLASS32
+
#define	Elf_Note		Elf32_Nhdr
+
#else
+
#define	LIBELF_ARCH		ELF64_MACHDEP_ID
+
#define	LIBELF_BYTEORDER	ELF64_MACHDEP_ENDIANNESS
+
#define	LIBELF_CLASS		ELFCLASS64
+
#define	Elf_Note		Elf64_Nhdr
+
#endif
+

+
#endif	/* __NetBSD__ */
+

+
#if defined(__OpenBSD__)
+

+
#include <machine/exec.h>
+

+
#define	LIBELF_ARCH		ELF_TARG_MACH
+
#define	LIBELF_BYTEORDER	ELF_TARG_DATA
+
#define	LIBELF_CLASS		ELF_TARG_CLASS
+

+
#endif
+

+
/*
+
 * GNU & Linux compatibility.
+
 *
+
 * `__linux__' is defined in an environment runs the Linux kernel and glibc.
+
 * `__GNU__' is defined in an environment runs a GNU kernel (Hurd) and glibc.
+
 * `__GLIBC__' is defined for an environment that runs glibc over a non-GNU
+
 *     kernel such as GNU/kFreeBSD.
+
 */
+

+
#if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)
+

+
#if defined(__linux__)
+

+
#include "native-elf-format.h"
+

+
#define	LIBELF_CLASS		ELFTC_CLASS
+
#define	LIBELF_ARCH		ELFTC_ARCH
+
#define	LIBELF_BYTEORDER	ELFTC_BYTEORDER
+

+
#endif	/* defined(__linux__) */
+

+
#if	LIBELF_CLASS == ELFCLASS32
+
#define	Elf_Note		Elf32_Nhdr
+
#elif   LIBELF_CLASS == ELFCLASS64
+
#define	Elf_Note		Elf64_Nhdr
+
#else
+
#error  LIBELF_CLASS needs to be one of ELFCLASS32 or ELFCLASS64
+
#endif
+

+
#endif /* defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) */
modified external/libelf/elf.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006,2007 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006-2008,2011 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: head/lib/libelf/elf.3 236438 2012-06-02 08:47:26Z joel $
+
.\" $Id: elf.3 1730 2011-08-14 10:03:34Z jkoshy $
.\"
-
.Dd October 21, 2007
-
.Dt ELF 3
+
.Dd August 14, 2011
.Os
+
.Dt ELF 3
.Sh NAME
.Nm elf
.Nd API for manipulating ELF objects
@@ -111,13 +111,11 @@ constraints.
Accordingly, the
.Xr ELF 3
library offers translation facilities
-
.Po
-
.Xr elf32_xlatetof 3 ,
+
.Xr ( elf32_xlatetof 3 ,
.Xr elf32_xlatetom 3 ,
.Xr elf64_xlatetof 3
and
-
.Xr elf64_xlatetom 3
-
.Pc
+
.Xr elf64_xlatetom 3 )
to and from these
representations and also provides higher-level APIs that retrieve and store
data from the ELF object in a transparent manner.
@@ -146,24 +144,24 @@ In the current implementation, all three versions have to be
.Ss Namespace use
The ELF library uses the following prefixes:
.Bl -tag -width "ELF_F_*"
-
.It elf_*
+
.It Dv elf_
Used for class-independent functions.
-
.It elf32_*
+
.It Dv elf32_
Used for functions working with 32 bit ELF objects.
-
.It elf64_*
+
.It Dv elf64_
Used for functions working with 64 bit ELF objects.
-
.It Elf_*
+
.It Dv Elf_
Used for class-independent data types.
-
.It ELF_C_*
+
.It Dv ELF_C_
Used for command values used in a few functions.
These symbols are defined as members of the
-
.Vt Elf_Cmd
+
.Vt Dv Elf_Cmd
enumeration.
-
.It ELF_E_*
+
.It Dv ELF_E_
Used for error numbers.
-
.It ELF_F_*
+
.It Dv ELF_F_
Used for flags.
-
.It ELF_K_*
+
.It Dv ELF_K_
These constants define the kind of file associated with an ELF
descriptor.
See
@@ -171,12 +169,18 @@ See
The symbols are defined by the
.Vt Elf_Kind
enumeration.
-
.It ELF_T_*
+
.It Dv ELF_T_
These values are defined by the
.Vt Elf_Type
enumeration, and denote the types of ELF data structures
that can be present in an ELF object.
.El
+
.Pp
+
In addition, the library uses symbols with prefixes
+
.Dv _ELF
+
and
+
.Dv _libelf
+
for its internal use.
.Ss Descriptors
Applications communicate with the library using descriptors.
These are:
@@ -239,11 +243,13 @@ An
.Vt Elf_Data
data structure describes an individual chunk of a ELF file as
represented in memory.
-
It has the following application visible members:
+
It has the following application-visible members:
.Bl -tag -width ".Vt unsigned int d_version" -compact
.It Vt "uint64_t d_align"
The in-file alignment of the data buffer within its containing ELF section.
-
This value must be a power of two.
+
This value must be non-zero and a power of two.
+
.It Vt "void *d_buf"
+
A pointer to data in memory.
.It Vt "uint64_t d_off"
The offset with the containing section where this descriptors data
would be placed.
@@ -251,8 +257,6 @@ This field will be computed by the library unless the application
requests full control of the ELF object's layout.
.It Vt "uint64_t d_size"
The number of bytes of data in this descriptor.
-
.It Vt "void *d_buf"
-
A pointer to data in memory.
.It Vt "Elf_Type d_type"
The ELF type (see below) of the data in this descriptor.
.It Vt "unsigned int d_version"
@@ -266,7 +270,9 @@ descriptors.
Existing data descriptors associated with an ELF section may be
structures are retrieved using the
.Fn elf_getdata
-
function.
+
and
+
.Fn elf_rawdata
+
functions.
The
.Fn elf_newdata
function may be used to attach new data descriptors to an ELF section.
@@ -305,6 +311,8 @@ Records used in a section of type
.Dv SHT_DYNAMIC .
.It Dv ELF_T_EHDR
ELF executable header.
+
.It Dv ELF_T_GNUHASH
+
GNU-style hash tables.
.It Dv ELF_T_HALF
16-bit unsigned words.
.It Dv ELF_T_LWORD
@@ -381,13 +389,14 @@ See
.It Dv SHT_SUNW_move Ta Dv ELF_T_MOVE Ta ELF move records.
.It Dv SHT_SUNW_syminfo Ta Dv ELF_T_SYMINFO Ta Additional symbol flags.
.El
+
.TE
.Ss Functional Grouping
This section contains a brief overview of the available functionality
in the ELF library.
Each function listed here is described further in its own manual page.
-
.Bl -tag -width 2n
+
.Bl -tag -width indent
.It "Archive Access"
-
.Bl -tag -width 17n -compact
+
.Bl -tag -compact
.It Fn elf_getarsym
Retrieve the archive symbol table.
.It Fn elf_getarhdr
@@ -404,7 +413,7 @@ Random access inside an
archive.
.El
.It "Data Structures"
-
.Bl -tag -width 17n -compact
+
.Bl -tag -compact
.It Fn elf_getdata
Retrieve translated data for an ELF section.
.It Fn elf_getscn
@@ -437,7 +446,7 @@ Allocate an Executable Header in an ELF object.
Allocate or resize the Program Header Table in an ELF object.
.El
.It "Data Translation"
-
.Bl -tag -width 17n -compact
+
.Bl -tag -compact
.It Fn elf32_xlatetof , Fn elf64_xlatetof
Translate an ELF data structure from its native representation to its
file representation.
@@ -446,14 +455,14 @@ Translate an ELF data structure from its file representation to a
native representation.
.El
.It "Error Reporting"
-
.Bl -tag -width 17n -compact
+
.Bl -tag -compact
.It Fn elf_errno
Retrieve the current error.
.It Fn elf_errmsg
Retrieve a human readable description of the current error.
.El
.It "Initialization"
-
.Bl -tag -width 17n -compact
+
.Bl -tag -compact
.It Fn elf_begin
Opens an
.Xr ar 1
@@ -463,12 +472,12 @@ Close an ELF descriptor and release all its resources.
.It Fn elf_memory
Opens an
.Xr ar 1
-
archive or ELF object present in a memory area.
+
archive or ELF object present in a memory arena.
.It Fn elf_version
Sets the operating version.
.El
.It "IO Control"
-
.Bl -tag -width 17n -compact
+
.Bl -tag -width ".Fn elf_setshstrndx" -compact
.It Fn elf_cntl
Manage the association between and ELF descriptor and its underlying file.
.It Fn elf_flagdata
@@ -492,7 +501,7 @@ Recompute ELF object layout and optionally write the modified object
back to the underlying file.
.El
.It "Queries"
-
.Bl -tag -width 17n -compact
+
.Bl -tag -width ".Fn elf_getshstrndx" -compact
.It Fn elf32_checksum , Fn elf64_checkum
Compute checksum of an ELF object.
.It Fn elf_getident
@@ -523,7 +532,7 @@ flag on an ELF descriptor using
.Xr elf_flagelf 3 ,
following which the library will use the data offsets and alignments
specified by the application when laying out the file.
-
Application control of file layout is described further in the
+
Application control of file layout is described further in the 
.Xr elf_update 3
manual page.
.Pp
@@ -563,7 +572,7 @@ descriptor and can set the
member of the descriptor to point to a region of memory allocated
using
.Xr malloc 3 .
-
It is the applications responsibility to free this area, though the
+
It is the applications responsibility to free this arena, though the
library will reclaim the space used by the
.Vt Elf_Data
descriptor itself.
added external/libelf/elf.c
@@ -0,0 +1,40 @@
+
/*-
+
 * Copyright (c) 2006,2008,2011 Joseph Koshy
+
 * 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.
+
 *
+
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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.
+
 */
+

+
#include <libelf.h>
+

+
#include "_libelf.h"
+

+
ELFTC_VCSID("$Id: elf.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

+
struct _libelf_globals _libelf = {
+
	.libelf_arch		= LIBELF_ARCH,
+
	.libelf_byteorder	= LIBELF_BYTEORDER,
+
	.libelf_class		= LIBELF_CLASS,
+
	.libelf_error		= 0,
+
	.libelf_fillchar	= 0,
+
	.libelf_version		= EV_NONE
+
};
modified external/libelf/elf_begin.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008-2011 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: head/lib/libelf/elf_begin.3 236626 2012-06-05 18:19:52Z joel $
+
.\" $Id: elf_begin.3 2313 2011-12-11 06:19:24Z jkoshy $ 
.\"
-
.Dd June 20, 2010
-
.Dt ELF_BEGIN 3
+
.Dd December 11, 2011
.Os
+
.Dt ELF_BEGIN 3
.Sh NAME
.Nm elf_begin
.Nd open an ELF file or ar(1) archive
@@ -81,26 +81,34 @@ and
are ignored, and no additional error is signalled.
.It ELF_C_READ
This value is to be when the application wishes to examine (but not
-
modify) the contents of the file specified by argument
-
.Ar fd .
+
modify) the contents of the file specified by the arguments
+
.Ar fd
+
and
+
.Ar elf .
It can be used for both
.Xr ar 1
-
archives and for regular ELF files.
+
archives and for ELF objects.
.Pp
-
Argument
-
.Ar fd
-
should have been opened for reading.
If argument
.Ar elf
-
is NULL, the library will allocate a new ELF descriptor for
-
the file being processed.
+
is NULL, the library will allocate a new ELF descriptor for the file
+
being processed.
+
The argument
+
.Ar fd
+
should have been opened for reading.
+
.Pp
If argument
.Ar elf
is not NULL, and references a regular ELF file previously opened with
.Fn elf_begin ,
-
then the activation count for
+
then the activation count for the descriptor referenced by argument
.Ar elf
is incremented.
+
The value in argument
+
.Ar fd
+
should match that used to open the descriptor argument
+
.Ar elf .
+
.Pp
If argument
.Ar elf
is not NULL, and references a descriptor for an
@@ -111,9 +119,24 @@ a descriptor for an element in the archive is returned as
described in the section
.Sx "Processing ar(1) archives"
below.
+
The value for argument
+
.Ar fd
+
should match that used to open the archive earlier.
+
.Pp
+
If argument
+
.Ar elf
+
is not NULL, and references an
+
.Xr ar 1
+
archive opened earlier with
+
.Fn elf_memory ,
+
then the value of the argument
+
.Ar fd
+
is ignored.
.It Dv ELF_C_RDWR
-
The command is used to prepare an ELF file for reading and writing.
-
It is not supported for archives.
+
This command is used to prepare an ELF file for reading and writing.
+
This command is not supported for
+
.Xr ar 1
+
archives.
.Pp
Argument
.Ar fd
@@ -134,14 +157,11 @@ and
in this case the library will increment the activation count for descriptor
.Ar elf
and return the same descriptor.
-
Changes to the in-memory image of the ELF file are written back to
+
.Pp
+
Changes to the in-memory image of the ELF file may be written back to
disk using the
.Xr elf_update 3
function.
-
.Pp
-
This command is not valid for
-
.Xr ar 1
-
archives.
.It Dv ELF_C_WRITE
This command is used when the application wishes to create a new ELF
file.
@@ -150,8 +170,7 @@ Argument
should have been opened for writing.
Argument
.Ar elf
-
is ignored, and the previous contents of file referenced by
-
argument
+
is ignored, and the previous contents of file referenced by argument
.Ar fd
are overwritten.
.El
@@ -228,8 +247,9 @@ The archive denoted by argument
.Ar elf
could not be parsed.
.It Bq Er ELF_E_ARGUMENT
-
An unrecognized value was specified in argument
-
.Ar cmd .
+
The value in argument
+
.Ar cmd
+
was unrecognized.
.It Bq Er ELF_E_ARGUMENT
A non-null value for argument
.Ar elf
@@ -252,15 +272,26 @@ was created.
.It Bq Er ELF_E_ARGUMENT
An
.Xr ar 1
-
archive was opened with
+
archive was opened with with
.Ar cmd
set to
.Dv ELF_C_RDWR .
+
.It Bq Er ELF_E_ARGUMENT
+
The file referenced by argument
+
.Ar fd
+
was empty.
+
.It Bq Er ELF_E_ARGUMENT
+
The underlying file for argument
+
.Ar fd
+
was of an unsupported type.
.It Bq Er ELF_E_IO
-
Function
-
.Fn elf_begin
-
was unable to truncate a file opened for writing using
-
.Dv ELF_C_WRITE .
+
The file descriptor in argument
+
.Ar fd
+
was invalid.
+
.It Bq Er ELF_E_IO
+
The file descriptor in argument
+
.Ar fd
+
could not be read or written to.
.It Bq Er ELF_E_RESOURCE
An out of memory condition was encountered.
.It Bq Er ELF_E_SEQUENCE
@@ -268,6 +299,10 @@ Function
.Fn elf_begin
was called before a working version was established with
.Xr elf_version 3 .
+
.It Bq Er ELF_E_VERSION
+
The ELF object referenced by argument
+
.Ar fd
+
was of an unsupported ELF version.
.El
.Sh SEE ALSO
.Xr elf 3 ,
modified external/libelf/elf_begin.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008-2011 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -24,63 +24,11 @@
 * SUCH DAMAGE.
 */

-
#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_begin.c 210351 2010-07-21 13:18:57Z kaiw $");
-

-
#include <sys/types.h>
-
#include <sys/errno.h>
-
#include <sys/mman.h>
-
#include <sys/stat.h>
-

-
#include <ar.h>
-
#include <ctype.h>
#include <libelf.h>
-
#include <unistd.h>

#include "_libelf.h"

-
static Elf *
-
_libelf_open_object(int fd, Elf_Cmd c)
-
{
-
	Elf *e;
-
	void *m;
-
	struct stat sb;
-

-
	/*
-
	 * 'Raw' files are always mapped with 'PROT_READ'.  At
-
	 * elf_update(3) time for files opened with ELF_C_RDWR the
-
	 * mapping is unmapped, file data is written to using write(2)
-
	 * and then the raw data is immediately mapped back in.
-
	 */
-
	if (fstat(fd, &sb) < 0) {
-
		LIBELF_SET_ERROR(IO, errno);
-
		return (NULL);
-
	}
-

-
	m = NULL;
-
	if ((m = mmap(NULL, (size_t) sb.st_size, PROT_READ, MAP_PRIVATE, fd,
-
	    (off_t) 0)) == MAP_FAILED) {
-
		LIBELF_SET_ERROR(IO, errno);
-
		return (NULL);
-
	}
-

-
	if ((e = elf_memory(m, (size_t) sb.st_size)) == NULL) {
-
		(void) munmap(m, (size_t) sb.st_size);
-
		return (NULL);
-
	}
-

-
	e->e_flags |= LIBELF_F_MMAP;
-
	e->e_fd = fd;
-
	e->e_cmd = c;
-

-
	if (c == ELF_C_RDWR && e->e_kind == ELF_K_AR) {
-
		(void) elf_end(e);
-
		LIBELF_SET_ERROR(ARGUMENT, 0);
-
		return (NULL);
-
	}
-

-
	return (e);
-
}
+
ELFTC_VCSID("$Id: elf_begin.c 2364 2011-12-28 17:55:25Z jkoshy $");

Elf *
elf_begin(int fd, Elf_Cmd c, Elf *a)
@@ -99,28 +47,12 @@ elf_begin(int fd, Elf_Cmd c, Elf *a)
		return (NULL);

	case ELF_C_WRITE:
-

-
		if (a != NULL) { /* not allowed for ar(1) archives. */
-
			LIBELF_SET_ERROR(ARGUMENT, 0);
-
			return (NULL);
-
		}
-

		/*
-
		 * Check writeability of `fd' immediately and fail if
-
		 * not writeable.
+
		 * The ELF_C_WRITE command is required to ignore the
+
		 * descriptor passed in.
		 */
-
		if (ftruncate(fd, (off_t) 0) < 0) {
-
			LIBELF_SET_ERROR(IO, errno);
-
			return (NULL);
-
		}
-

-
		if ((e = _libelf_allocate_elf()) != NULL) {
-
			_libelf_init_elf(e, ELF_K_ELF);
-
			e->e_byteorder = LIBELF_PRIVATE(byteorder);
-
			e->e_fd = fd;
-
			e->e_cmd = c;
-
		}
-
		return (e);
+
		a = NULL;
+
		break;

	case ELF_C_RDWR:
		if (a != NULL) { /* not allowed for ar(1) archives. */
@@ -149,7 +81,7 @@ elf_begin(int fd, Elf_Cmd c, Elf *a)
	}

	if (a == NULL)
-
		e = _libelf_open_object(fd, c);
+
		e = _libelf_open_object(fd, c, 1);
	else if (a->e_kind == ELF_K_AR)
		e = _libelf_ar_open_member(a->e_fd, c, a);
	else
modified external/libelf/elf_cntl.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_cntl.3 219210 2011-03-02 21:59:53Z uqs $
+
.\" $Id: elf_cntl.3 289 2009-01-08 08:26:08Z jkoshy $ 
.\"
.Dd August 9, 2006
-
.Dt ELF_CNTL 3
.Os
+
.Dt ELF_CNTL 3
.Sh NAME
.Nm elf_cntl
.Nd control an elf file descriptor
modified external/libelf/elf_cntl.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -24,13 +24,12 @@
 * SUCH DAMAGE.
 */

-
#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_cntl.c 164190 2006-11-11 17:16:35Z jkoshy $");
-

#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_cntl.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

int
elf_cntl(Elf *e, Elf_Cmd c)
{
modified external/libelf/elf_data.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008,2011 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -24,9 +24,6 @@
 * SUCH DAMAGE.
 */

-
#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_data.c 221595 2011-05-07 11:04:36Z kaiw $");
-

#include <assert.h>
#include <errno.h>
#include <libelf.h>
@@ -34,31 +31,41 @@ __FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_data.c 221595 2011-05-07 11:04:36Z

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_data.c 2272 2011-12-03 17:07:31Z jkoshy $");

Elf_Data *
-
elf_getdata(Elf_Scn *s, Elf_Data *d)
+
elf_getdata(Elf_Scn *s, Elf_Data *ed)
{
	Elf *e;
-
	size_t fsz, msz, count;
-
	int elfclass, elftype;
	unsigned int sh_type;
+
	int elfclass, elftype;
+
	size_t fsz, msz, count;
+
	struct _Libelf_Data *d;
	uint64_t sh_align, sh_offset, sh_size;
	int (*xlate)(char *_d, size_t _dsz, char *_s, size_t _c, int _swap);

-
	if (s == NULL || (e = s->s_elf) == NULL || e->e_kind != ELF_K_ELF ||
+
	d = (struct _Libelf_Data *) ed;
+

+
	if (s == NULL || (e = s->s_elf) == NULL ||
	    (d != NULL && s != d->d_scn)) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (NULL);
	}

+
	assert(e->e_kind == ELF_K_ELF);
+

	if (d == NULL && (d = STAILQ_FIRST(&s->s_data)) != NULL)
-
		return (d);
+
		return (&d->d_data);

	if (d != NULL)
-
		return (STAILQ_NEXT(d, d_next));
+
		return (&STAILQ_NEXT(d, d_next)->d_data);

	if (e->e_rawfile == NULL) {
-
		LIBELF_SET_ERROR(SEQUENCE, 0);
+
		/*
+
		 * In the ELF_C_WRITE case, there is no source that
+
		 * can provide data for the section.
+
		 */
+
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (NULL);
	}

@@ -78,8 +85,10 @@ elf_getdata(Elf_Scn *s, Elf_Data *d)
		sh_align  = s->s_shdr.s_shdr64.sh_addralign;
	}

-
	if (sh_type == SHT_NULL)
+
	if (sh_type == SHT_NULL) {
+
		LIBELF_SET_ERROR(SECTION, 0);
		return (NULL);
+
	}

	if ((elftype = _libelf_xlate_shtype(sh_type)) < ELF_T_FIRST ||
	    elftype > ELF_T_LAST || (sh_type != SHT_NOBITS &&
@@ -108,28 +117,29 @@ elf_getdata(Elf_Scn *s, Elf_Data *d)
	if ((d = _libelf_allocate_data(s)) == NULL)
		return (NULL);

-
	d->d_buf     = NULL;
-
	d->d_off     = 0;
-
	d->d_align   = sh_align;
-
	d->d_size    = msz * count;
-
	d->d_type    = elftype;
-
	d->d_version = e->e_version;
+
	d->d_data.d_buf     = NULL;
+
	d->d_data.d_off     = 0;
+
	d->d_data.d_align   = sh_align;
+
	d->d_data.d_size    = msz * count;
+
	d->d_data.d_type    = elftype;
+
	d->d_data.d_version = e->e_version;

	if (sh_type == SHT_NOBITS || sh_size == 0) {
	        STAILQ_INSERT_TAIL(&s->s_data, d, d_next);
-
		return (d);
+
		return (&d->d_data);
        }

-
	if ((d->d_buf = malloc(msz*count)) == NULL) {
+
	if ((d->d_data.d_buf = malloc(msz*count)) == NULL) {
		(void) _libelf_release_data(d);
		LIBELF_SET_ERROR(RESOURCE, 0);
		return (NULL);
	}

-
	d->d_flags  |= LIBELF_F_MALLOCED;
+
	d->d_flags  |= LIBELF_F_DATA_MALLOCED;

	xlate = _libelf_get_translator(elftype, ELF_TOMEMORY, elfclass);
-
	if (!(*xlate)(d->d_buf, d->d_size, e->e_rawfile + sh_offset, count,
+
	if (!(*xlate)(d->d_data.d_buf, d->d_data.d_size,
+
	    e->e_rawfile + sh_offset, count,
	    e->e_byteorder != LIBELF_PRIVATE(byteorder))) {
		_libelf_release_data(d);
		LIBELF_SET_ERROR(DATA, 0);
@@ -138,21 +148,22 @@ elf_getdata(Elf_Scn *s, Elf_Data *d)

	STAILQ_INSERT_TAIL(&s->s_data, d, d_next);

-
	return (d);
+
	return (&d->d_data);
}

Elf_Data *
elf_newdata(Elf_Scn *s)
{
	Elf *e;
-
	Elf_Data *d;
+
	struct _Libelf_Data *d;

-
	if (s == NULL || (e = s->s_elf) == NULL ||
-
	    e->e_kind != ELF_K_ELF) {
+
	if (s == NULL || (e = s->s_elf) == NULL) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (NULL);
	}

+
	assert(e->e_kind == ELF_K_ELF);
+

	/*
	 * elf_newdata() has to append a data descriptor, so
	 * bring in existing section data if not already present.
@@ -166,16 +177,16 @@ elf_newdata(Elf_Scn *s)

	STAILQ_INSERT_TAIL(&s->s_data, d, d_next);

-
	d->d_align = 1;
-
	d->d_buf = NULL;
-
	d->d_off = (uint64_t) ~0;
-
	d->d_size = 0;
-
	d->d_type = ELF_T_BYTE;
-
	d->d_version = LIBELF_PRIVATE(version);
+
	d->d_data.d_align = 1;
+
	d->d_data.d_buf = NULL;
+
	d->d_data.d_off = (uint64_t) ~0;
+
	d->d_data.d_size = 0;
+
	d->d_data.d_type = ELF_T_BYTE;
+
	d->d_data.d_version = LIBELF_PRIVATE(version);

	(void) elf_flagscn(s, ELF_C_SET, ELF_F_DIRTY);

-
	return (d);
+
	return (&d->d_data);
}

/*
@@ -184,24 +195,28 @@ elf_newdata(Elf_Scn *s)
 */

Elf_Data *
-
elf_rawdata(Elf_Scn *s, Elf_Data *d)
+
elf_rawdata(Elf_Scn *s, Elf_Data *ed)
{
	Elf *e;
	int elf_class;
	uint32_t sh_type;
+
	struct _Libelf_Data *d;
	uint64_t sh_align, sh_offset, sh_size;

-
	if (s == NULL || (e = s->s_elf) == NULL ||
-
	    e->e_kind != ELF_K_ELF || e->e_rawfile == NULL) {
+
	if (s == NULL || (e = s->s_elf) == NULL || e->e_rawfile == NULL) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (NULL);
	}

+
	assert(e->e_kind == ELF_K_ELF);
+

+
	d = (struct _Libelf_Data *) ed;
+

	if (d == NULL && (d = STAILQ_FIRST(&s->s_rawdata)) != NULL)
-
		return (d);
+
		return (&d->d_data);

	if (d != NULL)
-
		return (STAILQ_NEXT(d, d_next));
+
		return (&STAILQ_NEXT(d, d_next)->d_data);

	elf_class = e->e_class;

@@ -225,15 +240,15 @@ elf_rawdata(Elf_Scn *s, Elf_Data *d)
	if ((d = _libelf_allocate_data(s)) == NULL)
		return (NULL);

-
	d->d_buf     = (sh_type == SHT_NOBITS || sh_size == 0) ? NULL :
+
	d->d_data.d_buf = (sh_type == SHT_NOBITS || sh_size == 0) ? NULL :
	    e->e_rawfile + sh_offset;
-
	d->d_off     = 0;
-
	d->d_align   = sh_align;
-
	d->d_size    = sh_size;
-
	d->d_type    = ELF_T_BYTE;
-
	d->d_version = e->e_version;
+
	d->d_data.d_off     = 0;
+
	d->d_data.d_align   = sh_align;
+
	d->d_data.d_size    = sh_size;
+
	d->d_data.d_type    = ELF_T_BYTE;
+
	d->d_data.d_version = e->e_version;

	STAILQ_INSERT_TAIL(&s->s_rawdata, d, d_next);

-
	return (d);
+
	return (&d->d_data);
}
modified external/libelf/elf_end.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_end.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: elf_end.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd June 29, 2006
-
.Dt ELF_END 3
.Os
+
.Dt ELF_END 3
.Sh NAME
.Nm elf_end
.Nd release an ELF descriptor
modified external/libelf/elf_end.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008-2009,2011 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,9 +25,6 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_end.c 164190 2006-11-11 17:16:35Z jkoshy $");
-

-
#include <sys/mman.h>

#include <assert.h>
#include <libelf.h>
@@ -35,6 +32,12 @@ __FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_end.c 164190 2006-11-11 17:16:35Z

#include "_libelf.h"

+
#if	ELFTC_HAVE_MMAP
+
#include <sys/mman.h>
+
#endif
+

+
ELFTC_VCSID("$Id: elf_end.c 2240 2011-11-28 06:36:48Z jkoshy $");
+

int
elf_end(Elf *e)
{
@@ -65,7 +68,8 @@ elf_end(Elf *e)
			/*
			 * Reclaim all section descriptors.
			 */
-
			STAILQ_FOREACH_SAFE(scn, &e->e_u.e_elf.e_scn, s_next, tscn)
+
			STAILQ_FOREACH_SAFE(scn, &e->e_u.e_elf.e_scn, s_next,
+
			    tscn)
 				scn = _libelf_release_scn(scn);
			break;
		case ELF_K_NUM:
@@ -74,8 +78,14 @@ elf_end(Elf *e)
			break;
		}

-
		if (e->e_flags & LIBELF_F_MMAP)
-
			(void) munmap(e->e_rawfile, e->e_rawsize);
+
		if (e->e_rawfile) {
+
			if (e->e_flags & LIBELF_F_RAWFILE_MALLOC)
+
				free(e->e_rawfile);
+
#if	ELFTC_HAVE_MMAP
+
			else if (e->e_flags & LIBELF_F_RAWFILE_MMAP)
+
				(void) munmap(e->e_rawfile, e->e_rawsize);
+
#endif
+
		}

		sv = e;
		if ((e = e->e_parent) != NULL)
@@ -85,4 +95,3 @@ elf_end(Elf *e)

	return (0);
}
-

modified external/libelf/elf_errmsg.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_errmsg.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: elf_errmsg.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd June 11, 2006
-
.Dt ELF_ERRMSG 3
.Os
+
.Dt ELF_ERRMSG 3
.Sh NAME
.Nm elf_errmsg ,
.Nm elf_errno
modified external/libelf/elf_errmsg.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008,2011 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,18 +25,20 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: head/lib/libelf/elf_errmsg.c 241720 2012-10-19 05:43:38Z ed $");

#include <libelf.h>
+
#include <stdio.h>
#include <string.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_errmsg.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

/*
 * Retrieve a human readable translation for an error message.
 */

-
static const char *_libelf_errors[] = {
+
const char *_libelf_errors[] = {
#define	DEFINE_ERROR(N,S)	[ELF_E_##N] = S
	DEFINE_ERROR(NONE,	"No Error"),
	DEFINE_ERROR(ARCHIVE,	"Malformed ar(1) archive"),
@@ -62,7 +64,8 @@ elf_errmsg(int error)
{
	int oserr;

-
	if (error == 0 && (error = LIBELF_PRIVATE(error)) == 0)
+
	if (error == ELF_E_NONE &&
+
	    (error = LIBELF_PRIVATE(error)) == 0)
	    return NULL;
	else if (error == -1)
	    error = LIBELF_PRIVATE(error);
@@ -70,31 +73,13 @@ elf_errmsg(int error)
	oserr = error >> LIBELF_OS_ERROR_SHIFT;
	error &= LIBELF_ELF_ERROR_MASK;

-
	if (error < 0 || error >= ELF_E_NUM)
+
	if (error < ELF_E_NONE || error >= ELF_E_NUM)
		return _libelf_errors[ELF_E_NUM];
	if (oserr) {
-
		strlcpy(LIBELF_PRIVATE(msg), _libelf_errors[error],
-
		    sizeof(LIBELF_PRIVATE(msg)));
-
		strlcat(LIBELF_PRIVATE(msg), ": ", sizeof(LIBELF_PRIVATE(msg)));
-
		strlcat(LIBELF_PRIVATE(msg), strerror(oserr),
-
		    sizeof(LIBELF_PRIVATE(msg)));
+
		(void) snprintf(LIBELF_PRIVATE(msg),
+
		    sizeof(LIBELF_PRIVATE(msg)), "%s: %s",
+
		    _libelf_errors[error], strerror(oserr));
		return (const char *)&LIBELF_PRIVATE(msg);
	}
	return _libelf_errors[error];
}
-

-
#if	defined(LIBELF_TEST_HOOKS)
-

-
const char *
-
_libelf_get_unknown_error_message(void)
-
{
-
	return _libelf_errors[ELF_E_NUM];
-
}
-

-
const char *
-
_libelf_get_no_error_message(void)
-
{
-
	return _libelf_errors[0];
-
}
-

-
#endif	/* LIBELF_TEST_HOOKS */
modified external/libelf/elf_errno.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008,2011 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,12 +25,13 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_errno.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_errno.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

int
elf_errno(void)
{
@@ -40,19 +41,3 @@ elf_errno(void)
	LIBELF_PRIVATE(error) = 0;
	return (old & LIBELF_ELF_ERROR_MASK);
}
-

-
#if	defined(LIBELF_TEST_HOOKS)
-

-
int
-
_libelf_get_max_error(void)
-
{
-
	return ELF_E_NUM;
-
}
-

-
void
-
_libelf_set_error(int error)
-
{
-
	LIBELF_PRIVATE(error) = error;
-
}
-

-
#endif	/* LIBELF_TEST_HOOKS */
modified external/libelf/elf_fill.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_fill.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: elf_fill.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd June 11, 2006
-
.Dt ELF_FILL 3
.Os
+
.Dt ELF_FILL 3
.Sh NAME
.Nm elf_fill
.Nd set fill byte for inter-section padding
modified external/libelf/elf_fill.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,12 +25,13 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_fill.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_fill.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

void
elf_fill(int fill)
{
modified external/libelf/elf_flag.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008-2009,2011 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,35 +25,58 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_flag.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_flag.c 2272 2011-12-03 17:07:31Z jkoshy $");
+

+
unsigned int
+
elf_flagarhdr(Elf_Arhdr *a, Elf_Cmd c, unsigned int flags)
+
{
+
	unsigned int r;
+

+
	if (a == NULL)
+
		return (0);
+

+
	if ((c != ELF_C_SET && c != ELF_C_CLR) ||
+
	    (flags & ~ELF_F_DIRTY) != 0) {
+
		LIBELF_SET_ERROR(ARGUMENT, 0);
+
		return (0);
+
	}
+

+
	if (c == ELF_C_SET)
+
		r = a->ar_flags |= flags;
+
	else
+
		r = a->ar_flags &= ~flags;
+

+
	return (r & LIBELF_F_API_MASK);
+
}
+

unsigned int
elf_flagdata(Elf_Data *d, Elf_Cmd c, unsigned int flags)
{
-
	Elf *e;
-
	Elf_Scn *scn;
	unsigned int r;
+
	struct _Libelf_Data *ld;

	if (d == NULL)
		return (0);

-
	if ((c != ELF_C_SET && c != ELF_C_CLR) || (scn = d->d_scn) == NULL ||
-
	    (e = scn->s_elf) == NULL || e->e_kind != ELF_K_ELF ||
+
	if ((c != ELF_C_SET && c != ELF_C_CLR) ||
	    (flags & ~ELF_F_DIRTY) != 0) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (0);
	}

+
	ld = (struct _Libelf_Data *) d;
+

	if (c == ELF_C_SET)
-
	    r = scn->s_flags |= flags;
+
		r = ld->d_flags |= flags;
	else
-
	    r = scn->s_flags &= ~flags;
+
		r = ld->d_flags &= ~flags;

-
	return (r);
+
	return (r & LIBELF_F_API_MASK);
}

unsigned int
@@ -95,16 +118,27 @@ elf_flagelf(Elf *e, Elf_Cmd c, unsigned int flags)

	if ((c != ELF_C_SET && c != ELF_C_CLR) ||
	    (e->e_kind != ELF_K_ELF) ||
-
	    (flags & ~(ELF_F_DIRTY|ELF_F_LAYOUT)) != 0) {
+
	    (flags & ~(ELF_F_ARCHIVE | ELF_F_ARCHIVE_SYSV |
+
	    ELF_F_DIRTY | ELF_F_LAYOUT)) != 0) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (0);
	}

+
	if ((flags & ELF_F_ARCHIVE_SYSV) && (flags & ELF_F_ARCHIVE) == 0) {
+
		LIBELF_SET_ERROR(ARGUMENT, 0);
+
		return (0);
+
	}
+

+
	if ((flags & ELF_F_ARCHIVE) && e->e_cmd != ELF_C_WRITE) {
+
		LIBELF_SET_ERROR(MODE, 0);
+
		return (0);
+
	}
+

	if (c == ELF_C_SET)
		r = e->e_flags |= flags;
	else
		r = e->e_flags &= ~flags;
-
	return (r);
+
	return (r & LIBELF_F_API_MASK);
}

unsigned int
@@ -154,7 +188,7 @@ elf_flagscn(Elf_Scn *s, Elf_Cmd c, unsigned int flags)
		r = s->s_flags |= flags;
	else
		r = s->s_flags &= ~flags;
-
	return (r);
+
	return (r & LIBELF_F_API_MASK);
}

unsigned int
modified external/libelf/elf_flagdata.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006,2007 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006-2008,2011 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,12 +21,13 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_flagdata.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: elf_flagdata.3 2267 2011-12-03 17:04:25Z jkoshy $
.\"
-
.Dd October 22, 2007
-
.Dt ELF_FLAGDATA 3
+
.Dd December 3, 2011
.Os
+
.Dt ELF_FLAGDATA 3
.Sh NAME
+
.Nm elf_flagarhdr ,
.Nm elf_flagdata ,
.Nm elf_flagehdr ,
.Nm elf_flagelf ,
@@ -39,6 +40,8 @@
.Sh SYNOPSIS
.In libelf.h
.Ft "unsigned int"
+
.Fn elf_flagarhdr "Elf_Arhdr *arhdr" "Elf_Cmd cmd" "unsigned int flags"
+
.Ft "unsigned int"
.Fn elf_flagdata "Elf_Data *data" "Elf_Cmd cmd" "unsigned int flags"
.Ft "unsigned int"
.Fn elf_flagehdr "Elf *elf" "Elf_Cmd cmd" "unsigned int flags"
@@ -55,11 +58,44 @@ These functions are used to query, set or reset flags on data
structures associated with an ELF file.
.Pp
Arguments
+
.Ar arhdr ,
.Ar data ,
.Ar elf
and
.Ar scn
denote the data structures whose flags need to be changed.
+
These values should have been returned by prior calls to
+
functions in the ELF(3) API set:
+
.Bl -bullet -compact
+
.It
+
Argument
+
.Ar arhdr
+
should have been returned by a prior call to
+
.Xr elf_getarhdr 3 .
+
.It
+
Argument
+
.Ar data
+
should have been returned by a prior call to one of
+
.Xr elf_newdata 3 ,
+
.Xr elf_getdata 3
+
or
+
.Xr elf_rawdata 3 .
+
.It
+
Argument
+
.Ar elf
+
should have been allocated by a prior call to one of
+
.Xr elf_begin 3
+
or
+
.Xr elf_memory 3 .
+
.It
+
Argument
+
.Ar scn
+
should have been returned by a prior call to one of
+
.Xr elf_getscn 3 ,
+
.Xr elf_newscn 3
+
or
+
.Xr elf_nextscn 3 .
+
.El
These values are allowed to be NULL to simplify error handling in
application code.
.Pp
@@ -80,7 +116,26 @@ specifies the flags to be set.
The argument
.Ar flags
is allowed to have the following flags set:
-
.Bl -tag -width ELF_F_LAYOUT
+
.Bl -tag -width ELF_F_ARCHIVE_SYSV
+
.It Dv ELF_F_ARCHIVE
+
This flag is only valid with the
+
.Fn elf_flagelf
+
API.
+
It informs the library that the application desires to create an
+
.Xr ar 1
+
archive.
+
Argument
+
.Ar elf
+
should have been opened for writing using the
+
.Dv ELF_C_WRITE
+
command to function
+
.Fn elf_begin .
+
.It Dv ELF_F_ARCHIVE_SYSV
+
This flag is used in conjunction with the
+
.Dv ELF_F_ARCHIVE
+
flag to indicate that library should create archives that conform
+
to System V layout rules.
+
The default is to create BSD style archives.
.It Dv ELF_F_DIRTY
Mark the associated data structure as needing to be written back
to the underlying file.
@@ -113,6 +168,14 @@ queried.
.Sh RETURN VALUES
These functions return the updated flags is successful, and zero if
an error is detected.
+
.Sh COMPATIBILITY
+
The
+
.Fn elf_flagarhdr
+
function and the
+
.Dv ELF_F_ARCHIVE
+
and
+
.Dv ELF_F_ARCHIVE_SYSV
+
flags are an extension to the ELF(3) API.
.Sh ERRORS
These functions may fail with the following errors:
.Bl -tag -width "[ELF_E_RESOURCE]"
@@ -128,6 +191,10 @@ had unsupported flags set.
The argument
.Ar elf
was not a descriptor for an ELF object.
+
.It Bq Er ELF_E_MODE
+
The
+
.Dv ELF_F_ARCHIVE
+
flag was used with an ELF descriptor that had not been opened for writing.
.It Bq Er ELF_E_SEQUENCE
Function
.Fn elf_flagehdr
modified external/libelf/elf_getarhdr.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_getarhdr.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: elf_getarhdr.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd August 15, 2006
-
.Dt ELF_GETARHDR 3
.Os
+
.Dt ELF_GETARHDR 3
.Sh NAME
.Nm elf_getarhdr
.Nd retrieve ar(1) header for an archive member
modified external/libelf/elf_getarhdr.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008,2010 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,24 +25,23 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_getarhdr.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_getarhdr.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

Elf_Arhdr *
elf_getarhdr(Elf *e)
{
-
	Elf_Arhdr *arh;
-

	if (e == NULL) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (NULL);
	}

-
	if ((arh = e->e_arhdr) != NULL)
-
		return (arh);
+
	if (e->e_flags & LIBELF_F_AR_HEADER)
+
		return (e->e_hdr.e_arhdr);

	return (_libelf_ar_gethdr(e));
}
modified external/libelf/elf_getarsym.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_getarsym.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: elf_getarsym.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd August 15, 2006
-
.Dt ELF_GETARSYM 3
.Os
+
.Dt ELF_GETARSYM 3
.Sh NAME
.Nm elf_getarsym
.Nd retrieve the symbol table of an archive
modified external/libelf/elf_getarsym.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,12 +25,13 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_getarsym.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_getarsym.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

Elf_Arsym *
elf_getarsym(Elf *ar, size_t *ptr)
{
@@ -45,7 +46,9 @@ elf_getarsym(Elf *ar, size_t *ptr)
	else if ((symtab = ar->e_u.e_ar.e_symtab) != NULL)
		n = ar->e_u.e_ar.e_symtabsz;
	else if (ar->e_u.e_ar.e_rawsymtab)
-
		symtab = _libelf_ar_process_symtab(ar, &n);
+
		symtab = (ar->e_flags & LIBELF_F_AR_VARIANT_SVR4) ?
+
		    _libelf_ar_process_svr4_symtab(ar, &n) :
+
		    _libelf_ar_process_bsd_symtab(ar, &n);
	else
		LIBELF_SET_ERROR(ARCHIVE, 0);

@@ -53,4 +56,3 @@ elf_getarsym(Elf *ar, size_t *ptr)
		*ptr = n;
	return (symtab);
}
-

modified external/libelf/elf_getbase.3
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_getbase.3 209122 2010-06-13 10:58:50Z kaiw $
+
.\" $Id: elf_getbase.3 978 2010-06-06 12:40:19Z jkoshy $
.\"
.Dd June 6, 2010
-
.Dt ELF_GETBASE 3
.Os
+
.Dt ELF_GETBASE 3
.Sh NAME
.Nm elf_getbase
.Nd get the base offset for an object file
modified external/libelf/elf_getbase.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,12 +25,13 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_getbase.c 209122 2010-06-13 10:58:50Z kaiw $");

#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_getbase.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

off_t
elf_getbase(Elf *e)
{
modified external/libelf/elf_getdata.3
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: head/lib/libelf/elf_getdata.3 235286 2012-05-11 20:06:46Z gjb $
+
.\" $Id: elf_getdata.3 1766 2011-08-22 06:01:03Z jkoshy $
.\"
.Dd January 26, 2011
-
.Dt ELF_GETDATA 3
.Os
+
.Dt ELF_GETDATA 3
.Sh NAME
.Nm elf_getdata ,
.Nm elf_newdata ,
@@ -144,7 +144,7 @@ structures of type
.Dv ELF_T_BYTE .
.Ss Special handling of zero-sized and SHT_NOBITS sections
For sections of type
-
.Dv SHT_NOBITS ,
+
.Dv SHT_NOBITS,
and for zero-sized sections,
the functions
.Fn elf_getdata
@@ -174,18 +174,47 @@ These functions return a valid pointer to a data descriptor if successful, or
NULL if an error occurs.
.Sh ERRORS
These functions may fail with the following errors:
-
.Bl -tag -width "[ELF_E_RESOURCE]"
+
.Bl -tag -width "[ELF_E_RESOURCE]" 
.It Bq Er ELF_E_ARGUMENT
-
Arguments
+
Either of the arguments
.Ar scn
+
or
+
.Ar data
was NULL.
.It Bq Er ELF_E_ARGUMENT
-
Data descriptor
+
The data descriptor referenced by argument
.Ar data
-
was not associated with section descriptor
+
is not associated with section descriptor
.Ar scn .
+
.It Bq Er ELF_E_ARGUMENT
+
The section denoted by argument
+
.Ar scn
+
had no data associated with it.
+
.It Bq Er ELF_E_DATA
+
Retrieval of data from the underlying object failed.
.It Bq Er ELF_E_RESOURCE
An out of memory condition was detected.
+
.It Bq Er ELF_E_SECTION
+
Section
+
.Ar scn
+
had type
+
.Dv SHT_NULL .
+
.It Bq Er ELF_E_SECTION
+
The type of the section
+
.Ar scn
+
was not recognized by the library.
+
.It Bq Er ELF_E_SECTION
+
The size of the section
+
.Ar scn
+
is not a multiple of the file size for its section type.
+
.It Bq Er ELF_E_SECTION
+
The file offset for section
+
.Ar scn
+
is incorrect.
+
.It Bq Er ELF_E_UNIMPL
+
The section type associated with section
+
.Ar scn
+
is currently unsupported by the library.
.El
.Sh SEE ALSO
.Xr elf 3 ,
modified external/libelf/elf_getident.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_getident.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: elf_getident.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd July 3, 2006
-
.Dt ELF_GETIDENT 3
.Os
+
.Dt ELF_GETIDENT 3
.Sh NAME
.Nm elf_getident
.Nd return the initial bytes of a file
modified external/libelf/elf_getident.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,7 +25,6 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_getident.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <ar.h>
#include <assert.h>
@@ -33,6 +32,8 @@ __FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_getident.c 164190 2006-11-11 17:16

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_getident.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

char *
elf_getident(Elf *e, size_t *sz)
{
@@ -58,7 +59,7 @@ elf_getident(Elf *e, size_t *sz)
			*sz = e->e_rawsize;
	}

-
	return (e->e_rawfile);
+
	return ((char *) e->e_rawfile);

 error:
	if (sz)
modified external/libelf/elf_getphdrnum.3
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: head/lib/libelf/elf_getphdrnum.3 233520 2012-03-26 19:23:57Z joel $
+
.\" $Id: elf_getphdrnum.3 467 2009-08-05 18:18:49Z jkoshy $
.\"
.Dd August 5, 2009
-
.Dt ELF_GETPHDRNUM 3
.Os
+
.Dt ELF_GETPHDRNUM 3
.Sh NAME
.Nm elf_getphdrnum
.Nd return the number of program headers in an ELF file
@@ -45,6 +45,7 @@ and stores it into the location pointed to by argument
.Pp
This routine allows applications to uniformly process both normal ELF
objects and ELF objects that use extended numbering.
+
.Pp
.Sh RETURN VALUES
Function
.Fn elf_getphdrnum
modified external/libelf/elf_getphnum.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: head/lib/libelf/elf_getphnum.3 233462 2012-03-25 12:13:24Z joel $
+
.\" $Id: elf_getphnum.3 467 2009-08-05 18:18:49Z jkoshy $
.\"
.Dd August 5, 2009
-
.Dt ELF_GETPHNUM 3
.Os
+
.Dt ELF_GETPHNUM 3
.Sh NAME
.Nm elf_getphnum
.Nd return the number of program headers in an ELF file
@@ -50,6 +50,7 @@ and stores it into the location pointed to by argument
.Pp
This routine allows applications to uniformly process both normal ELF
objects and ELF objects that use extended numbering.
+
.Pp
.Sh RETURN VALUES
Function
.Fn elf_getphnum
modified external/libelf/elf_getscn.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006,2007 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006-2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_getscn.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: elf_getscn.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd October 22, 2007
-
.Dt ELF_GETSCN 3
.Os
+
.Dt ELF_GETSCN 3
.Sh NAME
.Nm elf_getscn ,
.Nm elf_ndxscn ,
modified external/libelf/elf_getshdrnum.3
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: head/lib/libelf/elf_getshdrnum.3 233520 2012-03-26 19:23:57Z joel $
+
.\" $Id: elf_getshdrnum.3 467 2009-08-05 18:18:49Z jkoshy $
.\"
.Dd August 4, 2009
-
.Dt ELF_GETSHDRNUM 3
.Os
+
.Dt ELF_GETSHDRNUM 3
.Sh NAME
.Nm elf_getshdrnum
.Nd return the number of sections in an ELF file
@@ -45,6 +45,7 @@ and stores it into the location pointed to by argument
.Pp
This routine allows applications to uniformly process both normal ELF
objects, and ELF objects that use extended section numbering.
+
.Pp
.Sh RETURN VALUES
Function
.Fn elf_getshdrnum
modified external/libelf/elf_getshdrstrndx.3
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: head/lib/libelf/elf_getshdrstrndx.3 233520 2012-03-26 19:23:57Z joel $
+
.\" $Id: elf_getshdrstrndx.3 467 2009-08-05 18:18:49Z jkoshy $
.\"
.Dd August 5, 2009
-
.Dt ELF_GETSHDRSTRNDX 3
.Os
+
.Dt ELF_GETSHDRSTRNDX 3
.Sh NAME
.Nm elf_getshdrstrndx
.Nd retrieve the index of the section name string table
@@ -46,6 +46,7 @@ and stores it into the location pointed to by argument
.Pp
This function allow applications to process both normal ELF
objects and ELF objects that use extended section numbering uniformly.
+
.Pp
.Sh RETURN VALUES
These functions return zero if successful, or -1 in case of an error.
.Sh ERRORS
modified external/libelf/elf_getshnum.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: head/lib/libelf/elf_getshnum.3 233462 2012-03-25 12:13:24Z joel $
+
.\" $Id: elf_getshnum.3 467 2009-08-05 18:18:49Z jkoshy $
.\"
.Dd August 5, 2009
-
.Dt ELF_GETSHNUM 3
.Os
+
.Dt ELF_GETSHNUM 3
.Sh NAME
.Nm elf_getshnum
.Nd return the number of sections in an ELF file
@@ -50,6 +50,7 @@ and stores it into the location pointed to by argument
.Pp
This routine allows applications to uniformly process both normal ELF
objects, and ELF objects that use extended section numbering.
+
.Pp
.Sh RETURN VALUES
Function
.Fn elf_getshnum
modified external/libelf/elf_getshstrndx.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: head/lib/libelf/elf_getshstrndx.3 233462 2012-03-25 12:13:24Z joel $
+
.\" $Id: elf_getshstrndx.3 467 2009-08-05 18:18:49Z jkoshy $
.\"
.Dd August 5, 2009
-
.Dt ELF_GETSHSTRNDX 3
.Os
+
.Dt ELF_GETSHSTRNDX 3
.Sh NAME
.Nm elf_getshstrndx ,
.Nm elf_setshstrndx
@@ -60,6 +60,7 @@ sets the index of the section name string table to argument
.Pp
These routines allow applications to process both normal ELF
objects and ELF objects that use extended section numbering uniformly.
+
.Pp
.Sh RETURN VALUES
These functions return a non-zero value if successful, or zero in case
of an error.
modified external/libelf/elf_hash.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_hash.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: elf_hash.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd August 15, 2006
-
.Dt ELF_HASH 3
.Os
+
.Dt ELF_HASH 3
.Sh NAME
.Nm elf_hash
.Nd compute a hash value for a string
modified external/libelf/elf_hash.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,13 +25,15 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_hash.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <libelf.h>

+
#include "_libelf.h"
+

+
ELFTC_VCSID("$Id: elf_hash.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

/*
-
 * This elf_hash function is defined by the System V ABI.  It must be
-
 * kept compatible with "src/libexec/rtld-elf/rtld.c".
+
 * This elf_hash function is defined by the System V ABI.
 */

unsigned long
modified external/libelf/elf_kind.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_kind.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: elf_kind.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd June 1, 2006
-
.Dt ELF_KIND 3
.Os
+
.Dt ELF_KIND 3
.Sh NAME
.Nm elf_kind
.Nd determine ELF file type
modified external/libelf/elf_kind.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,12 +25,13 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_kind.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_kind.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

Elf_Kind
elf_kind(Elf *e)
{
modified external/libelf/elf_memory.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_memory.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: elf_memory.3 2314 2011-12-11 06:19:51Z jkoshy $
.\"
.Dd June 28, 2006
-
.Dt ELF_MEMORY 3
.Os
+
.Dt ELF_MEMORY 3
.Sh NAME
.Nm elf_memory
.Nd process an ELF or ar(1) archive mapped into memory
@@ -109,9 +109,9 @@ Function
was called before a working version was set using
.Xr elf_version 3 .
.It Bq Er ELF_E_VERSION
-
The argument
+
The ELF object referenced by argument
.Ar image
-
corresponds to an ELF file with an unsupported version.
+
was of an unsupported ELF version.
.El
.Sh SEE ALSO
.Xr elf 3 ,
modified external/libelf/elf_memory.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -24,20 +24,15 @@
 * SUCH DAMAGE.
 */

-
#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_memory.c 164190 2006-11-11 17:16:35Z jkoshy $");
-

-
#include <ar.h>
#include <libelf.h>
-
#include <string.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_memory.c 2368 2011-12-29 06:34:28Z jkoshy $");
+

Elf *
elf_memory(char *image, size_t sz)
{
-
	Elf *e;
-

	if (LIBELF_PRIVATE(version) == EV_NONE) {
		LIBELF_SET_ERROR(SEQUENCE, 0);
		return (NULL);
@@ -48,44 +43,5 @@ elf_memory(char *image, size_t sz)
		return (NULL);
	}

-
	if ((e = _libelf_allocate_elf()) == NULL)
-
		return (NULL);
-

-
	e->e_cmd = ELF_C_READ;
-
	e->e_rawfile = image;
-
	e->e_rawsize = sz;
-

-
#undef	LIBELF_IS_ELF
-
#define	LIBELF_IS_ELF(P) ((P)[EI_MAG0] == ELFMAG0 && 		\
-
	(P)[EI_MAG1] == ELFMAG1 && (P)[EI_MAG2] == ELFMAG2 &&	\
-
	(P)[EI_MAG3] == ELFMAG3)
-

-
	if (sz > EI_NIDENT && LIBELF_IS_ELF(image)) {
-
		_libelf_init_elf(e, ELF_K_ELF);
-
		e->e_class = image[EI_CLASS];
-
		e->e_byteorder = image[EI_DATA];
-
		e->e_version = image[EI_VERSION];
-

-
		if (e->e_version > EV_CURRENT) {
-
			e = _libelf_release_elf(e);
-
			LIBELF_SET_ERROR(VERSION, 0);
-
			return (NULL);
-
		}
-

-
		if ((e->e_byteorder != ELFDATA2LSB && e->e_byteorder !=
-
 		    ELFDATA2MSB) || (e->e_class != ELFCLASS32 && e->e_class !=
-
		    ELFCLASS64)) {
-
			e = _libelf_release_elf(e);
-
			LIBELF_SET_ERROR(HEADER, 0);
-
			return (NULL);
-
		}
-

-
	} else if (sz >= SARMAG &&
-
	    strncmp(image, ARMAG, (size_t) SARMAG) == 0) {
-
		_libelf_init_elf(e, ELF_K_AR);
-
		e = _libelf_ar_open(e);
-
	} else
-
		_libelf_init_elf(e, ELF_K_NONE);
-

-
	return (e);
+
	return (_libelf_memory(image, sz, 1));
}
modified external/libelf/elf_next.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_next.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: elf_next.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd June 17, 2006
-
.Dt ELF_NEXT 3
.Os
+
.Dt ELF_NEXT 3
.Sh NAME
.Nm elf_next
.Nd provide sequential access to the next archive member
modified external/libelf/elf_next.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,7 +25,6 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_next.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <ar.h>
#include <assert.h>
@@ -33,6 +32,8 @@ __FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_next.c 164190 2006-11-11 17:16:35Z

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_next.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

Elf_Cmd
elf_next(Elf *e)
{
@@ -49,13 +50,13 @@ elf_next(Elf *e)

	assert (parent->e_kind == ELF_K_AR);
	assert (parent->e_cmd == ELF_C_READ);
-
	assert((uintptr_t) e->e_rawfile % 2 == 0);
	assert(e->e_rawfile > parent->e_rawfile);

	next = e->e_rawfile - parent->e_rawfile + e->e_rawsize;
	next = (next + 1) & ~1;	/* round up to an even boundary */

-
	parent->e_u.e_ar.e_next = (next >= (off_t) parent->e_rawsize) ? (off_t) 0 : next;
+
	parent->e_u.e_ar.e_next = (next >= (off_t) parent->e_rawsize) ?
+
	    (off_t) 0 : next;

	return (ELF_C_READ);
}
added external/libelf/elf_open.3
@@ -0,0 +1,121 @@
+
.\" Copyright (c) 2012 Joseph Koshy.  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.
+
.\"
+
.\" This software is provided by Joseph Koshy ``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 Joseph Koshy 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: elf_open.3 2512 2012-05-31 06:15:57Z jkoshy $ 
+
.\"
+
.Dd May 31, 2012
+
.Os
+
.Dt ELF_OPEN 3 
+
.Sh NAME
+
.Nm elf_open
+
.Nd open ELF objects and ar(1) archives
+
.Sh LIBRARY
+
.Lb libelf
+
.Sh SYNOPSIS
+
.In libelf.h
+
.Ft "Elf *"
+
.Fn elf_open "int fd"
+
.Ft "Elf *"
+
.Fn elf_openmemory "char *image" "size_t sz"
+
.Sh DESCRIPTION
+
.Em Important :
+
The functions
+
.Fn elf_open
+
and
+
.Fn elf_openmemory
+
are extensions to the ELF(3) API, for the internal use of the
+
Elftoolchain project.
+
Portable applications should not use these functions.
+
.Pp
+
The function
+
.Fn elf_open
+
returns an Elf descriptor opened with mode
+
.Dv ELF_C_READ
+
for the ELF object or
+
.Xr ar 1
+
archive referenced by the file descriptor in argument
+
.Ar fd .
+
.Pp
+
The function
+
.Fn elf_openmemory
+
returns an ELF descriptor opened with mode
+
.Dv ELF_C_READ
+
for the ELF object or
+
.Xr ar 1
+
archive contained in the memory area pointed to by the argument
+
.Ar image .
+
The argument
+
.Ar sz
+
specifies the size of the memory area in bytes.
+
.Sh COMPATIBILITY
+
These functions are non-standard extensions to the ELF(3) API set.
+
.Pp
+
The behavior of these functions differs from their counterparts
+
.Xr elf_begin 3
+
and
+
.Xr elf_memory 3
+
in that these functions will successfully open malformed ELF objects
+
and
+
.Xr ar 1
+
archives, returning an Elf descriptor of type
+
.Dv ELF_K_NONE .
+
.Sh RETURN VALUES
+
The function returns a pointer to a ELF descriptor if successful, or
+
NULL if an error occurred.
+
.Sh ERRORS
+
These functions can fail with the following errors:
+
.Bl -tag -width "[ELF_E_RESOURCE]"
+
.It Bq Er ELF_E_ARGUMENT
+
The argument
+
.Ar fd
+
was of an unsupported file type.
+
.It Bq Er ELF_E_ARGUMENT
+
The argument
+
.Ar sz
+
was zero, or the argument
+
.Ar image
+
was NULL.
+
.It Bq Er ELF_E_IO
+
The file descriptor in argument
+
.Ar fd
+
was invalid.
+
.It Bq Er ELF_E_IO
+
The file descriptor in argument
+
.Ar fd
+
could not be read.
+
.It Bq Er ELF_E_RESOURCE
+
An out of memory condition was encountered.
+
.It Bq Er ELF_E_SEQUENCE
+
Functions
+
.Fn elf_open
+
or
+
.Fn elf_openmemory
+
was called before a working version was established with
+
.Xr elf_version 3 .
+
.El
+
.Sh SEE ALSO
+
.Xr elf 3 ,
+
.Xr elf_begin 3 ,
+
.Xr elf_errno 3 ,
+
.Xr elf_memory 3 ,
+
.Xr gelf 3
added external/libelf/elf_open.c
@@ -0,0 +1,67 @@
+
/*-
+
 * Copyright (c) 2011 Joseph Koshy
+
 * 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.
+
 *
+
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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.
+
 */
+

+
#include <libelf.h>
+

+
#include "_libelf.h"
+

+
ELFTC_VCSID("$Id$");
+

+
/*
+
 * Extension API: open a file for reading, ignoring parse errors.
+
 */
+

+
Elf *
+
elf_open(int fd)
+
{
+
	if (LIBELF_PRIVATE(version) == EV_NONE) {
+
		LIBELF_SET_ERROR(SEQUENCE, 0);
+
		return (NULL);
+
	}
+

+
	return (_libelf_open_object(fd, ELF_C_READ, 0));
+
}
+

+
/*
+
 * Extension API: create an ELF descriptor for an in-memory object,
+
 * ignoring parse errors.
+
 */
+

+
Elf *
+
elf_openmemory(char *image, size_t sz)
+
{
+
	if (LIBELF_PRIVATE(version) == EV_NONE) {
+
		LIBELF_SET_ERROR(SEQUENCE, 0);
+
		return (NULL);
+
	}
+

+
	if (image == NULL || sz == 0) {
+
		LIBELF_SET_ERROR(ARGUMENT, 0);
+
		return (NULL);
+
	}
+

+
	return (_libelf_memory(image, sz, 0));
+
}
modified external/libelf/elf_phnum.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,13 +25,14 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_phnum.c 210345 2010-07-21 12:14:50Z kaiw $");

#include <ar.h>
#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_phnum.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

static int
_libelf_getphdrnum(Elf *e, size_t *phnum)
{
modified external/libelf/elf_rand.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_rand.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: elf_rand.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd June 17, 2006
-
.Dt ELF_RAND 3
.Os
+
.Dt ELF_RAND 3
.Sh NAME
.Nm elf_rand
.Nd provide sequential access to the next archive member
modified external/libelf/elf_rand.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,13 +25,14 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_rand.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <ar.h>
#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_rand.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

off_t
elf_rand(Elf *ar, off_t offset)
{
modified external/libelf/elf_rawfile.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_rawfile.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: elf_rawfile.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd July 3, 2006
-
.Dt ELF_RAWFILE 3
.Os
+
.Dt ELF_RAWFILE 3
.Sh NAME
.Nm elf_rawfile
.Nd return uninterpreted contents of an ELF file
modified external/libelf/elf_rawfile.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,12 +25,13 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_rawfile.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_rawfile.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

char *
elf_rawfile(Elf *e, size_t *sz)
{
modified external/libelf/elf_scn.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008-2010 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,21 +25,24 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_scn.c 210338 2010-07-21 10:25:02Z kaiw $");
+
#include <sys/queue.h>

#include <assert.h>
#include <errno.h>
#include <gelf.h>
#include <libelf.h>
+
#include <stddef.h>
#include <stdlib.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_scn.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

/*
 * Load an ELF section table and create a list of Elf_Scn structures.
 */
int
-
_libelf_load_scn(Elf *e, void *ehdr)
+
_libelf_load_section_headers(Elf *e, void *ehdr)
{
	int ec, swapbytes;
	size_t fsz, i, shnum;
@@ -139,7 +142,7 @@ elf_getscn(Elf *e, size_t index)

	if (e->e_cmd != ELF_C_WRITE &&
	    (e->e_flags & LIBELF_F_SHDRS_LOADED) == 0 &&
-
	    _libelf_load_scn(e, ehdr) == 0)
+
	    _libelf_load_section_headers(e, ehdr) == 0)
		return (NULL);

	STAILQ_FOREACH(s, &e->e_u.e_elf.e_scn, s_next)
@@ -192,7 +195,7 @@ elf_newscn(Elf *e)
	 */
	if (e->e_cmd != ELF_C_WRITE &&
	    (e->e_flags & LIBELF_F_SHDRS_LOADED) == 0 &&
-
	    _libelf_load_scn(e, ehdr) == 0)
+
	    _libelf_load_section_headers(e, ehdr) == 0)
		return (NULL);

	if (STAILQ_EMPTY(&e->e_u.e_elf.e_scn)) {
modified external/libelf/elf_shnum.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,13 +25,14 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_shnum.c 210345 2010-07-21 12:14:50Z kaiw $");

#include <ar.h>
#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_shnum.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

static int
_libelf_getshdrnum(Elf *e, size_t *shnum)
{
modified external/libelf/elf_shstrndx.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,13 +25,14 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_shstrndx.c 210345 2010-07-21 12:14:50Z kaiw $");

#include <ar.h>
#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_shstrndx.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

static int
_libelf_getshdrstrndx(Elf *e, size_t *strndx)
{
modified external/libelf/elf_strptr.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: head/lib/libelf/elf_strptr.3 235286 2012-05-11 20:06:46Z gjb $
+
.\" $Id: elf_strptr.3 1081 2010-08-14 02:23:48Z jkoshy $
.\"
.Dd December 16, 2006
-
.Dt ELF_STRPTR 3
.Os
+
.Dt ELF_STRPTR 3
.Sh NAME
.Nm elf_strptr
.Nd retrieve a string pointer in a string table
@@ -64,7 +64,7 @@ encountered.
.It Bq Er ELF_E_ARGUMENT
Argument
.Ar elf
-
was NULL.
+
was NULL
.It Bq Er ELF_E_ARGUMENT
Argument
.Ar elf
modified external/libelf/elf_strptr.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -24,9 +24,6 @@
 * SUCH DAMAGE.
 */

-
#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_strptr.c 179241 2008-05-23 07:35:36Z jb $");
-

#include <sys/param.h>

#include <assert.h>
@@ -34,6 +31,8 @@ __FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_strptr.c 179241 2008-05-23 07:35:3

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_strptr.c 2271 2011-12-03 17:06:35Z jkoshy $");
+

/*
 * Convert an ELF section#,offset pair to a string pointer.
 */
@@ -55,7 +54,7 @@ elf_strptr(Elf *e, size_t scndx, size_t offset)
	    gelf_getshdr(s, &shdr) == NULL)
		return (NULL);

-
	if (/*shdr.sh_type != SHT_STRTAB || */
+
	if (shdr.sh_type != SHT_STRTAB ||
	    offset >= shdr.sh_size) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (NULL);
modified external/libelf/elf_types.m4
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -23,49 +23,43 @@
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
-
 * $FreeBSD: releng/9.1/lib/libelf/elf_types.m4 210341 2010-07-21 10:57:22Z kaiw $
+
 * $Id: elf_types.m4 321 2009-03-07 16:59:14Z jkoshy $
 */

/*
 * ELF types, defined in the "enum Elf_Type" API.
 *
-
 * The members of the list form a 3-tuple: (name, C-type-suffix, OSversion).
+
 * The members of the list form a 2-tuple: (name, C-type-suffix).
 * + `name' is an Elf_Type symbol without the `ELF_T_' prefix.
 * + `C-type-suffix' is the suffix for Elf32_ and Elf64_ type names.
-
 * + `version' is the OS version the symbol first appeared in.
-
 *
-
 * OS revisions of note are:
-
 * 600102 - The earliest (6.0-STABLE) version supported by this code.
-
 * 700009 - Symbol versioning and ELF64 type changes.
-
 * 700025 - More ELF types and the introduction of libelf.
 */

define(`ELF_TYPE_LIST',
-
	``ADDR,		Addr,	600102',
-
	`BYTE,		Byte,	600102',
-
	`CAP,		Cap,	700025',
-
	`DYN,		Dyn,	600102',
-
	`EHDR,		Ehdr,	600102',
-
	`GNUHASH,	-,	800062',
-
	`HALF,		Half,	600102',
-
	`LWORD,		Lword,	700025',
-
	`MOVE,		Move,	700025',
-
	`MOVEP,		MoveP,	700025',
-
	`NOTE,		Note,	600102',
-
	`OFF,		Off,	600102',
-
	`PHDR,		Phdr,	600102',
-
	`REL,		Rel,	600102',
-
	`RELA,		Rela,	600102',
-
	`SHDR,		Shdr,	600102',
-
	`SWORD,		Sword,	600102',
-
	`SXWORD,	Sxword,	700009',
-
	`SYMINFO,	Syminfo, 700025',
-
	`SYM,		Sym,	600102',
-
	`VDEF,		Verdef,	700009',
-
	`VNEED,		Verneed, 700009',
-
	`WORD,		Word,	600102',
-
	`XWORD,		Xword,	700009',
-
	`NUM,		_,	_'')
+
	``ADDR,		Addr',
+
	`BYTE,		Byte',
+
	`CAP,		Cap',
+
	`DYN,		Dyn',
+
	`EHDR,		Ehdr',
+
	`GNUHASH,	-',
+
	`HALF,		Half',
+
	`LWORD,		Lword',
+
	`MOVE,		Move',
+
	`MOVEP,		MoveP',
+
	`NOTE,		Note',
+
	`OFF,		Off',
+
	`PHDR,		Phdr',
+
	`REL,		Rel',
+
	`RELA,		Rela',
+
	`SHDR,		Shdr',
+
	`SWORD,		Sword',
+
	`SXWORD,	Sxword',
+
	`SYMINFO,	Syminfo',
+
	`SYM,		Sym',
+
	`VDEF,		Verdef',
+
	`VNEED,		Verneed',
+
	`WORD,		Word',
+
	`XWORD,		Xword',
+
	`NUM,		_'')

/*
 * DEFINE_STRUCT(NAME,MEMBERLIST...)
modified external/libelf/elf_update.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006,2007-2008 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006-2011 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: head/lib/libelf/elf_update.3 226436 2011-10-16 14:30:28Z eadler $
+
.\" $Id: elf_update.3 1729 2011-08-14 09:13:00Z jkoshy $
.\"
-
.Dd March 19, 2008
-
.Dt ELF_UPDATE 3
+
.Dd August 14, 2011
.Os
+
.Dt ELF_UPDATE 3
.Sh NAME
.Nm elf_update
.Nd update an ELF descriptor
@@ -44,58 +44,123 @@ to file.
.Pp
Argument
.Ar elf
-
is a descriptor to an ELF object.
+
should reference a valid ELF descriptor.
+
.Pp
Argument
.Ar cmd
-
can take on the following values:
-
.Bl -tag -width "ELF_C_WRITE"
+
can be one of the following values:
+
.Bl -tag -width "Dv ELF_C_WRITE"
.It Dv ELF_C_NULL
The library will recalculate structural information flagging
modified structures with the
.Dv ELF_F_DIRTY
-
flag, but will not write back data to the underlying file image.
+
flag, but will not write data to the underlying file image.
.It Dv ELF_C_WRITE
The library will recalculate structural information and will
also write the new image to the underlying file.
+
The ELF descriptor referenced by argument
+
.Ar elf
+
should permit the underlying ELF object to be written or updated
+
(see
+
.Xr elf_begin 3 ) .
.El
-
.Ss File Layout
+
.Pp
+
All pointers to
+
.Vt Elf_Scn
+
and
+
.Vt Elf_Data
+
descriptors associated with descriptor
+
.Ar elf
+
should be considered invalid after a call to
+
.Fn elf_update .
+
.Ss Specifying Object Layout
+
The
+
.Lb libelf
+
supports two layout modes.
+
.Bl -tag -width indent
+
.It "Library Layout"
If the
.Dv ELF_F_LAYOUT
-
flag has been set on the ELF descriptor, the application assumes full
-
responsibility for the layout of the ELF object.
-
If this flag is not set, the ELF library will compute the layout of the
-
file from its associated section descriptors.
+
flag is not set on the ELF descriptor, the ELF library will lay out
+
the ELF object according to the following scheme:
+
.Bl -tag -compact -width "Section Data"
+
.It Em EHDR
+
The ELF executable header will be placed at the start of the object.
+
.It Em PHDR
+
If the ELF descriptor contains a program header table, it will be
+
placed after the Executable Header.
+
.It Em Section Data
+
ELF section data, if any, will be placed next, keeping each section's
+
alignment requirements in mind.
+
.It Em SHDR
+
The ELF section header table, if any, will be placed last.
+
.El
+
.It "Application Controlled Layout"
+
The application can take full control of the layout of the ELF object
+
by setting the
+
.Dv ELF_F_LAYOUT
+
flag on the ELF descriptor (see
+
.Xr elf_flagelf 3 ) .
+
In this case the library will lay out the ELF object using
+
application-supplied information as below:
.Pp
-
It is the application's responsibility to manage the following
-
structure members in the ELF file:
+
.Bl -tag -compact -width "Section Data"
+
.It Em EHDR
+
The ELF executable header will be placed at the start of the object.
+
.It Em PHDR
+
The ELF program header table, if any, it will be placed at the offset
+
specified in the
+
.Va e_phoff
+
field of the ELF executable header.
+
.It Em Section Data
+
The data for each ELF section will be placed at the offset specified
+
by the
+
.Va sh_offset
+
field of the section's header.
+
The size of the section will be taken from the
+
.Va sh_size
+
field of the section header.
+
.It Em SHDR
+
The ELF section header table, if any, will be placed at the offset
+
specified by the
+
.Va e_shoff
+
field of the executable header.
+
.El
+
.El
+
.Pp
+
Gaps in the coverage of the file's contents will be set to the fill value
+
specified by
+
.Xr elf_fill 3 .
+
.Ss Application Supplied Information
+
The application needs to set the following fields in the data
+
structures associated with the ELF descriptor prior to calling
+
.Fn elf_update .
.Bl -tag -width indent
.It "Executable Header"
-
The ELF executable header is described in
-
.Xr elf 5 .
-
The following members of the ELF executable header are the application's
-
responsibility:
+
The fields of the ELF executable header that need to be set by the
+
application are:
.Pp
.Bl -tag -width "e_ident[EI_OSABI]" -compact
.It Va e_entry
-
Set to the desired entry address for executables.
+
To be set to the desired entry address for executables.
.It Va e_flags
-
Set to the desired processor specific flags.
+
To be set to the desired processor specific flags.
.It Va "e_ident[EI_DATA]"
Must be set to one of
.Dv ELFDATA2LSB
or
.Dv ELFDATA2MSB .
.It Va "e_ident[EI_OSABI]"
-
Set to the OS ABI desired.
-
For
+
To be set to the OS ABI desired.
+
For example, for
.Fx
executables, this field should be set to
.Dv ELFOSABI_FREEBSD .
.It Va e_machine
-
Set to the desired machine architecture, one of the
+
To be set to the desired machine architecture, one of the
.Dv EM_*
-
values in
-
.In sys/elf_common.h .
+
values in the header file
+
.In elfdefinitions.h .
.It Va e_phoff
If the application is managing the object's layout, it must
set this field to the file offset of the ELF program header table.
@@ -103,48 +168,49 @@ set this field to the file offset of the ELF program header table.
If the application is managing the object's layout, it must
set this field to the file offset of the ELF section header table.
.It Va e_shstrndx
-
Set to the index of the string table containing
+
To be set to the index of the string table containing
section names.
.It Va e_type
-
Set to the type of the ELF object, one of the
+
To be set to the type of the ELF object, one of the
.Dv ET_*
-
values in
-
.In sys/elf_common.h .
+
values in the header file
+
.In elfdefinitions.h .
.It Va e_version
-
Set to the desired version of the ELF object.
+
To be set to the desired version of the ELF object.
.El
.It "Program Header"
-
All fields of the entries in the program header table are
-
under application control.
+
All fields of the entries in the program header table need to be
+
set by the application.
.It "Section Header"
-
The ELF section header is described in
-
.Xr elf 5 .
-
The following members of the ELF section header are the
-
application's responsibility:
+
The fields of ELF section headers that need to be set by the
+
application are:
.Pp
.Bl -tag -width "sh_addralign" -compact
.It Va sh_addr
-
Set to the physical memory address where the section should reside.
+
To be set to the memory address where the section should reside.
.It Va sh_addralign
If the application is managing the file layout, it must set this
field to the desired alignment for the section's contents.
-
This value must be a power of two.
+
This value must be a power of two and must be at least as large as the
+
largest alignment needed by any
+
.Vt Elf_Data
+
descriptor associated with the section.
.It Va sh_entsize
-
Set to the size of each entry, for sections containing fixed size
+
To be set to the size of each entry, for sections containing fixed size
elements, or set to zero for sections without fixed size elements.
If the application is not managing file layout, it may leave this
-
field as zero for those sections whose types known to the library.
+
field as zero for those sections whose types are known to the library.
.It Va sh_flags
-
Set to the desired section flags.
+
To be set to the desired section flags.
.It Va sh_info
-
Set as described in
+
To be set as described in
.Xr elf 5 .
.It Va sh_link
-
Set as described in
+
To be set as described in
.Xr elf 5 .
.It Va sh_name
-
Set to the index of the section's name in the string table containing
-
section names.
+
To be set to the index of the section's name in the string table
+
containing section names.
.It Va sh_offset
If the application is managing the file layout, it must set this
field to the file offset of the section's contents.
@@ -152,28 +218,29 @@ field to the file offset of the section's contents.
If the application is managing the file layout, it must set this
field to the file size of the section's contents.
.It Va sh_type
-
Set to the type of the section.
-
.El
+
To be set to the type of the section.
.El
-
.Pp
-
Gaps in the coverage of the file's contents will be set to the fill value
-
specified by
-
.Xr elf_fill 3 .
-
.Pp
-
If the application has requested full control over the file's layout by
-
setting the
-
.Dv ELF_F_LAYOUT
-
flag on the ELF descriptor, it should ensure that there are no
-
gaps in the coverage of the file's contents.
-
.Pp
-
All pointers to
-
.Vt Elf_Scn
-
and
+
.It "Section Data"
+
The
.Vt Elf_Data
-
descriptors associated with descriptor
-
.Ar elf
-
should be considered as invalid after a call to
-
.Fn elf_update .
+
descriptors associated with each section specify its contents
+
(see
+
.Xr elf_getdata 3 ) .
+
While all the fields in these descriptors are under application
+
control, the following fields influence object layout:
+
.Bl -tag -width "Va d_align" -compact
+
.It Va d_align
+
To be set to the desired alignment, within the containing section, of
+
the descriptor's data.
+
.It Va d_off
+
If the application is managing object layout, it must set this field
+
to the file offset, within the section, at which the descriptor's data
+
should be placed.
+
.It Va d_size
+
To be set to the size in bytes of the memory representation of the
+
descriptor's data.
+
.El
+
.El
.Sh RETURN VALUES
Function
.Fn elf_update
@@ -205,7 +272,12 @@ An
.Vt Elf_Data
descriptor contained in argument
.Ar elf
-
specified a type incompatible with its containing section.
+
specified an unsupported type.
+
.It Bq Er ELF_E_DATA
+
An
+
.Vt Elf_Data
+
descriptor specified an alignment that was zero or was not a power of
+
two.
.It Bq Er ELF_E_HEADER
The ELF header in argument
.Ar elf
@@ -231,8 +303,27 @@ too small for their data.
.It Bq Er ELF_E_LAYOUT
The flag
.Dv ELF_F_LAYOUT
+
was set on the Elf descriptor and the executable header overlapped
+
with the program header table.
+
.It Bq Er ELF_E_LAYOUT
+
The flag
+
.Dv ELF_F_LAYOUT
+
was set on the Elf descriptor and the program header table was placed
+
at a misaligned file offset.
+
.It Bq Er ELF_E_LAYOUT
+
The flag
+
.Dv ELF_F_LAYOUT
was set on the Elf descriptor and the section header table overlapped
-
an extent in the object mapped by a section descriptor.
+
an extent mapped by a section descriptor.
+
.It Bq Er ELF_E_LAYOUT
+
The
+
.Dv ELF_F_LAYOUT
+
flag was set on the Elf descriptor, and the
+
.Va d_offset
+
field in an
+
.Vt Elf_Data
+
descriptor contained a value that was not a multiple of the
+
descriptor's specified alignment.
.It Bq Er ELF_E_MODE
An
.Dv ELF_C_WRITE
@@ -271,6 +362,7 @@ descriptor with an unsupported version.
.Xr elf64_getphdr 3 ,
.Xr elf64_newehdr 3 ,
.Xr elf64_newphdr 3 ,
+
.Xr elf_begin 3 ,
.Xr elf_cntl 3 ,
.Xr elf_fill 3 ,
.Xr elf_flagehdr 3 ,
modified external/libelf/elf_update.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006-2008 Joseph Koshy
+
 * Copyright (c) 2006-2011 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -24,11 +24,8 @@
 * SUCH DAMAGE.
 */

-
#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_update.c 212373 2010-09-09 18:51:50Z kaiw $");
-

-
#include <sys/mman.h>
#include <sys/param.h>
+
#include <sys/stat.h>

#include <assert.h>
#include <errno.h>
@@ -40,90 +37,110 @@ __FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_update.c 212373 2010-09-09 18:51:5

#include "_libelf.h"

+
#if	ELFTC_HAVE_MMAP
+
#include <sys/mman.h>
+
#endif
+

+
ELFTC_VCSID("$Id: elf_update.c 2348 2011-12-19 02:22:45Z jkoshy $");
+

/*
-
 * Update the internal data structures associated with an ELF object.
-
 * Returns the size in bytes the ELF object would occupy in its file
-
 * representation.
+
 * Layout strategy:
 *
-
 * After a successful call to this function, the following structures
-
 * are updated:
+
 * - Case 1: ELF_F_LAYOUT is asserted
+
 *     In this case the application has full control over where the
+
 *     section header table, program header table, and section data
+
 *     will reside.   The library only perform error checks.
 *
-
 * - The ELF header is updated.
-
 * - All sections are sorted in order of ascending addresses and their
-
 *   section header table entries updated.   An error is signalled
-
 *   if an overlap was detected among sections.
-
 * - All data descriptors associated with a section are sorted in order
-
 *   of ascending addresses.  Overlaps, if detected, are signalled as
-
 *   errors.  Other sanity checks for alignments, section types etc. are
-
 *   made.
+
 * - Case 2: ELF_F_LAYOUT is not asserted
 *
-
 * After a resync_elf() successfully returns, the ELF descriptor is
-
 * ready for being handed over to _libelf_write_elf().
+
 *     The library will do the object layout using the following
+
 *     ordering:
+
 *     - The executable header is placed first, are required by the
+
 *     	 ELF specification.
+
 *     - The program header table is placed immediately following the
+
 *       executable header.
+
 *     - Section data, if any, is placed after the program header
+
 *       table, aligned appropriately.
+
 *     - The section header table, if needed, is placed last.
+
 *
+
 *     There are two sub-cases to be taken care of:
 *
-
 * File alignments:
-
 * PHDR - Addr
-
 * SHDR - Addr
+
 *     - Case 2a: e->e_cmd == ELF_C_READ or ELF_C_RDWR
 *
-
 * XXX: how do we handle 'flags'.
+
 *       In this sub-case, the underlying ELF object may already have
+
 *       content in it, which the application may have modified.  The
+
 *       library will retrieve content from the existing object as
+
 *       needed.
+
 *
+
 *     - Case 2b: e->e_cmd == ELF_C_WRITE
+
 *
+
 *       The ELF object is being created afresh in this sub-case;
+
 *       there is no pre-existing content in the underlying ELF
+
 *       object.
+
 */
+

+
/*
+
 * The types of extents in an ELF object.
+
 */
+
enum elf_extent {
+
	ELF_EXTENT_EHDR,
+
	ELF_EXTENT_PHDR,
+
	ELF_EXTENT_SECTION,
+
	ELF_EXTENT_SHDR
+
};
+

+
/*
+
 * A extent descriptor, used when laying out an ELF object.
 */
+
struct _Elf_Extent {
+
	SLIST_ENTRY(_Elf_Extent) ex_next;
+
	uint64_t	ex_start; /* Start of the region. */
+
	uint64_t	ex_size;  /* The size of the region. */
+
	enum elf_extent	ex_type;  /* Type of region. */
+
	void		*ex_desc; /* Associated descriptor. */
+
};
+

+
SLIST_HEAD(_Elf_Extent_List, _Elf_Extent);

/*
 * Compute the extents of a section, by looking at the data
-
 * descriptors associated with it.  The function returns zero if an
-
 * error was detected.  `*rc' holds the maximum file extent seen so
-
 * far.
+
 * descriptors associated with it.  The function returns 1
+
 * if successful, or zero if an error was detected.
 */
static int
-
_libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t *rc)
+
_libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t rc)
{
	int ec;
-
	Elf_Data *d, *td;
-
	unsigned int elftype;
+
	Elf_Data *d;
+
	size_t fsz, msz;
	uint32_t sh_type;
	uint64_t d_align;
-
	uint64_t sh_align, sh_entsize, sh_offset, sh_size;
+
	Elf32_Shdr *shdr32;
+
	Elf64_Shdr *shdr64;
+
	unsigned int elftype;
+
	struct _Libelf_Data *ld;
	uint64_t scn_size, scn_alignment;
-

-
	/*
-
	 * We need to recompute library private data structures if one
-
	 * or more of the following is true:
-
	 * - The underlying Shdr structure has been marked `dirty'.  Significant
-
	 *   fields include: `sh_offset', `sh_type', `sh_size', `sh_addralign'.
-
	 * - The Elf_Data structures part of this section have been marked
-
	 *   `dirty'.  Affected members include `d_align', `d_offset', `d_type',
-
	 *   and `d_size'.
-
	 * - The section as a whole is `dirty', e.g., it has been allocated
-
	 *   using elf_newscn(), or if a new Elf_Data structure was added using
-
	 *   elf_newdata().
-
	 *
-
	 * Each of these conditions would result in the ELF_F_DIRTY bit being
-
	 * set on the section descriptor's `s_flags' field.
-
	 */
+
	uint64_t sh_align, sh_entsize, sh_offset, sh_size;

	ec = e->e_class;

+
	shdr32 = &s->s_shdr.s_shdr32;
+
	shdr64 = &s->s_shdr.s_shdr64;
	if (ec == ELFCLASS32) {
-
		sh_type    = s->s_shdr.s_shdr32.sh_type;
-
		sh_align   = (uint64_t) s->s_shdr.s_shdr32.sh_addralign;
-
		sh_entsize = (uint64_t) s->s_shdr.s_shdr32.sh_entsize;
-
		sh_offset  = (uint64_t) s->s_shdr.s_shdr32.sh_offset;
-
		sh_size    = (uint64_t) s->s_shdr.s_shdr32.sh_size;
+
		sh_type    = shdr32->sh_type;
+
		sh_align   = (uint64_t) shdr32->sh_addralign;
+
		sh_entsize = (uint64_t) shdr32->sh_entsize;
+
		sh_offset  = (uint64_t) shdr32->sh_offset;
+
		sh_size    = (uint64_t) shdr32->sh_size;
	} else {
-
		sh_type    = s->s_shdr.s_shdr64.sh_type;
-
		sh_align   = s->s_shdr.s_shdr64.sh_addralign;
-
		sh_entsize = s->s_shdr.s_shdr64.sh_entsize;
-
		sh_offset  = s->s_shdr.s_shdr64.sh_offset;
-
		sh_size    = s->s_shdr.s_shdr64.sh_size;
+
		sh_type    = shdr64->sh_type;
+
		sh_align   = shdr64->sh_addralign;
+
		sh_entsize = shdr64->sh_entsize;
+
		sh_offset  = shdr64->sh_offset;
+
		sh_size    = shdr64->sh_size;
	}

-
	if (sh_type == SHT_NULL || sh_type == SHT_NOBITS)
-
		return (1);
-

-
	if ((s->s_flags & ELF_F_DIRTY) == 0) {
-
		if ((size_t) *rc < sh_offset + sh_size)
-
			*rc = sh_offset + sh_size;
-
		return (1);
-
	}
+
	assert(sh_type != SHT_NULL && sh_type != SHT_NOBITS);

	elftype = _libelf_xlate_shtype(sh_type);
	if (elftype > ELF_T_LAST) {
@@ -131,48 +148,128 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t *rc)
		return (0);
	}

+
	if (sh_align == 0)
+
		sh_align = _libelf_falign(elftype, ec);
+

+
	/*
+
	 * Compute the section's size and alignment using the data
+
	 * descriptors associated with the section.
+
	 */
+
	if (STAILQ_EMPTY(&s->s_data)) {
+
		/*
+
		 * The section's content (if any) has not been read in
+
		 * yet.  If section is not dirty marked dirty, we can
+
		 * reuse the values in the 'sh_size' and 'sh_offset'
+
		 * fields of the section header.
+
		 */
+
		if ((s->s_flags & ELF_F_DIRTY) == 0) {
+
			/*
+
			 * If the library is doing the layout, then we
+
			 * compute the new start offset for the
+
			 * section based on the current offset and the
+
			 * section's alignment needs.
+
			 *
+
			 * If the application is doing the layout, we
+
			 * can use the value in the 'sh_offset' field
+
			 * in the section header directly.
+
			 */
+
			if (e->e_flags & ELF_F_LAYOUT)
+
				goto updatedescriptor;
+
			else
+
				goto computeoffset;
+
		}
+

+
		/*
+
		 * Otherwise, we need to bring in the section's data
+
		 * from the underlying ELF object.
+
		 */
+
		if (e->e_cmd != ELF_C_WRITE && elf_getdata(s, NULL) == NULL)
+
			return (0);
+
	}
+

	/*
-
	 * Compute the extent of the data descriptors associated with
-
	 * this section.
+
	 * Loop through the section's data descriptors.
	 */
+
	scn_size = 0L;
	scn_alignment = 0;
-
	if (sh_align == 0)
-
		sh_align = _libelf_falign(elftype, ec);
+
	STAILQ_FOREACH(ld, &s->s_data, d_next)  {
+

+
		d = &ld->d_data;

-
	/* Compute the section alignment. */
-
	STAILQ_FOREACH(d, &s->s_data, d_next)  {
-
		if (d->d_type > ELF_T_LAST) {
+
		/*
+
		 * The data buffer's type is known.
+
		 */
+
		if (d->d_type >= ELF_T_NUM) {
			LIBELF_SET_ERROR(DATA, 0);
			return (0);
		}
+

+
		/*
+
		 * The data buffer's version is supported.
+
		 */
		if (d->d_version != e->e_version) {
			LIBELF_SET_ERROR(VERSION, 0);
			return (0);
		}
-
		if ((d_align = d->d_align) == 0 || (d_align & (d_align - 1))) {
+

+
		/*
+
		 * The buffer's alignment is non-zero and a power of
+
		 * two.
+
		 */
+
		if ((d_align = d->d_align) == 0 ||
+
		    (d_align & (d_align - 1))) {
			LIBELF_SET_ERROR(DATA, 0);
			return (0);
		}
-
		if (d_align > scn_alignment)
-
			scn_alignment = d_align;
-
	}

-
	scn_size = 0L;
+
		/*
+
		 * The buffer's size should be a multiple of the
+
		 * memory size of the underlying type.
+
		 */
+
		msz = _libelf_msize(d->d_type, ec, e->e_version);
+
		if (d->d_size % msz) {
+
			LIBELF_SET_ERROR(DATA, 0);
+
			return (0);
+
		}

-
	STAILQ_FOREACH_SAFE(d, &s->s_data, d_next, td) {
+
		/*
+
		 * If the application is controlling layout, then the
+
		 * d_offset field should be compatible with the
+
		 * buffer's specified alignment.
+
		 */
+
		if ((e->e_flags & ELF_F_LAYOUT) &&
+
		    (d->d_off & (d_align - 1))) {
+
			LIBELF_SET_ERROR(LAYOUT, 0);
+
			return (0);
+
		}
+

+
		/*
+
		 * Compute the section's size.
+
		 */
		if (e->e_flags & ELF_F_LAYOUT) {
			if ((uint64_t) d->d_off + d->d_size > scn_size)
				scn_size = d->d_off + d->d_size;
		} else {
			scn_size = roundup2(scn_size, d->d_align);
			d->d_off = scn_size;
-
			scn_size += d->d_size;
+
			fsz = _libelf_fsize(d->d_type, ec, d->d_version,
+
			    d->d_size / msz);
+
			scn_size += fsz;
		}
+

+
		/*
+
		 * The section's alignment is the maximum alignment
+
		 * needed for its data buffers.
+
		 */
+
		if (d_align > scn_alignment)
+
			scn_alignment = d_align;
	}

+

	/*
-
	 * If the application is requesting full control over the layout
-
	 * of the section, check its values for sanity.
+
	 * If the application is requesting full control over the
+
	 * layout of the section, check the section's specified size,
+
	 * offsets and alignment for sanity.
	 */
	if (e->e_flags & ELF_F_LAYOUT) {
		if (scn_alignment > sh_align || sh_offset % sh_align ||
@@ -180,114 +277,181 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t *rc)
			LIBELF_SET_ERROR(LAYOUT, 0);
			return (0);
		}
-
	} else {
-
		/*
-
		 * Otherwise compute the values in the section header.
-
		 */
+
		goto updatedescriptor;
+
	}

-
		if (scn_alignment > sh_align)
-
			sh_align = scn_alignment;
+
	/*
+
	 * Otherwise, compute the values in the section header.
+
	 *
+
	 * The section alignment is the maximum alignment for any of
+
	 * its contained data descriptors.
+
	 */
+
	if (scn_alignment > sh_align)
+
		sh_align = scn_alignment;

-
		/*
-
		 * If the section entry size is zero, try and fill in an
-
		 * appropriate entry size.  Per the elf(5) manual page
-
		 * sections without fixed-size entries should have their
-
		 * 'sh_entsize' field set to zero.
-
		 */
-
		if (sh_entsize == 0 &&
-
		    (sh_entsize = _libelf_fsize(elftype, ec, e->e_version,
-
		    (size_t) 1)) == 1)
-
			sh_entsize = 0;
+
	/*
+
	 * If the section entry size is zero, try and fill in an
+
	 * appropriate entry size.  Per the elf(5) manual page
+
	 * sections without fixed-size entries should have their
+
	 * 'sh_entsize' field set to zero.
+
	 */
+
	if (sh_entsize == 0 &&
+
	    (sh_entsize = _libelf_fsize(elftype, ec, e->e_version,
+
		(size_t) 1)) == 1)
+
		sh_entsize = 0;

-
		sh_size = scn_size;
-
		sh_offset = roundup(*rc, sh_align);
+
	sh_size = scn_size;

-
		if (ec == ELFCLASS32) {
-
			s->s_shdr.s_shdr32.sh_addralign = (uint32_t) sh_align;
-
			s->s_shdr.s_shdr32.sh_entsize   = (uint32_t) sh_entsize;
-
			s->s_shdr.s_shdr32.sh_offset    = (uint32_t) sh_offset;
-
			s->s_shdr.s_shdr32.sh_size      = (uint32_t) sh_size;
-
		} else {
-
			s->s_shdr.s_shdr64.sh_addralign = sh_align;
-
			s->s_shdr.s_shdr64.sh_entsize   = sh_entsize;
-
			s->s_shdr.s_shdr64.sh_offset    = sh_offset;
-
			s->s_shdr.s_shdr64.sh_size      = sh_size;
-
		}
-
	}
+
computeoffset:
+
	/*
+
	 * Compute the new offset for the section based on
+
	 * the section's alignment needs.
+
	 */
+
	sh_offset = roundup(rc, sh_align);

-
	if ((size_t) *rc < sh_offset + sh_size)
-
		*rc = sh_offset + sh_size;
+
	/*
+
	 * Update the section header.
+
	 */
+
	if (ec == ELFCLASS32) {
+
		shdr32->sh_addralign = (uint32_t) sh_align;
+
		shdr32->sh_entsize   = (uint32_t) sh_entsize;
+
		shdr32->sh_offset    = (uint32_t) sh_offset;
+
		shdr32->sh_size      = (uint32_t) sh_size;
+
	} else {
+
		shdr64->sh_addralign = sh_align;
+
		shdr64->sh_entsize   = sh_entsize;
+
		shdr64->sh_offset    = sh_offset;
+
		shdr64->sh_size      = sh_size;
+
	}

+
updatedescriptor:
+
	/*
+
	 * Update the section descriptor.
+
	 */
	s->s_size = sh_size;
	s->s_offset = sh_offset;
+

	return (1);
}

+
/*
+
 * Free a list of extent descriptors.
+
 */
+

+
static void
+
_libelf_release_extents(struct _Elf_Extent_List *extents)
+
{
+
	struct _Elf_Extent *ex;
+

+
	while ((ex = SLIST_FIRST(extents)) != NULL) {
+
		SLIST_REMOVE_HEAD(extents, ex_next);
+
		free(ex);
+
	}
+
}

/*
-
 * Insert a section in ascending order in the list
+
 * Check if an extent 's' defined by [start..start+size) is free.
+
 * This routine assumes that the given extent list is sorted in order
+
 * of ascending extent offsets.
 */

static int
-
_libelf_insert_section(Elf *e, Elf_Scn *s)
+
_libelf_extent_is_unused(struct _Elf_Extent_List *extents,
+
    const uint64_t start, const uint64_t size, struct _Elf_Extent **prevt)
{
-
	Elf_Scn *t, *prevt;
-
	uint64_t smax, smin, tmax, tmin;
+
	uint64_t tmax, tmin;
+
	struct _Elf_Extent *t, *pt;
+
	const uint64_t smax = start + size;

-
	smin = s->s_offset;
-
	smax = smin + s->s_size;
+
	/* First, look for overlaps with existing extents. */
+
	pt = NULL;
+
	SLIST_FOREACH(t, extents, ex_next) {
+
		tmin = t->ex_start;
+
		tmax = tmin + t->ex_size;

-
	prevt = NULL;
-
	STAILQ_FOREACH(t, &e->e_u.e_elf.e_scn, s_next) {
-
		tmin = t->s_offset;
-
		tmax = tmin + t->s_size;
-

-
		if (tmax <= smin) {
+
		if (tmax <= start) {
			/*
			 * 't' lies entirely before 's': ...| t |...| s |...
			 */
-
			prevt = t;
+
			pt = t;
			continue;
-
		} else if (smax <= tmin)
+
		} else if (smax <= tmin) {
			/*
-
			 * 's' lies entirely before 't', and after 'prevt':
-
			 *      ...| prevt |...| s |...| t |...
+
			 * 's' lies entirely before 't', and after 'pt':
+
			 *      ...| pt |...| s |...| t |...
			 */
+
			assert(pt == NULL ||
+
			    pt->ex_start + pt->ex_size <= start);
			break;
-
		else {	/* 's' and 't' overlap. */
-
			LIBELF_SET_ERROR(LAYOUT, 0);
+
		} else
+
			/* 's' and 't' overlap. */
			return (0);
-
		}
	}

	if (prevt)
-
		STAILQ_INSERT_AFTER(&e->e_u.e_elf.e_scn, prevt, s, s_next);
+
		*prevt = pt;
+
	return (1);
+
}
+

+
/*
+
 * Insert an extent into the list of extents.
+
 */
+

+
static int
+
_libelf_insert_extent(struct _Elf_Extent_List *extents, int type,
+
    uint64_t start, uint64_t size, void *desc)
+
{
+
	struct _Elf_Extent *ex, *prevt;
+

+
	assert(type >= ELF_EXTENT_EHDR && type <= ELF_EXTENT_SHDR);
+

+
	prevt = NULL;
+

+
	/*
+
	 * If the requested range overlaps with an existing extent,
+
	 * signal an error.
+
	 */
+
	if (!_libelf_extent_is_unused(extents, start, size, &prevt)) {
+
		LIBELF_SET_ERROR(LAYOUT, 0);
+
		return (0);
+
	}
+

+
	/* Allocate and fill in a new extent descriptor. */
+
	if ((ex = malloc(sizeof(struct _Elf_Extent))) == NULL) {
+
		LIBELF_SET_ERROR(RESOURCE, errno);
+
		return (0);
+
	}
+
	ex->ex_start = start;
+
	ex->ex_size = size;
+
	ex->ex_desc = desc;
+
	ex->ex_type = type;
+

+
	/* Insert the region descriptor into the list. */
+
	if (prevt)
+
		SLIST_INSERT_AFTER(prevt, ex, ex_next);
	else
-
		STAILQ_INSERT_HEAD(&e->e_u.e_elf.e_scn, s, s_next);
+
		SLIST_INSERT_HEAD(extents, ex, ex_next);
	return (1);
}

+
/*
+
 * Recompute section layout.
+
 */
+

static off_t
-
_libelf_resync_sections(Elf *e, off_t rc)
+
_libelf_resync_sections(Elf *e, off_t rc, struct _Elf_Extent_List *extents)
{
	int ec;
-
	off_t nrc;
-
	size_t sh_type, shdr_start, shdr_end;
-
	Elf_Scn *s, *ts;
+
	Elf_Scn *s;
+
	size_t sh_type;

	ec = e->e_class;

	/*
	 * Make a pass through sections, computing the extent of each
-
	 * section. Order in increasing order of addresses.
+
	 * section.
	 */
-

-
	nrc = rc;
-
	STAILQ_FOREACH(s, &e->e_u.e_elf.e_scn, s_next)
-
		if (_libelf_compute_section_extents(e, s, &nrc) == 0)
-
			return ((off_t) -1);
-

-
	STAILQ_FOREACH_SAFE(s, &e->e_u.e_elf.e_scn, s_next, ts) {
+
	STAILQ_FOREACH(s, &e->e_u.e_elf.e_scn, s_next) {
		if (ec == ELFCLASS32)
			sh_type = s->s_shdr.s_shdr32.sh_type;
		else
@@ -296,62 +460,54 @@ _libelf_resync_sections(Elf *e, off_t rc)
		if (sh_type == SHT_NOBITS || sh_type == SHT_NULL)
			continue;

-
		if (s->s_offset < (uint64_t) rc) {
-
			if (s->s_offset + s->s_size < (uint64_t) rc) {
-
				/*
-
				 * Try insert this section in the
-
				 * correct place in the list,
-
				 * detecting overlaps if any.
-
				 */
-
				STAILQ_REMOVE(&e->e_u.e_elf.e_scn, s, _Elf_Scn,
-
				    s_next);
-
				if (_libelf_insert_section(e, s) == 0)
-
					return ((off_t) -1);
-
			} else {
-
				LIBELF_SET_ERROR(LAYOUT, 0);
-
				return ((off_t) -1);
-
			}
-
		} else
-
			rc = s->s_offset + s->s_size;
-
	}
-

-
	/*
-
	 * If the application is controlling file layout, check for an
-
	 * overlap between this section's extents and the SHDR table.
-
	 */
-
	if (e->e_flags & ELF_F_LAYOUT) {
-

-
		if (e->e_class == ELFCLASS32)
-
			shdr_start = e->e_u.e_elf.e_ehdr.e_ehdr32->e_shoff;
-
		else
-
			shdr_start = e->e_u.e_elf.e_ehdr.e_ehdr64->e_shoff;
+
		if (_libelf_compute_section_extents(e, s, rc) == 0)
+
			return ((off_t) -1);

-
		shdr_end = shdr_start + _libelf_fsize(ELF_T_SHDR, e->e_class,
-
		    e->e_version, e->e_u.e_elf.e_nscn);
+
		if (s->s_size == 0)
+
			continue;

-
		STAILQ_FOREACH(s, &e->e_u.e_elf.e_scn, s_next) {
-
			if (s->s_offset >= shdr_end ||
-
			    s->s_offset + s->s_size <= shdr_start)
-
				continue;
-
			LIBELF_SET_ERROR(LAYOUT, 0);
+
		if (!_libelf_insert_extent(extents, ELF_EXTENT_SECTION,
+
		    s->s_offset, s->s_size, s))
			return ((off_t) -1);
-
		}
-
	}

-
	assert(nrc == rc);
+
		if ((size_t) rc < s->s_offset + s->s_size)
+
			rc = s->s_offset + s->s_size;
+
	}

	return (rc);
}

+
/*
+
 * Recompute the layout of the ELF object and update the internal data
+
 * structures associated with the ELF descriptor.
+
 *
+
 * Returns the size in bytes the ELF object would occupy in its file
+
 * representation.
+
 *
+
 * After a successful call to this function, the following structures
+
 * are updated:
+
 *
+
 * - The ELF header is updated.
+
 * - All extents in the ELF object are sorted in order of ascending
+
 *   addresses.  Sections have their section header table entries
+
 *   updated.  An error is signalled if an overlap was detected among
+
 *   extents.
+
 * - Data descriptors associated with sections are checked for valid
+
 *   types, offsets and alignment.
+
 *
+
 * After a resync_elf() successfully returns, the ELF descriptor is
+
 * ready for being handed over to _libelf_write_elf().
+
 */
+

static off_t
-
_libelf_resync_elf(Elf *e)
+
_libelf_resync_elf(Elf *e, struct _Elf_Extent_List *extents)
{
	int ec, eh_class, eh_type;
	unsigned int eh_byteorder, eh_version;
	size_t align, fsz;
	size_t phnum, shnum;
	off_t rc, phoff, shoff;
-
	void *ehdr;
+
	void *ehdr, *phdr;
	Elf32_Ehdr *eh32;
	Elf64_Ehdr *eh64;

@@ -433,6 +589,9 @@ _libelf_resync_elf(Elf *e)

	rc += _libelf_fsize(ELF_T_EHDR, ec, eh_version, (size_t) 1);

+
	if (!_libelf_insert_extent(extents, ELF_EXTENT_EHDR, 0, rc, ehdr))
+
		return ((off_t) -1);
+

	/*
	 * Compute the layout the program header table, if one is
	 * present.  The program header table needs to be aligned to a
@@ -447,7 +606,7 @@ _libelf_resync_elf(Elf *e)
			 * Check offsets for sanity.
			 */
			if (rc > phoff) {
-
				LIBELF_SET_ERROR(HEADER, 0);
+
				LIBELF_SET_ERROR(LAYOUT, 0);
				return ((off_t) -1);
			}

@@ -460,6 +619,12 @@ _libelf_resync_elf(Elf *e)
			phoff = roundup(rc, align);

		rc = phoff + fsz;
+

+
		phdr = _libelf_getphdr(e, ec);
+

+
		if (!_libelf_insert_extent(extents, ELF_EXTENT_PHDR, phoff,
+
			fsz, phdr))
+
			return ((off_t) -1);
	} else
		phoff = 0;

@@ -470,22 +635,26 @@ _libelf_resync_elf(Elf *e)

	if (e->e_cmd != ELF_C_WRITE &&
	    (e->e_flags & LIBELF_F_SHDRS_LOADED) == 0 &&
-
	    _libelf_load_scn(e, ehdr) == 0)
+
	    _libelf_load_section_headers(e, ehdr) == 0)
		return ((off_t) -1);

-
	if ((rc = _libelf_resync_sections(e, rc)) < 0)
+
	if ((rc = _libelf_resync_sections(e, rc, extents)) < 0)
		return ((off_t) -1);

	/*
	 * Compute the space taken up by the section header table, if
-
	 * one is needed.  If ELF_F_LAYOUT is asserted, the
-
	 * application may have placed the section header table in
-
	 * between existing sections, so the net size of the file need
-
	 * not increase due to the presence of the section header
-
	 * table.
+
	 * one is needed.
+
	 *
+
	 * If ELF_F_LAYOUT has been asserted, the application may have
+
	 * placed the section header table in between existing
+
	 * sections, so the net size of the file need not increase due
+
	 * to the presence of the section header table.
+
	 *
+
	 * If the library is responsible for laying out the object,
+
	 * the section header table is placed after section data.
	 */
	if (shnum) {
-
		fsz = _libelf_fsize(ELF_T_SHDR, ec, eh_version, (size_t) 1);
+
		fsz = _libelf_fsize(ELF_T_SHDR, ec, eh_version, shnum);
		align = _libelf_falign(ELF_T_SHDR, ec);

		if (e->e_flags & ELF_F_LAYOUT) {
@@ -496,8 +665,12 @@ _libelf_resync_elf(Elf *e)
		} else
			shoff = roundup(rc, align);

-
		if (shoff + fsz * shnum > (size_t) rc)
-
			rc = shoff + fsz * shnum;
+
		if (shoff + fsz > (size_t) rc)
+
			rc = shoff + fsz;
+

+
		if (!_libelf_insert_extent(extents, ELF_EXTENT_SHDR, shoff,
+
		    fsz, NULL))
+
			return ((off_t) -1);
	} else
		shoff = 0;

@@ -526,18 +699,25 @@ _libelf_resync_elf(Elf *e)
}

/*
-
 * Write out the contents of a section.
+
 * Write out the contents of an ELF section.
 */

-
static off_t
-
_libelf_write_scn(Elf *e, char *nf, Elf_Scn *s, off_t rc)
+
static size_t
+
_libelf_write_scn(Elf *e, char *nf, struct _Elf_Extent *ex)
{
	int ec;
-
	size_t fsz, msz, nobjects;
-
	uint32_t sh_type;
-
	uint64_t sh_off, sh_size;
+
	Elf_Scn *s;
	int elftype;
	Elf_Data *d, dst;
+
	uint32_t sh_type;
+
	struct _Libelf_Data *ld;
+
	uint64_t sh_off, sh_size;
+
	size_t fsz, msz, nobjects, rc;
+

+
	assert(ex->ex_type == ELF_EXTENT_SECTION);
+

+
	s = ex->ex_desc;
+
	rc = ex->ex_start;

	if ((ec = e->e_class) == ELFCLASS32) {
		sh_type = s->s_shdr.s_shdr32.sh_type;
@@ -572,7 +752,10 @@ _libelf_write_scn(Elf *e, char *nf, Elf_Scn *s, off_t rc)
		if ((d = elf_rawdata(s, NULL)) == NULL)
			return ((off_t) -1);

-
		STAILQ_FOREACH(d, &s->s_rawdata, d_next) {
+
		STAILQ_FOREACH(ld, &s->s_rawdata, d_next) {
+

+
			d = &ld->d_data;
+

			if ((uint64_t) rc < sh_off + d->d_off)
				(void) memset(nf + rc,
				    LIBELF_PRIVATE(fillchar), sh_off +
@@ -600,7 +783,9 @@ _libelf_write_scn(Elf *e, char *nf, Elf_Scn *s, off_t rc)

	dst.d_version = e->e_version;

-
	STAILQ_FOREACH(d, &s->s_data, d_next) {
+
	STAILQ_FOREACH(ld, &s->s_data, d_next) {
+

+
		d = &ld->d_data;

		msz = _libelf_msize(d->d_type, ec, e->e_version);

@@ -632,195 +817,298 @@ _libelf_write_scn(Elf *e, char *nf, Elf_Scn *s, off_t rc)
}

/*
-
 * Write out the file image.
-
 *
-
 * The original file could have been mapped in with an ELF_C_RDWR
-
 * command and the application could have added new content or
-
 * re-arranged its sections before calling elf_update().  Consequently
-
 * its not safe to work `in place' on the original file.  So we
-
 * malloc() the required space for the updated ELF object and build
-
 * the object there and write it out to the underlying file at the
-
 * end.  Note that the application may have opened the underlying file
-
 * in ELF_C_RDWR and only retrieved/modified a few sections.  We take
-
 * care to avoid translating file sections unnecessarily.
-
 *
-
 * Gaps in the coverage of the file by the file's sections will be
-
 * filled with the fill character set by elf_fill(3).
+
 * Write out an ELF Executable Header.
 */

static off_t
-
_libelf_write_elf(Elf *e, off_t newsize)
+
_libelf_write_ehdr(Elf *e, char *nf, struct _Elf_Extent *ex)
{
	int ec;
-
	off_t maxrc, rc;
-
	size_t fsz, msz, phnum, shnum;
-
	uint64_t phoff, shoff;
	void *ehdr;
-
	char *newfile;
+
	size_t fsz, msz;
	Elf_Data dst, src;
-
	Elf_Scn *scn, *tscn;
-
	Elf32_Ehdr *eh32;
-
	Elf64_Ehdr *eh64;

-
	assert(e->e_kind == ELF_K_ELF);
-
	assert(e->e_cmd != ELF_C_READ);
-
	assert(e->e_fd >= 0);
-

-
	if ((newfile = malloc((size_t) newsize)) == NULL) {
-
		LIBELF_SET_ERROR(RESOURCE, errno);
-
		return ((off_t) -1);
-
	}
+
	assert(ex->ex_type == ELF_EXTENT_EHDR);
+
	assert(ex->ex_start == 0); /* Ehdr always comes first. */

	ec = e->e_class;

	ehdr = _libelf_ehdr(e, ec, 0);
	assert(ehdr != NULL);

+
	fsz = _libelf_fsize(ELF_T_EHDR, ec, e->e_version, (size_t) 1);
+
	msz = _libelf_msize(ELF_T_EHDR, ec, e->e_version);
+

+
	(void) memset(&dst, 0, sizeof(dst));
+
	(void) memset(&src, 0, sizeof(src));
+

+
	src.d_buf     = ehdr;
+
	src.d_size    = msz;
+
	src.d_type    = ELF_T_EHDR;
+
	src.d_version = dst.d_version = e->e_version;
+

+
	dst.d_buf     = nf;
+
	dst.d_size    = fsz;
+

+
	if (_libelf_xlate(&dst, &src, e->e_byteorder, ec, ELF_TOFILE) ==
+
	    NULL)
+
		return ((off_t) -1);
+

+
	return ((off_t) fsz);
+
}
+

+
/*
+
 * Write out an ELF program header table.
+
 */
+

+
static off_t
+
_libelf_write_phdr(Elf *e, char *nf, struct _Elf_Extent *ex)
+
{
+
	int ec;
+
	void *ehdr;
+
	Elf32_Ehdr *eh32;
+
	Elf64_Ehdr *eh64;
+
	Elf_Data dst, src;
+
	size_t fsz, phnum;
+
	uint64_t phoff;
+

+
	assert(ex->ex_type == ELF_EXTENT_PHDR);
+

+
	ec = e->e_class;
+
	ehdr = _libelf_ehdr(e, ec, 0);
	phnum = e->e_u.e_elf.e_nphdr;

+
	assert(phnum > 0);
+

	if (ec == ELFCLASS32) {
		eh32 = (Elf32_Ehdr *) ehdr;
-

		phoff = (uint64_t) eh32->e_phoff;
-
		shnum = eh32->e_shnum;
-
		shoff = (uint64_t) eh32->e_shoff;
	} else {
		eh64 = (Elf64_Ehdr *) ehdr;
-

		phoff = eh64->e_phoff;
-
		shnum = eh64->e_shnum;
-
		shoff = eh64->e_shoff;
	}

-
	fsz = _libelf_fsize(ELF_T_EHDR, ec, e->e_version, (size_t) 1);
-
	msz = _libelf_msize(ELF_T_EHDR, ec, e->e_version);
+
	assert(phoff > 0);
+
	assert(ex->ex_start == phoff);
+
	assert(phoff % _libelf_falign(ELF_T_PHDR, ec) == 0);

	(void) memset(&dst, 0, sizeof(dst));
	(void) memset(&src, 0, sizeof(src));

-
	src.d_buf     = ehdr;
-
	src.d_size    = msz;
-
	src.d_type    = ELF_T_EHDR;
-
	src.d_version = dst.d_version = e->e_version;
+
	fsz = _libelf_fsize(ELF_T_PHDR, ec, e->e_version, phnum);
+
	assert(fsz > 0);

-
	rc = 0;
+
	src.d_buf = _libelf_getphdr(e, ec);
+
	src.d_version = dst.d_version = e->e_version;
+
	src.d_type = ELF_T_PHDR;
+
	src.d_size = phnum * _libelf_msize(ELF_T_PHDR, ec,
+
	    e->e_version);

-
	dst.d_buf     = newfile + rc;
-
	dst.d_size    = fsz;
+
	dst.d_size = fsz;
+
	dst.d_buf = nf + ex->ex_start;

	if (_libelf_xlate(&dst, &src, e->e_byteorder, ec, ELF_TOFILE) ==
	    NULL)
-
		goto error;
+
		return ((off_t) -1);

-
	rc += fsz;
+
	return (phoff + fsz);
+
}

-
	/*
-
	 * Write the program header table if present.
-
	 */
+
/*
+
 * Write out an ELF section header table.
+
 */

-
	if (phnum != 0 && phoff != 0) {
-
		assert((unsigned) rc <= phoff);
+
static off_t
+
_libelf_write_shdr(Elf *e, char *nf, struct _Elf_Extent *ex)
+
{
+
	int ec;
+
	void *ehdr;
+
	Elf_Scn *scn;
+
	uint64_t shoff;
+
	Elf32_Ehdr *eh32;
+
	Elf64_Ehdr *eh64;
+
	size_t fsz, nscn;
+
	Elf_Data dst, src;

-
		fsz = _libelf_fsize(ELF_T_PHDR, ec, e->e_version, phnum);
+
	assert(ex->ex_type == ELF_EXTENT_SHDR);

-
		assert(phoff % _libelf_falign(ELF_T_PHDR, ec) == 0);
-
		assert(fsz > 0);
+
	ec = e->e_class;
+
	ehdr = _libelf_ehdr(e, ec, 0);
+
	nscn = e->e_u.e_elf.e_nscn;

-
		src.d_buf = _libelf_getphdr(e, ec);
-
		src.d_version = dst.d_version = e->e_version;
-
		src.d_type = ELF_T_PHDR;
-
		src.d_size = phnum * _libelf_msize(ELF_T_PHDR, ec,
-
		    e->e_version);
+
	if (ec == ELFCLASS32) {
+
		eh32 = (Elf32_Ehdr *) ehdr;
+
		shoff = (uint64_t) eh32->e_shoff;
+
	} else {
+
		eh64 = (Elf64_Ehdr *) ehdr;
+
		shoff = eh64->e_shoff;
+
	}

-
		dst.d_size = fsz;
+
	assert(nscn > 0);
+
	assert(shoff % _libelf_falign(ELF_T_SHDR, ec) == 0);
+
	assert(ex->ex_start == shoff);

-
		if ((uint64_t) rc < phoff)
-
			(void) memset(newfile + rc,
-
			    LIBELF_PRIVATE(fillchar), phoff - rc);
+
	(void) memset(&dst, 0, sizeof(dst));
+
	(void) memset(&src, 0, sizeof(src));

-
		dst.d_buf = newfile + rc;
+
	src.d_type = ELF_T_SHDR;
+
	src.d_size = _libelf_msize(ELF_T_SHDR, ec, e->e_version);
+
	src.d_version = dst.d_version = e->e_version;

-
		if (_libelf_xlate(&dst, &src, e->e_byteorder, ec, ELF_TOFILE) ==
-
		    NULL)
-
			goto error;
+
	fsz = _libelf_fsize(ELF_T_SHDR, ec, e->e_version, (size_t) 1);

-
		rc = phoff + fsz;
+
	STAILQ_FOREACH(scn, &e->e_u.e_elf.e_scn, s_next) {
+
		if (ec == ELFCLASS32)
+
			src.d_buf = &scn->s_shdr.s_shdr32;
+
		else
+
			src.d_buf = &scn->s_shdr.s_shdr64;
+

+
		dst.d_size = fsz;
+
		dst.d_buf = nf + ex->ex_start + scn->s_ndx * fsz;
+

+
		if (_libelf_xlate(&dst, &src, e->e_byteorder, ec,
+
		    ELF_TOFILE) == NULL)
+
			return ((off_t) -1);
	}

-
	/*
-
	 * Write out individual sections.
-
	 */
+
	return (ex->ex_start + nscn * fsz);
+
}

-
	STAILQ_FOREACH(scn, &e->e_u.e_elf.e_scn, s_next)
-
 		if ((rc = _libelf_write_scn(e, newfile, scn, rc)) < 0)
-
			goto error;
+
/*
+
 * Write out the file image.
+
 *
+
 * The original file could have been mapped in with an ELF_C_RDWR
+
 * command and the application could have added new content or
+
 * re-arranged its sections before calling elf_update().  Consequently
+
 * its not safe to work `in place' on the original file.  So we
+
 * malloc() the required space for the updated ELF object and build
+
 * the object there and write it out to the underlying file at the
+
 * end.  Note that the application may have opened the underlying file
+
 * in ELF_C_RDWR and only retrieved/modified a few sections.  We take
+
 * care to avoid translating file sections unnecessarily.
+
 *
+
 * Gaps in the coverage of the file by the file's sections will be
+
 * filled with the fill character set by elf_fill(3).
+
 */

-
	/*
-
	 * Write out the section header table, if required.  Note that
-
	 * if flag ELF_F_LAYOUT has been set the section header table
-
	 * could reside in between byte ranges mapped by section
-
	 * descriptors.
-
	 */
-
	if (shnum != 0 && shoff != 0) {
-
		if ((uint64_t) rc < shoff)
-
			(void) memset(newfile + rc,
-
			    LIBELF_PRIVATE(fillchar), shoff - rc);
+
static off_t
+
_libelf_write_elf(Elf *e, off_t newsize, struct _Elf_Extent_List *extents)
+
{
+
	off_t nrc, rc;
+
	char *newfile;
+
	Elf_Scn *scn, *tscn;
+
	struct _Elf_Extent *ex;

-
		maxrc = rc;
-
		rc = shoff;
+
	assert(e->e_kind == ELF_K_ELF);
+
	assert(e->e_cmd == ELF_C_RDWR || e->e_cmd == ELF_C_WRITE);
+
	assert(e->e_fd >= 0);
+

+
	if ((newfile = malloc((size_t) newsize)) == NULL) {
+
		LIBELF_SET_ERROR(RESOURCE, errno);
+
		return ((off_t) -1);
+
	}

-
		assert(rc % _libelf_falign(ELF_T_SHDR, ec) == 0);
+
	nrc = rc = 0;
+
	SLIST_FOREACH(ex, extents, ex_next) {

-
		src.d_type = ELF_T_SHDR;
-
		src.d_size = _libelf_msize(ELF_T_SHDR, ec, e->e_version);
-
		src.d_version = dst.d_version = e->e_version;
+
		/* Fill inter-extent gaps. */
+
		if (ex->ex_start > (size_t) rc)
+
			(void) memset(newfile + rc, LIBELF_PRIVATE(fillchar),
+
			    ex->ex_start - rc);

-
		fsz = _libelf_fsize(ELF_T_SHDR, ec, e->e_version, (size_t) 1);
+
		switch (ex->ex_type) {
+
		case ELF_EXTENT_EHDR:
+
			if ((nrc = _libelf_write_ehdr(e, newfile, ex)) < 0)
+
				goto error;
+
			break;

-
		STAILQ_FOREACH(scn, &e->e_u.e_elf.e_scn, s_next) {
-
			if (ec == ELFCLASS32)
-
				src.d_buf = &scn->s_shdr.s_shdr32;
-
			else
-
				src.d_buf = &scn->s_shdr.s_shdr64;
+
		case ELF_EXTENT_PHDR:
+
			if ((nrc = _libelf_write_phdr(e, newfile, ex)) < 0)
+
				goto error;
+
			break;

-
			dst.d_size = fsz;
-
			dst.d_buf = newfile + rc + scn->s_ndx * fsz;
+
		case ELF_EXTENT_SECTION:
+
			if ((nrc = _libelf_write_scn(e, newfile, ex)) < 0)
+
				goto error;
+
			break;

-
			if (_libelf_xlate(&dst, &src, e->e_byteorder, ec,
-
				ELF_TOFILE) != &dst)
+
		case ELF_EXTENT_SHDR:
+
			if ((nrc = _libelf_write_shdr(e, newfile, ex)) < 0)
				goto error;
+
			break;
+

+
		default:
+
			assert(0);
+
			break;
		}

-
		rc += e->e_u.e_elf.e_nscn * fsz;
-
		if (maxrc > rc)
-
			rc = maxrc;
+
		assert(ex->ex_start + ex->ex_size == (size_t) nrc);
+
		assert(rc < nrc);
+

+
		rc = nrc;
	}

	assert(rc == newsize);

	/*
-
	 * Write out the constructed contents and remap the file in
-
	 * read-only.
+
	 * For regular files, throw away existing file content and
+
	 * unmap any existing mappings.
	 */
-

-
	if (e->e_rawfile && munmap(e->e_rawfile, e->e_rawsize) < 0) {
-
		LIBELF_SET_ERROR(IO, errno);
-
		goto error;
+
	if ((e->e_flags & LIBELF_F_SPECIAL_FILE) == 0) {
+
		if (ftruncate(e->e_fd, (off_t) 0) < 0 ||
+
		    lseek(e->e_fd, (off_t) 0, SEEK_SET)) {
+
			LIBELF_SET_ERROR(IO, errno);
+
			goto error;
+
		}
+
#if	ELFTC_HAVE_MMAP
+
		if (e->e_flags & LIBELF_F_RAWFILE_MMAP) {
+
			assert(e->e_rawfile != NULL);
+
			assert(e->e_cmd == ELF_C_RDWR);
+
			if (munmap(e->e_rawfile, e->e_rawsize) < 0) {
+
				LIBELF_SET_ERROR(IO, errno);
+
				goto error;
+
			}
+
		}
+
#endif
	}

-
	if (write(e->e_fd, newfile, (size_t) newsize) != newsize ||
-
	    lseek(e->e_fd, (off_t) 0, SEEK_SET) < 0) {
+
	/*
+
	 * Write out the new contents.
+
	 */
+
	if (write(e->e_fd, newfile, (size_t) newsize) != newsize) {
		LIBELF_SET_ERROR(IO, errno);
		goto error;
	}

-
	if (e->e_cmd != ELF_C_WRITE) {
-
		if ((e->e_rawfile = mmap(NULL, (size_t) newsize, PROT_READ,
-
		    MAP_PRIVATE, e->e_fd, (off_t) 0)) == MAP_FAILED) {
-
			LIBELF_SET_ERROR(IO, errno);
-
			goto error;
+
	/*
+
	 * For files opened in ELF_C_RDWR mode, set up the new 'raw'
+
	 * contents.
+
	 */
+
	if (e->e_cmd == ELF_C_RDWR) {
+
		assert(e->e_rawfile != NULL);
+
		assert((e->e_flags & LIBELF_F_RAWFILE_MALLOC) ||
+
		    (e->e_flags & LIBELF_F_RAWFILE_MMAP));
+
		if (e->e_flags & LIBELF_F_RAWFILE_MALLOC) {
+
			free(e->e_rawfile);
+
			e->e_rawfile = newfile;
+
			newfile = NULL;
+
		}
+
#if	ELFTC_HAVE_MMAP
+
		else if (e->e_flags & LIBELF_F_RAWFILE_MMAP) {
+
			if ((e->e_rawfile = mmap(NULL, (size_t) newsize,
+
			    PROT_READ, MAP_PRIVATE, e->e_fd, (off_t) 0)) ==
+
			    MAP_FAILED) {
+
				LIBELF_SET_ERROR(IO, errno);
+
				goto error;
+
			}
		}
+
#endif	/* ELFTC_HAVE_MMAP */
+

+
		/* Record the new size of the file. */
		e->e_rawsize = newsize;
+
	} else {
+
		/* File opened in ELF_C_WRITE mode. */
+
		assert(e->e_rawfile == NULL);
	}

	/*
@@ -834,7 +1122,7 @@ _libelf_write_elf(Elf *e, off_t newsize)
	STAILQ_FOREACH_SAFE(scn, &e->e_u.e_elf.e_scn, s_next, tscn)
		_libelf_release_scn(scn);

-
	if (ec == ELFCLASS32) {
+
	if (e->e_class == ELFCLASS32) {
		free(e->e_u.e_elf.e_ehdr.e_ehdr32);
		if (e->e_u.e_elf.e_phdr.e_phdr32)
			free(e->e_u.e_elf.e_phdr.e_phdr32);
@@ -850,7 +1138,9 @@ _libelf_write_elf(Elf *e, off_t newsize)
		e->e_u.e_elf.e_phdr.e_phdr64 = NULL;
	}

-
	free(newfile);
+
	/* Free the temporary buffer. */
+
	if (newfile)
+
		free(newfile);

	return (rc);

@@ -860,11 +1150,16 @@ _libelf_write_elf(Elf *e, off_t newsize)
	return ((off_t) -1);
}

+
/*
+
 * Update an ELF object.
+
 */
+

off_t
elf_update(Elf *e, Elf_Cmd c)
{
	int ec;
	off_t rc;
+
	struct _Elf_Extent_List extents;

	rc = (off_t) -1;

@@ -887,28 +1182,23 @@ elf_update(Elf *e, Elf_Cmd c)
		return (rc);
	}

-
	if ((rc = _libelf_resync_elf(e)) < 0)
-
		return (rc);
+
	SLIST_INIT(&extents);

-
	if (c == ELF_C_NULL)
-
		return (rc);
+
	if ((rc = _libelf_resync_elf(e, &extents)) < 0)
+
		goto done;

-
	if (e->e_cmd == ELF_C_READ) {
-
		/*
-
		 * This descriptor was opened in read-only mode or by
-
		 * elf_memory().
-
		 */
-
		if (e->e_fd)
-
			LIBELF_SET_ERROR(MODE, 0);
-
		else
-
			LIBELF_SET_ERROR(ARGUMENT, 0);
-
		return ((off_t) -1);
-
	}
+
	if (c == ELF_C_NULL)
+
		goto done;

	if (e->e_fd < 0) {
+
		rc = (off_t) -1;
		LIBELF_SET_ERROR(SEQUENCE, 0);
-
		return ((off_t) -1);
+
		goto done;
	}

-
	return (_libelf_write_elf(e, rc));
+
	rc = _libelf_write_elf(e, rc, &extents);
+

+
done:
+
	_libelf_release_extents(&extents);
+
	return (rc);
}
modified external/libelf/elf_version.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/elf_version.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: elf_version.3 2123 2011-11-09 15:40:09Z jkoshy $
.\"
-
.Dd June 1, 2006
-
.Dt ELF_VERSION 3
+
.Dd November 9, 2011
.Os
+
.Dt ELF_VERSION 3
.Sh NAME
.Nm elf_version
.Nd retrieve or set ELF library operating version
@@ -80,7 +80,7 @@ operating version and check for an error using the following code
snippet:
.Bd -literal -offset indent
if (elf_version(EV_CURRENT) == EV_NONE)
-
	err(EX_SOFTWARE, "ELF library too old");
+
	err(EXIT_FAILURE, "ELF library too old");
.Ed
.Sh ERRORS
Function
modified external/libelf/elf_version.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,12 +25,13 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/elf_version.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: elf_version.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

unsigned int
elf_version(unsigned int v)
{
added external/libelf/elfdefinitions.h
@@ -0,0 +1,2560 @@
+
/*-
+
 * Copyright (c) 2010 Joseph Koshy
+
 * 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.
+
 *
+
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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.
+
 *
+
 * $Id: elfdefinitions.h 2132 2011-11-10 08:27:41Z jkoshy $
+
 */
+

+
/*
+
 * These definitions are based on:
+
 * - The public specification of the ELF format as defined in the
+
 *   October 2009 draft of System V ABI.
+
 *   See: http://www.sco.com/developers/gabi/latest/ch4.intro.html
+
 * - The May 1998 (version 1.5) draft of "The ELF-64 object format".
+
 * - Processor-specific ELF ABI definitions for sparc, i386, amd64, mips,
+
 *   ia64, and powerpc processors.
+
 * - The "Linkers and Libraries Guide", from Sun Microsystems.
+
 */
+

+
#ifndef _ELFDEFINITIONS_H_
+
#define _ELFDEFINITIONS_H_
+

+
#include <stdint.h>
+

+
/*
+
 * Types of capabilities.
+
 */
+

+
#define	_ELF_DEFINE_CAPABILITIES()				\
+
_ELF_DEFINE_CA(CA_SUNW_NULL,	0,	"ignored")		\
+
_ELF_DEFINE_CA(CA_SUNW_HW_1,	1,	"hardware capability")	\
+
_ELF_DEFINE_CA(CA_SUNW_SW_1,	2,	"software capability")
+

+
#undef	_ELF_DEFINE_CA
+
#define	_ELF_DEFINE_CA(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_CAPABILITIES()
+
	CA__LAST__
+
};
+

+
/*
+
 * Flags used with dynamic linking entries.
+
 */
+

+
#define	_ELF_DEFINE_DYN_FLAGS()					\
+
_ELF_DEFINE_DF(DF_ORIGIN,           0x1,			\
+
	"object being loaded may refer to $ORIGIN")		\
+
_ELF_DEFINE_DF(DF_SYMBOLIC,         0x2,			\
+
	"search library for references before executable")	\
+
_ELF_DEFINE_DF(DF_TEXTREL,          0x4,			\
+
	"relocation entries may modify text segment")		\
+
_ELF_DEFINE_DF(DF_BIND_NOW,         0x8,			\
+
	"process relocation entries at load time")		\
+
_ELF_DEFINE_DF(DF_STATIC_TLS,       0x10,			\
+
	"uses static thread-local storage")
+
#undef	_ELF_DEFINE_DF
+
#define	_ELF_DEFINE_DF(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_DYN_FLAGS()
+
	DF__LAST__
+
};
+

+

+
/*
+
 * Dynamic linking entry types.
+
 */
+

+
#define	_ELF_DEFINE_DYN_TYPES()						\
+
_ELF_DEFINE_DT(DT_NULL,             0, "end of array")			\
+
_ELF_DEFINE_DT(DT_NEEDED,           1, "names a needed library")	\
+
_ELF_DEFINE_DT(DT_PLTRELSZ,         2,					\
+
	"size in bytes of associated relocation entries")		\
+
_ELF_DEFINE_DT(DT_PLTGOT,           3,					\
+
	"address associated with the procedure linkage table")		\
+
_ELF_DEFINE_DT(DT_HASH,             4,					\
+
	"address of the symbol hash table")				\
+
_ELF_DEFINE_DT(DT_STRTAB,           5,					\
+
	"address of the string table")					\
+
_ELF_DEFINE_DT(DT_SYMTAB,           6,					\
+
	"address of the symbol table")					\
+
_ELF_DEFINE_DT(DT_RELA,             7,					\
+
	"address of the relocation table")				\
+
_ELF_DEFINE_DT(DT_RELASZ,           8, "size of the DT_RELA table")	\
+
_ELF_DEFINE_DT(DT_RELAENT,          9, "size of each DT_RELA entry")	\
+
_ELF_DEFINE_DT(DT_STRSZ,            10, "size of the string table")	\
+
_ELF_DEFINE_DT(DT_SYMENT,           11,					\
+
	"size of a symbol table entry")					\
+
_ELF_DEFINE_DT(DT_INIT,             12,					\
+
	"address of the initialization function")			\
+
_ELF_DEFINE_DT(DT_FINI,             13,					\
+
	"address of the finalization function")				\
+
_ELF_DEFINE_DT(DT_SONAME,           14, "names the shared object")	\
+
_ELF_DEFINE_DT(DT_RPATH,            15,					\
+
	"runtime library search path")					\
+
_ELF_DEFINE_DT(DT_SYMBOLIC,         16,					\
+
	"alter symbol resolution algorithm")				\
+
_ELF_DEFINE_DT(DT_REL,              17,					\
+
	"address of the DT_REL table")					\
+
_ELF_DEFINE_DT(DT_RELSZ,            18, "size of the DT_REL table")	\
+
_ELF_DEFINE_DT(DT_RELENT,           19, "size of each DT_REL entry")	\
+
_ELF_DEFINE_DT(DT_PLTREL,           20,					\
+
	"type of relocation entry in the procedure linkage table")	\
+
_ELF_DEFINE_DT(DT_DEBUG,            21, "used for debugging")		\
+
_ELF_DEFINE_DT(DT_TEXTREL,          22,					\
+
	"text segment may be written to during relocation")		\
+
_ELF_DEFINE_DT(DT_JMPREL,           23,					\
+
	"address of relocation entries associated with the procedure linkage table") \
+
_ELF_DEFINE_DT(DT_BIND_NOW,         24,					\
+
	"bind symbols at loading time")					\
+
_ELF_DEFINE_DT(DT_INIT_ARRAY,       25,					\
+
	"pointers to initialization functions")				\
+
_ELF_DEFINE_DT(DT_FINI_ARRAY,       26,					\
+
	"pointers to termination functions")				\
+
_ELF_DEFINE_DT(DT_INIT_ARRAYSZ,     27, "size of the DT_INIT_ARRAY")	\
+
_ELF_DEFINE_DT(DT_FINI_ARRAYSZ,     28, "size of the DT_FINI_ARRAY")	\
+
_ELF_DEFINE_DT(DT_RUNPATH,          29,					\
+
	"index of library search path string")				\
+
_ELF_DEFINE_DT(DT_FLAGS,            30,					\
+
	"flags specific to the object being loaded")			\
+
_ELF_DEFINE_DT(DT_ENCODING,         32, "standard semantics")		\
+
_ELF_DEFINE_DT(DT_PREINIT_ARRAY,    32,					\
+
	"pointers to pre-initialization functions")			\
+
_ELF_DEFINE_DT(DT_PREINIT_ARRAYSZ,  33,					\
+
	"size of pre-initialization array")				\
+
_ELF_DEFINE_DT(DT_MAXPOSTAGS,	    34,					\
+
	"the number of positive tags")					\
+
_ELF_DEFINE_DT(DT_LOOS,             0x6000000DUL,			\
+
	"start of OS-specific types")					\
+
_ELF_DEFINE_DT(DT_SUNW_AUXILIARY,   0x6000000DUL,			\
+
	"offset of string naming auxiliary filtees")			\
+
_ELF_DEFINE_DT(DT_SUNW_RTLDINF,     0x6000000EUL, "rtld internal use")	\
+
_ELF_DEFINE_DT(DT_SUNW_FILTER,      0x6000000FUL,			\
+
	"offset of string naming standard filtees")			\
+
_ELF_DEFINE_DT(DT_SUNW_CAP,         0x60000010UL,			\
+
	"address of hardware capabilities section")			\
+
_ELF_DEFINE_DT(DT_HIOS,             0x6FFFF000UL,			\
+
	"end of OS-specific types")					\
+
_ELF_DEFINE_DT(DT_VALRNGLO,         0x6FFFFD00UL,			\
+
	"start of range using the d_val field")				\
+
_ELF_DEFINE_DT(DT_GNU_PRELINKED,    0x6FFFFDF5UL,			\
+
	"prelinking timestamp")						\
+
_ELF_DEFINE_DT(DT_GNU_CONFLICTSZ,   0x6FFFFDF6UL,			\
+
	"size of conflict section")					\
+
_ELF_DEFINE_DT(DT_GNU_LIBLISTSZ,    0x6FFFFDF7UL,			\
+
	"size of library list")						\
+
_ELF_DEFINE_DT(DT_CHECKSUM,         0x6FFFFDF8UL,			\
+
	"checksum for the object")					\
+
_ELF_DEFINE_DT(DT_PLTPADSZ,         0x6FFFFDF9UL,			\
+
	"size of PLT padding")						\
+
_ELF_DEFINE_DT(DT_MOVEENT,          0x6FFFFDFAUL,			\
+
	"size of DT_MOVETAB entries")					\
+
_ELF_DEFINE_DT(DT_MOVESZ,           0x6FFFFDFBUL,			\
+
	"total size of the MOVETAB table")				\
+
_ELF_DEFINE_DT(DT_FEATURE_1,        0x6FFFFDFCUL, "feature values")	\
+
_ELF_DEFINE_DT(DT_POSFLAG_1,        0x6FFFFDFDUL,			\
+
	"dynamic position flags")					\
+
_ELF_DEFINE_DT(DT_SYMINSZ,          0x6FFFFDFEUL,			\
+
	"size of the DT_SYMINFO table")					\
+
_ELF_DEFINE_DT(DT_SYMINENT,         0x6FFFFDFFUL,			\
+
	"size of a DT_SYMINFO entry")					\
+
_ELF_DEFINE_DT(DT_VALRNGHI,         0x6FFFFDFFUL,			\
+
	"end of range using the d_val field")				\
+
_ELF_DEFINE_DT(DT_ADDRRNGLO,        0x6FFFFE00UL,			\
+
	"start of range using the d_ptr field")				\
+
_ELF_DEFINE_DT(DT_GNU_HASH,	    0x6FFFFEF5UL,			\
+
	"GNU style hash tables")					\
+
_ELF_DEFINE_DT(DT_GNU_CONFLICT,     0x6FFFFEF8UL,			\
+
	"address of conflict section")					\
+
_ELF_DEFINE_DT(DT_GNU_LIBLIST,      0x6FFFFEF9UL,			\
+
	"address of conflict section")					\
+
_ELF_DEFINE_DT(DT_CONFIG,           0x6FFFFEFAUL,			\
+
	"configuration file")						\
+
_ELF_DEFINE_DT(DT_DEPAUDIT,         0x6FFFFEFBUL,			\
+
	"string defining audit libraries")				\
+
_ELF_DEFINE_DT(DT_AUDIT,            0x6FFFFEFCUL,			\
+
	"string defining audit libraries")				\
+
_ELF_DEFINE_DT(DT_PLTPAD,           0x6FFFFEFDUL, "PLT padding")	\
+
_ELF_DEFINE_DT(DT_MOVETAB,          0x6FFFFEFEUL,			\
+
	"address of a move table")					\
+
_ELF_DEFINE_DT(DT_SYMINFO,          0x6FFFFEFFUL,			\
+
	"address of the symbol information table")			\
+
_ELF_DEFINE_DT(DT_ADDRRNGHI,        0x6FFFFEFFUL,			\
+
	"end of range using the d_ptr field")				\
+
_ELF_DEFINE_DT(DT_VERSYM,	    0x6FFFFFF0UL,			\
+
	"address of the version section")				\
+
_ELF_DEFINE_DT(DT_RELACOUNT,        0x6FFFFFF9UL,			\
+
	"count of RELA relocations")					\
+
_ELF_DEFINE_DT(DT_RELCOUNT,         0x6FFFFFFAUL,			\
+
	"count of REL relocations")					\
+
_ELF_DEFINE_DT(DT_FLAGS_1,          0x6FFFFFFBUL, "flag values")	\
+
_ELF_DEFINE_DT(DT_VERDEF,	    0x6FFFFFFCUL,			\
+
	"address of the version definition segment")			\
+
_ELF_DEFINE_DT(DT_VERDEFNUM,	    0x6FFFFFFDUL,			\
+
	"the number of version definition entries")			\
+
_ELF_DEFINE_DT(DT_VERNEED,	    0x6FFFFFFEUL,			\
+
	"address of section with needed versions")			\
+
_ELF_DEFINE_DT(DT_VERNEEDNUM,       0x6FFFFFFFUL,			\
+
	"the number of version needed entries")				\
+
_ELF_DEFINE_DT(DT_LOPROC,           0x70000000UL,			\
+
	"start of processor-specific types")				\
+
_ELF_DEFINE_DT(DT_ARM_SYMTABSZ,	    0x70000001UL,			\
+
	"number of entries in the dynamic symbol table")		\
+
_ELF_DEFINE_DT(DT_SPARC_REGISTER,   0x70000001UL,			\
+
	"index of an STT_SPARC_REGISTER symbol")			\
+
_ELF_DEFINE_DT(DT_ARM_PREEMPTMAP,   0x70000002UL,			\
+
	"address of the preemption map")				\
+
_ELF_DEFINE_DT(DT_MIPS_RLD_VERSION, 0x70000001UL,			\
+
	"version ID for runtime linker interface")			\
+
_ELF_DEFINE_DT(DT_MIPS_TIME_STAMP,  0x70000002UL,			\
+
	"timestamp")							\
+
_ELF_DEFINE_DT(DT_MIPS_ICHECKSUM,   0x70000003UL,			\
+
	"checksum of all external strings and common sizes")		\
+
_ELF_DEFINE_DT(DT_MIPS_IVERSION,    0x70000004UL,			\
+
	"string table index of a version string")			\
+
_ELF_DEFINE_DT(DT_MIPS_FLAGS,       0x70000005UL,			\
+
	"MIPS-specific flags")						\
+
_ELF_DEFINE_DT(DT_MIPS_BASE_ADDRESS, 0x70000006UL,			\
+
	"base address for the executable/DSO")				\
+
_ELF_DEFINE_DT(DT_MIPS_CONFLICT,    0x70000008UL,			\
+
	"address of .conflict section")					\
+
_ELF_DEFINE_DT(DT_MIPS_LIBLIST,     0x70000009UL,			\
+
	"address of .liblist section")					\
+
_ELF_DEFINE_DT(DT_MIPS_LOCAL_GOTNO, 0x7000000AUL,			\
+
	"number of local GOT entries")					\
+
_ELF_DEFINE_DT(DT_MIPS_CONFLICTNO,  0x7000000BUL,			\
+
	"number of entries in the .conflict section")			\
+
_ELF_DEFINE_DT(DT_MIPS_LIBLISTNO,   0x70000010UL,			\
+
	"number of entries in the .liblist section")			\
+
_ELF_DEFINE_DT(DT_MIPS_SYMTABNO,    0x70000011UL,			\
+
	"number of entries in the .dynsym section")			\
+
_ELF_DEFINE_DT(DT_MIPS_UNREFEXTNO,  0x70000012UL,			\
+
	"index of first external dynamic symbol not ref'ed locally")	\
+
_ELF_DEFINE_DT(DT_MIPS_GOTSYM,      0x70000013UL,			\
+
	"index of first dynamic symbol corresponds to a GOT entry")	\
+
_ELF_DEFINE_DT(DT_MIPS_HIPAGENO,    0x70000014UL,			\
+
	"number of page table entries in GOT")				\
+
_ELF_DEFINE_DT(DT_MIPS_RLD_MAP,     0x70000016UL,			\
+
	"address of runtime linker map")				\
+
_ELF_DEFINE_DT(DT_MIPS_DELTA_CLASS, 0x70000017UL,			\
+
	"Delta C++ class definition")					\
+
_ELF_DEFINE_DT(DT_MIPS_DELTA_CLASS_NO, 0x70000018UL,			\
+
	"number of entries in DT_MIPS_DELTA_CLASS")			\
+
_ELF_DEFINE_DT(DT_MIPS_DELTA_INSTANCE, 0x70000019UL,			\
+
	"Delta C++ class instances")					\
+
_ELF_DEFINE_DT(DT_MIPS_DELTA_INSTANCE_NO, 0x7000001AUL,			\
+
	"number of entries in DT_MIPS_DELTA_INSTANCE")			\
+
_ELF_DEFINE_DT(DT_MIPS_DELTA_RELOC, 0x7000001BUL,			\
+
	"Delta relocations")						\
+
_ELF_DEFINE_DT(DT_MIPS_DELTA_RELOC_NO, 0x7000001CUL,			\
+
	"number of entries in DT_MIPS_DELTA_RELOC")			\
+
_ELF_DEFINE_DT(DT_MIPS_DELTA_SYM,   0x7000001DUL,			\
+
	"Delta symbols refered by Delta relocations")			\
+
_ELF_DEFINE_DT(DT_MIPS_DELTA_SYM_NO, 0x7000001EUL,			\
+
	"number of entries in DT_MIPS_DELTA_SYM")			\
+
_ELF_DEFINE_DT(DT_MIPS_DELTA_CLASSSYM, 0x70000020UL,			\
+
	"Delta symbols for class declarations")				\
+
_ELF_DEFINE_DT(DT_MIPS_DELTA_CLASSSYM_NO, 0x70000021UL,			\
+
	"number of entries in DT_MIPS_DELTA_CLASSSYM")			\
+
_ELF_DEFINE_DT(DT_MIPS_CXX_FLAGS,   0x70000022UL,			\
+
	"C++ flavor flags")						\
+
_ELF_DEFINE_DT(DT_MIPS_PIXIE_INIT,  0x70000023UL,			\
+
	"address of an initialization routine created by pixie")	\
+
_ELF_DEFINE_DT(DT_MIPS_SYMBOL_LIB,  0x70000024UL,			\
+
	"address of .MIPS.symlib section")				\
+
_ELF_DEFINE_DT(DT_MIPS_LOCALPAGE_GOTIDX, 0x70000025UL,			\
+
	"GOT index of first page table entry for a segment")		\
+
_ELF_DEFINE_DT(DT_MIPS_LOCAL_GOTIDX, 0x70000026UL,			\
+
	"GOT index of first page table entry for a local symbol")	\
+
_ELF_DEFINE_DT(DT_MIPS_HIDDEN_GOTIDX, 0x70000027UL,			\
+
	"GOT index of first page table entry for a hidden symbol")	\
+
_ELF_DEFINE_DT(DT_MIPS_PROTECTED_GOTIDX, 0x70000028UL,			\
+
	"GOT index of first page table entry for a protected symbol")	\
+
_ELF_DEFINE_DT(DT_MIPS_OPTIONS,     0x70000029UL,			\
+
	"address of .MIPS.options section")				\
+
_ELF_DEFINE_DT(DT_MIPS_INTERFACE,   0x7000002AUL,			\
+
	"address of .MIPS.interface section")				\
+
_ELF_DEFINE_DT(DT_MIPS_DYNSTR_ALIGN, 0x7000002BUL, "???")		\
+
_ELF_DEFINE_DT(DT_MIPS_INTERFACE_SIZE, 0x7000002CUL,			\
+
	"size of .MIPS.interface section")				\
+
_ELF_DEFINE_DT(DT_MIPS_RLD_TEXT_RESOLVE_ADDR, 0x7000002DUL,		\
+
	"address of _rld_text_resolve in GOT")				\
+
_ELF_DEFINE_DT(DT_MIPS_PERF_SUFFIX, 0x7000002EUL,			\
+
	"default suffix of DSO to be appended by dlopen")		\
+
_ELF_DEFINE_DT(DT_MIPS_COMPACT_SIZE, 0x7000002FUL,			\
+
	"size of a ucode compact relocation record (o32)")		\
+
_ELF_DEFINE_DT(DT_MIPS_GP_VALUE,    0x70000030UL,			\
+
	"GP value of a specified GP relative range")			\
+
_ELF_DEFINE_DT(DT_MIPS_AUX_DYNAMIC, 0x70000031UL,			\
+
	"address of an auxiliary dynamic table")			\
+
_ELF_DEFINE_DT(DT_MIPS_PLTGOT,      0x70000032UL,			\
+
	"address of the PLTGOT")					\
+
_ELF_DEFINE_DT(DT_MIPS_RLD_OBJ_UPDATE, 0x70000033UL,			\
+
	"object list update callback")					\
+
_ELF_DEFINE_DT(DT_MIPS_RWPLT,       0x70000034UL,			\
+
	"address of a writable PLT")					\
+
_ELF_DEFINE_DT(DT_PPC_GOT,          0x70000000UL,			\
+
	"value of _GLOBAL_OFFSET_TABLE_")				\
+
_ELF_DEFINE_DT(DT_PPC_TLSOPT,       0x70000001UL,			\
+
	"TLS descriptor should be optimized")				\
+
_ELF_DEFINE_DT(DT_PPC64_GLINK,      0x70000000UL,			\
+
	"address of .glink section")					\
+
_ELF_DEFINE_DT(DT_PPC64_OPD,        0x70000001UL,			\
+
	"address of .opd section")					\
+
_ELF_DEFINE_DT(DT_PPC64_OPDSZ,      0x70000002UL,			\
+
	"size of .opd section")						\
+
_ELF_DEFINE_DT(DT_PPC64_TLSOPT,     0x70000003UL,			\
+
	"TLS descriptor should be optimized")				\
+
_ELF_DEFINE_DT(DT_AUXILIARY,        0x7FFFFFFDUL,			\
+
	"offset of string naming auxiliary filtees")			\
+
_ELF_DEFINE_DT(DT_USED,             0x7FFFFFFEUL, "ignored")		\
+
_ELF_DEFINE_DT(DT_FILTER,           0x7FFFFFFFUL,			\
+
	"index of string naming filtees")				\
+
_ELF_DEFINE_DT(DT_HIPROC,           0x7FFFFFFFUL,			\
+
	"end of processor-specific types")
+

+
#undef	_ELF_DEFINE_DT
+
#define	_ELF_DEFINE_DT(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_DYN_TYPES()
+
	DT__LAST__ = DT_HIPROC
+
};
+

+
#define	DT_DEPRECATED_SPARC_REGISTER	DT_SPARC_REGISTER
+

+
/*
+
 * Flags used in the executable header (field: e_flags).
+
 */
+
#define	_ELF_DEFINE_EHDR_FLAGS()					\
+
_ELF_DEFINE_EF(EF_ARM_RELEXEC,      0x00000001UL,			\
+
	"dynamic segment describes only how to relocate segments")	\
+
_ELF_DEFINE_EF(EF_ARM_HASENTRY,     0x00000002UL,			\
+
	"e_entry contains a program entry point")			\
+
_ELF_DEFINE_EF(EF_ARM_SYMSARESORTED, 0x00000004UL,			\
+
	"subsection of symbol table is sorted by symbol value")		\
+
_ELF_DEFINE_EF(EF_ARM_DYNSYMSUSESEGIDX, 0x00000008UL,			\
+
	"dynamic symbol st_shndx = containing segment index + 1")	\
+
_ELF_DEFINE_EF(EF_ARM_MAPSYMSFIRST, 0x00000010UL,			\
+
	"mapping symbols precede other local symbols in symtab")	\
+
_ELF_DEFINE_EF(EF_ARM_BE8,          0x00800000UL,			\
+
	"file contains BE-8 code")					\
+
_ELF_DEFINE_EF(EF_ARM_LE8,          0x00400000UL,			\
+
	"file contains LE-8 code")					\
+
_ELF_DEFINE_EF(EF_ARM_EABIMASK,     0xFF000000UL,			\
+
	"mask for ARM EABI version number (0 denotes GNU or unknown)")	\
+
_ELF_DEFINE_EF(EF_ARM_INTERWORK,    0x00000004UL,			\
+
	"GNU EABI extension")						\
+
_ELF_DEFINE_EF(EF_ARM_APCS_26,      0x00000008UL,			\
+
	"GNU EABI extension")						\
+
_ELF_DEFINE_EF(EF_ARM_APCS_FLOAT,   0x00000010UL,			\
+
	"GNU EABI extension")						\
+
_ELF_DEFINE_EF(EF_ARM_PIC,          0x00000020UL,			\
+
	"GNU EABI extension")						\
+
_ELF_DEFINE_EF(EF_ARM_ALIGN8,       0x00000040UL,			\
+
	"GNU EABI extension")						\
+
_ELF_DEFINE_EF(EF_ARM_NEW_ABI,      0x00000080UL,			\
+
	"GNU EABI extension")						\
+
_ELF_DEFINE_EF(EF_ARM_OLD_ABI,      0x00000100UL,			\
+
	"GNU EABI extension")						\
+
_ELF_DEFINE_EF(EF_ARM_SOFT_FLOAT,   0x00000200UL,			\
+
	"GNU EABI extension")						\
+
_ELF_DEFINE_EF(EF_ARM_VFP_FLOAT,    0x00000400UL,			\
+
	"GNU EABI extension")						\
+
_ELF_DEFINE_EF(EF_ARM_MAVERICK_FLOAT, 0x00000800UL,			\
+
	"GNU EABI extension")						\
+
_ELF_DEFINE_EF(EF_MIPS_NOREORDER,   0x00000001UL,			\
+
	"at least one .noreorder directive appeared in the source")	\
+
_ELF_DEFINE_EF(EF_MIPS_PIC,         0x00000002UL,			\
+
	"file contains position independent code")			\
+
_ELF_DEFINE_EF(EF_MIPS_CPIC,        0x00000004UL,			\
+
	"file's code uses standard conventions for calling PIC")	\
+
_ELF_DEFINE_EF(EF_MIPS_UCODE,       0x00000010UL,			\
+
	"file contains UCODE (obsolete)")				\
+
_ELF_DEFINE_EF(EF_MIPS_ABI2,        0x00000020UL,			\
+
	"file follows MIPS III 32-bit ABI")				\
+
_ELF_DEFINE_EF(EF_MIPS_OPTIONS_FIRST, 0x00000080UL,			\
+
	"ld(1) should process .MIPS.options section first")		\
+
_ELF_DEFINE_EF(EF_MIPS_ARCH_ASE,    0x0F000000UL,			\
+
	"file uses application-specific architectural extensions")	\
+
_ELF_DEFINE_EF(EF_MIPS_ARCH_ASE_MDMX, 0x08000000UL,			\
+
	"file uses MDMX multimedia extensions")				\
+
_ELF_DEFINE_EF(EF_MIPS_ARCH_ASE_M16, 0x04000000UL,			\
+
	"file uses MIPS-16 ISA extensions")				\
+
_ELF_DEFINE_EF(EF_MIPS_ARCH,         0xF0000000UL,			\
+
	"4-bit MIPS architecture field")				\
+
_ELF_DEFINE_EF(EF_PPC_EMB,          0x80000000UL,			\
+
	"Embedded PowerPC flag")					\
+
_ELF_DEFINE_EF(EF_PPC_RELOCATABLE,  0x00010000UL,			\
+
	"-mrelocatable flag")						\
+
_ELF_DEFINE_EF(EF_PPC_RELOCATABLE_LIB, 0x00008000UL,			\
+
	"-mrelocatable-lib flag")					\
+
_ELF_DEFINE_EF(EF_SPARC_EXT_MASK,   0x00ffff00UL,			\
+
	"Vendor Extension mask")					\
+
_ELF_DEFINE_EF(EF_SPARC_32PLUS,     0x00000100UL,			\
+
	"Generic V8+ features")						\
+
_ELF_DEFINE_EF(EF_SPARC_SUN_US1,    0x00000200UL,			\
+
	"Sun UltraSPARCTM 1 Extensions")				\
+
_ELF_DEFINE_EF(EF_SPARC_HAL_R1,     0x00000400UL, "HAL R1 Extensions")	\
+
_ELF_DEFINE_EF(EF_SPARC_SUN_US3,    0x00000800UL,			\
+
	"Sun UltraSPARC 3 Extensions")					\
+
_ELF_DEFINE_EF(EF_SPARCV9_MM,       0x00000003UL,			\
+
	"Mask for Memory Model")					\
+
_ELF_DEFINE_EF(EF_SPARCV9_TSO,      0x00000000UL,			\
+
	"Total Store Ordering")						\
+
_ELF_DEFINE_EF(EF_SPARCV9_PSO,      0x00000001UL,			\
+
	"Partial Store Ordering")					\
+
_ELF_DEFINE_EF(EF_SPARCV9_RMO,      0x00000002UL,			\
+
	"Relaxed Memory Ordering")
+

+
#undef	_ELF_DEFINE_EF
+
#define	_ELF_DEFINE_EF(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_EHDR_FLAGS()
+
	EF__LAST__
+
};
+

+
/*
+
 * Offsets in the `ei_ident[]` field of an ELF executable header.
+
 */
+
#define	_ELF_DEFINE_EI_OFFSETS()			\
+
_ELF_DEFINE_EI(EI_MAG0,     0, "magic number")		\
+
_ELF_DEFINE_EI(EI_MAG1,     1, "magic number")		\
+
_ELF_DEFINE_EI(EI_MAG2,     2, "magic number")		\
+
_ELF_DEFINE_EI(EI_MAG3,     3, "magic number")		\
+
_ELF_DEFINE_EI(EI_CLASS,    4, "file class")		\
+
_ELF_DEFINE_EI(EI_DATA,     5, "data encoding")		\
+
_ELF_DEFINE_EI(EI_VERSION,  6, "file version")		\
+
_ELF_DEFINE_EI(EI_OSABI,    7, "OS ABI kind")		\
+
_ELF_DEFINE_EI(EI_ABIVERSION, 8, "OS ABI version")	\
+
_ELF_DEFINE_EI(EI_PAD,	    9, "padding start")		\
+
_ELF_DEFINE_EI(EI_NIDENT,  16, "total size")
+

+
#undef	_ELF_DEFINE_EI
+
#define	_ELF_DEFINE_EI(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_EI_OFFSETS()
+
	EI__LAST__
+
};
+

+
/*
+
 * The ELF class of an object.
+
 */
+
#define	_ELF_DEFINE_ELFCLASS()				\
+
_ELF_DEFINE_EC(ELFCLASSNONE, 0, "Unknown ELF class")	\
+
_ELF_DEFINE_EC(ELFCLASS32,   1, "32 bit objects")	\
+
_ELF_DEFINE_EC(ELFCLASS64,   2, "64 bit objects")
+

+
#undef	_ELF_DEFINE_EC
+
#define	_ELF_DEFINE_EC(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_ELFCLASS()
+
	EC__LAST__
+
};
+

+
/*
+
 * Endianness of data in an ELF object.
+
 */
+

+
#define	_ELF_DEFINE_ELF_DATA_ENDIANNESS()			\
+
_ELF_DEFINE_ED(ELFDATANONE, 0, "Unknown data endianness")	\
+
_ELF_DEFINE_ED(ELFDATA2LSB, 1, "little endian")			\
+
_ELF_DEFINE_ED(ELFDATA2MSB, 2, "big endian")
+

+
#undef	_ELF_DEFINE_ED
+
#define	_ELF_DEFINE_ED(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_ELF_DATA_ENDIANNESS()
+
	ED__LAST__
+
};
+

+
/*
+
 * Values of the magic numbers used in identification array.
+
 */
+
#define	_ELF_DEFINE_ELF_MAGIC()			\
+
_ELF_DEFINE_EMAG(ELFMAG0, 0x7FU)		\
+
_ELF_DEFINE_EMAG(ELFMAG1, 'E')			\
+
_ELF_DEFINE_EMAG(ELFMAG2, 'L')			\
+
_ELF_DEFINE_EMAG(ELFMAG3, 'F')
+

+
#undef	_ELF_DEFINE_EMAG
+
#define	_ELF_DEFINE_EMAG(N, V)		N = V ,
+
enum {
+
	_ELF_DEFINE_ELF_MAGIC()
+
	ELFMAG__LAST__
+
};
+

+
/*
+
 * ELF OS ABI field.
+
 */
+
#define	_ELF_DEFINE_ELF_OSABI()						\
+
_ELF_DEFINE_EABI(ELFOSABI_NONE,       0,				\
+
	"No extensions or unspecified")					\
+
_ELF_DEFINE_EABI(ELFOSABI_SYSV,       0, "SYSV")			\
+
_ELF_DEFINE_EABI(ELFOSABI_HPUX,       1, "Hewlett-Packard HP-UX")	\
+
_ELF_DEFINE_EABI(ELFOSABI_NETBSD,     2, "NetBSD")			\
+
_ELF_DEFINE_EABI(ELFOSABI_GNU,        3, "GNU")				\
+
_ELF_DEFINE_EABI(ELFOSABI_HURD,       4, "GNU/HURD")			\
+
_ELF_DEFINE_EABI(ELFOSABI_86OPEN,     5, "86Open Common ABI")		\
+
_ELF_DEFINE_EABI(ELFOSABI_SOLARIS,    6, "Sun Solaris")			\
+
_ELF_DEFINE_EABI(ELFOSABI_AIX,        7, "AIX")				\
+
_ELF_DEFINE_EABI(ELFOSABI_IRIX,       8, "IRIX")			\
+
_ELF_DEFINE_EABI(ELFOSABI_FREEBSD,    9, "FreeBSD")			\
+
_ELF_DEFINE_EABI(ELFOSABI_TRU64,      10, "Compaq TRU64 UNIX")		\
+
_ELF_DEFINE_EABI(ELFOSABI_MODESTO,    11, "Novell Modesto")		\
+
_ELF_DEFINE_EABI(ELFOSABI_OPENBSD,    12, "Open BSD")			\
+
_ELF_DEFINE_EABI(ELFOSABI_OPENVMS,    13, "Open VMS")			\
+
_ELF_DEFINE_EABI(ELFOSABI_NSK,        14,				\
+
	"Hewlett-Packard Non-Stop Kernel")				\
+
_ELF_DEFINE_EABI(ELFOSABI_AROS,       15, "Amiga Research OS")		\
+
_ELF_DEFINE_EABI(ELFOSABI_FENIXOS,    16,				\
+
	"The FenixOS highly scalable multi-core OS")			\
+
_ELF_DEFINE_EABI(ELFOSABI_ARM_AEABI,  64,				\
+
	"ARM specific symbol versioning extensions")			\
+
_ELF_DEFINE_EABI(ELFOSABI_ARM,        97, "ARM ABI")			\
+
_ELF_DEFINE_EABI(ELFOSABI_STANDALONE, 255,				\
+
	"Standalone (embedded) application")
+

+
#undef	_ELF_DEFINE_EABI
+
#define	_ELF_DEFINE_EABI(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_ELF_OSABI()
+
	ELFOSABI__LAST__
+
};
+

+
#define	ELFOSABI_LINUX			ELFOSABI_GNU
+

+
/*
+
 * ELF Machine types: (EM_*).
+
 */
+
#define	_ELF_DEFINE_ELF_MACHINES()					\
+
_ELF_DEFINE_EM(EM_NONE,             0, "No machine")			\
+
_ELF_DEFINE_EM(EM_M32,              1, "AT&T WE 32100")			\
+
_ELF_DEFINE_EM(EM_SPARC,            2, "SPARC")				\
+
_ELF_DEFINE_EM(EM_386,              3, "Intel 80386")			\
+
_ELF_DEFINE_EM(EM_68K,              4, "Motorola 68000")		\
+
_ELF_DEFINE_EM(EM_88K,              5, "Motorola 88000")		\
+
_ELF_DEFINE_EM(EM_860,              7, "Intel 80860")			\
+
_ELF_DEFINE_EM(EM_MIPS,             8, "MIPS I Architecture")		\
+
_ELF_DEFINE_EM(EM_S370,             9, "IBM System/370 Processor")	\
+
_ELF_DEFINE_EM(EM_MIPS_RS3_LE,      10, "MIPS RS3000 Little-endian")	\
+
_ELF_DEFINE_EM(EM_PARISC,           15, "Hewlett-Packard PA-RISC")	\
+
_ELF_DEFINE_EM(EM_VPP500,           17, "Fujitsu VPP500")		\
+
_ELF_DEFINE_EM(EM_SPARC32PLUS,      18,					\
+
	"Enhanced instruction set SPARC")				\
+
_ELF_DEFINE_EM(EM_960,              19, "Intel 80960")			\
+
_ELF_DEFINE_EM(EM_PPC,              20, "PowerPC")			\
+
_ELF_DEFINE_EM(EM_PPC64,            21, "64-bit PowerPC")		\
+
_ELF_DEFINE_EM(EM_S390,             22, "IBM System/390 Processor")	\
+
_ELF_DEFINE_EM(EM_SPU,              23, "IBM SPU/SPC")			\
+
_ELF_DEFINE_EM(EM_V800,             36, "NEC V800")			\
+
_ELF_DEFINE_EM(EM_FR20,             37, "Fujitsu FR20")			\
+
_ELF_DEFINE_EM(EM_RH32,             38, "TRW RH-32")			\
+
_ELF_DEFINE_EM(EM_RCE,              39, "Motorola RCE")			\
+
_ELF_DEFINE_EM(EM_ARM,              40, "Advanced RISC Machines ARM")	\
+
_ELF_DEFINE_EM(EM_ALPHA,            41, "Digital Alpha")		\
+
_ELF_DEFINE_EM(EM_SH,               42, "Hitachi SH")			\
+
_ELF_DEFINE_EM(EM_SPARCV9,          43, "SPARC Version 9")		\
+
_ELF_DEFINE_EM(EM_TRICORE,          44,					\
+
	"Siemens TriCore embedded processor")				\
+
_ELF_DEFINE_EM(EM_ARC,              45,					\
+
	"Argonaut RISC Core, Argonaut Technologies Inc.")		\
+
_ELF_DEFINE_EM(EM_H8_300,           46, "Hitachi H8/300")		\
+
_ELF_DEFINE_EM(EM_H8_300H,          47, "Hitachi H8/300H")		\
+
_ELF_DEFINE_EM(EM_H8S,              48, "Hitachi H8S")			\
+
_ELF_DEFINE_EM(EM_H8_500,           49, "Hitachi H8/500")		\
+
_ELF_DEFINE_EM(EM_IA_64,            50,					\
+
	"Intel IA-64 processor architecture")				\
+
_ELF_DEFINE_EM(EM_MIPS_X,           51, "Stanford MIPS-X")		\
+
_ELF_DEFINE_EM(EM_COLDFIRE,         52, "Motorola ColdFire")		\
+
_ELF_DEFINE_EM(EM_68HC12,           53, "Motorola M68HC12")		\
+
_ELF_DEFINE_EM(EM_MMA,              54,					\
+
	"Fujitsu MMA Multimedia Accelerator")				\
+
_ELF_DEFINE_EM(EM_PCP,              55, "Siemens PCP")			\
+
_ELF_DEFINE_EM(EM_NCPU,             56,					\
+
	"Sony nCPU embedded RISC processor")				\
+
_ELF_DEFINE_EM(EM_NDR1,             57, "Denso NDR1 microprocessor")	\
+
_ELF_DEFINE_EM(EM_STARCORE,         58, "Motorola Star*Core processor")	\
+
_ELF_DEFINE_EM(EM_ME16,             59, "Toyota ME16 processor")	\
+
_ELF_DEFINE_EM(EM_ST100,            60,					\
+
	"STMicroelectronics ST100 processor")				\
+
_ELF_DEFINE_EM(EM_TINYJ,            61,					\
+
	"Advanced Logic Corp. TinyJ embedded processor family")		\
+
_ELF_DEFINE_EM(EM_X86_64,           62, "AMD x86-64 architecture")	\
+
_ELF_DEFINE_EM(EM_PDSP,             63, "Sony DSP Processor")		\
+
_ELF_DEFINE_EM(EM_PDP10,            64,					\
+
	"Digital Equipment Corp. PDP-10")				\
+
_ELF_DEFINE_EM(EM_PDP11,            65,					\
+
	"Digital Equipment Corp. PDP-11")				\
+
_ELF_DEFINE_EM(EM_FX66,             66, "Siemens FX66 microcontroller")	\
+
_ELF_DEFINE_EM(EM_ST9PLUS,          67,					\
+
	"STMicroelectronics ST9+ 8/16 bit microcontroller")		\
+
_ELF_DEFINE_EM(EM_ST7,              68,					\
+
	"STMicroelectronics ST7 8-bit microcontroller")			\
+
_ELF_DEFINE_EM(EM_68HC16,           69,					\
+
	"Motorola MC68HC16 Microcontroller")				\
+
_ELF_DEFINE_EM(EM_68HC11,           70,					\
+
	"Motorola MC68HC11 Microcontroller")				\
+
_ELF_DEFINE_EM(EM_68HC08,           71,					\
+
	"Motorola MC68HC08 Microcontroller")				\
+
_ELF_DEFINE_EM(EM_68HC05,           72,					\
+
	"Motorola MC68HC05 Microcontroller")				\
+
_ELF_DEFINE_EM(EM_SVX,              73, "Silicon Graphics SVx")		\
+
_ELF_DEFINE_EM(EM_ST19,             74,					\
+
	"STMicroelectronics ST19 8-bit microcontroller")		\
+
_ELF_DEFINE_EM(EM_VAX,              75, "Digital VAX")			\
+
_ELF_DEFINE_EM(EM_CRIS,             76,					\
+
	"Axis Communications 32-bit embedded processor")		\
+
_ELF_DEFINE_EM(EM_JAVELIN,          77,					\
+
	"Infineon Technologies 32-bit embedded processor")		\
+
_ELF_DEFINE_EM(EM_FIREPATH,         78,					\
+
	"Element 14 64-bit DSP Processor")				\
+
_ELF_DEFINE_EM(EM_ZSP,              79,					\
+
	"LSI Logic 16-bit DSP Processor")				\
+
_ELF_DEFINE_EM(EM_MMIX,             80,					\
+
	"Donald Knuth's educational 64-bit processor")			\
+
_ELF_DEFINE_EM(EM_HUANY,            81,					\
+
	"Harvard University machine-independent object files")		\
+
_ELF_DEFINE_EM(EM_PRISM,            82, "SiTera Prism")			\
+
_ELF_DEFINE_EM(EM_AVR,              83,					\
+
	"Atmel AVR 8-bit microcontroller")				\
+
_ELF_DEFINE_EM(EM_FR30,             84, "Fujitsu FR30")			\
+
_ELF_DEFINE_EM(EM_D10V,             85, "Mitsubishi D10V")		\
+
_ELF_DEFINE_EM(EM_D30V,             86, "Mitsubishi D30V")		\
+
_ELF_DEFINE_EM(EM_V850,             87, "NEC v850")			\
+
_ELF_DEFINE_EM(EM_M32R,             88, "Mitsubishi M32R")		\
+
_ELF_DEFINE_EM(EM_MN10300,          89, "Matsushita MN10300")		\
+
_ELF_DEFINE_EM(EM_MN10200,          90, "Matsushita MN10200")		\
+
_ELF_DEFINE_EM(EM_PJ,               91, "picoJava")			\
+
_ELF_DEFINE_EM(EM_OPENRISC,         92,					\
+
	"OpenRISC 32-bit embedded processor")				\
+
_ELF_DEFINE_EM(EM_ARC_COMPACT,      93,					\
+
	"ARC International ARCompact processor")			\
+
_ELF_DEFINE_EM(EM_XTENSA,           94,					\
+
	"Tensilica Xtensa Architecture")				\
+
_ELF_DEFINE_EM(EM_VIDEOCORE,        95,					\
+
	"Alphamosaic VideoCore processor")				\
+
_ELF_DEFINE_EM(EM_TMM_GPP,          96,					\
+
	"Thompson Multimedia General Purpose Processor")		\
+
_ELF_DEFINE_EM(EM_NS32K,            97,					\
+
	"National Semiconductor 32000 series")				\
+
_ELF_DEFINE_EM(EM_TPC,              98, "Tenor Network TPC processor")	\
+
_ELF_DEFINE_EM(EM_SNP1K,            99, "Trebia SNP 1000 processor")	\
+
_ELF_DEFINE_EM(EM_ST200,            100,				\
+
	"STMicroelectronics (www.st.com) ST200 microcontroller")	\
+
_ELF_DEFINE_EM(EM_IP2K,             101,				\
+
	"Ubicom IP2xxx microcontroller family")				\
+
_ELF_DEFINE_EM(EM_MAX,              102, "MAX Processor")		\
+
_ELF_DEFINE_EM(EM_CR,               103,				\
+
	"National Semiconductor CompactRISC microprocessor")		\
+
_ELF_DEFINE_EM(EM_F2MC16,           104, "Fujitsu F2MC16")		\
+
_ELF_DEFINE_EM(EM_MSP430,           105,				\
+
	"Texas Instruments embedded microcontroller msp430")		\
+
_ELF_DEFINE_EM(EM_BLACKFIN,         106,				\
+
	"Analog Devices Blackfin (DSP) processor")			\
+
_ELF_DEFINE_EM(EM_SE_C33,           107,				\
+
	"S1C33 Family of Seiko Epson processors")			\
+
_ELF_DEFINE_EM(EM_SEP,              108,				\
+
	"Sharp embedded microprocessor")				\
+
_ELF_DEFINE_EM(EM_ARCA,             109, "Arca RISC Microprocessor")	\
+
_ELF_DEFINE_EM(EM_UNICORE,          110,				\
+
	"Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University") \
+
_ELF_DEFINE_EM(EM_EXCESS,           111,				\
+
	"eXcess: 16/32/64-bit configurable embedded CPU")		\
+
_ELF_DEFINE_EM(EM_DXP,              112,				\
+
	"Icera Semiconductor Inc. Deep Execution Processor")		\
+
_ELF_DEFINE_EM(EM_ALTERA_NIOS2,     113,				\
+
	"Altera Nios II soft-core processor")				\
+
_ELF_DEFINE_EM(EM_CRX,              114,				\
+
	"National Semiconductor CompactRISC CRX microprocessor")	\
+
_ELF_DEFINE_EM(EM_XGATE,            115,				\
+
	"Motorola XGATE embedded processor")				\
+
_ELF_DEFINE_EM(EM_C166,             116,				\
+
	"Infineon C16x/XC16x processor")				\
+
_ELF_DEFINE_EM(EM_M16C,             117,				\
+
	"Renesas M16C series microprocessors")				\
+
_ELF_DEFINE_EM(EM_DSPIC30F,         118,				\
+
	"Microchip Technology dsPIC30F Digital Signal Controller")	\
+
_ELF_DEFINE_EM(EM_CE,               119,				\
+
	"Freescale Communication Engine RISC core")			\
+
_ELF_DEFINE_EM(EM_M32C,             120,				\
+
	"Renesas M32C series microprocessors")				\
+
_ELF_DEFINE_EM(EM_TSK3000,          131, "Altium TSK3000 core")		\
+
_ELF_DEFINE_EM(EM_RS08,             132,				\
+
	"Freescale RS08 embedded processor")				\
+
_ELF_DEFINE_EM(EM_SHARC,            133,				\
+
	"Analog Devices SHARC family of 32-bit DSP processors")		\
+
_ELF_DEFINE_EM(EM_ECOG2,            134,				\
+
	"Cyan Technology eCOG2 microprocessor")				\
+
_ELF_DEFINE_EM(EM_SCORE7,           135,				\
+
	"Sunplus S+core7 RISC processor")				\
+
_ELF_DEFINE_EM(EM_DSP24,            136,				\
+
	"New Japan Radio (NJR) 24-bit DSP Processor")			\
+
_ELF_DEFINE_EM(EM_VIDEOCORE3,       137,				\
+
	"Broadcom VideoCore III processor")				\
+
_ELF_DEFINE_EM(EM_LATTICEMICO32,    138,				\
+
	"RISC processor for Lattice FPGA architecture")			\
+
_ELF_DEFINE_EM(EM_SE_C17,           139, "Seiko Epson C17 family")	\
+
_ELF_DEFINE_EM(EM_TI_C6000,         140,				\
+
	"The Texas Instruments TMS320C6000 DSP family")			\
+
_ELF_DEFINE_EM(EM_TI_C2000,         141,				\
+
	"The Texas Instruments TMS320C2000 DSP family")			\
+
_ELF_DEFINE_EM(EM_TI_C5500,         142,				\
+
	"The Texas Instruments TMS320C55x DSP family")			\
+
_ELF_DEFINE_EM(EM_MMDSP_PLUS,       160,				\
+
	"STMicroelectronics 64bit VLIW Data Signal Processor")		\
+
_ELF_DEFINE_EM(EM_CYPRESS_M8C,      161, "Cypress M8C microprocessor")	\
+
_ELF_DEFINE_EM(EM_R32C,             162,				\
+
	"Renesas R32C series microprocessors")				\
+
_ELF_DEFINE_EM(EM_TRIMEDIA,         163,				\
+
	"NXP Semiconductors TriMedia architecture family")		\
+
_ELF_DEFINE_EM(EM_QDSP6,            164, "QUALCOMM DSP6 Processor")	\
+
_ELF_DEFINE_EM(EM_8051,             165, "Intel 8051 and variants")	\
+
_ELF_DEFINE_EM(EM_STXP7X,           166,				\
+
	"STMicroelectronics STxP7x family of configurable and extensible RISC processors") \
+
_ELF_DEFINE_EM(EM_NDS32,            167,				\
+
	"Andes Technology compact code size embedded RISC processor family") \
+
_ELF_DEFINE_EM(EM_ECOG1,            168,				\
+
	"Cyan Technology eCOG1X family")				\
+
_ELF_DEFINE_EM(EM_ECOG1X,           168,				\
+
	"Cyan Technology eCOG1X family")				\
+
_ELF_DEFINE_EM(EM_MAXQ30,           169,				\
+
	"Dallas Semiconductor MAXQ30 Core Micro-controllers")		\
+
_ELF_DEFINE_EM(EM_XIMO16,           170,				\
+
	"New Japan Radio (NJR) 16-bit DSP Processor")			\
+
_ELF_DEFINE_EM(EM_MANIK,            171,				\
+
	"M2000 Reconfigurable RISC Microprocessor")			\
+
_ELF_DEFINE_EM(EM_CRAYNV2,          172,				\
+
	"Cray Inc. NV2 vector architecture")				\
+
_ELF_DEFINE_EM(EM_RX,               173, "Renesas RX family")		\
+
_ELF_DEFINE_EM(EM_METAG,            174,				\
+
	"Imagination Technologies META processor architecture")		\
+
_ELF_DEFINE_EM(EM_MCST_ELBRUS,      175,				\
+
	"MCST Elbrus general purpose hardware architecture")		\
+
_ELF_DEFINE_EM(EM_ECOG16,           176,				\
+
	"Cyan Technology eCOG16 family")				\
+
_ELF_DEFINE_EM(EM_CR16,             177,				\
+
	"National Semiconductor CompactRISC CR16 16-bit microprocessor") \
+
_ELF_DEFINE_EM(EM_ETPU,             178,				\
+
	"Freescale Extended Time Processing Unit")			\
+
_ELF_DEFINE_EM(EM_SLE9X,            179,				\
+
	"Infineon Technologies SLE9X core")				\
+
_ELF_DEFINE_EM(EM_AVR32,            185,				\
+
	"Atmel Corporation 32-bit microprocessor family")		\
+
_ELF_DEFINE_EM(EM_STM8,             186,				\
+
	"STMicroeletronics STM8 8-bit microcontroller")			\
+
_ELF_DEFINE_EM(EM_TILE64,           187,				\
+
	"Tilera TILE64 multicore architecture family")			\
+
_ELF_DEFINE_EM(EM_TILEPRO,          188,				\
+
	"Tilera TILEPro multicore architecture family")			\
+
_ELF_DEFINE_EM(EM_MICROBLAZE,       189,				\
+
	"Xilinx MicroBlaze 32-bit RISC soft processor core")		\
+
_ELF_DEFINE_EM(EM_CUDA,             190, "NVIDIA CUDA architecture")	\
+
_ELF_DEFINE_EM(EM_TILEGX,           191,				\
+
	"Tilera TILE-Gx multicore architecture family")			\
+
_ELF_DEFINE_EM(EM_CLOUDSHIELD,      192,				\
+
	"CloudShield architecture family")				\
+
_ELF_DEFINE_EM(EM_COREA_1ST,        193,				\
+
	"KIPO-KAIST Core-A 1st generation processor family")		\
+
_ELF_DEFINE_EM(EM_COREA_2ND,        194,				\
+
	"KIPO-KAIST Core-A 2nd generation processor family")		\
+
_ELF_DEFINE_EM(EM_ARC_COMPACT2,     195, "Synopsys ARCompact V2")	\
+
_ELF_DEFINE_EM(EM_OPEN8,            196,				\
+
	"Open8 8-bit RISC soft processor core")				\
+
_ELF_DEFINE_EM(EM_RL78,             197, "Renesas RL78 family")		\
+
_ELF_DEFINE_EM(EM_VIDEOCORE5,       198, "Broadcom VideoCore V processor") \
+
_ELF_DEFINE_EM(EM_78KOR,            199, "Renesas 78KOR family")
+

+
#undef	_ELF_DEFINE_EM
+
#define	_ELF_DEFINE_EM(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_ELF_MACHINES()
+
	EM__LAST__
+
};
+

+
/* Older synonyms. */
+
#define	EM_ARC_A5		EM_ARC_COMPACT
+

+
/*
+
 * ELF file types: (ET_*).
+
 */
+
#define	_ELF_DEFINE_ELF_TYPES()						\
+
_ELF_DEFINE_ET(ET_NONE,   0,	    "No file type")			\
+
_ELF_DEFINE_ET(ET_REL,    1, 	    "Relocatable object")		\
+
_ELF_DEFINE_ET(ET_EXEC,   2, 	    "Executable")			\
+
_ELF_DEFINE_ET(ET_DYN,    3, 	    "Shared object")			\
+
_ELF_DEFINE_ET(ET_CORE,   4, 	    "Core file")			\
+
_ELF_DEFINE_ET(ET_LOOS,   0xFE00U,  "Begin OS-specific range")		\
+
_ELF_DEFINE_ET(ET_HIOS,   0xFEFFU,  "End OS-specific range")		\
+
_ELF_DEFINE_ET(ET_LOPROC, 0xFF00U,  "Begin processor-specific range")	\
+
_ELF_DEFINE_ET(ET_HIPROC, 0xFFFFU,  "End processor-specific range")
+

+
#undef	_ELF_DEFINE_ET
+
#define	_ELF_DEFINE_ET(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_ELF_TYPES()
+
	ET__LAST__
+
};
+

+
/* ELF file format version numbers. */
+
#define	EV_NONE		0
+
#define	EV_CURRENT	1
+

+
/*
+
 * Flags for section groups.
+
 */
+
#define	GRP_COMDAT 	0x1		/* COMDAT semantics */
+
#define	GRP_MASKOS 	0x0ff00000	/* OS-specific flags */
+
#define	GRP_MASKPROC 	0xf0000000	/* processor-specific flags */
+

+
/*
+
 * Flags used by program header table entries.
+
 */
+

+
#define	_ELF_DEFINE_PHDR_FLAGS()					\
+
_ELF_DEFINE_PF(PF_X,                0x1, "Execute")			\
+
_ELF_DEFINE_PF(PF_W,                0x2, "Write")			\
+
_ELF_DEFINE_PF(PF_R,                0x4, "Read")			\
+
_ELF_DEFINE_PF(PF_MASKOS,           0x0ff00000, "OS-specific flags")	\
+
_ELF_DEFINE_PF(PF_MASKPROC,         0xf0000000, "Processor-specific flags") \
+
_ELF_DEFINE_PF(PF_ARM_SB,           0x10000000,				\
+
	"segment contains the location addressed by the static base")	\
+
_ELF_DEFINE_PF(PF_ARM_PI,           0x20000000,				\
+
	"segment is position-independent")				\
+
_ELF_DEFINE_PF(PF_ARM_ABS,          0x40000000,				\
+
	"segment must be loaded at its base address")
+

+
#undef	_ELF_DEFINE_PF
+
#define	_ELF_DEFINE_PF(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_PHDR_FLAGS()
+
	PF__LAST__
+
};
+

+
/*
+
 * Types of program header table entries.
+
 */
+

+
#define	_ELF_DEFINE_PHDR_TYPES()				\
+
_ELF_DEFINE_PT(PT_NULL,             0, "ignored entry")		\
+
_ELF_DEFINE_PT(PT_LOAD,             1, "loadable segment")	\
+
_ELF_DEFINE_PT(PT_DYNAMIC,          2,				\
+
	"contains dynamic linking information")			\
+
_ELF_DEFINE_PT(PT_INTERP,           3, "names an interpreter")	\
+
_ELF_DEFINE_PT(PT_NOTE,             4, "auxiliary information")	\
+
_ELF_DEFINE_PT(PT_SHLIB,            5, "reserved")		\
+
_ELF_DEFINE_PT(PT_PHDR,             6,				\
+
	"describes the program header itself")			\
+
_ELF_DEFINE_PT(PT_TLS,              7, "thread local storage")	\
+
_ELF_DEFINE_PT(PT_LOOS,             0x60000000UL,		\
+
	"start of OS-specific range")				\
+
_ELF_DEFINE_PT(PT_SUNW_UNWIND,      0x6464E550UL,		\
+
	"Solaris/amd64 stack unwind tables")			\
+
_ELF_DEFINE_PT(PT_GNU_EH_FRAME,     0x6474E550UL,		\
+
	"GCC generated .eh_frame_hdr segment")			\
+
_ELF_DEFINE_PT(PT_GNU_STACK,	    0x6474E551UL,		\
+
	"Stack flags")						\
+
_ELF_DEFINE_PT(PT_GNU_RELRO,	    0x6474E552UL,		\
+
	"Segment becomes read-only after relocation")		\
+
_ELF_DEFINE_PT(PT_SUNWBSS,          0x6FFFFFFAUL,		\
+
	"A Solaris .SUNW_bss section")				\
+
_ELF_DEFINE_PT(PT_SUNWSTACK,        0x6FFFFFFBUL,		\
+
	"A Solaris process stack")				\
+
_ELF_DEFINE_PT(PT_SUNWDTRACE,       0x6FFFFFFCUL,		\
+
	"Used by dtrace(1)")					\
+
_ELF_DEFINE_PT(PT_SUNWCAP,          0x6FFFFFFDUL,		\
+
	"Special hardware capability requirements")		\
+
_ELF_DEFINE_PT(PT_HIOS,             0x6FFFFFFFUL,		\
+
	"end of OS-specific range")				\
+
_ELF_DEFINE_PT(PT_LOPROC,           0x70000000UL,		\
+
	"start of processor-specific range")			\
+
_ELF_DEFINE_PT(PT_ARM_ARCHEXT,      0x70000000UL,		\
+
	"platform architecture compatibility information")	\
+
_ELF_DEFINE_PT(PT_ARM_EXIDX,        0x70000001UL,		\
+
	"exception unwind tables")				\
+
_ELF_DEFINE_PT(PT_MIPS_REGINFO,     0x70000000UL,		\
+
	"register usage information")				\
+
_ELF_DEFINE_PT(PT_MIPS_RTPROC,      0x70000001UL,		\
+
	"runtime procedure table")				\
+
_ELF_DEFINE_PT(PT_MIPS_OPTIONS,     0x70000002UL,		\
+
	"options segment")					\
+
_ELF_DEFINE_PT(PT_HIPROC,           0x7FFFFFFFUL,		\
+
	"end of processor-specific range")
+

+
#undef	_ELF_DEFINE_PT
+
#define	_ELF_DEFINE_PT(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_PHDR_TYPES()
+
	PT__LAST__ = PT_HIPROC
+
};
+

+
/* synonyms. */
+
#define	PT_ARM_UNWIND	PT_ARM_EXIDX
+
#define	PT_HISUNW	PT_HIOS
+
#define	PT_LOSUNW	PT_SUNWBSS
+

+
/*
+
 * Section flags.
+
 */
+

+
#define	_ELF_DEFINE_SECTION_FLAGS()					\
+
_ELF_DEFINE_SHF(SHF_WRITE,           0x1,				\
+
	"writable during program execution")				\
+
_ELF_DEFINE_SHF(SHF_ALLOC,           0x2,				\
+
	"occupies memory during program execution")			\
+
_ELF_DEFINE_SHF(SHF_EXECINSTR,       0x4, "executable instructions")	\
+
_ELF_DEFINE_SHF(SHF_MERGE,           0x10,				\
+
	"may be merged to prevent duplication")				\
+
_ELF_DEFINE_SHF(SHF_STRINGS,         0x20,				\
+
	"NUL-terminated character strings")				\
+
_ELF_DEFINE_SHF(SHF_INFO_LINK,       0x40,				\
+
	"the sh_info field holds a link")				\
+
_ELF_DEFINE_SHF(SHF_LINK_ORDER,      0x80,				\
+
	"special ordering requirements during linking")			\
+
_ELF_DEFINE_SHF(SHF_OS_NONCONFORMING, 0x100,				\
+
	"requires OS-specific processing during linking")		\
+
_ELF_DEFINE_SHF(SHF_GROUP,           0x200,				\
+
	"member of a section group")					\
+
_ELF_DEFINE_SHF(SHF_TLS,             0x400,				\
+
	"holds thread-local storage")					\
+
_ELF_DEFINE_SHF(SHF_MASKOS,          0x0FF00000UL,			\
+
	"bits reserved for OS-specific semantics")			\
+
_ELF_DEFINE_SHF(SHF_AMD64_LARGE,     0x10000000UL,			\
+
	"section uses large code model")				\
+
_ELF_DEFINE_SHF(SHF_ENTRYSECT,       0x10000000UL,			\
+
	"section contains an entry point (ARM)")			\
+
_ELF_DEFINE_SHF(SHF_COMDEF,          0x80000000UL,			\
+
	"section may be multiply defined in input to link step (ARM)")	\
+
_ELF_DEFINE_SHF(SHF_MIPS_GPREL,      0x10000000UL,			\
+
	"section must be part of global data area")			\
+
_ELF_DEFINE_SHF(SHF_MIPS_MERGE,      0x20000000UL,			\
+
	"section data should be merged to eliminate duplication")	\
+
_ELF_DEFINE_SHF(SHF_MIPS_ADDR,       0x40000000UL,			\
+
	"section data is addressed by default")				\
+
_ELF_DEFINE_SHF(SHF_MIPS_STRING,     0x80000000UL,			\
+
	"section data is string data by default")			\
+
_ELF_DEFINE_SHF(SHF_MIPS_NOSTRIP,    0x08000000UL,			\
+
	"section data may not be stripped")				\
+
_ELF_DEFINE_SHF(SHF_MIPS_LOCAL,      0x04000000UL,			\
+
	"section data local to process")				\
+
_ELF_DEFINE_SHF(SHF_MIPS_NAMES,      0x02000000UL,			\
+
	"linker must generate implicit hidden weak names")		\
+
_ELF_DEFINE_SHF(SHF_MIPS_NODUPE,     0x01000000UL,			\
+
	"linker must retain only one copy")				\
+
_ELF_DEFINE_SHF(SHF_ORDERED,         0x40000000UL,			\
+
	"section is ordered with respect to other sections")		\
+
_ELF_DEFINE_SHF(SHF_EXCLUDE,	     0x80000000UL,			\
+
	"section is excluded from executables and shared objects")	\
+
_ELF_DEFINE_SHF(SHF_MASKPROC,        0xF0000000UL,			\
+
	"bits reserved for processor-specific semantics")
+

+
#undef	_ELF_DEFINE_SHF
+
#define	_ELF_DEFINE_SHF(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_SECTION_FLAGS()
+
	SHF__LAST__
+
};
+

+
/*
+
 * Special section indices.
+
 */
+
#define _ELF_DEFINE_SECTION_INDICES()					\
+
_ELF_DEFINE_SHN(SHN_UNDEF, 	0, 	 "undefined section")		\
+
_ELF_DEFINE_SHN(SHN_LORESERVE, 	0xFF00U, "start of reserved area")	\
+
_ELF_DEFINE_SHN(SHN_LOPROC, 	0xFF00U,				\
+
	"start of processor-specific range")				\
+
_ELF_DEFINE_SHN(SHN_BEFORE,	0xFF00U, "used for section ordering")	\
+
_ELF_DEFINE_SHN(SHN_AFTER,	0xFF01U, "used for section ordering")	\
+
_ELF_DEFINE_SHN(SHN_AMD64_LCOMMON, 0xFF02U, "large common block label") \
+
_ELF_DEFINE_SHN(SHN_MIPS_ACOMMON, 0xFF00U,				\
+
	"allocated common symbols in a DSO")				\
+
_ELF_DEFINE_SHN(SHN_MIPS_TEXT,	0xFF01U, "Reserved (obsolete)")		\
+
_ELF_DEFINE_SHN(SHN_MIPS_DATA,	0xFF02U, "Reserved (obsolete)")		\
+
_ELF_DEFINE_SHN(SHN_MIPS_SCOMMON, 0xFF03U,				\
+
	"gp-addressable common symbols")				\
+
_ELF_DEFINE_SHN(SHN_MIPS_SUNDEFINED, 0xFF04U,				\
+
	"gp-addressable undefined symbols")				\
+
_ELF_DEFINE_SHN(SHN_MIPS_LCOMMON, 0xFF05U, "local common symbols")	\
+
_ELF_DEFINE_SHN(SHN_MIPS_LUNDEFINED, 0xFF06U,				\
+
	"local undefined symbols")					\
+
_ELF_DEFINE_SHN(SHN_HIPROC, 	0xFF1FU,				\
+
	"end of processor-specific range")				\
+
_ELF_DEFINE_SHN(SHN_LOOS, 	0xFF20U,				\
+
	"start of OS-specific range")					\
+
_ELF_DEFINE_SHN(SHN_SUNW_IGNORE, 0xFF3FU, "used by dtrace")		\
+
_ELF_DEFINE_SHN(SHN_HIOS, 	0xFF3FU,				\
+
	"end of OS-specific range")					\
+
_ELF_DEFINE_SHN(SHN_ABS, 	0xFFF1U, "absolute references")		\
+
_ELF_DEFINE_SHN(SHN_COMMON, 	0xFFF2U, "references to COMMON areas")	\
+
_ELF_DEFINE_SHN(SHN_XINDEX, 	0xFFFFU, "extended index")		\
+
_ELF_DEFINE_SHN(SHN_HIRESERVE, 	0xFFFFU, "end of reserved area")
+

+
#undef	_ELF_DEFINE_SHN
+
#define	_ELF_DEFINE_SHN(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_SECTION_INDICES()
+
	SHN__LAST__
+
};
+

+
/*
+
 * Section types.
+
 */
+

+
#define	_ELF_DEFINE_SECTION_TYPES()					\
+
_ELF_DEFINE_SHT(SHT_NULL,            0, "inactive header")		\
+
_ELF_DEFINE_SHT(SHT_PROGBITS,        1, "program defined information")	\
+
_ELF_DEFINE_SHT(SHT_SYMTAB,          2, "symbol table")			\
+
_ELF_DEFINE_SHT(SHT_STRTAB,          3, "string table")			\
+
_ELF_DEFINE_SHT(SHT_RELA,            4,					\
+
	"relocation entries with addends")				\
+
_ELF_DEFINE_SHT(SHT_HASH,            5, "symbol hash table")		\
+
_ELF_DEFINE_SHT(SHT_DYNAMIC,         6,					\
+
	"information for dynamic linking")				\
+
_ELF_DEFINE_SHT(SHT_NOTE,            7, "additional notes")		\
+
_ELF_DEFINE_SHT(SHT_NOBITS,          8, "section occupying no space")	\
+
_ELF_DEFINE_SHT(SHT_REL,             9,					\
+
	"relocation entries without addends")				\
+
_ELF_DEFINE_SHT(SHT_SHLIB,           10, "reserved")			\
+
_ELF_DEFINE_SHT(SHT_DYNSYM,          11, "symbol table")		\
+
_ELF_DEFINE_SHT(SHT_INIT_ARRAY,      14,				\
+
	"pointers to initialization functions")				\
+
_ELF_DEFINE_SHT(SHT_FINI_ARRAY,      15,				\
+
	"pointers to termination functions")				\
+
_ELF_DEFINE_SHT(SHT_PREINIT_ARRAY,   16,				\
+
	"pointers to functions called before initialization")		\
+
_ELF_DEFINE_SHT(SHT_GROUP,           17, "defines a section group")	\
+
_ELF_DEFINE_SHT(SHT_SYMTAB_SHNDX,    18,				\
+
	"used for extended section numbering")				\
+
_ELF_DEFINE_SHT(SHT_LOOS,            0x60000000UL,			\
+
	"start of OS-specific range")					\
+
_ELF_DEFINE_SHT(SHT_SUNW_dof,	     0x6FFFFFF4UL,			\
+
	"used by dtrace")						\
+
_ELF_DEFINE_SHT(SHT_SUNW_cap,	     0x6FFFFFF5UL,			\
+
	"capability requirements")					\
+
_ELF_DEFINE_SHT(SHT_GNU_ATTRIBUTES,  0x6FFFFFF5UL,			\
+
	"object attributes")						\
+
_ELF_DEFINE_SHT(SHT_SUNW_SIGNATURE,  0x6FFFFFF6UL,			\
+
	"module verification signature")				\
+
_ELF_DEFINE_SHT(SHT_GNU_HASH,	     0x6FFFFFF6UL,			\
+
	"GNU Hash sections")						\
+
_ELF_DEFINE_SHT(SHT_GNU_LIBLIST,     0x6FFFFFF7UL,			\
+
	"List of libraries to be prelinked")				\
+
_ELF_DEFINE_SHT(SHT_SUNW_ANNOTATE,   0x6FFFFFF7UL,			\
+
	"special section where unresolved references are allowed")	\
+
_ELF_DEFINE_SHT(SHT_SUNW_DEBUGSTR,   0x6FFFFFF8UL,			\
+
	"debugging information")					\
+
_ELF_DEFINE_SHT(SHT_CHECKSUM, 	     0x6FFFFFF8UL,			\
+
	"checksum for dynamic shared objects")				\
+
_ELF_DEFINE_SHT(SHT_SUNW_DEBUG,      0x6FFFFFF9UL,			\
+
	"debugging information")					\
+
_ELF_DEFINE_SHT(SHT_SUNW_move,       0x6FFFFFFAUL,			\
+
	"information to handle partially initialized symbols")		\
+
_ELF_DEFINE_SHT(SHT_SUNW_COMDAT,     0x6FFFFFFBUL,			\
+
	"section supporting merging of multiple copies of data")	\
+
_ELF_DEFINE_SHT(SHT_SUNW_syminfo,    0x6FFFFFFCUL,			\
+
	"additional symbol information")				\
+
_ELF_DEFINE_SHT(SHT_SUNW_verdef,     0x6FFFFFFDUL,			\
+
	"symbol versioning information")				\
+
_ELF_DEFINE_SHT(SHT_SUNW_verneed,    0x6FFFFFFEUL,			\
+
	"symbol versioning requirements")				\
+
_ELF_DEFINE_SHT(SHT_SUNW_versym,     0x6FFFFFFFUL,			\
+
	"symbol versioning table")					\
+
_ELF_DEFINE_SHT(SHT_HIOS,            0x6FFFFFFFUL,			\
+
	"end of OS-specific range")					\
+
_ELF_DEFINE_SHT(SHT_LOPROC,          0x70000000UL,			\
+
	"start of processor-specific range")				\
+
_ELF_DEFINE_SHT(SHT_ARM_EXIDX,       0x70000001UL,			\
+
	"exception index table")					\
+
_ELF_DEFINE_SHT(SHT_ARM_PREEMPTMAP,  0x70000002UL,			\
+
	"BPABI DLL dynamic linking preemption map")			\
+
_ELF_DEFINE_SHT(SHT_ARM_ATTRIBUTES,  0x70000003UL,			\
+
	"object file compatibility attributes")				\
+
_ELF_DEFINE_SHT(SHT_ARM_DEBUGOVERLAY, 0x70000004UL,			\
+
	"overlay debug information")					\
+
_ELF_DEFINE_SHT(SHT_ARM_OVERLAYSECTION, 0x70000005UL,			\
+
	"overlay debug information")					\
+
_ELF_DEFINE_SHT(SHT_MIPS_LIBLIST,    0x70000000UL,			\
+
	"DSO library information used in link")				\
+
_ELF_DEFINE_SHT(SHT_MIPS_MSYM,       0x70000001UL,			\
+
	"MIPS symbol table extension")					\
+
_ELF_DEFINE_SHT(SHT_MIPS_CONFLICT,   0x70000002UL,			\
+
	"symbol conflicting with DSO-defined symbols ")			\
+
_ELF_DEFINE_SHT(SHT_MIPS_GPTAB,      0x70000003UL,			\
+
	"global pointer table")						\
+
_ELF_DEFINE_SHT(SHT_MIPS_UCODE,      0x70000004UL,			\
+
	"reserved")							\
+
_ELF_DEFINE_SHT(SHT_MIPS_DEBUG,      0x70000005UL,			\
+
	"reserved (obsolete debug information)")			\
+
_ELF_DEFINE_SHT(SHT_MIPS_REGINFO,    0x70000006UL,			\
+
	"register usage information")					\
+
_ELF_DEFINE_SHT(SHT_MIPS_PACKAGE,    0x70000007UL,			\
+
	"OSF reserved")							\
+
_ELF_DEFINE_SHT(SHT_MIPS_PACKSYM,    0x70000008UL,			\
+
	"OSF reserved")							\
+
_ELF_DEFINE_SHT(SHT_MIPS_RELD,       0x70000009UL,			\
+
	"dynamic relocation")						\
+
_ELF_DEFINE_SHT(SHT_MIPS_IFACE,      0x7000000BUL,			\
+
	"subprogram interface information")				\
+
_ELF_DEFINE_SHT(SHT_MIPS_CONTENT,    0x7000000CUL,			\
+
	"section content classification")				\
+
_ELF_DEFINE_SHT(SHT_MIPS_OPTIONS,     0x7000000DUL,			\
+
	"general options")						\
+
_ELF_DEFINE_SHT(SHT_MIPS_DELTASYM,   0x7000001BUL,			\
+
	"Delta C++: symbol table")					\
+
_ELF_DEFINE_SHT(SHT_MIPS_DELTAINST,  0x7000001CUL,			\
+
	"Delta C++: instance table")					\
+
_ELF_DEFINE_SHT(SHT_MIPS_DELTACLASS, 0x7000001DUL,			\
+
	"Delta C++: class table")					\
+
_ELF_DEFINE_SHT(SHT_MIPS_DWARF,      0x7000001EUL,			\
+
	"DWARF debug information")					\
+
_ELF_DEFINE_SHT(SHT_MIPS_DELTADECL,  0x7000001FUL,			\
+
	"Delta C++: declarations")					\
+
_ELF_DEFINE_SHT(SHT_MIPS_SYMBOL_LIB, 0x70000020UL,			\
+
	"symbol-to-library mapping")					\
+
_ELF_DEFINE_SHT(SHT_MIPS_EVENTS,     0x70000021UL,			\
+
	"event locations")						\
+
_ELF_DEFINE_SHT(SHT_MIPS_TRANSLATE,  0x70000022UL,			\
+
	"???")								\
+
_ELF_DEFINE_SHT(SHT_MIPS_PIXIE,      0x70000023UL,			\
+
	"special pixie sections")					\
+
_ELF_DEFINE_SHT(SHT_MIPS_XLATE,      0x70000024UL,			\
+
	"address translation table")					\
+
_ELF_DEFINE_SHT(SHT_MIPS_XLATE_DEBUG, 0x70000025UL,			\
+
	"SGI internal address translation table")			\
+
_ELF_DEFINE_SHT(SHT_MIPS_WHIRL,      0x70000026UL,			\
+
	"intermediate code")						\
+
_ELF_DEFINE_SHT(SHT_MIPS_EH_REGION,  0x70000027UL,			\
+
	"C++ exception handling region info")				\
+
_ELF_DEFINE_SHT(SHT_MIPS_XLATE_OLD,  0x70000028UL,			\
+
	"obsolete")							\
+
_ELF_DEFINE_SHT(SHT_MIPS_PDR_EXCEPTION, 0x70000029UL,			\
+
	"runtime procedure descriptor table exception information")	\
+
_ELF_DEFINE_SHT(SHT_SPARC_GOTDATA,   0x70000000UL,			\
+
	"SPARC-specific data")						\
+
_ELF_DEFINE_SHT(SHT_AMD64_UNWIND,    0x70000001UL,			\
+
	"unwind tables for the AMD64")					\
+
_ELF_DEFINE_SHT(SHT_ORDERED,         0x7FFFFFFFUL,			\
+
	"sort entries in the section")					\
+
_ELF_DEFINE_SHT(SHT_HIPROC,          0x7FFFFFFFUL,			\
+
	"end of processor-specific range")				\
+
_ELF_DEFINE_SHT(SHT_LOUSER,          0x80000000UL,			\
+
	"start of application-specific range")				\
+
_ELF_DEFINE_SHT(SHT_HIUSER,          0xFFFFFFFFUL,			\
+
	"end of application-specific range")
+

+
#undef	_ELF_DEFINE_SHT
+
#define	_ELF_DEFINE_SHT(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_SECTION_TYPES()
+
	SHT__LAST__ = SHT_HIUSER
+
};
+

+
/* Aliases for section types. */
+
#define	SHT_GNU_verdef		SHT_SUNW_verdef
+
#define	SHT_GNU_verneed		SHT_SUNW_verneed
+
#define	SHT_GNU_versym		SHT_SUNW_versym
+

+
/*
+
 * Symbol binding information.
+
 */
+

+
#define	_ELF_DEFINE_SYMBOL_BINDING()					\
+
_ELF_DEFINE_STB(STB_LOCAL,           0,					\
+
	"not visible outside defining object file")			\
+
_ELF_DEFINE_STB(STB_GLOBAL,          1,					\
+
	"visible across all object files being combined")		\
+
_ELF_DEFINE_STB(STB_WEAK,            2,					\
+
	"visible across all object files but with low precedence")	\
+
_ELF_DEFINE_STB(STB_LOOS,            10, "start of OS-specific range")	\
+
_ELF_DEFINE_STB(STB_HIOS,            12, "end of OS-specific range")	\
+
_ELF_DEFINE_STB(STB_LOPROC,          13,				\
+
	"start of processor-specific range")				\
+
_ELF_DEFINE_STB(STB_HIPROC,          15,				\
+
	"end of processor-specific range")
+

+
#undef	_ELF_DEFINE_STB
+
#define	_ELF_DEFINE_STB(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_SYMBOL_BINDING()
+
	STB__LAST__
+
};
+

+
/*
+
 * Symbol types
+
 */
+

+
#define	_ELF_DEFINE_SYMBOL_TYPES()					\
+
_ELF_DEFINE_STT(STT_NOTYPE,          0, "unspecified type")		\
+
_ELF_DEFINE_STT(STT_OBJECT,          1, "data object")			\
+
_ELF_DEFINE_STT(STT_FUNC,            2, "executable code")		\
+
_ELF_DEFINE_STT(STT_SECTION,         3, "section")			\
+
_ELF_DEFINE_STT(STT_FILE,            4, "source file")			\
+
_ELF_DEFINE_STT(STT_COMMON,          5, "uninitialized common block")	\
+
_ELF_DEFINE_STT(STT_TLS,             6, "thread local storage")		\
+
_ELF_DEFINE_STT(STT_LOOS,            10, "start of OS-specific types")	\
+
_ELF_DEFINE_STT(STT_HIOS,            12, "end of OS-specific types")	\
+
_ELF_DEFINE_STT(STT_LOPROC,          13,				\
+
	"start of processor-specific types")				\
+
_ELF_DEFINE_STT(STT_ARM_TFUNC,       13, "Thumb function (GNU)")	\
+
_ELF_DEFINE_STT(STT_ARM_16BIT,       15, "Thumb label (GNU)")		\
+
_ELF_DEFINE_STT(STT_HIPROC,          15,				\
+
	"end of processor-specific types")
+

+
#undef	_ELF_DEFINE_STT
+
#define	_ELF_DEFINE_STT(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_SYMBOL_TYPES()
+
	STT__LAST__
+
};
+

+
/*
+
 * Symbol binding.
+
 */
+

+
#define	_ELF_DEFINE_SYMBOL_BINDING_KINDS()		\
+
_ELF_DEFINE_SYB(SYMINFO_BT_SELF,	0xFFFFU,	\
+
	"bound to self")				\
+
_ELF_DEFINE_SYB(SYMINFO_BT_PARENT,	0xFFFEU,	\
+
	"bound to parent")				\
+
_ELF_DEFINE_SYB(SYMINFO_BT_NONE,	0xFFFDU,	\
+
	"no special binding")
+

+
#undef	_ELF_DEFINE_SYB
+
#define	_ELF_DEFINE_SYB(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_SYMBOL_BINDING_KINDS()
+
	SYMINFO__LAST__
+
};
+

+
/*
+
 * Symbol visibility.
+
 */
+

+
#define	_ELF_DEFINE_SYMBOL_VISIBILITY()		\
+
_ELF_DEFINE_STV(STV_DEFAULT,         0,		\
+
	"as specified by symbol type")		\
+
_ELF_DEFINE_STV(STV_INTERNAL,        1,		\
+
	"as defined by processor semantics")	\
+
_ELF_DEFINE_STV(STV_HIDDEN,          2,		\
+
	"hidden from other components")		\
+
_ELF_DEFINE_STV(STV_PROTECTED,       3,		\
+
	"local references are not preemptable")
+

+
#undef	_ELF_DEFINE_STV
+
#define	_ELF_DEFINE_STV(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_SYMBOL_VISIBILITY()
+
	STV__LAST__
+
};
+

+
/*
+
 * Symbol flags.
+
 */
+
#define	_ELF_DEFINE_SYMBOL_FLAGS()		\
+
_ELF_DEFINE_SYF(SYMINFO_FLG_DIRECT,	0x01,	\
+
	"directly assocated reference")		\
+
_ELF_DEFINE_SYF(SYMINFO_FLG_COPY,	0x04,	\
+
	"definition by copy-relocation")	\
+
_ELF_DEFINE_SYF(SYMINFO_FLG_LAZYLOAD,	0x08,	\
+
	"object should be lazily loaded")	\
+
_ELF_DEFINE_SYF(SYMINFO_FLG_DIRECTBIND,	0x10,	\
+
	"reference should be directly bound")	\
+
_ELF_DEFINE_SYF(SYMINFO_FLG_NOEXTDIRECT, 0x20,	\
+
	"external references not allowed to bind to definition")
+

+
#undef	_ELF_DEFINE_SYF
+
#define	_ELF_DEFINE_SYF(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_SYMBOL_FLAGS()
+
	SYMINFO_FLG__LAST__
+
};
+

+
/*
+
 * Version dependencies.
+
 */
+
#define	_ELF_DEFINE_VERSIONING_DEPENDENCIES()			\
+
_ELF_DEFINE_VERD(VER_NDX_LOCAL,		0,	"local scope")	\
+
_ELF_DEFINE_VERD(VER_NDX_GLOBAL,	1,	"global scope")
+
#undef	_ELF_DEFINE_VERD
+
#define	_ELF_DEFINE_VERD(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_VERSIONING_DEPENDENCIES()
+
	VER_NDX__LAST__
+
};
+

+
/*
+
 * Version flags.
+
 */
+
#define	_ELF_DEFINE_VERSIONING_FLAGS()				\
+
_ELF_DEFINE_VERF(VER_FLG_BASE,		0x1,	"file version") \
+
_ELF_DEFINE_VERF(VER_FLG_WEAK,		0x2,	"weak version")
+
#undef	_ELF_DEFINE_VERF
+
#define	_ELF_DEFINE_VERF(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_VERSIONING_FLAGS()
+
	VER_FLG__LAST__
+
};
+

+
/*
+
 * Version needs
+
 */
+
#define	_ELF_DEFINE_VERSIONING_NEEDS()					\
+
_ELF_DEFINE_VRN(VER_NEED_NONE,		0,	"invalid version")	\
+
_ELF_DEFINE_VRN(VER_NEED_CURRENT,	1,	"current version")
+
#undef	_ELF_DEFINE_VRN
+
#define	_ELF_DEFINE_VRN(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_VERSIONING_NEEDS()
+
	VER_NEED__LAST__
+
};
+

+
/*
+
 * Version numbers.
+
 */
+
#define	_ELF_DEFINE_VERSIONING_NUMBERS()				\
+
_ELF_DEFINE_VRNU(VER_DEF_NONE,		0,	"invalid version")	\
+
_ELF_DEFINE_VRNU(VER_DEF_CURRENT,	1, 	"current version")
+
#undef	_ELF_DEFINE_VRNU
+
#define	_ELF_DEFINE_VRNU(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_VERSIONING_NUMBERS()
+
	VER_DEF__LAST__
+
};
+

+
/**
+
 ** Relocation types.
+
 **/
+

+
#define	_ELF_DEFINE_386_RELOCATIONS()		\
+
_ELF_DEFINE_RELOC(R_386_NONE,		0)	\
+
_ELF_DEFINE_RELOC(R_386_32,		1)	\
+
_ELF_DEFINE_RELOC(R_386_PC32,		2)	\
+
_ELF_DEFINE_RELOC(R_386_GOT32,		3)	\
+
_ELF_DEFINE_RELOC(R_386_PLT32,		4)	\
+
_ELF_DEFINE_RELOC(R_386_COPY,		5)	\
+
_ELF_DEFINE_RELOC(R_386_GLOB_DAT,	6)	\
+
_ELF_DEFINE_RELOC(R_386_JMP_SLOT,	7)	\
+
_ELF_DEFINE_RELOC(R_386_RELATIVE,	8)	\
+
_ELF_DEFINE_RELOC(R_386_GOTOFF,		9)	\
+
_ELF_DEFINE_RELOC(R_386_GOTPC,		10)	\
+
_ELF_DEFINE_RELOC(R_386_32PLT,		11)	\
+
_ELF_DEFINE_RELOC(R_386_16,		20)	\
+
_ELF_DEFINE_RELOC(R_386_PC16,		21)	\
+
_ELF_DEFINE_RELOC(R_386_8,		22)	\
+
_ELF_DEFINE_RELOC(R_386_PC8,		23)
+

+
/*
+
 * These are the symbols used in the Sun ``Linkers and Loaders
+
 * Guide'', Document No: 817-1984-17.  See the X86_64 relocations list
+
 * below for the spellings used in the ELF specification.
+
 */
+
#define	_ELF_DEFINE_AMD64_RELOCATIONS()		\
+
_ELF_DEFINE_RELOC(R_AMD64_NONE,		0)	\
+
_ELF_DEFINE_RELOC(R_AMD64_64,		1)	\
+
_ELF_DEFINE_RELOC(R_AMD64_PC32,		2)	\
+
_ELF_DEFINE_RELOC(R_AMD64_GOT32,	3)	\
+
_ELF_DEFINE_RELOC(R_AMD64_PLT32,	4)	\
+
_ELF_DEFINE_RELOC(R_AMD64_COPY,		5)	\
+
_ELF_DEFINE_RELOC(R_AMD64_GLOB_DAT,	6)	\
+
_ELF_DEFINE_RELOC(R_AMD64_JUMP_SLOT,	7)	\
+
_ELF_DEFINE_RELOC(R_AMD64_RELATIVE,	8)	\
+
_ELF_DEFINE_RELOC(R_AMD64_GOTPCREL,	9)	\
+
_ELF_DEFINE_RELOC(R_AMD64_32,		10)	\
+
_ELF_DEFINE_RELOC(R_AMD64_32S,		11)	\
+
_ELF_DEFINE_RELOC(R_AMD64_16,		12)	\
+
_ELF_DEFINE_RELOC(R_AMD64_PC16,		13)	\
+
_ELF_DEFINE_RELOC(R_AMD64_8,		14)	\
+
_ELF_DEFINE_RELOC(R_AMD64_PC8,		15)	\
+
_ELF_DEFINE_RELOC(R_AMD64_PC64,		24)	\
+
_ELF_DEFINE_RELOC(R_AMD64_GOTOFF64,	25)	\
+
_ELF_DEFINE_RELOC(R_AMD64_GOTPC32,	26)
+

+
#define	_ELF_DEFINE_ARM_RELOCATIONS()			\
+
_ELF_DEFINE_RELOC(R_ARM_NONE,			0)	\
+
_ELF_DEFINE_RELOC(R_ARM_PC24,			1)	\
+
_ELF_DEFINE_RELOC(R_ARM_ABS32,			2)	\
+
_ELF_DEFINE_RELOC(R_ARM_REL32,			3)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDR_PC_G0,		4)	\
+
_ELF_DEFINE_RELOC(R_ARM_ABS16,			5)	\
+
_ELF_DEFINE_RELOC(R_ARM_ABS12,			6)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_ABS5,		7)	\
+
_ELF_DEFINE_RELOC(R_ARM_ABS8,			8)	\
+
_ELF_DEFINE_RELOC(R_ARM_SBREL32,		9)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_CALL,		10)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_PC8,		11)	\
+
_ELF_DEFINE_RELOC(R_ARM_BREL_ADJ,		12)	\
+
_ELF_DEFINE_RELOC(R_ARM_SWI24,			13)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_SWI8,		14)	\
+
_ELF_DEFINE_RELOC(R_ARM_XPC25,			15)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_XPC22,		16)	\
+
_ELF_DEFINE_RELOC(R_ARM_TLS_DTPMOD32,		17)	\
+
_ELF_DEFINE_RELOC(R_ARM_TLS_DTPOFF32,		18)	\
+
_ELF_DEFINE_RELOC(R_ARM_TLS_TPOFF32,		19)	\
+
_ELF_DEFINE_RELOC(R_ARM_COPY,			20)	\
+
_ELF_DEFINE_RELOC(R_ARM_GLOB_DAT,		21)	\
+
_ELF_DEFINE_RELOC(R_ARM_JUMP_SLOT,		22)	\
+
_ELF_DEFINE_RELOC(R_ARM_RELATIVE,		23)	\
+
_ELF_DEFINE_RELOC(R_ARM_GOTOFF32,		24)	\
+
_ELF_DEFINE_RELOC(R_ARM_BASE_PREL,		25)	\
+
_ELF_DEFINE_RELOC(R_ARM_GOT_BREL,		26)	\
+
_ELF_DEFINE_RELOC(R_ARM_PLT32,			27)	\
+
_ELF_DEFINE_RELOC(R_ARM_CALL,			28)	\
+
_ELF_DEFINE_RELOC(R_ARM_JUMP24,			29)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_JUMP24,		30)	\
+
_ELF_DEFINE_RELOC(R_ARM_BASE_ABS,		31)	\
+
_ELF_DEFINE_RELOC(R_ARM_ALU_PCREL7_0,		32)	\
+
_ELF_DEFINE_RELOC(R_ARM_ALU_PCREL15_8,		33)	\
+
_ELF_DEFINE_RELOC(R_ARM_ALU_PCREL23_15,		34)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDR_SBREL_11_0,		35)	\
+
_ELF_DEFINE_RELOC(R_ARM_ALU_SBREL_19_12,	36)	\
+
_ELF_DEFINE_RELOC(R_ARM_ALU_SBREL_27_20,	37)	\
+
_ELF_DEFINE_RELOC(R_ARM_TARGET1,		38)	\
+
_ELF_DEFINE_RELOC(R_ARM_SBREL31,		39)	\
+
_ELF_DEFINE_RELOC(R_ARM_V4BX,			40)	\
+
_ELF_DEFINE_RELOC(R_ARM_TARGET2,		41)	\
+
_ELF_DEFINE_RELOC(R_ARM_PREL31,			42)	\
+
_ELF_DEFINE_RELOC(R_ARM_MOVW_ABS_NC,		43)	\
+
_ELF_DEFINE_RELOC(R_ARM_MOVT_ABS,		44)	\
+
_ELF_DEFINE_RELOC(R_ARM_MOVW_PREL_NC,		45)	\
+
_ELF_DEFINE_RELOC(R_ARM_MOVT_PREL,		46)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_MOVW_ABS_NC,	47)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_MOVT_ABS,		48)	\
+
_ELF_DEFINE_RELOC(R_ARM_MOVW_PREL_NC,		49)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_MOVT_PREL,		50)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_JUMP19,		51)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_JUMP6,		52)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_ALU_PREL_11_0,	53)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_PC12,		54)	\
+
_ELF_DEFINE_RELOC(R_ARM_ABS32_NOI,		55)	\
+
_ELF_DEFINE_RELOC(R_ARM_REL32_NOI,		56)	\
+
_ELF_DEFINE_RELOC(R_ARM_ALU_PC_G0_NC,		57)	\
+
_ELF_DEFINE_RELOC(R_ARM_ALU_PC_G0,		58)	\
+
_ELF_DEFINE_RELOC(R_ARM_ALU_PC_G1_NC,		59)	\
+
_ELF_DEFINE_RELOC(R_ARM_ALU_PC_G1,		60)	\
+
_ELF_DEFINE_RELOC(R_ARM_ALU_PC_G2,		61)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDR_PC_G1,		62)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDR_PC_G2,		63)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDRS_PC_G0,		64)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDRS_PC_G1,		65)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDRS_PC_G2,		66)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDC_PC_G0,		67)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDC_PC_G1,		68)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDC_PC_G2,		69)	\
+
_ELF_DEFINE_RELOC(R_ARM_ALU_SB_G0_NC,		70)	\
+
_ELF_DEFINE_RELOC(R_ARM_ALU_SB_G0,		71)	\
+
_ELF_DEFINE_RELOC(R_ARM_ALU_SB_G1_NC,		72)	\
+
_ELF_DEFINE_RELOC(R_ARM_ALU_SB_G1,		73)	\
+
_ELF_DEFINE_RELOC(R_ARM_ALU_SB_G2,		74)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDR_SB_G0,		75)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDR_SB_G1,		76)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDR_SB_G2,		77)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDRS_SB_G0,		78)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDRS_SB_G1,		79)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDRS_SB_G2,		80)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDC_SB_G0,		81)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDC_SB_G1,		82)	\
+
_ELF_DEFINE_RELOC(R_ARM_LDC_SB_G2,		83)	\
+
_ELF_DEFINE_RELOC(R_ARM_MOVW_BREL_NC,		84)	\
+
_ELF_DEFINE_RELOC(R_ARM_MOVT_BREL,		85)	\
+
_ELF_DEFINE_RELOC(R_ARM_MOVW_BREL,		86)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_MOVW_BREL_NC,	87)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_MOVT_BREL,		88)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_MOVW_BREL,		89)	\
+
_ELF_DEFINE_RELOC(R_ARM_TLS_GOTDESC,		90)	\
+
_ELF_DEFINE_RELOC(R_ARM_TLS_CALL,		91)	\
+
_ELF_DEFINE_RELOC(R_ARM_TLS_DESCSEQ,		92)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_TLS_CALL,		93)	\
+
_ELF_DEFINE_RELOC(R_ARM_PLT32_ABS,		94)	\
+
_ELF_DEFINE_RELOC(R_ARM_GOT_ABS,		95)	\
+
_ELF_DEFINE_RELOC(R_ARM_GOT_PREL,		96)	\
+
_ELF_DEFINE_RELOC(R_ARM_GOT_BREL12,		97)	\
+
_ELF_DEFINE_RELOC(R_ARM_GOTOFF12,		98)	\
+
_ELF_DEFINE_RELOC(R_ARM_GOTRELAX,		99)	\
+
_ELF_DEFINE_RELOC(R_ARM_GNU_VTENTRY,		100)	\
+
_ELF_DEFINE_RELOC(R_ARM_GNU_VTINHERIT,		101)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_JUMP11,		102)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_JUMP8,		103)	\
+
_ELF_DEFINE_RELOC(R_ARM_TLS_GD32,		104)	\
+
_ELF_DEFINE_RELOC(R_ARM_TLS_LDM32,		105)	\
+
_ELF_DEFINE_RELOC(R_ARM_TLS_LDO32,		106)	\
+
_ELF_DEFINE_RELOC(R_ARM_TLS_IE32,		107)	\
+
_ELF_DEFINE_RELOC(R_ARM_TLS_LE32,		108)	\
+
_ELF_DEFINE_RELOC(R_ARM_TLS_LDO12,		109)	\
+
_ELF_DEFINE_RELOC(R_ARM_TLS_LE12,		110)	\
+
_ELF_DEFINE_RELOC(R_ARM_TLS_IE12GP,		111)	\
+
_ELF_DEFINE_RELOC(R_ARM_ME_TOO,			128)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_TLS_DESCSEQ16,	129)	\
+
_ELF_DEFINE_RELOC(R_ARM_THM_TLS_DESCSEQ32,	130)
+

+
#define	_ELF_DEFINE_IA64_RELOCATIONS()			\
+
_ELF_DEFINE_RELOC(R_IA_64_NONE,			0)	\
+
_ELF_DEFINE_RELOC(R_IA_64_IMM14,		0x21)	\
+
_ELF_DEFINE_RELOC(R_IA_64_IMM22,		0x22)	\
+
_ELF_DEFINE_RELOC(R_IA_64_IMM64,		0x23)	\
+
_ELF_DEFINE_RELOC(R_IA_64_DIR32MSB,		0x24)	\
+
_ELF_DEFINE_RELOC(R_IA_64_DIR32LSB,		0x25)	\
+
_ELF_DEFINE_RELOC(R_IA_64_DIR64MSB,		0x26)	\
+
_ELF_DEFINE_RELOC(R_IA_64_DIR64LSB,		0x27)	\
+
_ELF_DEFINE_RELOC(R_IA_64_GPREL22,		0x2a)	\
+
_ELF_DEFINE_RELOC(R_IA_64_GPREL64I,		0x2b)	\
+
_ELF_DEFINE_RELOC(R_IA_64_GPREL32MSB,		0x2c)	\
+
_ELF_DEFINE_RELOC(R_IA_64_GPREL32LSB,		0x2d)	\
+
_ELF_DEFINE_RELOC(R_IA_64_GPREL64MSB,		0x2e)	\
+
_ELF_DEFINE_RELOC(R_IA_64_GPREL64LSB,		0x2f)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTOFF22,		0x32)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTOFF64I,		0x33)	\
+
_ELF_DEFINE_RELOC(R_IA_64_PLTOFF22,		0x3a)	\
+
_ELF_DEFINE_RELOC(R_IA_64_PLTOFF64I,		0x3b)	\
+
_ELF_DEFINE_RELOC(R_IA_64_PLTOFF64MSB,		0x3e)	\
+
_ELF_DEFINE_RELOC(R_IA_64_PLTOFF64LSB,		0x3f)	\
+
_ELF_DEFINE_RELOC(R_IA_64_FPTR64I,		0x43)	\
+
_ELF_DEFINE_RELOC(R_IA_64_FPTR32MSB,		0x44)	\
+
_ELF_DEFINE_RELOC(R_IA_64_FPTR32LSB,		0x45)	\
+
_ELF_DEFINE_RELOC(R_IA_64_FPTR64MSB,		0x46)	\
+
_ELF_DEFINE_RELOC(R_IA_64_FPTR64LSB,		0x47)	\
+
_ELF_DEFINE_RELOC(R_IA_64_PCREL60B,		0x48)	\
+
_ELF_DEFINE_RELOC(R_IA_64_PCREL21B,		0x49)	\
+
_ELF_DEFINE_RELOC(R_IA_64_PCREL21M,		0x4a)	\
+
_ELF_DEFINE_RELOC(R_IA_64_PCREL21F,		0x4b)	\
+
_ELF_DEFINE_RELOC(R_IA_64_PCREL32MSB,		0x4c)	\
+
_ELF_DEFINE_RELOC(R_IA_64_PCREL32LSB,		0x4d)	\
+
_ELF_DEFINE_RELOC(R_IA_64_PCREL64MSB,		0x4e)	\
+
_ELF_DEFINE_RELOC(R_IA_64_PCREL64LSB,		0x4f)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTOFF_FPTR22,		0x52)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTOFF_FPTR64I,	0x53)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTOFF_FPTR32MSB,	0x54)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTOFF_FPTR32LSB,	0x55)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTOFF_FPTR64MSB,	0x56)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTOFF_FPTR64LSB,	0x57)	\
+
_ELF_DEFINE_RELOC(R_IA_64_SEGREL32MSB,		0x5c)	\
+
_ELF_DEFINE_RELOC(R_IA_64_SEGREL32LSB,		0x5d)	\
+
_ELF_DEFINE_RELOC(R_IA_64_SEGREL64MSB,		0x5e)	\
+
_ELF_DEFINE_RELOC(R_IA_64_SEGREL64LSB,		0x5f)	\
+
_ELF_DEFINE_RELOC(R_IA_64_SECREL32MSB,		0x64)	\
+
_ELF_DEFINE_RELOC(R_IA_64_SECREL32LSB,		0x65)	\
+
_ELF_DEFINE_RELOC(R_IA_64_SECREL64MSB,		0x66)	\
+
_ELF_DEFINE_RELOC(R_IA_64_SECREL64LSB,		0x67)	\
+
_ELF_DEFINE_RELOC(R_IA_64_REL32MSB,		0x6c)	\
+
_ELF_DEFINE_RELOC(R_IA_64_REL32LSB,		0x6d)	\
+
_ELF_DEFINE_RELOC(R_IA_64_REL64MSB,		0x6e)	\
+
_ELF_DEFINE_RELOC(R_IA_64_REL64LSB,		0x6f)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTV32MSB,		0x74)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTV32LSB,		0x75)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTV64MSB,		0x76)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTV64LSB,		0x77)	\
+
_ELF_DEFINE_RELOC(R_IA_64_PCREL21BIa,		0x79)	\
+
_ELF_DEFINE_RELOC(R_IA_64_PCREL22,		0x7A)	\
+
_ELF_DEFINE_RELOC(R_IA_64_PCREL64I,		0x7B)	\
+
_ELF_DEFINE_RELOC(R_IA_64_IPLTMSB,		0x80)	\
+
_ELF_DEFINE_RELOC(R_IA_64_IPLTLSB,		0x81)	\
+
_ELF_DEFINE_RELOC(R_IA_64_SUB,			0x85)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTOFF22X,		0x86)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LDXMOV,		0x87)	\
+
_ELF_DEFINE_RELOC(R_IA_64_TPREL14,		0x91)	\
+
_ELF_DEFINE_RELOC(R_IA_64_TPREL22,		0x92)	\
+
_ELF_DEFINE_RELOC(R_IA_64_TPREL64I,		0x93)	\
+
_ELF_DEFINE_RELOC(R_IA_64_TPREL64MSB,		0x96)	\
+
_ELF_DEFINE_RELOC(R_IA_64_TPREL64LSB,		0x97)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTOFF_TPREL22,	0x9A)	\
+
_ELF_DEFINE_RELOC(R_IA_64_DTPMOD64MSB,		0xA6)	\
+
_ELF_DEFINE_RELOC(R_IA_64_DTPMOD64LSB,		0xA7)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTOFF_DTPMOD22,	0xAA)	\
+
_ELF_DEFINE_RELOC(R_IA_64_DTPREL14,		0xB1)	\
+
_ELF_DEFINE_RELOC(R_IA_64_DTPREL22,		0xB2)	\
+
_ELF_DEFINE_RELOC(R_IA_64_DTPREL64I,		0xB3)	\
+
_ELF_DEFINE_RELOC(R_IA_64_DTPREL32MSB,		0xB4)	\
+
_ELF_DEFINE_RELOC(R_IA_64_DTPREL32LSB,		0xB5)	\
+
_ELF_DEFINE_RELOC(R_IA_64_DTPREL64MSB,		0xB6)	\
+
_ELF_DEFINE_RELOC(R_IA_64_DTPREL64LSB,		0xB7)	\
+
_ELF_DEFINE_RELOC(R_IA_64_LTOFF_DTPREL22,	0xBA)
+

+
#define	_ELF_DEFINE_MIPS_RELOCATIONS()		\
+
_ELF_DEFINE_RELOC(R_MIPS_NONE,		0)	\
+
_ELF_DEFINE_RELOC(R_MIPS_16,		1)	\
+
_ELF_DEFINE_RELOC(R_MIPS_32,		2)	\
+
_ELF_DEFINE_RELOC(R_MIPS_REL32,		3)	\
+
_ELF_DEFINE_RELOC(R_MIPS_26,		4)	\
+
_ELF_DEFINE_RELOC(R_MIPS_HI16,		5)	\
+
_ELF_DEFINE_RELOC(R_MIPS_LO16,		6)	\
+
_ELF_DEFINE_RELOC(R_MIPS_GPREL16,	7)	\
+
_ELF_DEFINE_RELOC(R_MIPS_LITERAL, 	8)	\
+
_ELF_DEFINE_RELOC(R_MIPS_GOT16,		9)	\
+
_ELF_DEFINE_RELOC(R_MIPS_PC16,		10)	\
+
_ELF_DEFINE_RELOC(R_MIPS_CALL16,	11)	\
+
_ELF_DEFINE_RELOC(R_MIPS_GPREL32,	12)	\
+
_ELF_DEFINE_RELOC(R_MIPS_64,		18)	\
+
_ELF_DEFINE_RELOC(R_MIPS_GOTHI16,	21)	\
+
_ELF_DEFINE_RELOC(R_MIPS_GOTLO16,	22)	\
+
_ELF_DEFINE_RELOC(R_MIPS_CALLHI16,	30)	\
+
_ELF_DEFINE_RELOC(R_MIPS_CALLLO16,	31)
+

+
#define	_ELF_DEFINE_PPC32_RELOCATIONS()		\
+
_ELF_DEFINE_RELOC(R_PPC_NONE,		0)	\
+
_ELF_DEFINE_RELOC(R_PPC_ADDR32,		1)	\
+
_ELF_DEFINE_RELOC(R_PPC_ADDR24,		2)	\
+
_ELF_DEFINE_RELOC(R_PPC_ADDR16,		3)	\
+
_ELF_DEFINE_RELOC(R_PPC_ADDR16_LO,	4)	\
+
_ELF_DEFINE_RELOC(R_PPC_ADDR16_HI,	5)	\
+
_ELF_DEFINE_RELOC(R_PPC_ADDR16_HA,	6)	\
+
_ELF_DEFINE_RELOC(R_PPC_ADDR14,		7)	\
+
_ELF_DEFINE_RELOC(R_PPC_ADDR14_BRTAKEN,	8)	\
+
_ELF_DEFINE_RELOC(R_PPC_ADDR14_BRNTAKEN, 9)	\
+
_ELF_DEFINE_RELOC(R_PPC_REL24,		10)	\
+
_ELF_DEFINE_RELOC(R_PPC_REL14,		11)	\
+
_ELF_DEFINE_RELOC(R_PPC_REL14_BRTAKEN,	12)	\
+
_ELF_DEFINE_RELOC(R_PPC_REL14_BRNTAKEN,	13)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT16,		14)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT16_LO,	15)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT16_HI,	16)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT16_HA,	17)	\
+
_ELF_DEFINE_RELOC(R_PPC_PLTREL24,	18)	\
+
_ELF_DEFINE_RELOC(R_PPC_COPY,		19)	\
+
_ELF_DEFINE_RELOC(R_PPC_GLOB_DAT,	20)	\
+
_ELF_DEFINE_RELOC(R_PPC_JMP_SLOT,	21)	\
+
_ELF_DEFINE_RELOC(R_PPC_RELATIVE,	22)	\
+
_ELF_DEFINE_RELOC(R_PPC_LOCAL24PC,	23)	\
+
_ELF_DEFINE_RELOC(R_PPC_UADDR32,	24)	\
+
_ELF_DEFINE_RELOC(R_PPC_UADDR16,	25)	\
+
_ELF_DEFINE_RELOC(R_PPC_REL32,		26)	\
+
_ELF_DEFINE_RELOC(R_PPC_PLT32,		27)	\
+
_ELF_DEFINE_RELOC(R_PPC_PLTREL32,	28)	\
+
_ELF_DEFINE_RELOC(R_PPC_PLT16_LO,	29)	\
+
_ELF_DEFINE_RELOC(R_PPL_PLT16_HI,	30)	\
+
_ELF_DEFINE_RELOC(R_PPC_PLT16_HA,	31)	\
+
_ELF_DEFINE_RELOC(R_PPC_SDAREL16,	32)	\
+
_ELF_DEFINE_RELOC(R_PPC_SECTOFF,	33)	\
+
_ELF_DEFINE_RELOC(R_PPC_SECTOFF_LO,	34)	\
+
_ELF_DEFINE_RELOC(R_PPC_SECTOFF_HI,	35)	\
+
_ELF_DEFINE_RELOC(R_PPC_SECTOFF_HA,	36)	\
+
_ELF_DEFINE_RELOC(R_PPC_ADDR30,		37)	\
+
_ELF_DEFINE_RELOC(R_PPC_TLS,		67)	\
+
_ELF_DEFINE_RELOC(R_PPC_DTPMOD32,	68)	\
+
_ELF_DEFINE_RELOC(R_PPC_TPREL16,	69)	\
+
_ELF_DEFINE_RELOC(R_PPC_TPREL16_LO,	70)	\
+
_ELF_DEFINE_RELOC(R_PPC_TPREL16_HI,	71)	\
+
_ELF_DEFINE_RELOC(R_PPC_TPREL16_HA,	72)	\
+
_ELF_DEFINE_RELOC(R_PPC_TPREL32,	73)	\
+
_ELF_DEFINE_RELOC(R_PPC_DTPREL16,	74)	\
+
_ELF_DEFINE_RELOC(R_PPC_DTPREL16_LO,	75)	\
+
_ELF_DEFINE_RELOC(R_PPC_DTPREL16_HI,	76)	\
+
_ELF_DEFINE_RELOC(R_PPC_DTPREL16_HA,	77)	\
+
_ELF_DEFINE_RELOC(R_PPC_DTPREL32,	78)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_TLSGD16,	79)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_TLSGD16_LO,	80)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_TLSGD16_HI,	81)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_TLSGD16_HA,	82)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_TLSLD16,	83)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_TLSLD16_LO,	84)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_TLSLD16_HI,	85)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_TLSLD16_HA,	86)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_TPREL16,	87)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_TPREL16_LO,	88)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_TPREL16_HI,	89)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_TPREL16_HA,	90)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_DTPREL16,	91)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_DTPREL16_LO, 92)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_DTPREL16_HI, 93)	\
+
_ELF_DEFINE_RELOC(R_PPC_GOT_DTPREL16_HA, 94)	\
+
_ELF_DEFINE_RELOC(R_PPC_TLSGD,		95)	\
+
_ELF_DEFINE_RELOC(R_PPC_TLSLD,		96)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_NADDR32,	101)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_NADDR16,	102)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_NADDR16_LO,	103)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_NADDR16_HI,	104)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_NADDR16_HA,	105)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_SDAI16,	106)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_SDA2I16,	107)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_SDA2REL,	108)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_SDA21,	109)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_MRKREF,	110)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_RELSEC16,	111)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_RELST_LO,	112)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_RELST_HI,	113)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_RELST_HA,	114)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_BIT_FLD,	115)	\
+
_ELF_DEFINE_RELOC(R_PPC_EMB_RELSDA,	116)	\
+

+
#define	_ELF_DEFINE_PPC64_RELOCATIONS()			\
+
_ELF_DEFINE_RELOC(R_PPC64_NONE,			0)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR32,		1)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR24,		2)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR16,		3)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR16_LO,		4)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR16_HI,		5)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR16_HA,		6)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR14,		7)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR14_BRTAKEN,	8)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR14_BRNTAKEN,	9)	\
+
_ELF_DEFINE_RELOC(R_PPC64_REL24,		10)	\
+
_ELF_DEFINE_RELOC(R_PPC64_REL14,		11)	\
+
_ELF_DEFINE_RELOC(R_PPC64_REL14_BRTAKEN,	12)	\
+
_ELF_DEFINE_RELOC(R_PPC64_REL14_BRNTAKEN,	13)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT16,		14)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT16_LO,		15)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT16_HI,		16)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT16_HA,		17)	\
+
_ELF_DEFINE_RELOC(R_PPC64_COPY,			19)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GLOB_DAT,		20)	\
+
_ELF_DEFINE_RELOC(R_PPC64_JMP_SLOT,		21)	\
+
_ELF_DEFINE_RELOC(R_PPC64_RELATIVE,		22)	\
+
_ELF_DEFINE_RELOC(R_PPC64_UADDR32,		24)	\
+
_ELF_DEFINE_RELOC(R_PPC64_UADDR16,		25)	\
+
_ELF_DEFINE_RELOC(R_PPC64_REL32,		26)	\
+
_ELF_DEFINE_RELOC(R_PPC64_PLT32,		27)	\
+
_ELF_DEFINE_RELOC(R_PPC64_PLTREL32,		28)	\
+
_ELF_DEFINE_RELOC(R_PPC64_PLT16_LO,		29)	\
+
_ELF_DEFINE_RELOC(R_PPC64_PLT16_HI,		30)	\
+
_ELF_DEFINE_RELOC(R_PPC64_PLT16_HA,		31)	\
+
_ELF_DEFINE_RELOC(R_PPC64_SECTOFF,		33)	\
+
_ELF_DEFINE_RELOC(R_PPC64_SECTOFF_LO,		34)	\
+
_ELF_DEFINE_RELOC(R_PPC64_SECTOFF_HI,		35)	\
+
_ELF_DEFINE_RELOC(R_PPC64_SECTOFF_HA,		36)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR30,		37)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR64,		38)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR16_HIGHER,	39)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR16_HIGHERA,	40)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR16_HIGHEST,	41)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR16_HIGHESTA,	42)	\
+
_ELF_DEFINE_RELOC(R_PPC64_UADDR64,		43)	\
+
_ELF_DEFINE_RELOC(R_PPC64_REL64,		44)	\
+
_ELF_DEFINE_RELOC(R_PPC64_PLT64,		45)	\
+
_ELF_DEFINE_RELOC(R_PPC64_PLTREL64,		46)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TOC16,		47)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TOC16_LO,		48)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TOC16_HI,		49)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TOC16_HA,		50)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TOC,			51)	\
+
_ELF_DEFINE_RELOC(R_PPC64_PLTGOT16,		52)	\
+
_ELF_DEFINE_RELOC(R_PPC64_PLTGOT16_LO,		53)	\
+
_ELF_DEFINE_RELOC(R_PPC64_PLTGOT16_HI,		54)	\
+
_ELF_DEFINE_RELOC(R_PPC64_PLTGOT16_HA,		55)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR16_DS,		56)	\
+
_ELF_DEFINE_RELOC(R_PPC64_ADDR16_LO_DS,		57)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT16_DS,		58)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT16_LO_DS,		59)	\
+
_ELF_DEFINE_RELOC(R_PPC64_PLT16_LO_DS,		60)	\
+
_ELF_DEFINE_RELOC(R_PPC64_SECTOFF_DS,		61)	\
+
_ELF_DEFINE_RELOC(R_PPC64_SECTOFF_LO_DS,	62)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TOC16_DS,		63)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TOC16_LO_DS,		64)	\
+
_ELF_DEFINE_RELOC(R_PPC64_PLTGOT16_DS,		65)	\
+
_ELF_DEFINE_RELOC(R_PPC64_PLTGOT16_LO_DS,	66)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TLS,			67)	\
+
_ELF_DEFINE_RELOC(R_PPC64_DTPMOD64,		68)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TPREL16,		69)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TPREL16_LO,		60)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TPREL16_HI,		71)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TPREL16_HA,		72)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TPREL64,		73)	\
+
_ELF_DEFINE_RELOC(R_PPC64_DTPREL16,		74)	\
+
_ELF_DEFINE_RELOC(R_PPC64_DTPREL16_LO,		75)	\
+
_ELF_DEFINE_RELOC(R_PPC64_DTPREL16_HI,		76)	\
+
_ELF_DEFINE_RELOC(R_PPC64_DTPREL16_HA,		77)	\
+
_ELF_DEFINE_RELOC(R_PPC64_DTPREL64,		78)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_TLSGD16,		79)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_TLSGD16_LO,	80)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_TLSGD16_HI,	81)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_TLSGD16_HA,	82)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_TLSLD16,		83)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_TLSLD16_LO,	84)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_TLSLD16_HI,	85)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_TLSLD16_HA,	86)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_TPREL16_DS,	87)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_TPREL16_LO_DS,	88)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_TPREL16_HI,	89)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_TPREL16_HA,	90)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_DTPREL16_DS,	91)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_DTPREL16_LO_DS,	92)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_DTPREL16_HI,	93)	\
+
_ELF_DEFINE_RELOC(R_PPC64_GOT_DTPREL16_HA,	94)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TPREL16_DS,		95)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TPREL16_LO_DS,	96)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TPREL16_HIGHER,	97)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TPREL16_HIGHERA,	98)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TPREL16_HIGHEST,	99)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TPREL16_HIGHESTA,	100)	\
+
_ELF_DEFINE_RELOC(R_PPC64_DTPREL16_DS,		101)	\
+
_ELF_DEFINE_RELOC(R_PPC64_DTPREL16_LO_DS,	102)	\
+
_ELF_DEFINE_RELOC(R_PPC64_DTPREL16_HIGHER,	103)	\
+
_ELF_DEFINE_RELOC(R_PPC64_DTPREL16_HIGHERA,	104)	\
+
_ELF_DEFINE_RELOC(R_PPC64_DTPREL16_HIGHEST,	105)	\
+
_ELF_DEFINE_RELOC(R_PPC64_DTPREL16_HIGHESTA,	106)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TLSGD,		107)	\
+
_ELF_DEFINE_RELOC(R_PPC64_TLSLD,		108)
+

+
#define	_ELF_DEFINE_SPARC_RELOCATIONS()		\
+
_ELF_DEFINE_RELOC(R_SPARC_NONE,		0)	\
+
_ELF_DEFINE_RELOC(R_SPARC_8,		1)	\
+
_ELF_DEFINE_RELOC(R_SPARC_16,		2)	\
+
_ELF_DEFINE_RELOC(R_SPARC_32, 		3)	\
+
_ELF_DEFINE_RELOC(R_SPARC_DISP8,	4)	\
+
_ELF_DEFINE_RELOC(R_SPARC_DISP16,	5)	\
+
_ELF_DEFINE_RELOC(R_SPARC_DISP32,	6)	\
+
_ELF_DEFINE_RELOC(R_SPARC_WDISP30,	7)	\
+
_ELF_DEFINE_RELOC(R_SPARC_WDISP22,	8)	\
+
_ELF_DEFINE_RELOC(R_SPARC_HI22,		9)	\
+
_ELF_DEFINE_RELOC(R_SPARC_22,		10)	\
+
_ELF_DEFINE_RELOC(R_SPARC_13,		11)	\
+
_ELF_DEFINE_RELOC(R_SPARC_LO10,		12)	\
+
_ELF_DEFINE_RELOC(R_SPARC_GOT10,	13)	\
+
_ELF_DEFINE_RELOC(R_SPARC_GOT13,	14)	\
+
_ELF_DEFINE_RELOC(R_SPARC_GOT22,	15)	\
+
_ELF_DEFINE_RELOC(R_SPARC_PC10,		16)	\
+
_ELF_DEFINE_RELOC(R_SPARC_PC22,		17)	\
+
_ELF_DEFINE_RELOC(R_SPARC_WPLT30,	18)	\
+
_ELF_DEFINE_RELOC(R_SPARC_COPY,		19)	\
+
_ELF_DEFINE_RELOC(R_SPARC_GLOB_DAT,	20)	\
+
_ELF_DEFINE_RELOC(R_SPARC_JMP_SLOT,	21)	\
+
_ELF_DEFINE_RELOC(R_SPARC_RELATIVE,	22)	\
+
_ELF_DEFINE_RELOC(R_SPARC_UA32,		23)	\
+
_ELF_DEFINE_RELOC(R_SPARC_PLT32,	24)	\
+
_ELF_DEFINE_RELOC(R_SPARC_HIPLT22,	25)	\
+
_ELF_DEFINE_RELOC(R_SPARC_LOPLT10,	26)	\
+
_ELF_DEFINE_RELOC(R_SPARC_PCPLT32,	27)	\
+
_ELF_DEFINE_RELOC(R_SPARC_PCPLT22,	28)	\
+
_ELF_DEFINE_RELOC(R_SPARC_PCPLT10,	29)	\
+
_ELF_DEFINE_RELOC(R_SPARC_10,		30)	\
+
_ELF_DEFINE_RELOC(R_SPARC_11,		31)	\
+
_ELF_DEFINE_RELOC(R_SPARC_64,		32)	\
+
_ELF_DEFINE_RELOC(R_SPARC_OLO10,	33)	\
+
_ELF_DEFINE_RELOC(R_SPARC_HH22,		34)	\
+
_ELF_DEFINE_RELOC(R_SPARC_HM10,		35)	\
+
_ELF_DEFINE_RELOC(R_SPARC_LM22,		36)	\
+
_ELF_DEFINE_RELOC(R_SPARC_PC_HH22,	37)	\
+
_ELF_DEFINE_RELOC(R_SPARC_PC_HM10,	38)	\
+
_ELF_DEFINE_RELOC(R_SPARC_PC_LM22,	39)	\
+
_ELF_DEFINE_RELOC(R_SPARC_WDISP16,	40)	\
+
_ELF_DEFINE_RELOC(R_SPARC_WDISP19,	41)	\
+
_ELF_DEFINE_RELOC(R_SPARC_7,		43)	\
+
_ELF_DEFINE_RELOC(R_SPARC_5,		44)	\
+
_ELF_DEFINE_RELOC(R_SPARC_6,		45)	\
+
_ELF_DEFINE_RELOC(R_SPARC_DISP64,	46)	\
+
_ELF_DEFINE_RELOC(R_SPARC_PLT64,	47)	\
+
_ELF_DEFINE_RELOC(R_SPARC_HIX22,	48)	\
+
_ELF_DEFINE_RELOC(R_SPARC_LOX10,	49)	\
+
_ELF_DEFINE_RELOC(R_SPARC_H44,		50)	\
+
_ELF_DEFINE_RELOC(R_SPARC_M44,		51)	\
+
_ELF_DEFINE_RELOC(R_SPARC_L44,		52)	\
+
_ELF_DEFINE_RELOC(R_SPARC_REGISTER,	53)	\
+
_ELF_DEFINE_RELOC(R_SPARC_UA64,		54)	\
+
_ELF_DEFINE_RELOC(R_SPARC_UA16,		55)	\
+
_ELF_DEFINE_RELOC(R_SPARC_GOTDATA_HIX22, 80)	\
+
_ELF_DEFINE_RELOC(R_SPARC_GOTDATA_LOX10, 81)	\
+
_ELF_DEFINE_RELOC(R_SPARC_GOTDATA_OP_HIX22, 82)	\
+
_ELF_DEFINE_RELOC(R_SPARC_GOTDATA_OP_LOX10, 83)	\
+
_ELF_DEFINE_RELOC(R_SPARC_GOTDATA_OP,	84)	\
+
_ELF_DEFINE_RELOC(R_SPARC_H34,		85)
+

+
#define	_ELF_DEFINE_X86_64_RELOCATIONS()	\
+
_ELF_DEFINE_RELOC(R_X86_64_NONE,	0)	\
+
_ELF_DEFINE_RELOC(R_X86_64_64,		1)	\
+
_ELF_DEFINE_RELOC(R_X86_64_PC32,	2)	\
+
_ELF_DEFINE_RELOC(R_X86_64_GOT32,	3)	\
+
_ELF_DEFINE_RELOC(R_X86_64_PLT32,	4)	\
+
_ELF_DEFINE_RELOC(R_X86_64_COPY,	5)	\
+
_ELF_DEFINE_RELOC(R_X86_64_GLOB_DAT,	6)	\
+
_ELF_DEFINE_RELOC(R_X86_64_JUMP_SLOT,	7)	\
+
_ELF_DEFINE_RELOC(R_X86_64_RELATIVE,	8)	\
+
_ELF_DEFINE_RELOC(R_X86_64_GOTPCREL,	9)	\
+
_ELF_DEFINE_RELOC(R_X86_64_32,		10)	\
+
_ELF_DEFINE_RELOC(R_X86_64_32S,		11)	\
+
_ELF_DEFINE_RELOC(R_X86_64_16,		12)	\
+
_ELF_DEFINE_RELOC(R_X86_64_PC16,	13)	\
+
_ELF_DEFINE_RELOC(R_X86_64_8,		14)	\
+
_ELF_DEFINE_RELOC(R_X86_64_PC8,		15)	\
+
_ELF_DEFINE_RELOC(R_X86_64_DTPMOD64,	16)	\
+
_ELF_DEFINE_RELOC(R_X86_64_DTPOFF64,	17)	\
+
_ELF_DEFINE_RELOC(R_X86_64_TPOFF64,	18)	\
+
_ELF_DEFINE_RELOC(R_X86_64_TLSGD,	19)	\
+
_ELF_DEFINE_RELOC(R_X86_64_TLSLD,	20)	\
+
_ELF_DEFINE_RELOC(R_X86_64_DTPOFF32,	21)	\
+
_ELF_DEFINE_RELOC(R_X86_64_GOTTPOFF,	22)	\
+
_ELF_DEFINE_RELOC(R_X86_64_TPOFF32,	23)	\
+
_ELF_DEFINE_RELOC(R_X86_64_PC64,	24)	\
+
_ELF_DEFINE_RELOC(R_X86_64_GOTOFF64,	25)	\
+
_ELF_DEFINE_RELOC(R_X86_64_GOTPC32,	26)	\
+
_ELF_DEFINE_RELOC(R_X86_64_SIZE32,	32)	\
+
_ELF_DEFINE_RELOC(R_X86_64_SIZE64,	33)	\
+
_ELF_DEFINE_RELOC(R_X86_64_GOTPC32_TLSDESC, 34)	\
+
_ELF_DEFINE_RELOC(R_X86_64_TLSDESC_CALL, 35)	\
+
_ELF_DEFINE_RELOC(R_X86_64_TLSDESC,	36)
+

+
#define	_ELF_DEFINE_RELOCATIONS()		\
+
_ELF_DEFINE_386_RELOCATIONS()			\
+
_ELF_DEFINE_AMD64_RELOCATIONS()			\
+
_ELF_DEFINE_IA64_RELOCATIONS()			\
+
_ELF_DEFINE_MIPS_RELOCATIONS()			\
+
_ELF_DEFINE_PPC32_RELOCATIONS()			\
+
_ELF_DEFINE_PPC64_RELOCATIONS()			\
+
_ELF_DEFINE_SPARC_RELOCATIONS()			\
+
_ELF_DEFINE_X86_64_RELOCATIONS()
+

+
#undef	_ELF_DEFINE_RELOC
+
#define	_ELF_DEFINE_RELOC(N, V)		N = V ,
+
enum {
+
	_ELF_DEFINE_RELOCATIONS()
+
	R__LAST__
+
};
+

+
#define	PN_XNUM			0xFFFFU /* Use extended section numbering. */
+

+
/**
+
 ** ELF Types.
+
 **/
+

+
typedef uint32_t	Elf32_Addr;	/* Program address. */
+
typedef uint8_t		Elf32_Byte;	/* Unsigned tiny integer. */
+
typedef uint16_t	Elf32_Half;	/* Unsigned medium integer. */
+
typedef uint32_t	Elf32_Off;	/* File offset. */
+
typedef uint16_t	Elf32_Section;	/* Section index. */
+
typedef int32_t		Elf32_Sword;	/* Signed integer. */
+
typedef uint32_t	Elf32_Word;	/* Unsigned integer. */
+
typedef uint64_t	Elf32_Lword;	/* Unsigned long integer. */
+

+
typedef uint64_t	Elf64_Addr;	/* Program address. */
+
typedef uint8_t		Elf64_Byte;	/* Unsigned tiny integer. */
+
typedef uint16_t	Elf64_Half;	/* Unsigned medium integer. */
+
typedef uint64_t	Elf64_Off;	/* File offset. */
+
typedef uint16_t	Elf64_Section;	/* Section index. */
+
typedef int32_t		Elf64_Sword;	/* Signed integer. */
+
typedef uint32_t	Elf64_Word;	/* Unsigned integer. */
+
typedef uint64_t	Elf64_Lword;	/* Unsigned long integer. */
+
typedef uint64_t	Elf64_Xword;	/* Unsigned long integer. */
+
typedef int64_t		Elf64_Sxword;	/* Signed long integer. */
+

+

+
/*
+
 * Capability descriptors.
+
 */
+

+
/* 32-bit capability descriptor. */
+
typedef struct {
+
	Elf32_Word	c_tag;	     /* Type of entry. */
+
	union {
+
		Elf32_Word	c_val; /* Integer value. */
+
		Elf32_Addr	c_ptr; /* Pointer value. */
+
	} c_un;
+
} Elf32_Cap;
+

+
/* 64-bit capability descriptor. */
+
typedef struct {
+
	Elf64_Xword	c_tag;	     /* Type of entry. */
+
	union {
+
		Elf64_Xword	c_val; /* Integer value. */
+
		Elf64_Addr	c_ptr; /* Pointer value. */
+
	} c_un;
+
} Elf64_Cap;
+

+
/*
+
 * MIPS .conflict section entries.
+
 */
+

+
/* 32-bit entry. */
+
typedef struct {
+
	Elf32_Addr	c_index;
+
} Elf32_Conflict;
+

+
/* 64-bit entry. */
+
typedef struct {
+
	Elf64_Addr	c_index;
+
} Elf64_Conflict;
+

+
/*
+
 * Dynamic section entries.
+
 */
+

+
/* 32-bit entry. */
+
typedef struct {
+
	Elf32_Sword	d_tag;	     /* Type of entry. */
+
	union {
+
		Elf32_Word	d_val; /* Integer value. */
+
		Elf32_Addr	d_ptr; /* Pointer value. */
+
	} d_un;
+
} Elf32_Dyn;
+

+
/* 64-bit entry. */
+
typedef struct {
+
	Elf64_Sxword	d_tag;	     /* Type of entry. */
+
	union {
+
		Elf64_Xword	d_val; /* Integer value. */
+
		Elf64_Addr	d_ptr; /* Pointer value; */
+
	} d_un;
+
} Elf64_Dyn;
+

+

+
/*
+
 * The executable header (EHDR).
+
 */
+

+
/* 32 bit EHDR. */
+
typedef struct {
+
	unsigned char   e_ident[EI_NIDENT]; /* ELF identification. */
+
	Elf32_Half      e_type;	     /* Object file type (ET_*). */
+
	Elf32_Half      e_machine;   /* Machine type (EM_*). */
+
	Elf32_Word      e_version;   /* File format version (EV_*). */
+
	Elf32_Addr      e_entry;     /* Start address. */
+
	Elf32_Off       e_phoff;     /* File offset to the PHDR table. */
+
	Elf32_Off       e_shoff;     /* File offset to the SHDRheader. */
+
	Elf32_Word      e_flags;     /* Flags (EF_*). */
+
	Elf32_Half      e_ehsize;    /* Elf header size in bytes. */
+
	Elf32_Half      e_phentsize; /* PHDR table entry size in bytes. */
+
	Elf32_Half      e_phnum;     /* Number of PHDR entries. */
+
	Elf32_Half      e_shentsize; /* SHDR table entry size in bytes. */
+
	Elf32_Half      e_shnum;     /* Number of SHDR entries. */
+
	Elf32_Half      e_shstrndx;  /* Index of section name string table. */
+
} Elf32_Ehdr;
+

+

+
/* 64 bit EHDR. */
+
typedef struct {
+
	unsigned char   e_ident[EI_NIDENT]; /* ELF identification. */
+
	Elf64_Half      e_type;	     /* Object file type (ET_*). */
+
	Elf64_Half      e_machine;   /* Machine type (EM_*). */
+
	Elf64_Word      e_version;   /* File format version (EV_*). */
+
	Elf64_Addr      e_entry;     /* Start address. */
+
	Elf64_Off       e_phoff;     /* File offset to the PHDR table. */
+
	Elf64_Off       e_shoff;     /* File offset to the SHDRheader. */
+
	Elf64_Word      e_flags;     /* Flags (EF_*). */
+
	Elf64_Half      e_ehsize;    /* Elf header size in bytes. */
+
	Elf64_Half      e_phentsize; /* PHDR table entry size in bytes. */
+
	Elf64_Half      e_phnum;     /* Number of PHDR entries. */
+
	Elf64_Half      e_shentsize; /* SHDR table entry size in bytes. */
+
	Elf64_Half      e_shnum;     /* Number of SHDR entries. */
+
	Elf64_Half      e_shstrndx;  /* Index of section name string table. */
+
} Elf64_Ehdr;
+

+

+
/*
+
 * Shared object information.
+
 */
+

+
/* 32-bit entry. */
+
typedef struct {
+
	Elf32_Word l_name;	     /* The name of a shared object. */
+
	Elf32_Word l_time_stamp;     /* 32-bit timestamp. */
+
	Elf32_Word l_checksum;	     /* Checksum of visible symbols, sizes. */
+
	Elf32_Word l_version;	     /* Interface version string index. */
+
	Elf32_Word l_flags;	     /* Flags (LL_*). */
+
} Elf32_Lib;
+

+
/* 64-bit entry. */
+
typedef struct {
+
	Elf64_Word l_name;
+
	Elf64_Word l_time_stamp;
+
	Elf64_Word l_checksum;
+
	Elf64_Word l_version;
+
	Elf64_Word l_flags;
+
} Elf64_Lib;
+

+
#define	_ELF_DEFINE_LL_FLAGS()			\
+
_ELF_DEFINE_LL(LL_NONE,			0,	\
+
	"no flags")				\
+
_ELF_DEFINE_LL(LL_EXACT_MATCH,		0x1,	\
+
	"require an exact match")		\
+
_ELF_DEFINE_LL(LL_IGNORE_INT_VER,	0x2,	\
+
	"ignore version incompatibilities")	\
+
_ELF_DEFINE_LL(LL_REQUIRE_MINOR,	0x4,	\
+
	"")					\
+
_ELF_DEFINE_LL(LL_EXPORTS,		0x8,	\
+
	"")					\
+
_ELF_DEFINE_LL(LL_DELAY_LOAD,		0x10,	\
+
	"")					\
+
_ELF_DEFINE_LL(LL_DELTA,		0x20,	\
+
	"")
+

+
#undef	_ELF_DEFINE_LL
+
#define	_ELF_DEFINE_LL(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_LL_FLAGS()
+
	LL__LAST__
+
};
+

+
/*
+
 * Note tags
+
 */
+

+
#define	_ELF_DEFINE_NOTE_ENTRY_TYPES()					\
+
_ELF_DEFINE_NT(NT_ABI_TAG,	1,	"Tag indicating the ABI")	\
+
_ELF_DEFINE_NT(NT_GNU_HWCAP,	2,	"Hardware capabilities")	\
+
_ELF_DEFINE_NT(NT_GNU_BUILD_ID,	3,	"Build id, set by ld(1)")	\
+
_ELF_DEFINE_NT(NT_GNU_GOLD_VERSION, 4,					\
+
	"Version number of the GNU gold linker")			\
+
_ELF_DEFINE_NT(NT_PRSTATUS,	1,	"Process status")		\
+
_ELF_DEFINE_NT(NT_FPREGSET,	2,	"Floating point information")	\
+
_ELF_DEFINE_NT(NT_PRPSINFO,	3,	"Process information")		\
+
_ELF_DEFINE_NT(NT_AUXV,		6,	"Auxiliary vector")		\
+
_ELF_DEFINE_NT(NT_PRXFPREG,	0x46E62B7FUL,				\
+
	"Linux user_xfpregs structure")					\
+
_ELF_DEFINE_NT(NT_PSTATUS,	10,	"Linux process status")		\
+
_ELF_DEFINE_NT(NT_FPREGS,	12,	"Linux floating point regset")	\
+
_ELF_DEFINE_NT(NT_PSINFO,	13,	"Linux process information")	\
+
_ELF_DEFINE_NT(NT_LWPSTATUS,	16,	"Linux lwpstatus_t type")	\
+
_ELF_DEFINE_NT(NT_LWPSINFO,	17,	"Linux lwpinfo_t type")
+

+
#undef	_ELF_DEFINE_NT
+
#define	_ELF_DEFINE_NT(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_NOTE_ENTRY_TYPES()
+
	NT__LAST__
+
};
+

+
/* Aliases for the ABI tag. */
+
#define	NT_FREEBSD_ABI_TAG	NT_ABI_TAG
+
#define	NT_GNU_ABI_TAG		NT_ABI_TAG
+
#define	NT_NETBSD_IDENT		NT_ABI_TAG
+
#define	NT_OPENBSD_IDENT	NT_ABI_TAG
+

+
/*
+
 * Note descriptors.
+
 */
+

+
typedef	struct {
+
	uint32_t	n_namesz;    /* Length of note's name. */
+
	uint32_t	n_descsz;    /* Length of note's value. */
+
	uint32_t	n_type;	     /* Type of note. */
+
} Elf_Note;
+

+
typedef Elf_Note Elf32_Nhdr;	     /* 32-bit note header. */
+
typedef Elf_Note Elf64_Nhdr;	     /* 64-bit note header. */
+

+
/*
+
 * MIPS ELF options descriptor header.
+
 */
+

+
typedef struct {
+
	Elf64_Byte	kind;        /* Type of options. */
+
	Elf64_Byte     	size;	     /* Size of option descriptor. */
+
	Elf64_Half	section;     /* Index of section affected. */
+
	Elf64_Word	info;        /* Kind-specific information. */
+
} Elf_Options;
+

+
/*
+
 * Option kinds.
+
 */
+

+
#define	_ELF_DEFINE_OPTION_KINDS()					\
+
_ELF_DEFINE_ODK(ODK_NULL,       0,      "undefined")			\
+
_ELF_DEFINE_ODK(ODK_REGINFO,    1,      "register usage info")		\
+
_ELF_DEFINE_ODK(ODK_EXCEPTIONS, 2,      "exception processing info")	\
+
_ELF_DEFINE_ODK(ODK_PAD,        3,      "section padding")		\
+
_ELF_DEFINE_ODK(ODK_HWPATCH,    4,      "hardware patch applied")	\
+
_ELF_DEFINE_ODK(ODK_FILL,       5,      "fill value used by linker")	\
+
_ELF_DEFINE_ODK(ODK_TAGS,       6,      "reserved space for tools")	\
+
_ELF_DEFINE_ODK(ODK_HWAND,      7,      "hardware AND patch applied")	\
+
_ELF_DEFINE_ODK(ODK_HWOR,       8,      "hardware OR patch applied")	\
+
_ELF_DEFINE_ODK(ODK_GP_GROUP,   9,					\
+
	"GP group to use for text/data sections")			\
+
_ELF_DEFINE_ODK(ODK_IDENT,      10,     "ID information")		\
+
_ELF_DEFINE_ODK(ODK_PAGESIZE,   11,     "page size infomation")
+

+
#undef	_ELF_DEFINE_ODK
+
#define	_ELF_DEFINE_ODK(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_OPTION_KINDS()
+
	ODK__LAST__
+
};
+

+
/*
+
 * ODK_EXCEPTIONS info field masks.
+
 */
+

+
#define	_ELF_DEFINE_ODK_EXCEPTIONS_MASK()				\
+
_ELF_DEFINE_OEX(OEX_FPU_MIN,    0x0000001FUL,				\
+
	"minimum FPU exception which must be enabled")			\
+
_ELF_DEFINE_OEX(OEX_FPU_MAX,    0x00001F00UL,				\
+
	"maximum FPU exception which can be enabled")			\
+
_ELF_DEFINE_OEX(OEX_PAGE0,      0x00010000UL,				\
+
	"page zero must be mapped")					\
+
_ELF_DEFINE_OEX(OEX_SMM,        0x00020000UL,				\
+
	"run in sequential memory mode")				\
+
_ELF_DEFINE_OEX(OEX_PRECISEFP,  0x00040000UL,				\
+
	"run in precise FP exception mode")				\
+
_ELF_DEFINE_OEX(OEX_DISMISS,    0x00080000UL,				\
+
	"dismiss invalid address traps")
+

+
#undef	_ELF_DEFINE_OEX
+
#define	_ELF_DEFINE_OEX(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_ODK_EXCEPTIONS_MASK()
+
	OEX__LAST__
+
};
+

+
/*
+
 * ODK_PAD info field masks.
+
 */
+

+
#define	_ELF_DEFINE_ODK_PAD_MASK()					\
+
_ELF_DEFINE_OPAD(OPAD_PREFIX,   0x0001)					\
+
_ELF_DEFINE_OPAD(OPAD_POSTFIX,  0x0002)					\
+
_ELF_DEFINE_OPAD(OPAD_SYMBOL,   0x0004)
+

+
#undef	_ELF_DEFINE_OPAD
+
#define	_ELF_DEFINE_OPAD(N, V)		N = V ,
+
enum {
+
	_ELF_DEFINE_ODK_PAD_MASK()
+
	OPAD__LAST__
+
};
+

+
/*
+
 * ODK_HWPATCH info field masks.
+
 */
+

+
#define	_ELF_DEFINE_ODK_HWPATCH_MASK()					\
+
_ELF_DEFINE_OHW(OHW_R4KEOP,     0x00000001UL,				\
+
	"patch for R4000 branch at end-of-page bug")			\
+
_ELF_DEFINE_OHW(OHW_R8KPFETCH,  0x00000002UL,				\
+
	"R8000 prefetch bug may occur")					\
+
_ELF_DEFINE_OHW(OHW_R5KEOP,     0x00000004UL,				\
+
	"patch for R5000 branch at end-of-page bug")			\
+
_ELF_DEFINE_OHW(OHW_R5KCVTL,    0x00000008UL,				\
+
	"R5000 cvt.[ds].l bug: clean == 1")				\
+
_ELF_DEFINE_OHW(OHW_R10KLDL,    0x00000010UL,				\
+
	"needd patch for R10000 misaligned load")
+

+
#undef	_ELF_DEFINE_OHW
+
#define	_ELF_DEFINE_OHW(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_ODK_HWPATCH_MASK()
+
	OHW__LAST__
+
};
+

+
/*
+
 * ODK_HWAND/ODK_HWOR info field and hwp_flags[12] masks.
+
 */
+

+
#define	_ELF_DEFINE_ODK_HWP_MASK()					\
+
_ELF_DEFINE_HWP(OHWA0_R4KEOP_CHECKED, 0x00000001UL,			\
+
	"object checked for R4000 end-of-page bug")			\
+
_ELF_DEFINE_HWP(OHWA0_R4KEOP_CLEAN, 0x00000002UL,			\
+
	"object verified clean for R4000 end-of-page bug")		\
+
_ELF_DEFINE_HWP(OHWO0_FIXADE,   0x00000001UL,				\
+
	"object requires call to fixade")
+

+
#undef	_ELF_DEFINE_HWP
+
#define	_ELF_DEFINE_HWP(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_ODK_HWP_MASK()
+
	OHWX0__LAST__
+
};
+

+
/*
+
 * ODK_IDENT/ODK_GP_GROUP info field masks.
+
 */
+

+
#define	_ELF_DEFINE_ODK_GP_MASK()					\
+
_ELF_DEFINE_OGP(OGP_GROUP,      0x0000FFFFUL, "GP group number")	\
+
_ELF_DEFINE_OGP(OGP_SELF,       0x00010000UL,				\
+
	"GP group is self-contained")
+

+
#undef	_ELF_DEFINE_OGP
+
#define	_ELF_DEFINE_OGP(N, V, DESCR)	N = V ,
+
enum {
+
	_ELF_DEFINE_ODK_GP_MASK()
+
	OGP__LAST__
+
};
+

+
/*
+
 * MIPS ELF register info descriptor.
+
 */
+

+
/* 32 bit RegInfo entry. */
+
typedef struct {
+
	Elf32_Word	ri_gprmask;  /* Mask of general register used. */
+
	Elf32_Word	ri_cprmask[4]; /* Mask of coprocessor register used. */
+
	Elf32_Addr	ri_gp_value; /* GP register value. */
+
} Elf32_RegInfo;
+

+
/* 64 bit RegInfo entry. */
+
typedef struct {
+
	Elf64_Word	ri_gprmask;  /* Mask of general register used. */
+
	Elf64_Word	ri_pad;	     /* Padding. */
+
	Elf64_Word	ri_cprmask[4]; /* Mask of coprocessor register used. */
+
	Elf64_Addr	ri_gp_value; /* GP register value. */
+
} Elf64_RegInfo;
+

+
/*
+
 * Program Header Table (PHDR) entries.
+
 */
+

+
/* 32 bit PHDR entry. */
+
typedef struct {
+
	Elf32_Word	p_type;	     /* Type of segment. */
+
	Elf32_Off	p_offset;    /* File offset to segment. */
+
	Elf32_Addr	p_vaddr;     /* Virtual address in memory. */
+
	Elf32_Addr	p_paddr;     /* Physical address (if relevant). */
+
	Elf32_Word	p_filesz;    /* Size of segment in file. */
+
	Elf32_Word	p_memsz;     /* Size of segment in memory. */
+
	Elf32_Word	p_flags;     /* Segment flags. */
+
	Elf32_Word	p_align;     /* Alignment constraints. */
+
} Elf32_Phdr;
+

+
/* 64 bit PHDR entry. */
+
typedef struct {
+
	Elf64_Word	p_type;	     /* Type of segment. */
+
	Elf64_Word	p_flags;     /* File offset to segment. */
+
	Elf64_Off	p_offset;    /* Virtual address in memory. */
+
	Elf64_Addr	p_vaddr;     /* Physical address (if relevant). */
+
	Elf64_Addr	p_paddr;     /* Size of segment in file. */
+
	Elf64_Xword	p_filesz;    /* Size of segment in memory. */
+
	Elf64_Xword	p_memsz;     /* Segment flags. */
+
	Elf64_Xword	p_align;     /* Alignment constraints. */
+
} Elf64_Phdr;
+

+

+
/*
+
 * Move entries, for describing data in COMMON blocks in a compact
+
 * manner.
+
 */
+

+
/* 32-bit move entry. */
+
typedef struct {
+
	Elf32_Lword	m_value;     /* Initialization value. */
+
	Elf32_Word 	m_info;	     /* Encoded size and index. */
+
	Elf32_Word	m_poffset;   /* Offset relative to symbol. */
+
	Elf32_Half	m_repeat;    /* Repeat count. */
+
	Elf32_Half	m_stride;    /* Number of units to skip. */
+
} Elf32_Move;
+

+
/* 64-bit move entry. */
+
typedef struct {
+
	Elf64_Lword	m_value;     /* Initialization value. */
+
	Elf64_Xword 	m_info;	     /* Encoded size and index. */
+
	Elf64_Xword	m_poffset;   /* Offset relative to symbol. */
+
	Elf64_Half	m_repeat;    /* Repeat count. */
+
	Elf64_Half	m_stride;    /* Number of units to skip. */
+
} Elf64_Move;
+

+
#define ELF32_M_SYM(I)		((I) >> 8)
+
#define ELF32_M_SIZE(I)		((unsigned char) (I))
+
#define ELF32_M_INFO(M, S)	(((M) << 8) + (unsigned char) (S))
+

+
#define ELF64_M_SYM(I)		((I) >> 8)
+
#define ELF64_M_SIZE(I)		((unsigned char) (I))
+
#define ELF64_M_INFO(M, S)	(((M) << 8) + (unsigned char) (S))
+

+
/*
+
 * Section Header Table (SHDR) entries.
+
 */
+

+
/* 32 bit SHDR */
+
typedef struct {
+
	Elf32_Word	sh_name;     /* index of section name */
+
	Elf32_Word	sh_type;     /* section type */
+
	Elf32_Word	sh_flags;    /* section flags */
+
	Elf32_Addr	sh_addr;     /* in-memory address of section */
+
	Elf32_Off	sh_offset;   /* file offset of section */
+
	Elf32_Word	sh_size;     /* section size in bytes */
+
	Elf32_Word	sh_link;     /* section header table link */
+
	Elf32_Word	sh_info;     /* extra information */
+
	Elf32_Word	sh_addralign; /* alignment constraint */
+
	Elf32_Word	sh_entsize;   /* size for fixed-size entries */
+
} Elf32_Shdr;
+

+
/* 64 bit SHDR */
+
typedef struct {
+
	Elf64_Word	sh_name;     /* index of section name */
+
	Elf64_Word	sh_type;     /* section type */
+
	Elf64_Xword	sh_flags;    /* section flags */
+
	Elf64_Addr	sh_addr;     /* in-memory address of section */
+
	Elf64_Off	sh_offset;   /* file offset of section */
+
	Elf64_Xword	sh_size;     /* section size in bytes */
+
	Elf64_Word	sh_link;     /* section header table link */
+
	Elf64_Word	sh_info;     /* extra information */
+
	Elf64_Xword	sh_addralign; /* alignment constraint */
+
	Elf64_Xword	sh_entsize;  /* size for fixed-size entries */
+
} Elf64_Shdr;
+

+

+
/*
+
 * Symbol table entries.
+
 */
+

+
typedef struct {
+
	Elf32_Word	st_name;     /* index of symbol's name */
+
	Elf32_Addr	st_value;    /* value for the symbol */
+
	Elf32_Word	st_size;     /* size of associated data */
+
	unsigned char	st_info;     /* type and binding attributes */
+
	unsigned char	st_other;    /* visibility */
+
	Elf32_Half	st_shndx;    /* index of related section */
+
} Elf32_Sym;
+

+
typedef struct {
+
	Elf64_Word	st_name;     /* index of symbol's name */
+
	unsigned char	st_info;     /* value for the symbol */
+
	unsigned char	st_other;    /* size of associated data */
+
	Elf64_Half	st_shndx;    /* type and binding attributes */
+
	Elf64_Addr	st_value;    /* visibility */
+
	Elf64_Xword	st_size;     /* index of related section */
+
} Elf64_Sym;
+

+
#define ELF32_ST_BIND(I)	((I) >> 4)
+
#define ELF32_ST_TYPE(I)	((I) & 0xFU)
+
#define ELF32_ST_INFO(B,T)	(((B) << 4) + ((T) & 0xF))
+

+
#define ELF64_ST_BIND(I)	((I) >> 4)
+
#define ELF64_ST_TYPE(I)	((I) & 0xFU)
+
#define ELF64_ST_INFO(B,T)	(((B) << 4) + ((T) & 0xF))
+

+
#define ELF32_ST_VISIBILITY(O)	((O) & 0x3)
+
#define ELF64_ST_VISIBILITY(O)	((O) & 0x3)
+

+
/*
+
 * Syminfo descriptors, containing additional symbol information.
+
 */
+

+
/* 32-bit entry. */
+
typedef struct {
+
	Elf32_Half	si_boundto;  /* Entry index with additional flags. */
+
	Elf32_Half	si_flags;    /* Flags. */
+
} Elf32_Syminfo;
+

+
/* 64-bit entry. */
+
typedef struct {
+
	Elf64_Half	si_boundto;  /* Entry index with additional flags. */
+
	Elf64_Half	si_flags;    /* Flags. */
+
} Elf64_Syminfo;
+

+
/*
+
 * Relocation descriptors.
+
 */
+

+
typedef struct {
+
	Elf32_Addr	r_offset;    /* location to apply relocation to */
+
	Elf32_Word	r_info;	     /* type+section for relocation */
+
} Elf32_Rel;
+

+
typedef struct {
+
	Elf32_Addr	r_offset;    /* location to apply relocation to */
+
	Elf32_Word	r_info;      /* type+section for relocation */
+
	Elf32_Sword	r_addend;    /* constant addend */
+
} Elf32_Rela;
+

+
typedef struct {
+
	Elf64_Addr	r_offset;    /* location to apply relocation to */
+
	Elf64_Xword	r_info;      /* type+section for relocation */
+
} Elf64_Rel;
+

+
typedef struct {
+
	Elf64_Addr	r_offset;    /* location to apply relocation to */
+
	Elf64_Xword	r_info;      /* type+section for relocation */
+
	Elf64_Sxword	r_addend;    /* constant addend */
+
} Elf64_Rela;
+

+

+
#define ELF32_R_SYM(I)		((I) >> 8)
+
#define ELF32_R_TYPE(I)		((unsigned char) (I))
+
#define ELF32_R_INFO(S,T)	(((S) << 8) + (unsigned char) (T))
+

+
#define ELF64_R_SYM(I)		((I) >> 32)
+
#define ELF64_R_TYPE(I)		((I) & 0xFFFFFFFFUL)
+
#define ELF64_R_INFO(S,T)	(((S) << 32) + ((T) & 0xFFFFFFFFUL))
+

+
/*
+
 * Symbol versioning structures.
+
 */
+

+
/* 32-bit structures. */
+
typedef struct
+
{
+
	Elf32_Word	vda_name;    /* Index to name. */
+
	Elf32_Word	vda_next;    /* Offset to next entry. */
+
} Elf32_Verdaux;
+

+
typedef struct
+
{
+
	Elf32_Word	vna_hash;    /* Hash value of dependency name. */
+
	Elf32_Half	vna_flags;   /* Flags. */
+
	Elf32_Half	vna_other;   /* Unused. */
+
	Elf32_Word	vna_name;    /* Offset to dependency name. */
+
	Elf32_Word	vna_next;    /* Offset to next vernaux entry. */
+
} Elf32_Vernaux;
+

+
typedef struct
+
{
+
	Elf32_Half	vd_version;  /* Version information. */
+
	Elf32_Half	vd_flags;    /* Flags. */
+
	Elf32_Half	vd_ndx;	     /* Index into the versym section. */
+
	Elf32_Half	vd_cnt;	     /* Number of aux entries. */
+
	Elf32_Word	vd_hash;     /* Hash value of name. */
+
	Elf32_Word	vd_aux;	     /* Offset to aux entries. */
+
	Elf32_Word	vd_next;     /* Offset to next version definition. */
+
} Elf32_Verdef;
+

+
typedef struct
+
{
+
	Elf32_Half	vn_version;  /* Version number. */
+
	Elf32_Half	vn_cnt;	     /* Number of aux entries. */
+
	Elf32_Word	vn_file;     /* Offset of associated file name. */
+
	Elf32_Word	vn_aux;	     /* Offset of vernaux array. */
+
	Elf32_Word	vn_next;     /* Offset of next verneed entry. */
+
} Elf32_Verneed;
+

+
typedef Elf32_Half	Elf32_Versym;
+

+
/* 64-bit structures. */
+

+
typedef struct {
+
	Elf64_Word	vda_name;    /* Index to name. */
+
	Elf64_Word	vda_next;    /* Offset to next entry. */
+
} Elf64_Verdaux;
+

+
typedef struct {
+
	Elf64_Word	vna_hash;    /* Hash value of dependency name. */
+
	Elf64_Half	vna_flags;   /* Flags. */
+
	Elf64_Half	vna_other;   /* Unused. */
+
	Elf64_Word	vna_name;    /* Offset to dependency name. */
+
	Elf64_Word	vna_next;    /* Offset to next vernaux entry. */
+
} Elf64_Vernaux;
+

+
typedef struct {
+
	Elf64_Half	vd_version;  /* Version information. */
+
	Elf64_Half	vd_flags;    /* Flags. */
+
	Elf64_Half	vd_ndx;	     /* Index into the versym section. */
+
	Elf64_Half	vd_cnt;	     /* Number of aux entries. */
+
	Elf64_Word	vd_hash;     /* Hash value of name. */
+
	Elf64_Word	vd_aux;	     /* Offset to aux entries. */
+
	Elf64_Word	vd_next;     /* Offset to next version definition. */
+
} Elf64_Verdef;
+

+
typedef struct {
+
	Elf64_Half	vn_version;  /* Version number. */
+
	Elf64_Half	vn_cnt;	     /* Number of aux entries. */
+
	Elf64_Word	vn_file;     /* Offset of associated file name. */
+
	Elf64_Word	vn_aux;	     /* Offset of vernaux array. */
+
	Elf64_Word	vn_next;     /* Offset of next verneed entry. */
+
} Elf64_Verneed;
+

+
typedef Elf64_Half	Elf64_Versym;
+

+

+
/*
+
 * The header for GNU-style hash sections.
+
 */
+

+
typedef struct {
+
	uint32_t	gh_nbuckets;	/* Number of hash buckets. */
+
	uint32_t	gh_symndx;	/* First visible symbol in .dynsym. */
+
	uint32_t	gh_maskwords;	/* #maskwords used in bloom filter. */
+
	uint32_t	gh_shift2;	/* Bloom filter shift count. */
+
} Elf_GNU_Hash_Header;
+

+
#endif	/* _ELFDEFINITIONS_H_ */
modified external/libelf/gelf.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: head/lib/libelf/gelf.3 236438 2012-06-02 08:47:26Z joel $
+
.\" $Id: gelf.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd September 1, 2006
-
.Dt GELF 3
.Os
+
.Dt GELF 3
.Sh NAME
.Nm GElf
.Nd class-independent API for ELF manipulation
@@ -115,7 +115,7 @@ routines will signal an error if a GElf value is out of range
for the underlying ELF data type.
.Ss Namespace use
The GElf interface uses the following symbols:
-
.Bl -tag -width 8n
+
.Bl -tag
.It GElf_*
Class-independent data types.
.It gelf_*
@@ -125,16 +125,16 @@ For functions defined in the API set.
This section provides an overview of the GElf programming APIs.
Further information is provided in the manual page of each function
listed here.
-
.Bl -tag -width 2n
+
.Bl -tag
.It "Allocating ELF Data Structures"
-
.Bl -tag -width 19n -compact
+
.Bl -tag -compact
.It Fn gelf_newehdr
Allocate a new ELF Executable Header.
.It Fn gelf_newphdr
Allocate a new ELF Program Header Table.
.El
.It "Data Translation"
-
.Bl -tag -width 19n -compact
+
.Bl -tag -compact
.It Fn gelf_xlatetof
Translate the native representation of an ELF data structure to its
file representation.
@@ -143,7 +143,7 @@ Translate from the file representation of an ELF data structure to a
native representation.
.El
.It "Retrieving ELF Data"
-
.Bl -tag -width 19n -compact
+
.Bl -tag -compact
.It Fn gelf_getdyn
Retrieve an ELF
.Sy .dynamic
@@ -162,7 +162,7 @@ Retrieve an ELF Section Header Table entry from the underlying ELF descriptor.
Retrieve an ELF symbol table entry.
.El
.It Queries
-
.Bl -tag -width 19n -compact
+
.Bl -tag -compact
.It Fn gelf_checksum
Retrieves the ELF checksum for an ELF descriptor.
.It Fn gelf_fsize
@@ -171,7 +171,7 @@ Retrieves the size of the file representation of an ELF type.
Retrieves the ELF class of an ELF descriptor.
.El
.It "Updating ELF Data"
-
.Bl -tag -width 19n -compact
+
.Bl -tag -compact -width ".Fn gelf_update_shdr"
.It Fn gelf_update_dyn
Copy back an ELF
.Sy .dynamic
modified external/libelf/gelf.h
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -23,7 +23,7 @@
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
-
 * $FreeBSD: releng/9.1/lib/libelf/gelf.h 167315 2007-03-08 04:01:30Z jkoshy $
+
 * $Id: gelf.h 1168 2010-09-04 01:03:25Z jkoshy $
 */

#ifndef	_GELF_H_
@@ -32,7 +32,6 @@
#include <sys/cdefs.h>

#include <libelf.h>
-
#include <osreldate.h>

typedef Elf64_Addr	GElf_Addr;	/* Addresses */
typedef Elf64_Half	GElf_Half;	/* Half words (16 bit) */
@@ -50,11 +49,9 @@ typedef Elf64_Sym GElf_Sym; /* Symbol table entries */
typedef Elf64_Rel	GElf_Rel;	/* Relocation entries */
typedef Elf64_Rela	GElf_Rela;	/* Relocation entries with addend */

-
#if	__FreeBSD_version >= 700025
typedef	Elf64_Cap	GElf_Cap;	/* SW/HW capabilities */
typedef Elf64_Move	GElf_Move;	/* Move entries */
typedef Elf64_Syminfo	GElf_Syminfo;	/* Symbol information */
-
#endif

#define	GELF_M_INFO			ELF64_M_INFO
#define	GELF_M_SIZE			ELF64_M_SIZE
@@ -100,14 +97,12 @@ int gelf_update_symshndx(Elf_Data *_symdst, Elf_Data *_shindexdst,
Elf_Data 	*gelf_xlatetof(Elf *_elf, Elf_Data *_dst, const Elf_Data *_src, unsigned int _encode);
Elf_Data 	*gelf_xlatetom(Elf *_elf, Elf_Data *_dst, const Elf_Data *_src, unsigned int _encode);

-
#if	__FreeBSD_version >= 700025
GElf_Cap	*gelf_getcap(Elf_Data *_data, int _index, GElf_Cap *_cap);
GElf_Move	*gelf_getmove(Elf_Data *_src, int _index, GElf_Move *_dst);
GElf_Syminfo	*gelf_getsyminfo(Elf_Data *_src, int _index, GElf_Syminfo *_dst);
int		gelf_update_cap(Elf_Data *_dst, int _index, GElf_Cap *_src);
int		gelf_update_move(Elf_Data *_dst, int _index, GElf_Move *_src);
int		gelf_update_syminfo(Elf_Data *_dst, int _index, GElf_Syminfo *_src);
-
#endif
__END_DECLS

#endif	/* _GELF_H_ */
modified external/libelf/gelf_cap.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,28 +25,28 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_cap.c 165317 2006-12-18 05:40:01Z jkoshy $");
-

-
#include <sys/limits.h>

#include <assert.h>
#include <gelf.h>
-
#include <osreldate.h>
+
#include <limits.h>

#include "_libelf.h"

-
#if	__FreeBSD_version >= 700025
+
ELFTC_VCSID("$Id: gelf_cap.c 2272 2011-12-03 17:07:31Z jkoshy $");

GElf_Cap *
-
gelf_getcap(Elf_Data *d, int ndx, GElf_Cap *dst)
+
gelf_getcap(Elf_Data *ed, int ndx, GElf_Cap *dst)
{
	int ec;
	Elf *e;
+
	size_t msz;
	Elf_Scn *scn;
	Elf32_Cap *cap32;
	Elf64_Cap *cap64;
-
	size_t msz;
	uint32_t sh_type;
+
	struct _Libelf_Data *d;
+

+
	d = (struct _Libelf_Data *) ed;

	if (d == NULL || ndx < 0 || dst == NULL ||
	    (scn = d->d_scn) == NULL ||
@@ -72,21 +72,21 @@ gelf_getcap(Elf_Data *d, int ndx, GElf_Cap *dst)

	assert(msz > 0);

-
	if (msz * ndx >= d->d_size) {
+
	if (msz * ndx >= d->d_data.d_size) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (NULL);
	}

	if (ec == ELFCLASS32) {

-
		cap32 = (Elf32_Cap *) d->d_buf + ndx;
+
		cap32 = (Elf32_Cap *) d->d_data.d_buf + ndx;

		dst->c_tag  = cap32->c_tag;
		dst->c_un.c_val = (Elf64_Xword) cap32->c_un.c_val;

	} else {

-
		cap64 = (Elf64_Cap *) d->d_buf + ndx;
+
		cap64 = (Elf64_Cap *) d->d_data.d_buf + ndx;

		*dst = *cap64;
	}
@@ -95,15 +95,18 @@ gelf_getcap(Elf_Data *d, int ndx, GElf_Cap *dst)
}

int
-
gelf_update_cap(Elf_Data *d, int ndx, GElf_Cap *gc)
+
gelf_update_cap(Elf_Data *ed, int ndx, GElf_Cap *gc)
{
	int ec;
	Elf *e;
+
	size_t msz;
	Elf_Scn *scn;
	Elf32_Cap *cap32;
	Elf64_Cap *cap64;
-
	size_t msz;
	uint32_t sh_type;
+
	struct _Libelf_Data *d;
+

+
	d = (struct _Libelf_Data *) ed;

	if (d == NULL || ndx < 0 || gc == NULL ||
	    (scn = d->d_scn) == NULL ||
@@ -128,23 +131,21 @@ gelf_update_cap(Elf_Data *d, int ndx, GElf_Cap *gc)
	msz = _libelf_msize(ELF_T_CAP, ec, e->e_version);
	assert(msz > 0);

-
	if (msz * ndx >= d->d_size) {
+
	if (msz * ndx >= d->d_data.d_size) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (0);
	}

	if (ec == ELFCLASS32) {
-
		cap32 = (Elf32_Cap *) d->d_buf + ndx;
+
		cap32 = (Elf32_Cap *) d->d_data.d_buf + ndx;

		LIBELF_COPY_U32(cap32, gc, c_tag);
		LIBELF_COPY_U32(cap32, gc, c_un.c_val);
	} else {
-
		cap64 = (Elf64_Cap *) d->d_buf + ndx;
+
		cap64 = (Elf64_Cap *) d->d_data.d_buf + ndx;

		*cap64 = *gc;
	}

	return (1);
}
-

-
#endif	/* __FreeBSD_version >= 700025 */
modified external/libelf/gelf_checksum.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_checksum.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: gelf_checksum.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd August 29, 2006
-
.Dt GELF_CHECKSUM 3
.Os
+
.Dt GELF_CHECKSUM 3
.Sh NAME
.Nm elf32_checksum ,
.Nm elf64_checksum ,
modified external/libelf/gelf_checksum.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,13 +25,14 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_checksum.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <gelf.h>
#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: gelf_checksum.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

long
elf32_checksum(Elf *e)
{
modified external/libelf/gelf_dyn.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,25 +25,28 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_dyn.c 164190 2006-11-11 17:16:35Z jkoshy $");
-

-
#include <sys/limits.h>

#include <assert.h>
#include <gelf.h>
+
#include <limits.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: gelf_dyn.c 2272 2011-12-03 17:07:31Z jkoshy $");
+

GElf_Dyn *
-
gelf_getdyn(Elf_Data *d, int ndx, GElf_Dyn *dst)
+
gelf_getdyn(Elf_Data *ed, int ndx, GElf_Dyn *dst)
{
	int ec;
	Elf *e;
+
	size_t msz;
	Elf_Scn *scn;
	Elf32_Dyn *dyn32;
	Elf64_Dyn *dyn64;
-
	size_t msz;
	uint32_t sh_type;
+
	struct _Libelf_Data *d;
+

+
	d = (struct _Libelf_Data *) ed;

	if (d == NULL || ndx < 0 || dst == NULL ||
	    (scn = d->d_scn) == NULL ||
@@ -69,20 +72,20 @@ gelf_getdyn(Elf_Data *d, int ndx, GElf_Dyn *dst)

	assert(msz > 0);

-
	if (msz * ndx >= d->d_size) {
+
	if (msz * ndx >= d->d_data.d_size) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (NULL);
	}

	if (ec == ELFCLASS32) {
-
		dyn32 = (Elf32_Dyn *) d->d_buf + ndx;
+
		dyn32 = (Elf32_Dyn *) d->d_data.d_buf + ndx;

		dst->d_tag      = dyn32->d_tag;
		dst->d_un.d_val = (Elf64_Xword) dyn32->d_un.d_val;

	} else {

-
		dyn64 = (Elf64_Dyn *) d->d_buf + ndx;
+
		dyn64 = (Elf64_Dyn *) d->d_data.d_buf + ndx;

		*dst = *dyn64;
	}
@@ -91,15 +94,18 @@ gelf_getdyn(Elf_Data *d, int ndx, GElf_Dyn *dst)
}

int
-
gelf_update_dyn(Elf_Data *d, int ndx, GElf_Dyn *ds)
+
gelf_update_dyn(Elf_Data *ed, int ndx, GElf_Dyn *ds)
{
	int ec;
	Elf *e;
+
	size_t msz;
	Elf_Scn *scn;
	Elf32_Dyn *dyn32;
	Elf64_Dyn *dyn64;
-
	size_t msz;
	uint32_t sh_type;
+
	struct _Libelf_Data *d;
+

+
	d = (struct _Libelf_Data *) ed;

	if (d == NULL || ndx < 0 || ds == NULL ||
	    (scn = d->d_scn) == NULL ||
@@ -124,18 +130,18 @@ gelf_update_dyn(Elf_Data *d, int ndx, GElf_Dyn *ds)
	msz = _libelf_msize(ELF_T_DYN, ec, e->e_version);
	assert(msz > 0);

-
	if (msz * ndx >= d->d_size) {
+
	if (msz * ndx >= d->d_data.d_size) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (0);
	}

	if (ec == ELFCLASS32) {
-
		dyn32 = (Elf32_Dyn *) d->d_buf + ndx;
+
		dyn32 = (Elf32_Dyn *) d->d_data.d_buf + ndx;

		LIBELF_COPY_S32(dyn32, ds, d_tag);
		LIBELF_COPY_U32(dyn32, ds, d_un.d_val);
	} else {
-
		dyn64 = (Elf64_Dyn *) d->d_buf + ndx;
+
		dyn64 = (Elf64_Dyn *) d->d_data.d_buf + ndx;

		*dyn64 = *ds;
	}
modified external/libelf/gelf_ehdr.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,17 +25,17 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_ehdr.c 210325 2010-07-21 08:58:52Z kaiw $");
-

-
#include <sys/limits.h>

#include <assert.h>
#include <gelf.h>
#include <libelf.h>
+
#include <limits.h>
#include <string.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: gelf_ehdr.c 2268 2011-12-03 17:05:11Z jkoshy $");
+

Elf32_Ehdr *
elf32_getehdr(Elf *e)
{
@@ -65,7 +65,8 @@ gelf_getehdr(Elf *e, GElf_Ehdr *d)
		if ((eh32 = _libelf_ehdr(e, ELFCLASS32, 0)) == NULL)
			return (NULL);

-
		(void) memcpy(d->e_ident, eh32->e_ident, sizeof(eh32->e_ident));
+
		(void) memcpy(d->e_ident, eh32->e_ident,
+
		    sizeof(eh32->e_ident));
		d->e_type		= eh32->e_type;
		d->e_machine		= eh32->e_machine;
		d->e_version		= eh32->e_version;
modified external/libelf/gelf_fsize.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_fsize.3 210340 2010-07-21 10:39:29Z kaiw $
+
.\" $Id: gelf_fsize.3 317 2009-03-06 17:29:22Z jkoshy $
.\"
.Dd February 5, 2008
-
.Dt GELF_FSIZE 3
.Os
+
.Dt GELF_FSIZE 3
.Sh NAME
.Nm gelf_fsize ,
.Nm elf32_fsize ,
modified external/libelf/gelf_fsize.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,13 +25,14 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_fsize.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <gelf.h>
#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: gelf_fsize.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

size_t
elf32_fsize(Elf_Type t, size_t c, unsigned int v)
{
modified external/libelf/gelf_getcap.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_getcap.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: gelf_getcap.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd August 29, 2006
-
.Dt GELF_GETCAP 3
.Os
+
.Dt GELF_GETCAP 3
.Sh NAME
.Nm gelf_getcap ,
.Nm gelf_update_cap
modified external/libelf/gelf_getclass.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_getclass.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: gelf_getclass.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd July 3, 2006
-
.Dt GELF_GETCLASS 3
.Os
+
.Dt GELF_GETCLASS 3
.Sh NAME
.Nm gelf_getclass
.Nd retrieve the class of an ELF descriptor
modified external/libelf/gelf_getclass.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,12 +25,13 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_getclass.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <gelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: gelf_getclass.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

int
gelf_getclass(Elf *e)
{
modified external/libelf/gelf_getdyn.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_getdyn.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: gelf_getdyn.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd August 29, 2006
-
.Dt GELF_GETDYN 3
.Os
+
.Dt GELF_GETDYN 3
.Sh NAME
.Nm gelf_getdyn ,
.Nm gelf_update_dyn
modified external/libelf/gelf_getehdr.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_getehdr.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: gelf_getehdr.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd December 16, 2006
-
.Dt GELF_GETEHDR 3
.Os
+
.Dt GELF_GETEHDR 3
.Sh NAME
.Nm elf32_getehdr ,
.Nm elf64_getehdr ,
modified external/libelf/gelf_getmove.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_getmove.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: gelf_getmove.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd August 29, 2006
-
.Dt GELF_GETMOVE 3
.Os
+
.Dt GELF_GETMOVE 3
.Sh NAME
.Nm gelf_getmove ,
.Nm gelf_update_move
modified external/libelf/gelf_getphdr.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006,2007 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006-2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: head/lib/libelf/gelf_getphdr.3 235286 2012-05-11 20:06:46Z gjb $
+
.\" $Id: gelf_getphdr.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd October 21, 2007
-
.Dt GELF_GETPHDR 3
.Os
+
.Dt GELF_GETPHDR 3
.Sh NAME
.Nm elf32_getphdr ,
.Nm elf64_getphdr ,
@@ -66,7 +66,7 @@ Function
will retrieve the program header table entry at index
.Ar index
from ELF descriptor
-
.Ar elf .
+
.Ar elf.
The translated program header table entry will be written to the
address pointed to be argument
.Ar dst .
modified external/libelf/gelf_getrel.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_getrel.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: gelf_getrel.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd August 29, 2006
-
.Dt GELF_GETREL 3
.Os
+
.Dt GELF_GETREL 3
.Sh NAME
.Nm gelf_getrel ,
.Nm gelf_update_rel
modified external/libelf/gelf_getrela.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_getrela.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: gelf_getrela.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd August 29, 2006
-
.Dt GELF_GETRELA 3
.Os
+
.Dt GELF_GETRELA 3
.Sh NAME
.Nm gelf_getrela ,
.Nm gelf_update_rela
modified external/libelf/gelf_getshdr.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_getshdr.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: gelf_getshdr.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd August 27, 2006
-
.Dt GELF_GETSHDR 3
.Os
+
.Dt GELF_GETSHDR 3
.Sh NAME
.Nm elf32_getshdr ,
.Nm elf64_getshdr ,
modified external/libelf/gelf_getsym.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_getsym.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: gelf_getsym.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd August 29, 2006
-
.Dt GELF_GETSYM 3
.Os
+
.Dt GELF_GETSYM 3
.Sh NAME
.Nm gelf_getsym ,
.Nm gelf_update_sym
modified external/libelf/gelf_getsyminfo.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_getsyminfo.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: gelf_getsyminfo.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd August 29, 2006
-
.Dt GELF_GETSYMINFO 3
.Os
+
.Dt GELF_GETSYMINFO 3
.Sh NAME
.Nm gelf_getsyminfo ,
.Nm gelf_update_syminfo
modified external/libelf/gelf_getsymshndx.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_getsymshndx.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: gelf_getsymshndx.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd November 5, 2006
-
.Dt GELF_GETSYMSHNDX 3
.Os
+
.Dt GELF_GETSYMSHNDX 3
.Sh NAME
.Nm gelf_getsymshndx ,
.Nm gelf_update_symshndx
modified external/libelf/gelf_move.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,28 +25,28 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_move.c 165317 2006-12-18 05:40:01Z jkoshy $");
-

-
#include <sys/limits.h>

#include <assert.h>
#include <gelf.h>
-
#include <osreldate.h>
+
#include <limits.h>

#include "_libelf.h"

-
#if	__FreeBSD_version >= 700025
+
ELFTC_VCSID("$Id: gelf_move.c 2272 2011-12-03 17:07:31Z jkoshy $");

GElf_Move *
-
gelf_getmove(Elf_Data *d, int ndx, GElf_Move *dst)
+
gelf_getmove(Elf_Data *ed, int ndx, GElf_Move *dst)
{
	int ec;
	Elf *e;
+
	size_t msz;
	Elf_Scn *scn;
+
	uint32_t sh_type;
	Elf32_Move *move32;
	Elf64_Move *move64;
-
	size_t msz;
-
	uint32_t sh_type;
+
	struct _Libelf_Data *d;
+

+
	d = (struct _Libelf_Data *) ed;

	if (d == NULL || ndx < 0 || dst == NULL ||
	    (scn = d->d_scn) == NULL ||
@@ -72,14 +72,14 @@ gelf_getmove(Elf_Data *d, int ndx, GElf_Move *dst)

	assert(msz > 0);

-
	if (msz * ndx >= d->d_size) {
+
	if (msz * ndx >= d->d_data.d_size) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (NULL);
	}

	if (ec == ELFCLASS32) {

-
		move32 = (Elf32_Move *) d->d_buf + ndx;
+
		move32 = (Elf32_Move *) d->d_data.d_buf + ndx;

		dst->m_value   = move32->m_value;
		dst->m_info    = (Elf64_Xword) move32->m_info;
@@ -88,7 +88,7 @@ gelf_getmove(Elf_Data *d, int ndx, GElf_Move *dst)
		dst->m_stride = move32->m_stride;
	} else {

-
		move64 = (Elf64_Move *) d->d_buf + ndx;
+
		move64 = (Elf64_Move *) d->d_data.d_buf + ndx;

		*dst = *move64;
	}
@@ -97,15 +97,18 @@ gelf_getmove(Elf_Data *d, int ndx, GElf_Move *dst)
}

int
-
gelf_update_move(Elf_Data *d, int ndx, GElf_Move *gm)
+
gelf_update_move(Elf_Data *ed, int ndx, GElf_Move *gm)
{
	int ec;
	Elf *e;
+
	size_t msz;
	Elf_Scn *scn;
+
	uint32_t sh_type;
	Elf32_Move *move32;
	Elf64_Move *move64;
-
	size_t msz;
-
	uint32_t sh_type;
+
	struct _Libelf_Data *d;
+

+
	d = (struct _Libelf_Data *) ed;

	if (d == NULL || ndx < 0 || gm == NULL ||
	    (scn = d->d_scn) == NULL ||
@@ -130,13 +133,13 @@ gelf_update_move(Elf_Data *d, int ndx, GElf_Move *gm)
	msz = _libelf_msize(ELF_T_MOVE, ec, e->e_version);
	assert(msz > 0);

-
	if (msz * ndx >= d->d_size) {
+
	if (msz * ndx >= d->d_data.d_size) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (0);
	}

	if (ec == ELFCLASS32) {
-
		move32 = (Elf32_Move *) d->d_buf + ndx;
+
		move32 = (Elf32_Move *) d->d_data.d_buf + ndx;

		move32->m_value  = gm->m_value;
		LIBELF_COPY_U32(move32, gm, m_info);
@@ -145,12 +148,10 @@ gelf_update_move(Elf_Data *d, int ndx, GElf_Move *gm)
		move32->m_stride = gm->m_stride;

	} else {
-
		move64 = (Elf64_Move *) d->d_buf + ndx;
+
		move64 = (Elf64_Move *) d->d_data.d_buf + ndx;

		*move64 = *gm;
	}

	return (1);
}
-

-
#endif	/* __FreeBSD_version >= 700025 */
modified external/libelf/gelf_newehdr.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006,2007 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006-2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: head/lib/libelf/gelf_newehdr.3 235286 2012-05-11 20:06:46Z gjb $
+
.\" $Id: gelf_newehdr.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd October 22, 2007
-
.Dt GELF_NEWEHDR 3
.Os
+
.Dt GELF_NEWEHDR 3
.Sh NAME
.Nm elf32_newehdr ,
.Nm elf64_newehdr ,
@@ -58,8 +58,7 @@ structure.
Function
.Fn elf64_newehdr
returns a pointer to a 64 bit
-
.Vt Elf64_Ehdr
-
structure.
+
.Vt Elf64_Ehdr structure.
.Pp
When argument
.Ar elfclass
modified external/libelf/gelf_newphdr.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006,2007 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006-2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_newphdr.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: gelf_newphdr.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd October 22, 2007
-
.Dt GELF_NEWPHDR 3
.Os
+
.Dt GELF_NEWPHDR 3
.Sh NAME
.Nm elf32_newphdr ,
.Nm elf64_newphdr ,
modified external/libelf/gelf_phdr.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,15 +25,15 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_phdr.c 210325 2010-07-21 08:58:52Z kaiw $");
-

-
#include <sys/limits.h>

#include <gelf.h>
#include <libelf.h>
+
#include <limits.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: gelf_phdr.c 2268 2011-12-03 17:05:11Z jkoshy $");
+

Elf32_Phdr *
elf32_getphdr(Elf *e)
{
modified external/libelf/gelf_rel.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,25 +25,28 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_rel.c 176727 2008-03-02 06:33:10Z jkoshy $");
-

-
#include <sys/limits.h>

#include <assert.h>
#include <gelf.h>
+
#include <limits.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: gelf_rel.c 2272 2011-12-03 17:07:31Z jkoshy $");
+

GElf_Rel *
-
gelf_getrel(Elf_Data *d, int ndx, GElf_Rel *dst)
+
gelf_getrel(Elf_Data *ed, int ndx, GElf_Rel *dst)
{
	int ec;
	Elf *e;
+
	size_t msz;
	Elf_Scn *scn;
+
	uint32_t sh_type;
	Elf32_Rel *rel32;
	Elf64_Rel *rel64;
-
	size_t msz;
-
	uint32_t sh_type;
+
	struct _Libelf_Data *d;
+

+
	d = (struct _Libelf_Data *) ed;

	if (d == NULL || ndx < 0 || dst == NULL ||
	    (scn = d->d_scn) == NULL ||
@@ -69,13 +72,13 @@ gelf_getrel(Elf_Data *d, int ndx, GElf_Rel *dst)

	assert(msz > 0);

-
	if (msz * ndx >= d->d_size) {
+
	if (msz * ndx >= d->d_data.d_size) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (NULL);
	}

	if (ec == ELFCLASS32) {
-
		rel32 = (Elf32_Rel *) d->d_buf + ndx;
+
		rel32 = (Elf32_Rel *) d->d_data.d_buf + ndx;

		dst->r_offset = (Elf64_Addr) rel32->r_offset;
		dst->r_info   = ELF64_R_INFO(
@@ -84,7 +87,7 @@ gelf_getrel(Elf_Data *d, int ndx, GElf_Rel *dst)

	} else {

-
		rel64 = (Elf64_Rel *) d->d_buf + ndx;
+
		rel64 = (Elf64_Rel *) d->d_data.d_buf + ndx;

		*dst = *rel64;
	}
@@ -93,15 +96,18 @@ gelf_getrel(Elf_Data *d, int ndx, GElf_Rel *dst)
}

int
-
gelf_update_rel(Elf_Data *d, int ndx, GElf_Rel *dr)
+
gelf_update_rel(Elf_Data *ed, int ndx, GElf_Rel *dr)
{
	int ec;
	Elf *e;
+
	size_t msz;
	Elf_Scn *scn;
+
	uint32_t sh_type;
	Elf32_Rel *rel32;
	Elf64_Rel *rel64;
-
	size_t msz;
-
	uint32_t sh_type;
+
	struct _Libelf_Data *d;
+

+
	d = (struct _Libelf_Data *) ed;

	if (d == NULL || ndx < 0 || dr == NULL ||
	    (scn = d->d_scn) == NULL ||
@@ -126,13 +132,13 @@ gelf_update_rel(Elf_Data *d, int ndx, GElf_Rel *dr)
	msz = _libelf_msize(ELF_T_REL, ec, e->e_version);
	assert(msz > 0);

-
	if (msz * ndx >= d->d_size) {
+
	if (msz * ndx >= d->d_data.d_size) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (0);
	}

	if (ec == ELFCLASS32) {
-
		rel32 = (Elf32_Rel *) d->d_buf + ndx;
+
		rel32 = (Elf32_Rel *) d->d_data.d_buf + ndx;

		LIBELF_COPY_U32(rel32, dr, r_offset);

@@ -144,7 +150,7 @@ gelf_update_rel(Elf_Data *d, int ndx, GElf_Rel *dr)
		rel32->r_info = ELF32_R_INFO(ELF64_R_SYM(dr->r_info),
		    ELF64_R_TYPE(dr->r_info));
	} else {
-
		rel64 = (Elf64_Rel *) d->d_buf + ndx;
+
		rel64 = (Elf64_Rel *) d->d_data.d_buf + ndx;

		*rel64 = *dr;
	}
modified external/libelf/gelf_rela.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,25 +25,28 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_rela.c 176727 2008-03-02 06:33:10Z jkoshy $");
-

-
#include <sys/limits.h>

#include <assert.h>
#include <gelf.h>
+
#include <limits.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: gelf_rela.c 2272 2011-12-03 17:07:31Z jkoshy $");
+

GElf_Rela *
-
gelf_getrela(Elf_Data *d, int ndx, GElf_Rela *dst)
+
gelf_getrela(Elf_Data *ed, int ndx, GElf_Rela *dst)
{
	int ec;
	Elf *e;
+
	size_t msz;
	Elf_Scn *scn;
+
	uint32_t sh_type;
	Elf32_Rela *rela32;
	Elf64_Rela *rela64;
-
	size_t msz;
-
	uint32_t sh_type;
+
	struct _Libelf_Data *d;
+

+
	d = (struct _Libelf_Data *) ed;

	if (d == NULL || ndx < 0 || dst == NULL ||
	    (scn = d->d_scn) == NULL ||
@@ -69,13 +72,13 @@ gelf_getrela(Elf_Data *d, int ndx, GElf_Rela *dst)

	assert(msz > 0);

-
	if (msz * ndx >= d->d_size) {
+
	if (msz * ndx >= d->d_data.d_size) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (NULL);
	}

	if (ec == ELFCLASS32) {
-
		rela32 = (Elf32_Rela *) d->d_buf + ndx;
+
		rela32 = (Elf32_Rela *) d->d_data.d_buf + ndx;

		dst->r_offset = (Elf64_Addr) rela32->r_offset;
		dst->r_info   = ELF64_R_INFO(
@@ -85,7 +88,7 @@ gelf_getrela(Elf_Data *d, int ndx, GElf_Rela *dst)

	} else {

-
		rela64 = (Elf64_Rela *) d->d_buf + ndx;
+
		rela64 = (Elf64_Rela *) d->d_data.d_buf + ndx;

		*dst = *rela64;
	}
@@ -94,15 +97,18 @@ gelf_getrela(Elf_Data *d, int ndx, GElf_Rela *dst)
}

int
-
gelf_update_rela(Elf_Data *d, int ndx, GElf_Rela *dr)
+
gelf_update_rela(Elf_Data *ed, int ndx, GElf_Rela *dr)
{
	int ec;
	Elf *e;
+
	size_t msz;
	Elf_Scn *scn;
+
	uint32_t sh_type;
	Elf32_Rela *rela32;
	Elf64_Rela *rela64;
-
	size_t msz;
-
	uint32_t sh_type;
+
	struct _Libelf_Data *d;
+

+
	d = (struct _Libelf_Data *) ed;

	if (d == NULL || ndx < 0 || dr == NULL ||
	    (scn = d->d_scn) == NULL ||
@@ -127,13 +133,13 @@ gelf_update_rela(Elf_Data *d, int ndx, GElf_Rela *dr)
	msz = _libelf_msize(ELF_T_RELA, ec, e->e_version);
	assert(msz > 0);

-
	if (msz * ndx >= d->d_size) {
+
	if (msz * ndx >= d->d_data.d_size) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (0);
	}

	if (ec == ELFCLASS32) {
-
		rela32 = (Elf32_Rela *) d->d_buf + ndx;
+
		rela32 = (Elf32_Rela *) d->d_data.d_buf + ndx;

		LIBELF_COPY_U32(rela32, dr, r_offset);

@@ -147,7 +153,7 @@ gelf_update_rela(Elf_Data *d, int ndx, GElf_Rela *dr)

		LIBELF_COPY_S32(rela32, dr, r_addend);
	} else {
-
		rela64 = (Elf64_Rela *) d->d_buf + ndx;
+
		rela64 = (Elf64_Rela *) d->d_data.d_buf + ndx;

		*rela64 = *dr;
	}
modified external/libelf/gelf_shdr.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,16 +25,16 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_shdr.c 210325 2010-07-21 08:58:52Z kaiw $");
-

-
#include <sys/limits.h>

#include <assert.h>
#include <gelf.h>
#include <libelf.h>
+
#include <limits.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: gelf_shdr.c 2268 2011-12-03 17:05:11Z jkoshy $");
+

Elf32_Shdr *
elf32_getshdr(Elf_Scn *s)
{
modified external/libelf/gelf_sym.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,25 +25,28 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_sym.c 164190 2006-11-11 17:16:35Z jkoshy $");
-

-
#include <sys/limits.h>

#include <assert.h>
#include <gelf.h>
+
#include <limits.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: gelf_sym.c 2272 2011-12-03 17:07:31Z jkoshy $");
+

GElf_Sym *
-
gelf_getsym(Elf_Data *d, int ndx, GElf_Sym *dst)
+
gelf_getsym(Elf_Data *ed, int ndx, GElf_Sym *dst)
{
	int ec;
	Elf *e;
+
	size_t msz;
	Elf_Scn *scn;
+
	uint32_t sh_type;
	Elf32_Sym *sym32;
	Elf64_Sym *sym64;
-
	size_t msz;
-
	uint32_t sh_type;
+
	struct _Libelf_Data *d;
+

+
	d = (struct _Libelf_Data *) ed;

	if (d == NULL || ndx < 0 || dst == NULL ||
	    (scn = d->d_scn) == NULL ||
@@ -69,14 +72,14 @@ gelf_getsym(Elf_Data *d, int ndx, GElf_Sym *dst)

	assert(msz > 0);

-
	if (msz * ndx >= d->d_size) {
+
	if (msz * ndx >= d->d_data.d_size) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (NULL);
	}

	if (ec == ELFCLASS32) {

-
		sym32 = (Elf32_Sym *) d->d_buf + ndx;
+
		sym32 = (Elf32_Sym *) d->d_data.d_buf + ndx;

		dst->st_name  = sym32->st_name;
		dst->st_value = (Elf64_Addr) sym32->st_value;
@@ -87,7 +90,7 @@ gelf_getsym(Elf_Data *d, int ndx, GElf_Sym *dst)
		dst->st_shndx = sym32->st_shndx;
	} else {

-
		sym64 = (Elf64_Sym *) d->d_buf + ndx;
+
		sym64 = (Elf64_Sym *) d->d_data.d_buf + ndx;

		*dst = *sym64;
	}
@@ -96,15 +99,18 @@ gelf_getsym(Elf_Data *d, int ndx, GElf_Sym *dst)
}

int
-
gelf_update_sym(Elf_Data *d, int ndx, GElf_Sym *gs)
+
gelf_update_sym(Elf_Data *ed, int ndx, GElf_Sym *gs)
{
	int ec;
	Elf *e;
+
	size_t msz;
	Elf_Scn *scn;
+
	uint32_t sh_type;
	Elf32_Sym *sym32;
	Elf64_Sym *sym64;
-
	size_t msz;
-
	uint32_t sh_type;
+
	struct _Libelf_Data *d;
+

+
	d = (struct _Libelf_Data *) ed;

	if (d == NULL || ndx < 0 || gs == NULL ||
	    (scn = d->d_scn) == NULL ||
@@ -129,13 +135,13 @@ gelf_update_sym(Elf_Data *d, int ndx, GElf_Sym *gs)
	msz = _libelf_msize(ELF_T_SYM, ec, e->e_version);
	assert(msz > 0);

-
	if (msz * ndx >= d->d_size) {
+
	if (msz * ndx >= d->d_data.d_size) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (0);
	}

	if (ec == ELFCLASS32) {
-
		sym32 = (Elf32_Sym *) d->d_buf + ndx;
+
		sym32 = (Elf32_Sym *) d->d_data.d_buf + ndx;

		sym32->st_name  = gs->st_name;
		sym32->st_info  = gs->st_info;
@@ -145,7 +151,7 @@ gelf_update_sym(Elf_Data *d, int ndx, GElf_Sym *gs)
		LIBELF_COPY_U32(sym32, gs, st_value);
		LIBELF_COPY_U32(sym32, gs, st_size);
	} else {
-
		sym64 = (Elf64_Sym *) d->d_buf + ndx;
+
		sym64 = (Elf64_Sym *) d->d_data.d_buf + ndx;

		*sym64 = *gs;
	}
modified external/libelf/gelf_syminfo.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,28 +25,27 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_syminfo.c 165317 2006-12-18 05:40:01Z jkoshy $");
-

-
#include <sys/limits.h>

#include <assert.h>
#include <gelf.h>
-
#include <osreldate.h>

#include "_libelf.h"

-
#if	__FreeBSD_version >= 700025
+
ELFTC_VCSID("$Id: gelf_syminfo.c 2272 2011-12-03 17:07:31Z jkoshy $");

GElf_Syminfo *
-
gelf_getsyminfo(Elf_Data *d, int ndx, GElf_Syminfo *dst)
+
gelf_getsyminfo(Elf_Data *ed, int ndx, GElf_Syminfo *dst)
{
	int ec;
	Elf *e;
+
	size_t msz;
	Elf_Scn *scn;
+
	uint32_t sh_type;
+
	struct _Libelf_Data *d;
	Elf32_Syminfo *syminfo32;
	Elf64_Syminfo *syminfo64;
-
	size_t msz;
-
	uint32_t sh_type;
+

+
	d = (struct _Libelf_Data *) ed;

	if (d == NULL || ndx < 0 || dst == NULL ||
	    (scn = d->d_scn) == NULL ||
@@ -72,21 +71,21 @@ gelf_getsyminfo(Elf_Data *d, int ndx, GElf_Syminfo *dst)

	assert(msz > 0);

-
	if (msz * ndx >= d->d_size) {
+
	if (msz * ndx >= d->d_data.d_size) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (NULL);
	}

	if (ec == ELFCLASS32) {

-
		syminfo32 = (Elf32_Syminfo *) d->d_buf + ndx;
+
		syminfo32 = (Elf32_Syminfo *) d->d_data.d_buf + ndx;

		dst->si_boundto = syminfo32->si_boundto;
		dst->si_flags   = syminfo32->si_flags;

	} else {

-
		syminfo64 = (Elf64_Syminfo *) d->d_buf + ndx;
+
		syminfo64 = (Elf64_Syminfo *) d->d_data.d_buf + ndx;

		*dst = *syminfo64;
	}
@@ -95,15 +94,18 @@ gelf_getsyminfo(Elf_Data *d, int ndx, GElf_Syminfo *dst)
}

int
-
gelf_update_syminfo(Elf_Data *d, int ndx, GElf_Syminfo *gs)
+
gelf_update_syminfo(Elf_Data *ed, int ndx, GElf_Syminfo *gs)
{
	int ec;
	Elf *e;
+
	size_t msz;
	Elf_Scn *scn;
+
	uint32_t sh_type;
+
	struct _Libelf_Data *d;
	Elf32_Syminfo *syminfo32;
	Elf64_Syminfo *syminfo64;
-
	size_t msz;
-
	uint32_t sh_type;
+

+
	d = (struct _Libelf_Data *) ed;

	if (d == NULL || ndx < 0 || gs == NULL ||
	    (scn = d->d_scn) == NULL ||
@@ -128,24 +130,22 @@ gelf_update_syminfo(Elf_Data *d, int ndx, GElf_Syminfo *gs)
	msz = _libelf_msize(ELF_T_SYMINFO, ec, e->e_version);
	assert(msz > 0);

-
	if (msz * ndx >= d->d_size) {
+
	if (msz * ndx >= d->d_data.d_size) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (0);
	}

	if (ec == ELFCLASS32) {
-
		syminfo32 = (Elf32_Syminfo *) d->d_buf + ndx;
+
		syminfo32 = (Elf32_Syminfo *) d->d_data.d_buf + ndx;

		syminfo32->si_boundto  = gs->si_boundto;
		syminfo32->si_flags  = gs->si_flags;

	} else {
-
		syminfo64 = (Elf64_Syminfo *) d->d_buf + ndx;
+
		syminfo64 = (Elf64_Syminfo *) d->d_data.d_buf + ndx;

		*syminfo64 = *gs;
	}

	return (1);
}
-

-
#endif	/* __FreeBSD_version >= 700025 */
modified external/libelf/gelf_symshndx.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,30 +25,33 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_symshndx.c 164190 2006-11-11 17:16:35Z jkoshy $");
-

-
#include <sys/limits.h>

#include <assert.h>
#include <gelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: gelf_symshndx.c 2283 2011-12-04 04:07:24Z jkoshy $");
+

GElf_Sym *
gelf_getsymshndx(Elf_Data *d, Elf_Data *id, int ndx, GElf_Sym *dst,
    Elf32_Word *shindex)
{
	int ec;
	Elf *e;
-
	Elf_Scn *scn;
	size_t msz;
+
	Elf_Scn *scn;
	uint32_t sh_type;
+
	struct _Libelf_Data *ld, *lid;
+

+
	ld = (struct _Libelf_Data *) d;
+
	lid = (struct _Libelf_Data *) id;

	if (gelf_getsym(d, ndx, dst) == 0)
		return (NULL);

-
	if (id == NULL || (scn = id->d_scn) == NULL ||
-
	    (e = scn->s_elf) == NULL || (e != d->d_scn->s_elf) ||
+
	if (lid == NULL || (scn = lid->d_scn) == NULL ||
+
	    (e = scn->s_elf) == NULL || (e != ld->d_scn->s_elf) ||
	    shindex == NULL) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (NULL);
@@ -88,15 +91,19 @@ gelf_update_symshndx(Elf_Data *d, Elf_Data *id, int ndx, GElf_Sym *gs,
{
	int ec;
	Elf *e;
-
	Elf_Scn *scn;
	size_t msz;
+
	Elf_Scn *scn;
	uint32_t sh_type;
+
	struct _Libelf_Data *ld, *lid;
+

+
	ld = (struct _Libelf_Data *) d;
+
	lid = (struct _Libelf_Data *) id;

	if (gelf_update_sym(d, ndx, gs) == 0)
		return (0);

-
	if (id == NULL || (scn = id->d_scn) == NULL ||
-
	    (e = scn->s_elf) == NULL || (e != d->d_scn->s_elf)) {
+
	if (lid == NULL || (scn = lid->d_scn) == NULL ||
+
	    (e = scn->s_elf) == NULL || (e != ld->d_scn->s_elf)) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (0);
	}
modified external/libelf/gelf_update_ehdr.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_update_ehdr.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: gelf_update_ehdr.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd August 27, 2006
-
.Dt GELF_UPDATE_EHDR 3
.Os
+
.Dt GELF_UPDATE_EHDR 3
.Sh NAME
.Nm gelf_update_ehdr ,
.Nm gelf_update_phdr ,
modified external/libelf/gelf_xlate.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,7 +25,6 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_xlate.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <gelf.h>
#include <libelf.h>
@@ -33,6 +32,7 @@ __FBSDID("$FreeBSD: releng/9.1/lib/libelf/gelf_xlate.c 164190 2006-11-11 17:16:3

#include "_libelf.h"

+
ELFTC_VCSID("$Id: gelf_xlate.c 2225 2011-11-26 18:55:54Z jkoshy $");

Elf_Data *
elf32_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
@@ -59,7 +59,8 @@ elf64_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
}

Elf_Data *
-
gelf_xlatetom(Elf *e, Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
+
gelf_xlatetom(Elf *e, Elf_Data *dst, const Elf_Data *src,
+
    unsigned int encoding)
{
	if (e != NULL)
		return (_libelf_xlate(dst, src, encoding, e->e_class,
@@ -69,7 +70,8 @@ gelf_xlatetom(Elf *e, Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
}

Elf_Data *
-
gelf_xlatetof(Elf *e, Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
+
gelf_xlatetof(Elf *e, Elf_Data *dst, const Elf_Data *src,
+
    unsigned int encoding)
{
	if (e != NULL)
		return (_libelf_xlate(dst, src, encoding, e->e_class,
modified external/libelf/gelf_xlatetof.3
@@ -1,4 +1,4 @@
-
.\" Copyright (c) 2006 Joseph Koshy.  All rights reserved.
+
.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -21,11 +21,11 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-
.\" $FreeBSD: releng/9.1/lib/libelf/gelf_xlatetof.3 206622 2010-04-14 19:08:06Z uqs $
+
.\" $Id: gelf_xlatetof.3 189 2008-07-20 10:38:08Z jkoshy $
.\"
.Dd July 24, 2006
-
.Dt GELF_XLATETOF 3
.Os
+
.Dt GELF_XLATETOF 3
.Sh NAME
.Nm elf32_xlate ,
.Nm elf64_xlate ,
deleted external/libelf/libelf.c
@@ -1,61 +0,0 @@
-
/*-
-
 * Copyright (c) 2006 Joseph Koshy
-
 * 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.
-
 *
-
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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.
-
 */
-

-
#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf.c 164190 2006-11-11 17:16:35Z jkoshy $");
-

-
#include <sys/param.h>
-

-
#include <machine/elf.h>
-
#include <machine/endian.h>
-

-
#include <libelf.h>
-

-
#include "_libelf.h"
-

-
struct _libelf_globals _libelf = {
-
	.libelf_arch		= ELF_ARCH,
-
	.libelf_byteorder	= ELF_TARG_DATA,
-
	.libelf_class		= ELF_TARG_CLASS,
-
	.libelf_error		= 0,
-
	.libelf_fillchar	= 0,
-
	.libelf_version		= EV_NONE
-
};
-

-

-
#if defined(LIBELF_TEST_HOOKS)
-
int
-
_libelf_get_elf_class(Elf *elf)
-
{
-
	return elf->e_class;
-
}
-

-
void
-
_libelf_set_elf_class(Elf *elf, int c)
-
{
-
	elf->e_class = c;
-
}
-
#endif	/* LIBELF_TEST_HOOKS */
modified external/libelf/libelf.h
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008-2010 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -23,16 +23,15 @@
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
-
 * $FreeBSD: releng/9.1/lib/libelf/libelf.h 210345 2010-07-21 12:14:50Z kaiw $
+
 * $Id: libelf.h 2366 2011-12-29 06:12:14Z jkoshy $
 */

#ifndef	_LIBELF_H_
#define	_LIBELF_H_

#include <sys/types.h>
-
#include <sys/elf32.h>
-
#include <sys/elf64.h>
-
#include <sys/queue.h>
+

+
#include <elfdefinitions.h>

/* Library private data structures */
typedef struct _Elf Elf;
@@ -112,13 +111,6 @@ typedef struct _Elf_Data {
	uint64_t	d_size;
	Elf_Type	d_type;
	unsigned int	d_version;
-

-
	/*
-
	 * Members that are not part of the public API.
-
	 */
-
	Elf_Scn		*d_scn;		/* containing section */
-
	unsigned int	d_flags;
-
	STAILQ_ENTRY(_Elf_Data)	d_next;
} Elf_Data;

/*
@@ -133,6 +125,11 @@ typedef struct {
	char		*ar_rawname;	/* 'raw' member name */
	size_t		ar_size;
	uid_t		ar_uid;
+

+
	/*
+
	 * Members that are not part of the public API.
+
	 */
+
	int		ar_flags;
} Elf_Arhdr;

/*
@@ -175,6 +172,10 @@ enum Elf_Error {
#define	ELF_F_LAYOUT	0x001U	/* application will layout the file */
#define	ELF_F_DIRTY	0x002U	/* a section or ELF file is dirty */

+
/* ELF(3) API extensions. */
+
#define	ELF_F_ARCHIVE	   0x100U /* archive creation */
+
#define	ELF_F_ARCHIVE_SYSV 0x200U /* SYSV style archive */
+

__BEGIN_DECLS
Elf		*elf_begin(int _fd, Elf_Cmd _cmd, Elf *_elf);
int		elf_cntl(Elf *_elf, Elf_Cmd _cmd);
@@ -182,7 +183,10 @@ int elf_end(Elf *_elf);
const char	*elf_errmsg(int _error);
int		elf_errno(void);
void		elf_fill(int _fill);
-
unsigned int	elf_flagdata(Elf_Data *_data, Elf_Cmd _cmd, unsigned int _flags);
+
unsigned int	elf_flagarhdr(Elf_Arhdr *_arh, Elf_Cmd _cmd,
+
			unsigned int _flags);
+
unsigned int	elf_flagdata(Elf_Data *_data, Elf_Cmd _cmd,
+
			unsigned int _flags);
unsigned int	elf_flagehdr(Elf *_elf, Elf_Cmd _cmd, unsigned int _flags);
unsigned int	elf_flagelf(Elf *_elf, Elf_Cmd _cmd, unsigned int _flags);
unsigned int	elf_flagphdr(Elf *_elf, Elf_Cmd _cmd, unsigned int _flags);
@@ -208,6 +212,8 @@ Elf_Data *elf_newdata(Elf_Scn *_scn);
Elf_Scn		*elf_newscn(Elf *_elf);
Elf_Scn		*elf_nextscn(Elf *_elf, Elf_Scn *_scn);
Elf_Cmd		elf_next(Elf *_elf);
+
Elf		*elf_open(int _fd);
+
Elf		*elf_openmemory(char *_image, size_t _size);
off_t		elf_rand(Elf *_elf, off_t _off);
Elf_Data	*elf_rawdata(Elf_Scn *_scn, Elf_Data *_data);
char		*elf_rawfile(Elf *_elf, size_t *_size);
@@ -241,15 +247,6 @@ Elf_Data *elf64_xlatetof(Elf_Data *_dst, const Elf_Data *_src,
			unsigned int _enc);
Elf_Data	*elf64_xlatetom(Elf_Data *_dst, const Elf_Data *_src,
			unsigned int _enc);
-

-
#if	defined(LIBELF_TEST_HOOKS)
-
int		_libelf_get_elf_class(Elf *_elf);
-
int		_libelf_get_max_error(void);
-
const char	*_libelf_get_no_error_message(void);
-
const char	*_libelf_get_unknown_error_message(void);
-
void		_libelf_set_elf_class(Elf *_elf, int _class);
-
void		_libelf_set_error(int _error);
-
#endif	/* LIBELF_TEST_HOOKS */
__END_DECLS

#endif	/* _LIBELF_H_ */
modified external/libelf/libelf_align.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,18 +25,15 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_align.c 210332 2010-07-21 09:56:42Z kaiw $");

#include <sys/types.h>

-
#include <machine/elf.h>
-
#include <machine/endian.h>
-

#include <libelf.h>
-
#include <osreldate.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: libelf_align.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

struct align {
	int a32;
	int a64;
@@ -66,20 +63,14 @@ struct align {
static struct align malign[ELF_T_NUM] = {
	[ELF_T_ADDR]	= MALIGN(Addr),
	[ELF_T_BYTE]	= { .a32 = 1, .a64 = 1 },
-
#if	__FreeBSD_version >= 700025
	[ELF_T_CAP]	= MALIGN(Cap),
-
#endif
	[ELF_T_DYN]	= MALIGN(Dyn),
	[ELF_T_EHDR]	= MALIGN(Ehdr),
	[ELF_T_HALF]	= MALIGN(Half),
-
#if	__FreeBSD_version >= 700025
	[ELF_T_LWORD]	= MALIGN(Lword),
	[ELF_T_MOVE]	= MALIGN(Move),
-
#endif
	[ELF_T_MOVEP] 	= UNSUPPORTED(),
-
#if	__FreeBSD_version >= 700025
	[ELF_T_NOTE]	= MALIGN(Nhdr),
-
#endif
	[ELF_T_OFF]	= MALIGN(Off),
	[ELF_T_PHDR]	= MALIGN(Phdr),
	[ELF_T_REL]	= MALIGN(Rel),
@@ -88,18 +79,12 @@ static struct align malign[ELF_T_NUM] = {
	[ELF_T_SWORD]	= MALIGN(Sword),
	[ELF_T_SXWORD]	= MALIGN64(Sxword),
	[ELF_T_SYM]	= MALIGN(Sym),
-
#if	__FreeBSD_version >= 700025
	[ELF_T_SYMINFO]	= MALIGN(Syminfo),
-
#endif
-
#if	__FreeBSD_version >= 700009
	[ELF_T_VDEF]	= MALIGN(Verdef),
	[ELF_T_VNEED]	= MALIGN(Verneed),
-
#endif
	[ELF_T_WORD]	= MALIGN(Word),
	[ELF_T_XWORD]	= MALIGN64(Xword),
-
#if	__FreeBSD_version >= 800062
	[ELF_T_GNUHASH] = MALIGN_WORD()
-
#endif
};

int
@@ -117,20 +102,14 @@ _libelf_malign(Elf_Type t, int elfclass)
static struct align falign[ELF_T_NUM] = {
	[ELF_T_ADDR]	= FALIGN(4,8),
	[ELF_T_BYTE]	= FALIGN(1,1),
-
#if	__FreeBSD_version >= 700025
	[ELF_T_CAP]	= FALIGN(4,8),
-
#endif
	[ELF_T_DYN]	= FALIGN(4,8),
	[ELF_T_EHDR]	= FALIGN(4,8),
	[ELF_T_HALF]	= FALIGN(2,2),
-
#if	__FreeBSD_version >= 700025
	[ELF_T_LWORD]	= FALIGN(8,8),
	[ELF_T_MOVE]	= FALIGN(8,8),
-
#endif
	[ELF_T_MOVEP] 	= UNSUPPORTED(),
-
#if	__FreeBSD_version >= 700025
-
	[ELF_T_NOTE]	= FALIGN(1,1),
-
#endif
+
	[ELF_T_NOTE]	= FALIGN(4,4),
	[ELF_T_OFF]	= FALIGN(4,8),
	[ELF_T_PHDR]	= FALIGN(4,8),
	[ELF_T_REL]	= FALIGN(4,8),
@@ -139,18 +118,12 @@ static struct align falign[ELF_T_NUM] = {
	[ELF_T_SWORD]	= FALIGN(4,4),
	[ELF_T_SXWORD]	= FALIGN(0,8),
	[ELF_T_SYM]	= FALIGN(4,8),
-
#if	__FreeBSD_version >= 700025
	[ELF_T_SYMINFO]	= FALIGN(2,2),
-
#endif
-
#if	__FreeBSD_version >= 700009
	[ELF_T_VDEF]	= FALIGN(4,4),
	[ELF_T_VNEED]	= FALIGN(4,4),
-
#endif
	[ELF_T_WORD]	= FALIGN(4,4),
	[ELF_T_XWORD]	= FALIGN(0,8),
-
#if	__FreeBSD_version >= 800062
	[ELF_T_GNUHASH] = FALIGN(4,8)
-
#endif
};

int
modified external/libelf/libelf_allocate.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008,2010 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -29,17 +29,17 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_allocate.c 166863 2007-02-21 08:14:22Z dumbbell $");
-

-
#include <sys/errno.h>

#include <assert.h>
+
#include <errno.h>
#include <libelf.h>
#include <stdlib.h>
#include <string.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: libelf_allocate.c 2272 2011-12-03 17:07:31Z jkoshy $");
+

Elf *
_libelf_allocate_elf(void)
{
@@ -51,7 +51,7 @@ _libelf_allocate_elf(void)
	}

	e->e_activations = 1;
-
	e->e_arhdr	 = NULL;
+
	e->e_hdr.e_rawhdr = NULL;
	e->e_byteorder   = ELFDATANONE;
	e->e_class       = ELFCLASSNONE;
	e->e_cmd         = ELF_C_NULL;
@@ -94,6 +94,8 @@ _libelf_init_elf(Elf *e, Elf_Kind kind)
Elf *
_libelf_release_elf(Elf *e)
{
+
	Elf_Arhdr *arh;
+

	switch (e->e_kind) {
	case ELF_K_AR:
		FREE(e->e_u.e_ar.e_symtab);
@@ -113,10 +115,11 @@ _libelf_release_elf(Elf *e)

		assert(STAILQ_EMPTY(&e->e_u.e_elf.e_scn));

-
		if (e->e_arhdr) {
-
			FREE(e->e_arhdr->ar_name);
-
			FREE(e->e_arhdr->ar_rawname);
-
			free(e->e_arhdr);
+
		if (e->e_flags & LIBELF_F_AR_HEADER) {
+
			arh = e->e_hdr.e_arhdr;
+
			FREE(arh->ar_name);
+
			FREE(arh->ar_rawname);
+
			free(arh);
		}

		break;
@@ -130,12 +133,12 @@ _libelf_release_elf(Elf *e)
	return (NULL);
}

-
Elf_Data *
+
struct _Libelf_Data *
_libelf_allocate_data(Elf_Scn *s)
{
-
	Elf_Data *d;
+
	struct _Libelf_Data *d;

-
	if ((d = calloc((size_t) 1, sizeof(Elf_Data))) == NULL) {
+
	if ((d = calloc((size_t) 1, sizeof(*d))) == NULL) {
		LIBELF_SET_ERROR(RESOURCE, 0);
		return (NULL);
	}
@@ -145,12 +148,12 @@ _libelf_allocate_data(Elf_Scn *s)
	return (d);
}

-
Elf_Data *
-
_libelf_release_data(Elf_Data *d)
+
struct _Libelf_Data *
+
_libelf_release_data(struct _Libelf_Data *d)
{

-
	if (d->d_flags & LIBELF_F_MALLOCED)
-
		free(d->d_buf);
+
	if (d->d_flags & LIBELF_F_DATA_MALLOCED)
+
		free(d->d_data.d_buf);

	free(d);

@@ -182,18 +185,18 @@ Elf_Scn *
_libelf_release_scn(Elf_Scn *s)
{
	Elf *e;
-
	Elf_Data *d, *td;
+
	struct _Libelf_Data *d, *td;

	assert(s != NULL);

	STAILQ_FOREACH_SAFE(d, &s->s_data, d_next, td) {
-
		STAILQ_REMOVE(&s->s_data, d, _Elf_Data, d_next);
+
		STAILQ_REMOVE(&s->s_data, d, _Libelf_Data, d_next);
		d = _libelf_release_data(d);
	}

	STAILQ_FOREACH_SAFE(d, &s->s_rawdata, d_next, td) {
-
		assert((d->d_flags & LIBELF_F_MALLOCED) == 0);
-
		STAILQ_REMOVE(&s->s_rawdata, d, _Elf_Data, d_next);
+
		assert((d->d_flags & LIBELF_F_DATA_MALLOCED) == 0);
+
		STAILQ_REMOVE(&s->s_rawdata, d, _Libelf_Data, d_next);
		d = _libelf_release_data(d);
	}

modified external/libelf/libelf_ar.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008,2010 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,9 +25,7 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_ar.c 210348 2010-07-21 12:54:34Z kaiw $");

-
#include <ar.h>
#include <assert.h>
#include <ctype.h>
#include <libelf.h>
@@ -35,6 +33,9 @@ __FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_ar.c 210348 2010-07-21 12:54:34
#include <string.h>

#include "_libelf.h"
+
#include "_libelf_ar.h"
+

+
ELFTC_VCSID("$Id: libelf_ar.c 2225 2011-11-26 18:55:54Z jkoshy $");

#define	LIBELF_NALLOC_SIZE	16

@@ -49,82 +50,136 @@ __FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_ar.c 210348 2010-07-21 12:54:34
 *
 * Special considerations for `ar' archives:
 *
-
 * The `ar' header only has space for a 16 character file name.  File
-
 * names are terminated with a '/', so this effectively leaves 15
-
 * characters for the actual file name.  In order to accomodate longer
-
 * file names, names may be stored in a separate 'string table' and
-
 * referenced indirectly by a member header.  The string table itself
-
 * appears as an archive member with name "// ".  An indirect file name
-
 * in an `ar' header matches the pattern "/[0-9]*". The digits form a
+
 * There are two variants of the `ar' archive format: traditional BSD
+
 * and SVR4.  These differ in the way long file names are treated, and
+
 * in the layout of the archive symbol table.
+
 *
+
 * The `ar' header only has space for a 16 character file name.
+
 *
+
 * In the SVR4 format, file names are terminated with a '/', so this
+
 * effectively leaves 15 characters for the actual file name.  Longer
+
 * file names stored in a separate 'string table' and referenced
+
 * indirectly from the name field.  The string table itself appears as
+
 * an archive member with name "// ".  An `indirect' file name in an
+
 * `ar' header matches the pattern "/[0-9]*". The digits form a
 * decimal number that corresponds to a byte offset into the string
 * table where the actual file name of the object starts.  Strings in
 * the string table are padded to start on even addresses.
 *
+
 * In the BSD format, file names can be upto 16 characters.  File
+
 * names shorter than 16 characters are padded to 16 characters using
+
 * (ASCII) space characters.  File names with embedded spaces and file
+
 * names longer than 16 characters are stored immediately after the
+
 * archive header and the name field set to a special indirect name
+
 * matching the pattern "#1/[0-9]+".  The digits form a decimal number
+
 * that corresponds to the actual length of the file name following
+
 * the archive header.  The content of the archive member immediately
+
 * follows the file name, and the size field of the archive member
+
 * holds the sum of the sizes of the member and of the appended file
+
 * name.
+
 *
 * Archives may also have a symbol table (see ranlib(1)), mapping
-
 * program symbols to object files inside the archive.  A symbol table
-
 * uses a file name of "/ " in its archive header.  The symbol table
-
 * is structured as:
+
 * program symbols to object files inside the archive.
+
 *
+
 * In the SVR4 format, a symbol table uses a file name of "/ " in its
+
 * archive header.  The symbol table is structured as:
 *  - a 4-byte count of entries stored as a binary value, MSB first
 *  - 'n' 4-byte offsets, stored as binary values, MSB first
 *  - 'n' NUL-terminated strings, for ELF symbol names, stored unpadded.
 *
+
 * In the BSD format, the symbol table uses a file name of "__.SYMDEF".
+
 * It is structured as two parts:
+
 *  - The first part is an array of "ranlib" structures preceded by
+
 *    the size of the array in bytes.  Each "ranlib" structure
+
 *    describes one symbol.  Each structure contains an offset into
+
 *    the string table for the symbol name, and a file offset into the
+
 *    archive for the member defining the symbol.
+
 *  - The second part is a string table containing NUL-terminated
+
 *    strings, preceded by the size of the string table in bytes.
+
 *
 * If the symbol table and string table are is present in an archive
 * they must be the very first objects and in that order.
 */


+
/*
+
 * Retrieve an archive header descriptor.
+
 */

Elf_Arhdr *
_libelf_ar_gethdr(Elf *e)
{
	Elf *parent;
-
	struct ar_hdr *arh;
+
	char *namelen;
	Elf_Arhdr *eh;
-
	size_t n;
+
	size_t n, nlen;
+
	struct ar_hdr *arh;

	if ((parent = e->e_parent) == NULL) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (NULL);
	}

-
	arh = (struct ar_hdr *) ((uintptr_t) e->e_rawfile - sizeof(struct ar_hdr));
+
	assert((e->e_flags & LIBELF_F_AR_HEADER) == 0);
+

+
	arh = (struct ar_hdr *) (uintptr_t) e->e_hdr.e_rawhdr;

	assert((uintptr_t) arh >= (uintptr_t) parent->e_rawfile + SARMAG);
-
	assert((uintptr_t) arh <= (uintptr_t) parent->e_rawfile + parent->e_rawsize -
-
	    sizeof(struct ar_hdr));
+
	assert((uintptr_t) arh <= (uintptr_t) parent->e_rawfile +
+
	    parent->e_rawsize - sizeof(struct ar_hdr));

	if ((eh = malloc(sizeof(Elf_Arhdr))) == NULL) {
		LIBELF_SET_ERROR(RESOURCE, 0);
		return (NULL);
	}

-
	e->e_arhdr = eh;
+
	e->e_hdr.e_arhdr = eh;
+
	e->e_flags |= LIBELF_F_AR_HEADER;
+

	eh->ar_name = eh->ar_rawname = NULL;

-
	if ((eh->ar_name = _libelf_ar_get_name(arh->ar_name, sizeof(arh->ar_name),
-
		 parent)) == NULL)
+
	if ((eh->ar_name = _libelf_ar_get_translated_name(arh, parent)) ==
+
	    NULL)
		goto error;

-
	if (_libelf_ar_get_number(arh->ar_uid, sizeof(arh->ar_uid), 10, &n) == 0)
+
	if (_libelf_ar_get_number(arh->ar_uid, sizeof(arh->ar_uid), 10,
+
	    &n) == 0)
		goto error;
	eh->ar_uid = (uid_t) n;

-
	if (_libelf_ar_get_number(arh->ar_gid, sizeof(arh->ar_gid), 10, &n) == 0)
+
	if (_libelf_ar_get_number(arh->ar_gid, sizeof(arh->ar_gid), 10,
+
	    &n) == 0)
		goto error;
	eh->ar_gid = (gid_t) n;

-
	if (_libelf_ar_get_number(arh->ar_mode, sizeof(arh->ar_mode), 8, &n) == 0)
+
	if (_libelf_ar_get_number(arh->ar_mode, sizeof(arh->ar_mode), 8,
+
	    &n) == 0)
		goto error;
	eh->ar_mode = (mode_t) n;

-
	if (_libelf_ar_get_number(arh->ar_size, sizeof(arh->ar_size), 10, &n) == 0)
+
	if (_libelf_ar_get_number(arh->ar_size, sizeof(arh->ar_size), 10,
+
	    &n) == 0)
		goto error;
+

+
	/*
+
	 * Get the true size of the member if extended naming is being used.
+
	 */
+
	if (IS_EXTENDED_BSD_NAME(arh->ar_name)) {
+
		namelen = arh->ar_name +
+
		    LIBELF_AR_BSD_EXTENDED_NAME_PREFIX_SIZE;
+
		if (_libelf_ar_get_number(namelen, sizeof(arh->ar_name) -
+
		    LIBELF_AR_BSD_EXTENDED_NAME_PREFIX_SIZE, 10, &nlen) == 0)
+
			goto error;
+
		n -= nlen;
+
	}
+

	eh->ar_size = n;

-
	if ((eh->ar_rawname = _libelf_ar_get_string(arh->ar_name,
-
		 sizeof(arh->ar_name), 1)) == NULL)
+
	if ((eh->ar_rawname = _libelf_ar_get_raw_name(arh)) == NULL)
		goto error;

+
	eh->ar_flags = 0;
+

	return (eh);

 error:
@@ -135,7 +190,9 @@ _libelf_ar_gethdr(Elf *e)
			free(eh->ar_rawname);
		free(eh);
	}
-
	e->e_arhdr = NULL;
+

+
	e->e_flags &= ~LIBELF_F_AR_HEADER;
+
	e->e_hdr.e_rawhdr = (char *) arh;

	return (NULL);
}
@@ -144,9 +201,10 @@ Elf *
_libelf_ar_open_member(int fd, Elf_Cmd c, Elf *elf)
{
	Elf *e;
+
	char *member, *namelen;
+
	size_t nsz, sz;
	off_t next;
	struct ar_hdr *arh;
-
	size_t sz;

	assert(elf->e_kind == ELF_K_AR);

@@ -163,20 +221,40 @@ _libelf_ar_open_member(int fd, Elf_Cmd c, Elf *elf)

	arh = (struct ar_hdr *) (elf->e_rawfile + next);

-
	if (_libelf_ar_get_number(arh->ar_size, sizeof(arh->ar_size), 10, &sz) == 0) {
+
	/*
+
	 * Retrieve the size of the member.
+
	 */
+
	if (_libelf_ar_get_number(arh->ar_size, sizeof(arh->ar_size), 10,
+
	    &sz) == 0) {
		LIBELF_SET_ERROR(ARCHIVE, 0);
		return (NULL);
	}

-
	assert(sz > 0);
+
	/*
+
	 * Adjust the size field for members in BSD archives using
+
	 * extended naming.
+
	 */
+
	if (IS_EXTENDED_BSD_NAME(arh->ar_name)) {
+
		namelen = arh->ar_name +
+
		    LIBELF_AR_BSD_EXTENDED_NAME_PREFIX_SIZE;
+
		if (_libelf_ar_get_number(namelen, sizeof(arh->ar_name) -
+
		    LIBELF_AR_BSD_EXTENDED_NAME_PREFIX_SIZE, 10, &nsz) == 0) {
+
			LIBELF_SET_ERROR(ARCHIVE, 0);
+
			return (NULL);
+
		}
+

+
		member = (char *) (arh + 1) + nsz;
+
		sz -= nsz;
+
	} else
+
		member = (char *) (arh + 1);

-
	arh++;	/* skip over archive member header */

-
	if ((e = elf_memory((char *) arh, sz)) == NULL)
+
	if ((e = elf_memory((char *) member, sz)) == NULL)
		return (NULL);

	e->e_fd = fd;
	e->e_cmd = c;
+
	e->e_hdr.e_rawhdr = (char *) arh;

	elf->e_u.e_ar.e_nchildren++;
	e->e_parent = elf;
@@ -185,14 +263,120 @@ _libelf_ar_open_member(int fd, Elf_Cmd c, Elf *elf)
}

/*
-
 * An ar(1) symbol table has the following layout:
+
 * A BSD-style ar(1) symbol table has the following layout:
 *
-
 * The first 4 bytes are a binary count of the number of entries in the
-
 * symbol table, stored MSB-first.
-
 *
-
 * Then there are 'n' 4-byte binary offsets, also stored MSB first.
+
 * - A count of bytes used by the following array of 'ranlib'
+
 *   structures, stored as a 'long'.
+
 * - An array of 'ranlib' structures.  Each array element is
+
 *   two 'long's in size.
+
 * - A count of bytes used for the following symbol table.
+
 * - The symbol table itself.
+
 */
+

+
/*
+
 * A helper macro to read in a 'long' value from the archive.  We use
+
 * memcpy() since the source pointer may be misaligned with respect to
+
 * the natural alignment for a C 'long'.
+
 */
+
#define	GET_LONG(P, V)do {				\
+
		memcpy(&(V), (P), sizeof(long));	\
+
		(P) += sizeof(long);			\
+
	} while (0)
+

+
Elf_Arsym *
+
_libelf_ar_process_bsd_symtab(Elf *e, size_t *count)
+
{
+
	Elf_Arsym *symtab, *sym;
+
	unsigned char *end, *p, *p0, *s, *s0;
+
	const unsigned int entrysize = 2 * sizeof(long);
+
	long arraysize, fileoffset, n, nentries, stroffset, strtabsize;
+

+
	assert(e != NULL);
+
	assert(count != NULL);
+
	assert(e->e_u.e_ar.e_symtab == NULL);
+

+
	symtab = NULL;
+

+
	/*
+
	 * The BSD symbol table always contains the count fields even
+
	 * if there are no entries in it.
+
	 */
+
	if (e->e_u.e_ar.e_rawsymtabsz < 2 * sizeof(long))
+
		goto symtaberror;
+

+
	p = p0 = (unsigned char *) e->e_u.e_ar.e_rawsymtab;
+
	end = p0 + e->e_u.e_ar.e_rawsymtabsz;
+

+
	/*
+
	 * Retrieve the size of the array of ranlib descriptors and
+
	 * check it for validity.
+
	 */
+
	GET_LONG(p, arraysize);
+

+
	if (p0 + arraysize >= end || (arraysize % entrysize != 0))
+
		goto symtaberror;
+

+
	/*
+
	 * Check the value of the string table size.
+
	 */
+
	s = p + arraysize;
+
	GET_LONG(s, strtabsize);
+

+
	s0 = s;			/* Start of string table. */
+
	if (s0 + strtabsize > end)
+
		goto symtaberror;
+

+
	nentries = arraysize / entrysize;
+

+
	/*
+
	 * Allocate space for the returned Elf_Arsym array.
+
	 */
+
	if ((symtab = malloc(sizeof(Elf_Arsym) * (nentries + 1))) == NULL) {
+
		LIBELF_SET_ERROR(RESOURCE, 0);
+
		return (NULL);
+
	}
+

+
	/* Read in symbol table entries. */
+
	for (n = 0, sym = symtab; n < nentries; n++, sym++) {
+
		GET_LONG(p, stroffset);
+
		GET_LONG(p, fileoffset);
+

+
		s = s0 + stroffset;
+

+
		if (s >= end)
+
			goto symtaberror;
+

+
		sym->as_off = fileoffset;
+
		sym->as_hash = elf_hash((char *) s);
+
		sym->as_name = (char *) s;
+
	}
+

+
	/* Fill up the sentinel entry. */
+
	sym->as_name = NULL;
+
	sym->as_hash = ~0UL;
+
	sym->as_off = (off_t) 0;
+

+
	/* Remember the processed symbol table. */
+
	e->e_u.e_ar.e_symtab = symtab;
+

+
	*count = e->e_u.e_ar.e_symtabsz = nentries + 1;
+

+
	return (symtab);
+

+
symtaberror:
+
	if (symtab)
+
		free(symtab);
+
	LIBELF_SET_ERROR(ARCHIVE, 0);
+
	return (NULL);
+
}
+

+
/*
+
 * An SVR4-style ar(1) symbol table has the following layout:
 *
-
 * Following this, there are 'n' null-terminated strings.
+
 * - The first 4 bytes are a binary count of the number of entries in the
+
 *   symbol table, stored MSB-first.
+
 * - Then there are 'n' 4-byte binary offsets, also stored MSB first.
+
 * - Following this, there are 'n' null-terminated strings.
 */

#define	GET_WORD(P, V) do {			\
@@ -205,20 +389,22 @@ _libelf_ar_open_member(int fd, Elf_Cmd c, Elf *elf)

#define	INTSZ	4

+

Elf_Arsym *
-
_libelf_ar_process_symtab(Elf *e, size_t *count)
+
_libelf_ar_process_svr4_symtab(Elf *e, size_t *count)
{
	size_t n, nentries, off;
	Elf_Arsym *symtab, *sym;
-
	unsigned char  *p, *s, *end;
+
	unsigned char *p, *s, *end;

	assert(e != NULL);
	assert(count != NULL);
+
	assert(e->e_u.e_ar.e_symtab == NULL);

-
	if (e->e_u.e_ar.e_rawsymtabsz < INTSZ) {
-
		LIBELF_SET_ERROR(ARCHIVE, 0);
-
		return (NULL);
-
	}
+
	symtab = NULL;
+

+
	if (e->e_u.e_ar.e_rawsymtabsz < INTSZ)
+
		goto symtaberror;

	p = (unsigned char *) e->e_u.e_ar.e_rawsymtab;
	end = p + e->e_u.e_ar.e_rawsymtabsz;
@@ -226,10 +412,8 @@ _libelf_ar_process_symtab(Elf *e, size_t *count)
	GET_WORD(p, nentries);
	p += INTSZ;

-
	if (nentries == 0 || p + nentries * INTSZ >= end) {
-
		LIBELF_SET_ERROR(ARCHIVE, 0);
-
		return (NULL);
-
	}
+
	if (nentries == 0 || p + nentries * INTSZ >= end)
+
		goto symtaberror;

	/* Allocate space for a nentries + a sentinel. */
	if ((symtab = malloc(sizeof(Elf_Arsym) * (nentries+1))) == NULL) {
@@ -240,24 +424,23 @@ _libelf_ar_process_symtab(Elf *e, size_t *count)
	s = p + (nentries * INTSZ); /* start of the string table. */

	for (n = nentries, sym = symtab; n > 0; n--) {
+

+
		if (s >= end)
+
			goto symtaberror;
+

		off = 0;

		GET_WORD(p, off);

		sym->as_off = off;
-
		sym->as_hash = elf_hash(s);
-
		sym->as_name = s;
+
		sym->as_hash = elf_hash((char *) s);
+
		sym->as_name = (char *) s;

		p += INTSZ;
		sym++;

		for (; s < end && *s++ != '\0';) /* skip to next string */
			;
-
		if (s > end) {
-
			LIBELF_SET_ERROR(ARCHIVE, 0);
-
			free(symtab);
-
			return (NULL);
-
		}
	}

	/* Fill up the sentinel entry. */
@@ -269,4 +452,10 @@ _libelf_ar_process_symtab(Elf *e, size_t *count)
	e->e_u.e_ar.e_symtab = symtab;

	return (symtab);
+

+
symtaberror:
+
	if (symtab)
+
		free(symtab);
+
	LIBELF_SET_ERROR(ARCHIVE, 0);
+
	return (NULL);
}
modified external/libelf/libelf_ar_util.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006,2009 Joseph Koshy
+
 * Copyright (c) 2006,2009,2010 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,26 +25,27 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_ar_util.c 210348 2010-07-21 12:54:34Z kaiw $");

-
#include <ar.h>
#include <assert.h>
#include <libelf.h>
#include <stdlib.h>
#include <string.h>

#include "_libelf.h"
+
#include "_libelf_ar.h"
+

+
ELFTC_VCSID("$Id: libelf_ar_util.c 2365 2011-12-29 04:36:44Z jkoshy $");

/*
 * Convert a string bounded by `start' and `start+sz' (exclusive) to a
 * number in the specified base.
 */
int
-
_libelf_ar_get_number(char *s, size_t sz, int base, size_t *ret)
+
_libelf_ar_get_number(const char *s, size_t sz, int base, size_t *ret)
{
	int c, v;
	size_t r;
-
	char *e;
+
	const char *e;

	assert(base <= 10);

@@ -73,67 +74,30 @@ _libelf_ar_get_number(char *s, size_t sz, int base, size_t *ret)
}

/*
-
 * Retrieve a string from a name field.  If `rawname' is set, leave
-
 * ar(1) control characters in.
+
 * Return the translated name for an archive member.
 */
char *
-
_libelf_ar_get_string(const char *buf, size_t bufsize, int rawname)
+
_libelf_ar_get_translated_name(const struct ar_hdr *arh, Elf *ar)
{
-
	const char *q;
-
	char *r;
-
	size_t sz;
+
	char c, *s;
+
	size_t len, offset;
+
	const char *buf, *p, *q, *r;
+
	const size_t bufsize = sizeof(arh->ar_name);

-
	if (rawname)
-
		sz = bufsize + 1;
-
	else {
-
		/* Skip back over trailing blanks. */
-
		for (q = buf + bufsize - 1; q >= buf && *q == ' '; --q)
-
			;
+
	assert(arh != NULL);
+
	assert(ar->e_kind == ELF_K_AR);
+
	assert((const char *) arh >= ar->e_rawfile &&
+
	    (const char *) arh < ar->e_rawfile + ar->e_rawsize);

-
		if (q < buf) {
-
			/*
-
			 * If the input buffer only had blanks in it,
-
			 * return a zero-length string.
-
			 */
-
			buf = "";
-
			sz = 1;
-
		} else {
-
			/*
-
			 * Remove the trailing '/' character, but only
-
			 * if the name isn't one of the special names
-
			 * "/" and "//".
-
			 */
-
			if (q > buf + 1 ||
-
			    (q == (buf + 1) && *buf != '/'))
-
				q--;
-

-
			sz = q - buf + 2; /* Space for a trailing NUL. */
-
		}
-
	}
-

-
	if ((r = malloc(sz)) == NULL) {
-
		LIBELF_SET_ERROR(RESOURCE, 0);
-
		return (NULL);
-
	}
-

-
	(void) strncpy(r, buf, sz);
-
	r[sz - 1] = '\0';
-

-
	return (r);
-
}
-

-
/*
-
 * Retrieve the full name of the archive member.
-
 */
-
char *
-
_libelf_ar_get_name(char *buf, size_t bufsize, Elf *e)
-
{
-
	char c, *q, *r, *s;
-
	size_t len;
-
	size_t offset;
-

-
	assert(e->e_kind == ELF_K_AR);
+
	buf = arh->ar_name;

+
	/*
+
	 * Check for extended naming.
+
	 *
+
	 * If the name matches the pattern "^/[0-9]+", it is an
+
	 * SVR4-style extended name.  If the name matches the pattern
+
	 * "#1/[0-9]+", the entry uses BSD style extended naming.
+
	 */
	if (buf[0] == '/' && (c = buf[1]) >= '0' && c <= '9') {
		/*
		 * The value in field ar_name is a decimal offset into
@@ -141,52 +105,135 @@ _libelf_ar_get_name(char *buf, size_t bufsize, Elf *e)
		 * resides.
		 */
		if (_libelf_ar_get_number(buf + 1, bufsize - 1, 10,
-
		    &offset) == 0) {
+
			&offset) == 0) {
			LIBELF_SET_ERROR(ARCHIVE, 0);
			return (NULL);
		}

-
		if (offset > e->e_u.e_ar.e_rawstrtabsz) {
+
		if (offset > ar->e_u.e_ar.e_rawstrtabsz) {
			LIBELF_SET_ERROR(ARCHIVE, 0);
			return (NULL);
		}

-
		s = q = e->e_u.e_ar.e_rawstrtab + offset;
-
		r = e->e_u.e_ar.e_rawstrtab + e->e_u.e_ar.e_rawstrtabsz;
+
		p = q = ar->e_u.e_ar.e_rawstrtab + offset;
+
		r = ar->e_u.e_ar.e_rawstrtab + ar->e_u.e_ar.e_rawstrtabsz;

-
		for (s = q; s < r && *s != '/'; s++)
+
		for (; p < r && *p != '/'; p++)
			;
-
		len = s - q + 1; /* space for the trailing NUL */
+
		len = p - q + 1; /* space for the trailing NUL */

		if ((s = malloc(len)) == NULL) {
			LIBELF_SET_ERROR(RESOURCE, 0);
			return (NULL);
		}

-
		(void) strncpy(s, q, len);
+
		(void) strncpy(s, q, len - 1);
		s[len - 1] = '\0';

		return (s);
+
	} else if (IS_EXTENDED_BSD_NAME(buf)) {
+
		r = buf + LIBELF_AR_BSD_EXTENDED_NAME_PREFIX_SIZE;
+

+
		if (_libelf_ar_get_number(r, bufsize -
+
			LIBELF_AR_BSD_EXTENDED_NAME_PREFIX_SIZE, 10,
+
			&len) == 0) {
+
			LIBELF_SET_ERROR(ARCHIVE, 0);
+
			return (NULL);
+
		}
+

+
		/*
+
		 * Allocate space for the file name plus a
+
		 * trailing NUL.
+
		 */
+
		if ((s = malloc(len + 1)) == NULL) {
+
			LIBELF_SET_ERROR(RESOURCE, 0);
+
			return (NULL);
+
		}
+

+
		/*
+
		 * The file name follows the archive header.
+
		 */
+
		q = (const char *) (arh + 1);
+

+
		(void) strncpy(s, q, len);
+
		s[len] = '\0';
+

+
		return (s);
	}

	/*
-
	 * Normal 'name'
+
	 * A 'normal' name.
+
	 *
+
	 * Skip back over trailing blanks from the end of the field.
+
	 * In the SVR4 format, a '/' is used as a terminator for
+
	 * non-special names.
	 */
-
	return (_libelf_ar_get_string(buf, bufsize, 0));
+
	for (q = buf + bufsize - 1; q >= buf && *q == ' '; --q)
+
		;
+

+
	if (q >= buf) {
+
		if (*q == '/') {
+
			/*
+
			 * SVR4 style names: ignore the trailing
+
			 * character '/', but only if the name is not
+
			 * one of the special names "/" and "//".
+
			 */
+
			if (q > buf + 1 ||
+
			    (q == (buf + 1) && *buf != '/'))
+
				q--;
+
		}
+

+
		len = q - buf + 2; /* Add space for a trailing NUL. */
+
	} else {
+
		/* The buffer only had blanks. */
+
		buf = "";
+
		len = 1;
+
	}
+

+
	if ((s = malloc(len)) == NULL) {
+
		LIBELF_SET_ERROR(RESOURCE, 0);
+
		return (NULL);
+
	}
+

+
	(void) strncpy(s, buf, len - 1);
+
	s[len - 1] = '\0';
+

+
	return (s);
+
}
+

+
/*
+
 * Return the raw name for an archive member, inclusive of any
+
 * formatting characters.
+
 */
+
char *
+
_libelf_ar_get_raw_name(const struct ar_hdr *arh)
+
{
+
	char *rawname;
+
	const size_t namesz = sizeof(arh->ar_name);
+

+
	if ((rawname = malloc(namesz + 1)) == NULL) {
+
		LIBELF_SET_ERROR(RESOURCE, 0);
+
		return (NULL);
+
	}
+

+
	(void) strncpy(rawname, arh->ar_name, namesz);
+
	rawname[namesz] = '\0';
+
	return (rawname);
}

/*
 * Open an 'ar' archive.
 */
Elf *
-
_libelf_ar_open(Elf *e)
+
_libelf_ar_open(Elf *e, int reporterror)
{
-
	int i;
-
	char *s, *end;
	size_t sz;
+
	int scanahead;
+
	char *s, *end;
	struct ar_hdr arh;

-
	e->e_kind = ELF_K_AR;
+
	_libelf_init_elf(e, ELF_K_AR);
+

	e->e_u.e_ar.e_nchildren = 0;
	e->e_u.e_ar.e_next = (off_t) -1;

@@ -200,54 +247,113 @@ _libelf_ar_open(Elf *e)
	assert(e->e_rawsize > 0);

	/*
-
	 * Look for magic names "/ " and "// " in the first two entries
-
	 * of the archive.
+
	 * We use heuristics to determine the flavor of the archive we
+
	 * are examining.
+
	 *
+
	 * SVR4 flavor archives use the name "/ " and "// " for
+
	 * special members.
+
	 *
+
	 * In BSD flavor archives the symbol table, if present, is the
+
	 * first archive with name "__.SYMDEF".
	 */
-
	for (i = 0; i < 2; i++) {
-

-
		if (s + sizeof(arh) > end) {
-
			LIBELF_SET_ERROR(ARCHIVE, 0);
-
			return (NULL);
-
		}

-
		(void) memcpy(&arh, s, sizeof(arh));
+
#define	READ_AR_HEADER(S, ARH, SZ, END)					\
+
	do {								\
+
		if ((S) + sizeof((ARH)) > (END))			\
+
		        goto error;					\
+
		(void) memcpy(&(ARH), (S), sizeof((ARH)));		\
+
		if ((ARH).ar_fmag[0] != '`' || (ARH).ar_fmag[1] != '\n') \
+
			goto error;					\
+
		if (_libelf_ar_get_number((ARH).ar_size,		\
+
		    sizeof((ARH).ar_size), 10, &(SZ)) == 0)		\
+
			goto error;					\
+
	} while (0)

-
		if (arh.ar_fmag[0] != '`' || arh.ar_fmag[1] != '\n') {
-
			LIBELF_SET_ERROR(ARCHIVE, 0);
-
			return (NULL);
-
		}
+
	READ_AR_HEADER(s, arh, sz, end);

-
		if (arh.ar_name[0] != '/')	/* not a special symbol */
-
			break;
-

-
		if (_libelf_ar_get_number(arh.ar_size, sizeof(arh.ar_size),
-
			10, &sz) == 0) {
-
			LIBELF_SET_ERROR(ARCHIVE, 0);
-
			return (NULL);
-
		}
+
	/*
+
	 * Handle special archive members for the SVR4 format.
+
	 */
+
	if (arh.ar_name[0] == '/') {

		assert(sz > 0);

-
		s += sizeof(arh);
+
		e->e_flags |= LIBELF_F_AR_VARIANT_SVR4;
+

+
		scanahead = 0;

-
		if (arh.ar_name[1] == ' ') {	/* "/ " => symbol table */
+
		/*
+
		 * The symbol table (file name "/ ") always comes before the
+
		 * string table (file name "// ").
+
		 */
+
		if (arh.ar_name[1] == ' ') {
+
			/* "/ " => symbol table. */
+
			scanahead = 1;	/* The string table to follow. */

+
			s += sizeof(arh);
			e->e_u.e_ar.e_rawsymtab = s;
			e->e_u.e_ar.e_rawsymtabsz = sz;

-
		} else if (arh.ar_name[1] == '/' && arh.ar_name[2] == ' ') {
+
			sz = LIBELF_ADJUST_AR_SIZE(sz);
+
			s += sz;

-
			/* "// " => string table for long file names */
+
		} else if (arh.ar_name[1] == '/' && arh.ar_name[2] == ' ') {
+
			/* "// " => string table for long file names. */
+
			s += sizeof(arh);
			e->e_u.e_ar.e_rawstrtab = s;
			e->e_u.e_ar.e_rawstrtabsz = sz;
+

+
			sz = LIBELF_ADJUST_AR_SIZE(sz);
+
			s += sz;
		}

-
		sz = LIBELF_ADJUST_AR_SIZE(sz);
+
		/*
+
		 * If the string table hasn't been seen yet, look for
+
		 * it in the next member.
+
		 */
+
		if (scanahead) {
+
			READ_AR_HEADER(s, arh, sz, end);

+
			/* "// " => string table for long file names. */
+
			if (arh.ar_name[0] == '/' && arh.ar_name[1] == '/' &&
+
			    arh.ar_name[2] == ' ') {
+

+
				s += sizeof(arh);
+

+
				e->e_u.e_ar.e_rawstrtab = s;
+
				e->e_u.e_ar.e_rawstrtabsz = sz;
+

+
				sz = LIBELF_ADJUST_AR_SIZE(sz);
+
				s += sz;
+
			}
+
		}
+
	} else if (strncmp(arh.ar_name, LIBELF_AR_BSD_SYMTAB_NAME,
+
		sizeof(LIBELF_AR_BSD_SYMTAB_NAME) - 1) == 0) {
+
		/*
+
		 * BSD style archive symbol table.
+
		 */
+
		s += sizeof(arh);
+
		e->e_u.e_ar.e_rawsymtab = s;
+
		e->e_u.e_ar.e_rawsymtabsz = sz;
+

+
		sz = LIBELF_ADJUST_AR_SIZE(sz);
		s += sz;
	}

+
	/*
+
	 * Update the 'next' offset, so that a subsequent elf_begin()
+
	 * works as expected.
+
	 */
	e->e_u.e_ar.e_next = (off_t) (s - e->e_rawfile);

	return (e);
+

+
error:
+
	if (!reporterror) {
+
		e->e_kind = ELF_K_NONE;
+
		return (e);
+
	}
+

+
	LIBELF_SET_ERROR(ARCHIVE, 0);
+
	return (NULL);
}
modified external/libelf/libelf_checksum.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,12 +25,13 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_checksum.c 165535 2006-12-25 02:22:22Z jkoshy $");

#include <gelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: libelf_checksum.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

static unsigned long
_libelf_sum(unsigned long c, const unsigned char *s, size_t size)
{
deleted external/libelf/libelf_convert.c
@@ -1,3015 +0,0 @@
-
/*-
-
 * Copyright (c) 2006-2008 Joseph Koshy
-
 * 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.
-
 *
-
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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.
-
 */
-

-
#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_convert.m4 219126 2011-03-01 11:47:51Z brucec $");
-

-
#include <sys/types.h>
-
#include <sys/elf32.h>
-
#include <sys/elf64.h>
-

-
#include <assert.h>
-
#include <libelf.h>
-
#include <osreldate.h>
-
#include <string.h>
-

-
#include "_libelf.h"
-

-
/* WARNING: GENERATED FROM libelf_convert.m4. */
-

-
/*
-
 * Macros to swap various integral quantities.
-
 */
-

-
#define	SWAP_HALF(X) 	do {						\
-
		uint16_t _x = (uint16_t) (X);				\
-
		uint16_t _t = _x & 0xFF;				\
-
		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
-
		(X) = _t;						\
-
	} while (0)
-
#define	SWAP_WORD(X) 	do {						\
-
		uint32_t _x = (uint32_t) (X);				\
-
		uint32_t _t = _x & 0xFF;				\
-
		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
-
		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
-
		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
-
		(X) = _t;						\
-
	} while (0)
-
#define	SWAP_ADDR32(X)	SWAP_WORD(X)
-
#define	SWAP_OFF32(X)	SWAP_WORD(X)
-
#define	SWAP_SWORD(X)	SWAP_WORD(X)
-
#define	SWAP_WORD64(X)	do {						\
-
		uint64_t _x = (uint64_t) (X);				\
-
		uint64_t _t = _x & 0xFF;				\
-
		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
-
		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
-
		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
-
		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
-
		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
-
		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
-
		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
-
		(X) = _t;						\
-
	} while (0)
-
#define	SWAP_ADDR64(X)	SWAP_WORD64(X)
-
#define	SWAP_LWORD(X)	SWAP_WORD64(X)
-
#define	SWAP_OFF64(X)	SWAP_WORD64(X)
-
#define	SWAP_SXWORD(X)	SWAP_WORD64(X)
-
#define	SWAP_XWORD(X)	SWAP_WORD64(X)
-

-
/*
-
 * Write out various integral values.  The destination pointer could
-
 * be unaligned.  Values are written out in native byte order.  The
-
 * destination pointer is incremented after the write.
-
 */
-
#define	WRITE_BYTE(P,X) do {						\
-
		char *const _p = (char *) (P);	\
-
		_p[0]		= (char) (X);			\
-
		(P)		= _p + 1;				\
-
	} while (0)
-
#define	WRITE_HALF(P,X)	do {						\
-
		uint16_t _t	= (X);					\
-
		char *const _p	= (char *) (P);	\
-
		const char *const _q = (char *) &_t;	\
-
		_p[0]		= _q[0];				\
-
		_p[1]		= _q[1];				\
-
		(P) 		= _p + 2;				\
-
	} while (0)
-
#define	WRITE_WORD(P,X)	do {						\
-
		uint32_t _t	= (X);					\
-
		char *const _p	= (char *) (P);	\
-
		const char *const _q = (char *) &_t;	\
-
		_p[0]		= _q[0];				\
-
		_p[1]		= _q[1];				\
-
		_p[2]		= _q[2];				\
-
		_p[3]		= _q[3];				\
-
		(P)		= _p + 4;				\
-
	} while (0)
-
#define	WRITE_ADDR32(P,X)	WRITE_WORD(P,X)
-
#define	WRITE_OFF32(P,X)	WRITE_WORD(P,X)
-
#define	WRITE_SWORD(P,X)	WRITE_WORD(P,X)
-
#define	WRITE_WORD64(P,X)	do {					\
-
		uint64_t _t	= (X);					\
-
		char *const _p	= (char *) (P);	\
-
		const char *const _q = (char *) &_t;	\
-
		_p[0]		= _q[0];				\
-
		_p[1]		= _q[1];				\
-
		_p[2]		= _q[2];				\
-
		_p[3]		= _q[3];				\
-
		_p[4]		= _q[4];				\
-
		_p[5]		= _q[5];				\
-
		_p[6]		= _q[6];				\
-
		_p[7]		= _q[7];				\
-
		(P)		= _p + 8;				\
-
	} while (0)
-
#define	WRITE_ADDR64(P,X)	WRITE_WORD64(P,X)
-
#define	WRITE_LWORD(P,X)	WRITE_WORD64(P,X)
-
#define	WRITE_OFF64(P,X)	WRITE_WORD64(P,X)
-
#define	WRITE_SXWORD(P,X)	WRITE_WORD64(P,X)
-
#define	WRITE_XWORD(P,X)	WRITE_WORD64(P,X)
-
#define	WRITE_IDENT(P,X)	do {					\
-
		(void) memcpy((P), (X), sizeof((X)));			\
-
		(P)		= (P) + EI_NIDENT;			\
-
	} while (0)
-

-
/*
-
 * Read in various integral values.  The source pointer could be
-
 * unaligned.  Values are read in native byte order.  The source
-
 * pointer is incremented appropriately.
-
 */
-

-
#define	READ_BYTE(P,X)	do {						\
-
		const char *const _p =				\
-
			(const char *) (P);			\
-
		(X)		= _p[0];				\
-
		(P)		= (P) + 1;				\
-
	} while (0)
-
#define	READ_HALF(P,X)	do {						\
-
		uint16_t _t;						\
-
		char *const _q = (char *) &_t;	\
-
		const char *const _p =				\
-
			(const char *) (P);			\
-
		_q[0]		= _p[0];				\
-
		_q[1]		= _p[1];				\
-
		(P)		= (P) + 2;				\
-
		(X)		= _t;					\
-
	} while (0)
-
#define	READ_WORD(P,X)	do {						\
-
		uint32_t _t;						\
-
		char *const _q = (char *) &_t;	\
-
		const char *const _p =				\
-
			(const char *) (P);			\
-
		_q[0]		= _p[0];				\
-
		_q[1]		= _p[1];				\
-
		_q[2]		= _p[2];				\
-
		_q[3]		= _p[3];				\
-
		(P)		= (P) + 4;				\
-
		(X)		= _t;					\
-
	} while (0)
-
#define	READ_ADDR32(P,X)	READ_WORD(P,X)
-
#define	READ_OFF32(P,X)		READ_WORD(P,X)
-
#define	READ_SWORD(P,X)		READ_WORD(P,X)
-
#define	READ_WORD64(P,X)	do {					\
-
		uint64_t _t;						\
-
		char *const _q = (char *) &_t;	\
-
		const char *const _p =				\
-
			(const char *) (P);			\
-
		_q[0]		= _p[0];				\
-
		_q[1]		= _p[1];				\
-
		_q[2]		= _p[2];				\
-
		_q[3]		= _p[3];				\
-
		_q[4]		= _p[4];				\
-
		_q[5]		= _p[5];				\
-
		_q[6]		= _p[6];				\
-
		_q[7]		= _p[7];				\
-
		(P)		= (P) + 8;				\
-
		(X)		= _t;					\
-
	} while (0)
-
#define	READ_ADDR64(P,X)	READ_WORD64(P,X)
-
#define	READ_LWORD(P,X)		READ_WORD64(P,X)
-
#define	READ_OFF64(P,X)		READ_WORD64(P,X)
-
#define	READ_SXWORD(P,X)	READ_WORD64(P,X)
-
#define	READ_XWORD(P,X)		READ_WORD64(P,X)
-
#define	READ_IDENT(P,X)		do {					\
-
		(void) memcpy((X), (P), sizeof((X)));			\
-
		(P)		= (P) + EI_NIDENT;			\
-
	} while (0)
-

-
#define	ROUNDUP2(V,N)	(V) = ((((V) + (N) - 1)) & ~((N) - 1))
-

-

-

-
/*
-
 * Sections of type ELF_T_BYTE are never byteswapped, consequently a
-
 * simple memcpy suffices for both directions of conversion.
-
 */
-

-
static int
-
libelf_cvt_BYTE_tox(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	(void) byteswap;
-
	if (dsz < count)
-
		return (0);
-
	if (dst != src)
-
		(void) memcpy(dst, src, count);
-
	return (1);
-
}
-

-
#if	__FreeBSD_version >= 600102 /* ADDR */
-

-
static int
-
libelf_cvt_ADDR32_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Addr t, *s = (Elf32_Addr *) (uintptr_t) src;
-
	size_t c;
-

-
	(void) dsz;
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*s));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		SWAP_ADDR32(t);
-
		WRITE_ADDR32(dst,t);
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt_ADDR32_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Addr t, *d = (Elf32_Addr *) (uintptr_t) dst;
-
	size_t c;
-

-
	if (dsz < count * sizeof(Elf32_Addr))
-
		return (0);
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*d));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		READ_ADDR32(src,t);
-
		SWAP_ADDR32(t);
-
		*d++ = t;
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt_ADDR64_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Addr t, *s = (Elf64_Addr *) (uintptr_t) src;
-
	size_t c;
-

-
	(void) dsz;
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*s));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		SWAP_ADDR64(t);
-
		WRITE_ADDR64(dst,t);
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt_ADDR64_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Addr t, *d = (Elf64_Addr *) (uintptr_t) dst;
-
	size_t c;
-

-
	if (dsz < count * sizeof(Elf64_Addr))
-
		return (0);
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*d));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		READ_ADDR64(src,t);
-
		SWAP_ADDR64(t);
-
		*d++ = t;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* ADDR */
-
#if	__FreeBSD_version >= 600102 /* BYTE */
-

-
#endif /* BYTE */
-
#if	__FreeBSD_version >= 700025 /* CAP */
-

-
static int
-
libelf_cvt32_CAP_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Cap	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf32_Cap *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf32_Cap */
-
			SWAP_WORD(t.c_tag);
-
			SWAP_WORD(t.c_un.c_val);
-
			/**/
-
		}
-
		/* Write an Elf32_Cap */
-
		WRITE_WORD(dst,t.c_tag);
-
		WRITE_WORD(dst,t.c_un.c_val);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_CAP_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Cap	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf64_Cap *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf64_Cap */
-
			SWAP_XWORD(t.c_tag);
-
			SWAP_XWORD(t.c_un.c_val);
-
			/**/
-
		}
-
		/* Write an Elf64_Cap */
-
		WRITE_XWORD(dst,t.c_tag);
-
		WRITE_XWORD(dst,t.c_un.c_val);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt32_CAP_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Cap	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf32_fsize(ELF_T_CAP, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf32_Cap *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf32_Cap))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf32_Cap */
-
		READ_WORD(s,t.c_tag);
-
		READ_WORD(s,t.c_un.c_val);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf32_Cap */
-
			SWAP_WORD(t.c_tag);
-
			SWAP_WORD(t.c_un.c_val);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_CAP_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Cap	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf64_fsize(ELF_T_CAP, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf64_Cap *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf64_Cap))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf64_Cap */
-
		READ_XWORD(s,t.c_tag);
-
		READ_XWORD(s,t.c_un.c_val);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf64_Cap */
-
			SWAP_XWORD(t.c_tag);
-
			SWAP_XWORD(t.c_un.c_val);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* CAP */
-
#if	__FreeBSD_version >= 600102 /* DYN */
-

-
static int
-
libelf_cvt32_DYN_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Dyn	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf32_Dyn *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf32_Dyn */
-
			SWAP_SWORD(t.d_tag);
-
			SWAP_WORD(t.d_un.d_ptr);
-
			/**/
-
		}
-
		/* Write an Elf32_Dyn */
-
		WRITE_SWORD(dst,t.d_tag);
-
		WRITE_WORD(dst,t.d_un.d_ptr);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_DYN_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Dyn	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf64_Dyn *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf64_Dyn */
-
			SWAP_SXWORD(t.d_tag);
-
			SWAP_XWORD(t.d_un.d_ptr);
-
			/**/
-
		}
-
		/* Write an Elf64_Dyn */
-
		WRITE_SXWORD(dst,t.d_tag);
-
		WRITE_XWORD(dst,t.d_un.d_ptr);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt32_DYN_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Dyn	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf32_fsize(ELF_T_DYN, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf32_Dyn *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf32_Dyn))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf32_Dyn */
-
		READ_SWORD(s,t.d_tag);
-
		READ_WORD(s,t.d_un.d_ptr);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf32_Dyn */
-
			SWAP_SWORD(t.d_tag);
-
			SWAP_WORD(t.d_un.d_ptr);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_DYN_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Dyn	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf64_fsize(ELF_T_DYN, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf64_Dyn *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf64_Dyn))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf64_Dyn */
-
		READ_SXWORD(s,t.d_tag);
-
		READ_XWORD(s,t.d_un.d_ptr);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf64_Dyn */
-
			SWAP_SXWORD(t.d_tag);
-
			SWAP_XWORD(t.d_un.d_ptr);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* DYN */
-
#if	__FreeBSD_version >= 600102 /* EHDR */
-

-
static int
-
libelf_cvt32_EHDR_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Ehdr	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf32_Ehdr *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf32_Ehdr */
-
			SWAP_HALF(t.e_type);
-
			SWAP_HALF(t.e_machine);
-
			SWAP_WORD(t.e_version);
-
			SWAP_ADDR32(t.e_entry);
-
			SWAP_OFF32(t.e_phoff);
-
			SWAP_OFF32(t.e_shoff);
-
			SWAP_WORD(t.e_flags);
-
			SWAP_HALF(t.e_ehsize);
-
			SWAP_HALF(t.e_phentsize);
-
			SWAP_HALF(t.e_phnum);
-
			SWAP_HALF(t.e_shentsize);
-
			SWAP_HALF(t.e_shnum);
-
			SWAP_HALF(t.e_shstrndx);
-
			/**/
-
		}
-
		/* Write an Elf32_Ehdr */
-
		WRITE_IDENT(dst,t.e_ident);
-
		WRITE_HALF(dst,t.e_type);
-
		WRITE_HALF(dst,t.e_machine);
-
		WRITE_WORD(dst,t.e_version);
-
		WRITE_ADDR32(dst,t.e_entry);
-
		WRITE_OFF32(dst,t.e_phoff);
-
		WRITE_OFF32(dst,t.e_shoff);
-
		WRITE_WORD(dst,t.e_flags);
-
		WRITE_HALF(dst,t.e_ehsize);
-
		WRITE_HALF(dst,t.e_phentsize);
-
		WRITE_HALF(dst,t.e_phnum);
-
		WRITE_HALF(dst,t.e_shentsize);
-
		WRITE_HALF(dst,t.e_shnum);
-
		WRITE_HALF(dst,t.e_shstrndx);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_EHDR_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Ehdr	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf64_Ehdr *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf64_Ehdr */
-
			SWAP_HALF(t.e_type);
-
			SWAP_HALF(t.e_machine);
-
			SWAP_WORD(t.e_version);
-
			SWAP_ADDR64(t.e_entry);
-
			SWAP_OFF64(t.e_phoff);
-
			SWAP_OFF64(t.e_shoff);
-
			SWAP_WORD(t.e_flags);
-
			SWAP_HALF(t.e_ehsize);
-
			SWAP_HALF(t.e_phentsize);
-
			SWAP_HALF(t.e_phnum);
-
			SWAP_HALF(t.e_shentsize);
-
			SWAP_HALF(t.e_shnum);
-
			SWAP_HALF(t.e_shstrndx);
-
			/**/
-
		}
-
		/* Write an Elf64_Ehdr */
-
		WRITE_IDENT(dst,t.e_ident);
-
		WRITE_HALF(dst,t.e_type);
-
		WRITE_HALF(dst,t.e_machine);
-
		WRITE_WORD(dst,t.e_version);
-
		WRITE_ADDR64(dst,t.e_entry);
-
		WRITE_OFF64(dst,t.e_phoff);
-
		WRITE_OFF64(dst,t.e_shoff);
-
		WRITE_WORD(dst,t.e_flags);
-
		WRITE_HALF(dst,t.e_ehsize);
-
		WRITE_HALF(dst,t.e_phentsize);
-
		WRITE_HALF(dst,t.e_phnum);
-
		WRITE_HALF(dst,t.e_shentsize);
-
		WRITE_HALF(dst,t.e_shnum);
-
		WRITE_HALF(dst,t.e_shstrndx);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt32_EHDR_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Ehdr	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf32_fsize(ELF_T_EHDR, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf32_Ehdr *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf32_Ehdr))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf32_Ehdr */
-
		READ_IDENT(s,t.e_ident);
-
		READ_HALF(s,t.e_type);
-
		READ_HALF(s,t.e_machine);
-
		READ_WORD(s,t.e_version);
-
		READ_ADDR32(s,t.e_entry);
-
		READ_OFF32(s,t.e_phoff);
-
		READ_OFF32(s,t.e_shoff);
-
		READ_WORD(s,t.e_flags);
-
		READ_HALF(s,t.e_ehsize);
-
		READ_HALF(s,t.e_phentsize);
-
		READ_HALF(s,t.e_phnum);
-
		READ_HALF(s,t.e_shentsize);
-
		READ_HALF(s,t.e_shnum);
-
		READ_HALF(s,t.e_shstrndx);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf32_Ehdr */
-
			SWAP_HALF(t.e_type);
-
			SWAP_HALF(t.e_machine);
-
			SWAP_WORD(t.e_version);
-
			SWAP_ADDR32(t.e_entry);
-
			SWAP_OFF32(t.e_phoff);
-
			SWAP_OFF32(t.e_shoff);
-
			SWAP_WORD(t.e_flags);
-
			SWAP_HALF(t.e_ehsize);
-
			SWAP_HALF(t.e_phentsize);
-
			SWAP_HALF(t.e_phnum);
-
			SWAP_HALF(t.e_shentsize);
-
			SWAP_HALF(t.e_shnum);
-
			SWAP_HALF(t.e_shstrndx);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_EHDR_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Ehdr	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf64_fsize(ELF_T_EHDR, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf64_Ehdr *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf64_Ehdr))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf64_Ehdr */
-
		READ_IDENT(s,t.e_ident);
-
		READ_HALF(s,t.e_type);
-
		READ_HALF(s,t.e_machine);
-
		READ_WORD(s,t.e_version);
-
		READ_ADDR64(s,t.e_entry);
-
		READ_OFF64(s,t.e_phoff);
-
		READ_OFF64(s,t.e_shoff);
-
		READ_WORD(s,t.e_flags);
-
		READ_HALF(s,t.e_ehsize);
-
		READ_HALF(s,t.e_phentsize);
-
		READ_HALF(s,t.e_phnum);
-
		READ_HALF(s,t.e_shentsize);
-
		READ_HALF(s,t.e_shnum);
-
		READ_HALF(s,t.e_shstrndx);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf64_Ehdr */
-
			SWAP_HALF(t.e_type);
-
			SWAP_HALF(t.e_machine);
-
			SWAP_WORD(t.e_version);
-
			SWAP_ADDR64(t.e_entry);
-
			SWAP_OFF64(t.e_phoff);
-
			SWAP_OFF64(t.e_shoff);
-
			SWAP_WORD(t.e_flags);
-
			SWAP_HALF(t.e_ehsize);
-
			SWAP_HALF(t.e_phentsize);
-
			SWAP_HALF(t.e_phnum);
-
			SWAP_HALF(t.e_shentsize);
-
			SWAP_HALF(t.e_shnum);
-
			SWAP_HALF(t.e_shstrndx);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* EHDR */
-
#if	__FreeBSD_version >= 800062 /* GNUHASH */
-
                     
-
#endif /* GNUHASH */
-
#if	__FreeBSD_version >= 600102 /* HALF */
-

-
static int
-
libelf_cvt_HALF_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Half t, *s = (Elf64_Half *) (uintptr_t) src;
-
	size_t c;
-

-
	(void) dsz;
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*s));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		SWAP_HALF(t);
-
		WRITE_HALF(dst,t);
-
	}
-

-
	return (1);
-
}
-

-
       
-
static int
-
libelf_cvt_HALF_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Half t, *d = (Elf64_Half *) (uintptr_t) dst;
-
	size_t c;
-

-
	if (dsz < count * sizeof(Elf64_Half))
-
		return (0);
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*d));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		READ_HALF(src,t);
-
		SWAP_HALF(t);
-
		*d++ = t;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* HALF */
-
#if	__FreeBSD_version >= 700025 /* LWORD */
-

-
static int
-
libelf_cvt_LWORD_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Lword t, *s = (Elf64_Lword *) (uintptr_t) src;
-
	size_t c;
-

-
	(void) dsz;
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*s));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		SWAP_LWORD(t);
-
		WRITE_LWORD(dst,t);
-
	}
-

-
	return (1);
-
}
-

-
       
-
static int
-
libelf_cvt_LWORD_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Lword t, *d = (Elf64_Lword *) (uintptr_t) dst;
-
	size_t c;
-

-
	if (dsz < count * sizeof(Elf64_Lword))
-
		return (0);
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*d));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		READ_LWORD(src,t);
-
		SWAP_LWORD(t);
-
		*d++ = t;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* LWORD */
-
#if	__FreeBSD_version >= 700025 /* MOVE */
-

-
static int
-
libelf_cvt32_MOVE_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Move	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf32_Move *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf32_Move */
-
			SWAP_LWORD(t.m_value);
-
			SWAP_WORD(t.m_info);
-
			SWAP_WORD(t.m_poffset);
-
			SWAP_HALF(t.m_repeat);
-
			SWAP_HALF(t.m_stride);
-
			/**/
-
		}
-
		/* Write an Elf32_Move */
-
		WRITE_LWORD(dst,t.m_value);
-
		WRITE_WORD(dst,t.m_info);
-
		WRITE_WORD(dst,t.m_poffset);
-
		WRITE_HALF(dst,t.m_repeat);
-
		WRITE_HALF(dst,t.m_stride);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_MOVE_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Move	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf64_Move *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf64_Move */
-
			SWAP_LWORD(t.m_value);
-
			SWAP_XWORD(t.m_info);
-
			SWAP_XWORD(t.m_poffset);
-
			SWAP_HALF(t.m_repeat);
-
			SWAP_HALF(t.m_stride);
-
			/**/
-
		}
-
		/* Write an Elf64_Move */
-
		WRITE_LWORD(dst,t.m_value);
-
		WRITE_XWORD(dst,t.m_info);
-
		WRITE_XWORD(dst,t.m_poffset);
-
		WRITE_HALF(dst,t.m_repeat);
-
		WRITE_HALF(dst,t.m_stride);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt32_MOVE_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Move	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf32_fsize(ELF_T_MOVE, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf32_Move *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf32_Move))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf32_Move */
-
		READ_LWORD(s,t.m_value);
-
		READ_WORD(s,t.m_info);
-
		READ_WORD(s,t.m_poffset);
-
		READ_HALF(s,t.m_repeat);
-
		READ_HALF(s,t.m_stride);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf32_Move */
-
			SWAP_LWORD(t.m_value);
-
			SWAP_WORD(t.m_info);
-
			SWAP_WORD(t.m_poffset);
-
			SWAP_HALF(t.m_repeat);
-
			SWAP_HALF(t.m_stride);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_MOVE_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Move	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf64_fsize(ELF_T_MOVE, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf64_Move *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf64_Move))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf64_Move */
-
		READ_LWORD(s,t.m_value);
-
		READ_XWORD(s,t.m_info);
-
		READ_XWORD(s,t.m_poffset);
-
		READ_HALF(s,t.m_repeat);
-
		READ_HALF(s,t.m_stride);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf64_Move */
-
			SWAP_LWORD(t.m_value);
-
			SWAP_XWORD(t.m_info);
-
			SWAP_XWORD(t.m_poffset);
-
			SWAP_HALF(t.m_repeat);
-
			SWAP_HALF(t.m_stride);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* MOVE */
-
#if	__FreeBSD_version >= 700025 /* MOVEP */
-
                     
-
#endif /* MOVEP */
-
#if	__FreeBSD_version >= 600102 /* NOTE */
-

-
#endif /* NOTE */
-
#if	__FreeBSD_version >= 600102 /* OFF */
-

-
static int
-
libelf_cvt_OFF32_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Off t, *s = (Elf32_Off *) (uintptr_t) src;
-
	size_t c;
-

-
	(void) dsz;
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*s));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		SWAP_OFF32(t);
-
		WRITE_OFF32(dst,t);
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt_OFF32_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Off t, *d = (Elf32_Off *) (uintptr_t) dst;
-
	size_t c;
-

-
	if (dsz < count * sizeof(Elf32_Off))
-
		return (0);
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*d));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		READ_OFF32(src,t);
-
		SWAP_OFF32(t);
-
		*d++ = t;
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt_OFF64_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Off t, *s = (Elf64_Off *) (uintptr_t) src;
-
	size_t c;
-

-
	(void) dsz;
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*s));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		SWAP_OFF64(t);
-
		WRITE_OFF64(dst,t);
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt_OFF64_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Off t, *d = (Elf64_Off *) (uintptr_t) dst;
-
	size_t c;
-

-
	if (dsz < count * sizeof(Elf64_Off))
-
		return (0);
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*d));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		READ_OFF64(src,t);
-
		SWAP_OFF64(t);
-
		*d++ = t;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* OFF */
-
#if	__FreeBSD_version >= 600102 /* PHDR */
-

-
static int
-
libelf_cvt32_PHDR_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Phdr	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf32_Phdr *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf32_Phdr */
-
			SWAP_WORD(t.p_type);
-
			SWAP_OFF32(t.p_offset);
-
			SWAP_ADDR32(t.p_vaddr);
-
			SWAP_ADDR32(t.p_paddr);
-
			SWAP_WORD(t.p_filesz);
-
			SWAP_WORD(t.p_memsz);
-
			SWAP_WORD(t.p_flags);
-
			SWAP_WORD(t.p_align);
-
			/**/
-
		}
-
		/* Write an Elf32_Phdr */
-
		WRITE_WORD(dst,t.p_type);
-
		WRITE_OFF32(dst,t.p_offset);
-
		WRITE_ADDR32(dst,t.p_vaddr);
-
		WRITE_ADDR32(dst,t.p_paddr);
-
		WRITE_WORD(dst,t.p_filesz);
-
		WRITE_WORD(dst,t.p_memsz);
-
		WRITE_WORD(dst,t.p_flags);
-
		WRITE_WORD(dst,t.p_align);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_PHDR_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Phdr	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf64_Phdr *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf64_Phdr */
-
			SWAP_WORD(t.p_type);
-
			SWAP_WORD(t.p_flags);
-
			SWAP_OFF64(t.p_offset);
-
			SWAP_ADDR64(t.p_vaddr);
-
			SWAP_ADDR64(t.p_paddr);
-
			SWAP_XWORD(t.p_filesz);
-
			SWAP_XWORD(t.p_memsz);
-
			SWAP_XWORD(t.p_align);
-
			/**/
-
		}
-
		/* Write an Elf64_Phdr */
-
		WRITE_WORD(dst,t.p_type);
-
		WRITE_WORD(dst,t.p_flags);
-
		WRITE_OFF64(dst,t.p_offset);
-
		WRITE_ADDR64(dst,t.p_vaddr);
-
		WRITE_ADDR64(dst,t.p_paddr);
-
		WRITE_XWORD(dst,t.p_filesz);
-
		WRITE_XWORD(dst,t.p_memsz);
-
		WRITE_XWORD(dst,t.p_align);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt32_PHDR_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Phdr	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf32_fsize(ELF_T_PHDR, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf32_Phdr *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf32_Phdr))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf32_Phdr */
-
		READ_WORD(s,t.p_type);
-
		READ_OFF32(s,t.p_offset);
-
		READ_ADDR32(s,t.p_vaddr);
-
		READ_ADDR32(s,t.p_paddr);
-
		READ_WORD(s,t.p_filesz);
-
		READ_WORD(s,t.p_memsz);
-
		READ_WORD(s,t.p_flags);
-
		READ_WORD(s,t.p_align);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf32_Phdr */
-
			SWAP_WORD(t.p_type);
-
			SWAP_OFF32(t.p_offset);
-
			SWAP_ADDR32(t.p_vaddr);
-
			SWAP_ADDR32(t.p_paddr);
-
			SWAP_WORD(t.p_filesz);
-
			SWAP_WORD(t.p_memsz);
-
			SWAP_WORD(t.p_flags);
-
			SWAP_WORD(t.p_align);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_PHDR_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Phdr	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf64_fsize(ELF_T_PHDR, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf64_Phdr *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf64_Phdr))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf64_Phdr */
-
		READ_WORD(s,t.p_type);
-
		READ_WORD(s,t.p_flags);
-
		READ_OFF64(s,t.p_offset);
-
		READ_ADDR64(s,t.p_vaddr);
-
		READ_ADDR64(s,t.p_paddr);
-
		READ_XWORD(s,t.p_filesz);
-
		READ_XWORD(s,t.p_memsz);
-
		READ_XWORD(s,t.p_align);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf64_Phdr */
-
			SWAP_WORD(t.p_type);
-
			SWAP_WORD(t.p_flags);
-
			SWAP_OFF64(t.p_offset);
-
			SWAP_ADDR64(t.p_vaddr);
-
			SWAP_ADDR64(t.p_paddr);
-
			SWAP_XWORD(t.p_filesz);
-
			SWAP_XWORD(t.p_memsz);
-
			SWAP_XWORD(t.p_align);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* PHDR */
-
#if	__FreeBSD_version >= 600102 /* REL */
-

-
static int
-
libelf_cvt32_REL_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Rel	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf32_Rel *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf32_Rel */
-
			SWAP_ADDR32(t.r_offset);
-
			SWAP_WORD(t.r_info);
-
			/**/
-
		}
-
		/* Write an Elf32_Rel */
-
		WRITE_ADDR32(dst,t.r_offset);
-
		WRITE_WORD(dst,t.r_info);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_REL_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Rel	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf64_Rel *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf64_Rel */
-
			SWAP_ADDR64(t.r_offset);
-
			SWAP_XWORD(t.r_info);
-
			/**/
-
		}
-
		/* Write an Elf64_Rel */
-
		WRITE_ADDR64(dst,t.r_offset);
-
		WRITE_XWORD(dst,t.r_info);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt32_REL_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Rel	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf32_fsize(ELF_T_REL, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf32_Rel *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf32_Rel))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf32_Rel */
-
		READ_ADDR32(s,t.r_offset);
-
		READ_WORD(s,t.r_info);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf32_Rel */
-
			SWAP_ADDR32(t.r_offset);
-
			SWAP_WORD(t.r_info);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_REL_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Rel	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf64_fsize(ELF_T_REL, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf64_Rel *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf64_Rel))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf64_Rel */
-
		READ_ADDR64(s,t.r_offset);
-
		READ_XWORD(s,t.r_info);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf64_Rel */
-
			SWAP_ADDR64(t.r_offset);
-
			SWAP_XWORD(t.r_info);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* REL */
-
#if	__FreeBSD_version >= 600102 /* RELA */
-

-
static int
-
libelf_cvt32_RELA_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Rela	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf32_Rela *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf32_Rela */
-
			SWAP_ADDR32(t.r_offset);
-
			SWAP_WORD(t.r_info);
-
			SWAP_SWORD(t.r_addend);
-
			/**/
-
		}
-
		/* Write an Elf32_Rela */
-
		WRITE_ADDR32(dst,t.r_offset);
-
		WRITE_WORD(dst,t.r_info);
-
		WRITE_SWORD(dst,t.r_addend);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_RELA_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Rela	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf64_Rela *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf64_Rela */
-
			SWAP_ADDR64(t.r_offset);
-
			SWAP_XWORD(t.r_info);
-
			SWAP_SXWORD(t.r_addend);
-
			/**/
-
		}
-
		/* Write an Elf64_Rela */
-
		WRITE_ADDR64(dst,t.r_offset);
-
		WRITE_XWORD(dst,t.r_info);
-
		WRITE_SXWORD(dst,t.r_addend);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt32_RELA_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Rela	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf32_fsize(ELF_T_RELA, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf32_Rela *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf32_Rela))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf32_Rela */
-
		READ_ADDR32(s,t.r_offset);
-
		READ_WORD(s,t.r_info);
-
		READ_SWORD(s,t.r_addend);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf32_Rela */
-
			SWAP_ADDR32(t.r_offset);
-
			SWAP_WORD(t.r_info);
-
			SWAP_SWORD(t.r_addend);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_RELA_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Rela	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf64_fsize(ELF_T_RELA, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf64_Rela *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf64_Rela))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf64_Rela */
-
		READ_ADDR64(s,t.r_offset);
-
		READ_XWORD(s,t.r_info);
-
		READ_SXWORD(s,t.r_addend);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf64_Rela */
-
			SWAP_ADDR64(t.r_offset);
-
			SWAP_XWORD(t.r_info);
-
			SWAP_SXWORD(t.r_addend);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* RELA */
-
#if	__FreeBSD_version >= 600102 /* SHDR */
-

-
static int
-
libelf_cvt32_SHDR_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Shdr	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf32_Shdr *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf32_Shdr */
-
			SWAP_WORD(t.sh_name);
-
			SWAP_WORD(t.sh_type);
-
			SWAP_WORD(t.sh_flags);
-
			SWAP_ADDR32(t.sh_addr);
-
			SWAP_OFF32(t.sh_offset);
-
			SWAP_WORD(t.sh_size);
-
			SWAP_WORD(t.sh_link);
-
			SWAP_WORD(t.sh_info);
-
			SWAP_WORD(t.sh_addralign);
-
			SWAP_WORD(t.sh_entsize);
-
			/**/
-
		}
-
		/* Write an Elf32_Shdr */
-
		WRITE_WORD(dst,t.sh_name);
-
		WRITE_WORD(dst,t.sh_type);
-
		WRITE_WORD(dst,t.sh_flags);
-
		WRITE_ADDR32(dst,t.sh_addr);
-
		WRITE_OFF32(dst,t.sh_offset);
-
		WRITE_WORD(dst,t.sh_size);
-
		WRITE_WORD(dst,t.sh_link);
-
		WRITE_WORD(dst,t.sh_info);
-
		WRITE_WORD(dst,t.sh_addralign);
-
		WRITE_WORD(dst,t.sh_entsize);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_SHDR_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Shdr	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf64_Shdr *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf64_Shdr */
-
			SWAP_WORD(t.sh_name);
-
			SWAP_WORD(t.sh_type);
-
			SWAP_XWORD(t.sh_flags);
-
			SWAP_ADDR64(t.sh_addr);
-
			SWAP_OFF64(t.sh_offset);
-
			SWAP_XWORD(t.sh_size);
-
			SWAP_WORD(t.sh_link);
-
			SWAP_WORD(t.sh_info);
-
			SWAP_XWORD(t.sh_addralign);
-
			SWAP_XWORD(t.sh_entsize);
-
			/**/
-
		}
-
		/* Write an Elf64_Shdr */
-
		WRITE_WORD(dst,t.sh_name);
-
		WRITE_WORD(dst,t.sh_type);
-
		WRITE_XWORD(dst,t.sh_flags);
-
		WRITE_ADDR64(dst,t.sh_addr);
-
		WRITE_OFF64(dst,t.sh_offset);
-
		WRITE_XWORD(dst,t.sh_size);
-
		WRITE_WORD(dst,t.sh_link);
-
		WRITE_WORD(dst,t.sh_info);
-
		WRITE_XWORD(dst,t.sh_addralign);
-
		WRITE_XWORD(dst,t.sh_entsize);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt32_SHDR_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Shdr	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf32_fsize(ELF_T_SHDR, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf32_Shdr *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf32_Shdr))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf32_Shdr */
-
		READ_WORD(s,t.sh_name);
-
		READ_WORD(s,t.sh_type);
-
		READ_WORD(s,t.sh_flags);
-
		READ_ADDR32(s,t.sh_addr);
-
		READ_OFF32(s,t.sh_offset);
-
		READ_WORD(s,t.sh_size);
-
		READ_WORD(s,t.sh_link);
-
		READ_WORD(s,t.sh_info);
-
		READ_WORD(s,t.sh_addralign);
-
		READ_WORD(s,t.sh_entsize);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf32_Shdr */
-
			SWAP_WORD(t.sh_name);
-
			SWAP_WORD(t.sh_type);
-
			SWAP_WORD(t.sh_flags);
-
			SWAP_ADDR32(t.sh_addr);
-
			SWAP_OFF32(t.sh_offset);
-
			SWAP_WORD(t.sh_size);
-
			SWAP_WORD(t.sh_link);
-
			SWAP_WORD(t.sh_info);
-
			SWAP_WORD(t.sh_addralign);
-
			SWAP_WORD(t.sh_entsize);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_SHDR_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Shdr	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf64_fsize(ELF_T_SHDR, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf64_Shdr *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf64_Shdr))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf64_Shdr */
-
		READ_WORD(s,t.sh_name);
-
		READ_WORD(s,t.sh_type);
-
		READ_XWORD(s,t.sh_flags);
-
		READ_ADDR64(s,t.sh_addr);
-
		READ_OFF64(s,t.sh_offset);
-
		READ_XWORD(s,t.sh_size);
-
		READ_WORD(s,t.sh_link);
-
		READ_WORD(s,t.sh_info);
-
		READ_XWORD(s,t.sh_addralign);
-
		READ_XWORD(s,t.sh_entsize);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf64_Shdr */
-
			SWAP_WORD(t.sh_name);
-
			SWAP_WORD(t.sh_type);
-
			SWAP_XWORD(t.sh_flags);
-
			SWAP_ADDR64(t.sh_addr);
-
			SWAP_OFF64(t.sh_offset);
-
			SWAP_XWORD(t.sh_size);
-
			SWAP_WORD(t.sh_link);
-
			SWAP_WORD(t.sh_info);
-
			SWAP_XWORD(t.sh_addralign);
-
			SWAP_XWORD(t.sh_entsize);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* SHDR */
-
#if	__FreeBSD_version >= 600102 /* SWORD */
-

-
static int
-
libelf_cvt_SWORD_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Sword t, *s = (Elf64_Sword *) (uintptr_t) src;
-
	size_t c;
-

-
	(void) dsz;
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*s));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		SWAP_SWORD(t);
-
		WRITE_SWORD(dst,t);
-
	}
-

-
	return (1);
-
}
-

-
       
-
static int
-
libelf_cvt_SWORD_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Sword t, *d = (Elf64_Sword *) (uintptr_t) dst;
-
	size_t c;
-

-
	if (dsz < count * sizeof(Elf64_Sword))
-
		return (0);
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*d));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		READ_SWORD(src,t);
-
		SWAP_SWORD(t);
-
		*d++ = t;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* SWORD */
-
#if	__FreeBSD_version >= 700009 /* SXWORD */
-

-
static int
-
libelf_cvt_SXWORD_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Sxword t, *s = (Elf64_Sxword *) (uintptr_t) src;
-
	size_t c;
-

-
	(void) dsz;
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*s));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		SWAP_SXWORD(t);
-
		WRITE_SXWORD(dst,t);
-
	}
-

-
	return (1);
-
}
-

-
       
-
static int
-
libelf_cvt_SXWORD_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Sxword t, *d = (Elf64_Sxword *) (uintptr_t) dst;
-
	size_t c;
-

-
	if (dsz < count * sizeof(Elf64_Sxword))
-
		return (0);
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*d));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		READ_SXWORD(src,t);
-
		SWAP_SXWORD(t);
-
		*d++ = t;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* SXWORD */
-
#if	__FreeBSD_version >= 700025 /* SYMINFO */
-

-
static int
-
libelf_cvt32_SYMINFO_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Syminfo	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf32_Syminfo *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf32_Syminfo */
-
			SWAP_HALF(t.si_boundto);
-
			SWAP_HALF(t.si_flags);
-
			/**/
-
		}
-
		/* Write an Elf32_Syminfo */
-
		WRITE_HALF(dst,t.si_boundto);
-
		WRITE_HALF(dst,t.si_flags);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_SYMINFO_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Syminfo	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf64_Syminfo *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf64_Syminfo */
-
			SWAP_HALF(t.si_boundto);
-
			SWAP_HALF(t.si_flags);
-
			/**/
-
		}
-
		/* Write an Elf64_Syminfo */
-
		WRITE_HALF(dst,t.si_boundto);
-
		WRITE_HALF(dst,t.si_flags);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt32_SYMINFO_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Syminfo	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf32_fsize(ELF_T_SYMINFO, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf32_Syminfo *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf32_Syminfo))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf32_Syminfo */
-
		READ_HALF(s,t.si_boundto);
-
		READ_HALF(s,t.si_flags);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf32_Syminfo */
-
			SWAP_HALF(t.si_boundto);
-
			SWAP_HALF(t.si_flags);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_SYMINFO_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Syminfo	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf64_fsize(ELF_T_SYMINFO, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf64_Syminfo *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf64_Syminfo))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf64_Syminfo */
-
		READ_HALF(s,t.si_boundto);
-
		READ_HALF(s,t.si_flags);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf64_Syminfo */
-
			SWAP_HALF(t.si_boundto);
-
			SWAP_HALF(t.si_flags);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* SYMINFO */
-
#if	__FreeBSD_version >= 600102 /* SYM */
-

-
static int
-
libelf_cvt32_SYM_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Sym	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf32_Sym *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf32_Sym */
-
			SWAP_WORD(t.st_name);
-
			SWAP_ADDR32(t.st_value);
-
			SWAP_WORD(t.st_size);
-
			SWAP_HALF(t.st_shndx);
-
			/**/
-
		}
-
		/* Write an Elf32_Sym */
-
		WRITE_WORD(dst,t.st_name);
-
		WRITE_ADDR32(dst,t.st_value);
-
		WRITE_WORD(dst,t.st_size);
-
		WRITE_BYTE(dst,t.st_info);
-
		WRITE_BYTE(dst,t.st_other);
-
		WRITE_HALF(dst,t.st_shndx);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_SYM_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Sym	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf64_Sym *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf64_Sym */
-
			SWAP_WORD(t.st_name);
-
			SWAP_HALF(t.st_shndx);
-
			SWAP_ADDR64(t.st_value);
-
			SWAP_XWORD(t.st_size);
-
			/**/
-
		}
-
		/* Write an Elf64_Sym */
-
		WRITE_WORD(dst,t.st_name);
-
		WRITE_BYTE(dst,t.st_info);
-
		WRITE_BYTE(dst,t.st_other);
-
		WRITE_HALF(dst,t.st_shndx);
-
		WRITE_ADDR64(dst,t.st_value);
-
		WRITE_XWORD(dst,t.st_size);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt32_SYM_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Sym	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf32_fsize(ELF_T_SYM, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf32_Sym *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf32_Sym))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf32_Sym */
-
		READ_WORD(s,t.st_name);
-
		READ_ADDR32(s,t.st_value);
-
		READ_WORD(s,t.st_size);
-
		READ_BYTE(s,t.st_info);
-
		READ_BYTE(s,t.st_other);
-
		READ_HALF(s,t.st_shndx);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf32_Sym */
-
			SWAP_WORD(t.st_name);
-
			SWAP_ADDR32(t.st_value);
-
			SWAP_WORD(t.st_size);
-
			SWAP_HALF(t.st_shndx);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_SYM_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Sym	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf64_fsize(ELF_T_SYM, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf64_Sym *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf64_Sym))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf64_Sym */
-
		READ_WORD(s,t.st_name);
-
		READ_BYTE(s,t.st_info);
-
		READ_BYTE(s,t.st_other);
-
		READ_HALF(s,t.st_shndx);
-
		READ_ADDR64(s,t.st_value);
-
		READ_XWORD(s,t.st_size);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf64_Sym */
-
			SWAP_WORD(t.st_name);
-
			SWAP_HALF(t.st_shndx);
-
			SWAP_ADDR64(t.st_value);
-
			SWAP_XWORD(t.st_size);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* SYM */
-
#if	__FreeBSD_version >= 700009 /* VDEF */
-

-
static int
-
libelf_cvt32_VDEF_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Verdef	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf32_Verdef *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf32_Verdef */
-
			SWAP_HALF(t.vd_version);
-
			SWAP_HALF(t.vd_flags);
-
			SWAP_HALF(t.vd_ndx);
-
			SWAP_HALF(t.vd_cnt);
-
			SWAP_WORD(t.vd_hash);
-
			SWAP_WORD(t.vd_aux);
-
			SWAP_WORD(t.vd_next);
-
			/**/
-
		}
-
		/* Write an Elf32_Verdef */
-
		WRITE_HALF(dst,t.vd_version);
-
		WRITE_HALF(dst,t.vd_flags);
-
		WRITE_HALF(dst,t.vd_ndx);
-
		WRITE_HALF(dst,t.vd_cnt);
-
		WRITE_WORD(dst,t.vd_hash);
-
		WRITE_WORD(dst,t.vd_aux);
-
		WRITE_WORD(dst,t.vd_next);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_VDEF_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Verdef	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf64_Verdef *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf64_Verdef */
-
			SWAP_HALF(t.vd_version);
-
			SWAP_HALF(t.vd_flags);
-
			SWAP_HALF(t.vd_ndx);
-
			SWAP_HALF(t.vd_cnt);
-
			SWAP_WORD(t.vd_hash);
-
			SWAP_WORD(t.vd_aux);
-
			SWAP_WORD(t.vd_next);
-
			/**/
-
		}
-
		/* Write an Elf64_Verdef */
-
		WRITE_HALF(dst,t.vd_version);
-
		WRITE_HALF(dst,t.vd_flags);
-
		WRITE_HALF(dst,t.vd_ndx);
-
		WRITE_HALF(dst,t.vd_cnt);
-
		WRITE_WORD(dst,t.vd_hash);
-
		WRITE_WORD(dst,t.vd_aux);
-
		WRITE_WORD(dst,t.vd_next);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt32_VDEF_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Verdef	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf32_fsize(ELF_T_VDEF, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf32_Verdef *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf32_Verdef))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf32_Verdef */
-
		READ_HALF(s,t.vd_version);
-
		READ_HALF(s,t.vd_flags);
-
		READ_HALF(s,t.vd_ndx);
-
		READ_HALF(s,t.vd_cnt);
-
		READ_WORD(s,t.vd_hash);
-
		READ_WORD(s,t.vd_aux);
-
		READ_WORD(s,t.vd_next);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf32_Verdef */
-
			SWAP_HALF(t.vd_version);
-
			SWAP_HALF(t.vd_flags);
-
			SWAP_HALF(t.vd_ndx);
-
			SWAP_HALF(t.vd_cnt);
-
			SWAP_WORD(t.vd_hash);
-
			SWAP_WORD(t.vd_aux);
-
			SWAP_WORD(t.vd_next);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_VDEF_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Verdef	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf64_fsize(ELF_T_VDEF, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf64_Verdef *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf64_Verdef))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf64_Verdef */
-
		READ_HALF(s,t.vd_version);
-
		READ_HALF(s,t.vd_flags);
-
		READ_HALF(s,t.vd_ndx);
-
		READ_HALF(s,t.vd_cnt);
-
		READ_WORD(s,t.vd_hash);
-
		READ_WORD(s,t.vd_aux);
-
		READ_WORD(s,t.vd_next);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf64_Verdef */
-
			SWAP_HALF(t.vd_version);
-
			SWAP_HALF(t.vd_flags);
-
			SWAP_HALF(t.vd_ndx);
-
			SWAP_HALF(t.vd_cnt);
-
			SWAP_WORD(t.vd_hash);
-
			SWAP_WORD(t.vd_aux);
-
			SWAP_WORD(t.vd_next);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* VDEF */
-
#if	__FreeBSD_version >= 700009 /* VNEED */
-

-
static int
-
libelf_cvt32_VNEED_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Verneed	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf32_Verneed *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf32_Verneed */
-
			SWAP_HALF(t.vn_version);
-
			SWAP_HALF(t.vn_cnt);
-
			SWAP_WORD(t.vn_file);
-
			SWAP_WORD(t.vn_aux);
-
			SWAP_WORD(t.vn_next);
-
			/**/
-
		}
-
		/* Write an Elf32_Verneed */
-
		WRITE_HALF(dst,t.vn_version);
-
		WRITE_HALF(dst,t.vn_cnt);
-
		WRITE_WORD(dst,t.vn_file);
-
		WRITE_WORD(dst,t.vn_aux);
-
		WRITE_WORD(dst,t.vn_next);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_VNEED_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Verneed	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf64_Verneed *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			/* Swap an Elf64_Verneed */
-
			SWAP_HALF(t.vn_version);
-
			SWAP_HALF(t.vn_cnt);
-
			SWAP_WORD(t.vn_file);
-
			SWAP_WORD(t.vn_aux);
-
			SWAP_WORD(t.vn_next);
-
			/**/
-
		}
-
		/* Write an Elf64_Verneed */
-
		WRITE_HALF(dst,t.vn_version);
-
		WRITE_HALF(dst,t.vn_cnt);
-
		WRITE_WORD(dst,t.vn_file);
-
		WRITE_WORD(dst,t.vn_aux);
-
		WRITE_WORD(dst,t.vn_next);
-
		/**/
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt32_VNEED_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf32_Verneed	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf32_fsize(ELF_T_VNEED, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf32_Verneed *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf32_Verneed))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf32_Verneed */
-
		READ_HALF(s,t.vn_version);
-
		READ_HALF(s,t.vn_cnt);
-
		READ_WORD(s,t.vn_file);
-
		READ_WORD(s,t.vn_aux);
-
		READ_WORD(s,t.vn_next);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf32_Verneed */
-
			SWAP_HALF(t.vn_version);
-
			SWAP_HALF(t.vn_cnt);
-
			SWAP_WORD(t.vn_file);
-
			SWAP_WORD(t.vn_aux);
-
			SWAP_WORD(t.vn_next);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-
       
-
static int
-
libelf_cvt64_VNEED_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Verneed	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf64_fsize(ELF_T_VNEED, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf64_Verneed *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf64_Verneed))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		/* Read an Elf64_Verneed */
-
		READ_HALF(s,t.vn_version);
-
		READ_HALF(s,t.vn_cnt);
-
		READ_WORD(s,t.vn_file);
-
		READ_WORD(s,t.vn_aux);
-
		READ_WORD(s,t.vn_next);
-
		/**/
-
		if (byteswap) {
-
			/* Swap an Elf64_Verneed */
-
			SWAP_HALF(t.vn_version);
-
			SWAP_HALF(t.vn_cnt);
-
			SWAP_WORD(t.vn_file);
-
			SWAP_WORD(t.vn_aux);
-
			SWAP_WORD(t.vn_next);
-
			/**/
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* VNEED */
-
#if	__FreeBSD_version >= 600102 /* WORD */
-

-
static int
-
libelf_cvt_WORD_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Word t, *s = (Elf64_Word *) (uintptr_t) src;
-
	size_t c;
-

-
	(void) dsz;
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*s));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		SWAP_WORD(t);
-
		WRITE_WORD(dst,t);
-
	}
-

-
	return (1);
-
}
-

-
       
-
static int
-
libelf_cvt_WORD_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Word t, *d = (Elf64_Word *) (uintptr_t) dst;
-
	size_t c;
-

-
	if (dsz < count * sizeof(Elf64_Word))
-
		return (0);
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*d));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		READ_WORD(src,t);
-
		SWAP_WORD(t);
-
		*d++ = t;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* WORD */
-
#if	__FreeBSD_version >= 700009 /* XWORD */
-

-
static int
-
libelf_cvt_XWORD_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Xword t, *s = (Elf64_Xword *) (uintptr_t) src;
-
	size_t c;
-

-
	(void) dsz;
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*s));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		SWAP_XWORD(t);
-
		WRITE_XWORD(dst,t);
-
	}
-

-
	return (1);
-
}
-

-
       
-
static int
-
libelf_cvt_XWORD_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf64_Xword t, *d = (Elf64_Xword *) (uintptr_t) dst;
-
	size_t c;
-

-
	if (dsz < count * sizeof(Elf64_Xword))
-
		return (0);
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*d));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		READ_XWORD(src,t);
-
		SWAP_XWORD(t);
-
		*d++ = t;
-
	}
-

-
	return (1);
-
}
-

-
#endif /* XWORD */
-

-

-
#if	__FreeBSD_version >= 800062
-
/*
-
 * Sections of type ELF_T_GNUHASH start with a header containing 4 32-bit
-
 * words.  Bloom filter data comes next, followed by hash buckets and the
-
 * hash chain.
-
 *
-
 * Bloom filter words are 64 bit wide on ELFCLASS64 objects and are 32 bit
-
 * wide on ELFCLASS32 objects.  The other objects in this section are 32
-
 * bits wide.
-
 *
-
 * Argument srcsz denotes the number of bytes to be converted.  In the
-
 * 32-bit case we need to translate srcsz to a count of 32-bit words.
-
 */
-

-
static int
-
libelf_cvt32_GNUHASH_tom(char *dst, size_t dsz, char *src, size_t srcsz,
-
    int byteswap)
-
{
-
	return (libelf_cvt_WORD_tom(dst, dsz, src, srcsz / sizeof(uint32_t),
-
	        byteswap));
-
}
-

-
static int
-
libelf_cvt32_GNUHASH_tof(char *dst, size_t dsz, char *src, size_t srcsz,
-
    int byteswap)
-
{
-
	return (libelf_cvt_WORD_tof(dst, dsz, src, srcsz / sizeof(uint32_t),
-
	        byteswap));
-
}
-

-
static int
-
libelf_cvt64_GNUHASH_tom(char *dst, size_t dsz, char *src, size_t srcsz,
-
    int byteswap)
-
{
-
	size_t sz;
-
	uint64_t t64, *bloom64;
-
	Elf_GNU_Hash_Header *gh;
-
	uint32_t n, nbuckets, nchains, maskwords, shift2, symndx, t32;
-
	uint32_t *buckets, *chains;
-

-
	sz = 4 * sizeof(uint32_t);	/* File header is 4 words long. */
-
	if (dsz < sizeof(Elf_GNU_Hash_Header) || srcsz < sz)
-
		return (0);
-

-
	/* Read in the section header and byteswap if needed. */
-
	READ_WORD(src, nbuckets);
-
	READ_WORD(src, symndx);
-
	READ_WORD(src, maskwords);
-
	READ_WORD(src, shift2);
-

-
	srcsz -= sz;
-

-
	if (byteswap) {
-
		SWAP_WORD(nbuckets);
-
		SWAP_WORD(symndx);
-
		SWAP_WORD(maskwords);
-
		SWAP_WORD(shift2);
-
	}
-

-
	/* Check source buffer and destination buffer sizes. */
-
	sz = nbuckets * sizeof(uint32_t) + maskwords * sizeof(uint64_t);
-
	if (srcsz < sz || dsz < sz + sizeof(Elf_GNU_Hash_Header))
-
		return (0);
-

-
	gh = (Elf_GNU_Hash_Header *) (uintptr_t) dst;
-
	gh->gh_nbuckets  = nbuckets;
-
	gh->gh_symndx    = symndx;
-
	gh->gh_maskwords = maskwords;
-
	gh->gh_shift2    = shift2;
-
	
-
	dsz -= sizeof(Elf_GNU_Hash_Header);
-
	dst += sizeof(Elf_GNU_Hash_Header);
-

-
	bloom64 = (uint64_t *) (uintptr_t) dst;
-

-
	/* Copy bloom filter data. */
-
	for (n = 0; n < maskwords; n++) {
-
		READ_XWORD(src, t64);
-
		if (byteswap)
-
			SWAP_XWORD(t64);
-
		bloom64[n] = t64;
-
	}
-

-
	/* The hash buckets follows the bloom filter. */
-
	dst += maskwords * sizeof(uint64_t);
-
	buckets = (uint32_t *) (uintptr_t) dst;
-

-
	for (n = 0; n < nbuckets; n++) {
-
		READ_WORD(src, t32);
-
		if (byteswap)
-
			SWAP_WORD(t32);
-
		buckets[n] = t32;
-
	}
-

-
	dst += nbuckets * sizeof(uint32_t);
-

-
	/* The hash chain follows the hash buckets. */
-
	dsz -= sz;
-
	srcsz -= sz;
-

-
	if (dsz < srcsz)	/* Destination lacks space. */
-
	        return (0);
-

-
	nchains = srcsz / sizeof(uint32_t);
-
	chains = (uint32_t *) (uintptr_t) dst;
-

-
	for (n = 0; n < nchains; n++) {
-
		READ_WORD(src, t32);
-
		if (byteswap)
-
			SWAP_WORD(t32);
-
		*chains++ = t32;
-
	}
-

-
	return (1);
-
}
-

-
static int
-
libelf_cvt64_GNUHASH_tof(char *dst, size_t dsz, char *src, size_t srcsz,
-
    int byteswap)
-
{
-
	uint32_t *s32;
-
	size_t sz, hdrsz;
-
	uint64_t *s64, t64;
-
	Elf_GNU_Hash_Header *gh;
-
	uint32_t maskwords, n, nbuckets, nchains, t0, t1, t2, t3, t32;
-

-
	hdrsz = 4 * sizeof(uint32_t);	/* Header is 4x32 bits. */
-
	if (dsz < hdrsz || srcsz < sizeof(Elf_GNU_Hash_Header))
-
		return (0);
-

-
	gh = (Elf_GNU_Hash_Header *) (uintptr_t) src;
-

-
	t0 = nbuckets = gh->gh_nbuckets;
-
	t1 = gh->gh_symndx;
-
	t2 = maskwords = gh->gh_maskwords;
-
	t3 = gh->gh_shift2;
-

-
	src   += sizeof(Elf_GNU_Hash_Header);
-
	srcsz -= sizeof(Elf_GNU_Hash_Header);
-
	dsz   -= hdrsz;
-

-
	sz = gh->gh_nbuckets * sizeof(uint32_t) + gh->gh_maskwords *
-
	    sizeof(uint64_t);
-

-
	if (srcsz < sz || dsz < sz)
-
		return (0);
-

-
 	/* Write out the header. */
-
	if (byteswap) {
-
		SWAP_WORD(t0);
-
		SWAP_WORD(t1);
-
		SWAP_WORD(t2);
-
		SWAP_WORD(t3);
-
	}
-

-
	WRITE_WORD(dst, t0);
-
	WRITE_WORD(dst, t1);
-
	WRITE_WORD(dst, t2);
-
	WRITE_WORD(dst, t3);
-

-
	/* Copy the bloom filter and the hash table. */
-
	s64 = (uint64_t *) (uintptr_t) src;
-
	for (n = 0; n < maskwords; n++) {
-
		t64 = *s64++;
-
		if (byteswap)
-
			SWAP_XWORD(t64);
-
		WRITE_WORD64(dst, t64);
-
	}
-

-
	s32 = (uint32_t *) s64;
-
	for (n = 0; n < nbuckets; n++) {
-
		t32 = *s32++;
-
		if (byteswap)
-
			SWAP_WORD(t32);
-
		WRITE_WORD(dst, t32);
-
	}
-

-
	srcsz -= sz;
-
	dsz   -= sz;
-

-
	/* Copy out the hash chains. */
-
	if (dsz < srcsz)
-
		return (0);
-

-
	nchains = srcsz / sizeof(uint32_t);
-
	for (n = 0; n < nchains; n++) {
-
		t32 = *s32++;
-
		if (byteswap)
-
			SWAP_WORD(t32);
-
		WRITE_WORD(dst, t32);
-
	}
-

-
	return (1);
-
}
-
#endif
-

-
/*
-
 * Elf_Note structures comprise a fixed size header followed by variable
-
 * length strings.  The fixed size header needs to be byte swapped, but
-
 * not the strings.
-
 *
-
 * Argument count denotes the total number of bytes to be converted.
-
 * The destination buffer needs to be at least count bytes in size.
-
 */
-
static int
-
libelf_cvt_NOTE_tom(char *dst, size_t dsz, char *src, size_t count, 
-
    int byteswap)
-
{
-
	uint32_t namesz, descsz, type;
-
	Elf_Note *en;
-
	size_t sz, hdrsz;
-

-
	if (dsz < count)	/* Destination buffer is too small. */
-
		return (0);
-

-
	hdrsz = 3 * sizeof(uint32_t);
-
	if (count < hdrsz)		/* Source too small. */
-
		return (0);
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count);
-
		return (1);
-
	}
-

-
	/* Process all notes in the section. */
-
	while (count > hdrsz) {
-
		/* Read the note header. */
-
		READ_WORD(src, namesz);
-
		READ_WORD(src, descsz);
-
		READ_WORD(src, type);
-

-
		/* Translate. */
-
		SWAP_WORD(namesz);
-
		SWAP_WORD(descsz);
-
		SWAP_WORD(type);
-

-
		/* Copy out the translated note header. */
-
		en = (Elf_Note *) (uintptr_t) dst;
-
		en->n_namesz = namesz;
-
		en->n_descsz = descsz;
-
		en->n_type = type;
-

-
		dsz -= sizeof(Elf_Note);
-
		dst += sizeof(Elf_Note);
-
		count -= hdrsz;
-

-
		ROUNDUP2(namesz, 4);
-
		ROUNDUP2(descsz, 4);
-

-
		sz = namesz + descsz;
-

-
		if (count < sz || dsz < sz)	/* Buffers are too small. */
-
			return (0);
-

-
		(void) memcpy(dst, src, sz);
-

-
		src += sz;
-
		dst += sz;
-

-
		count -= sz;
-
		dsz -= sz;
-
	}
-

-
	return (1);
-
}
-

-
static int
-
libelf_cvt_NOTE_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	uint32_t namesz, descsz, type;
-
	Elf_Note *en;
-
	size_t sz;
-

-
	if (dsz < count)
-
		return (0);
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count);
-
		return (1);
-
	}
-

-
	while (count > sizeof(Elf_Note)) {
-

-
		en = (Elf_Note *) (uintptr_t) src;
-
		namesz = en->n_namesz;
-
		descsz = en->n_descsz;
-
		type = en->n_type;
-

-
		SWAP_WORD(namesz);
-
		SWAP_WORD(descsz);
-
		SWAP_WORD(type);
-

-
		WRITE_WORD(dst, namesz);
-
		WRITE_WORD(dst, descsz);
-
		WRITE_WORD(dst, type);
-

-
		src += sizeof(Elf_Note);
-

-
		ROUNDUP2(namesz, 4);
-
		ROUNDUP2(descsz, 4);
-

-
		sz = namesz + descsz;
-

-
		if (count < sz)
-
			sz = count;
-

-
		(void) memcpy(dst, src, sz);
-

-
		src += sz;
-
		dst += sz;
-
		count -= sz;
-
	}
-

-
	return (1);
-
}
-

-
struct converters {
-
	int	(*tof32)(char *dst, size_t dsz, char *src, size_t cnt,
-
		    int byteswap);
-
	int	(*tom32)(char *dst, size_t dsz, char *src, size_t cnt,
-
		    int byteswap);
-
	int	(*tof64)(char *dst, size_t dsz, char *src, size_t cnt,
-
		    int byteswap);
-
	int	(*tom64)(char *dst, size_t dsz, char *src, size_t cnt,
-
		    int byteswap);
-
};
-

-

-

-
static struct converters cvt[ELF_T_NUM] = {
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_ADDR] = {
-
        .tof32 = libelf_cvt_ADDR32_tof, .tom32 = libelf_cvt_ADDR32_tom,
-
        .tof64 = libelf_cvt_ADDR64_tof, .tom64 = libelf_cvt_ADDR64_tom },
-
#endif
-
#if	__FreeBSD_version >= 700025
-
    [ELF_T_CAP] = {
-
        .tof32 = libelf_cvt32_CAP_tof, .tom32 = libelf_cvt32_CAP_tom,
-
        .tof64 = libelf_cvt64_CAP_tof, .tom64 = libelf_cvt64_CAP_tom },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_DYN] = {
-
        .tof32 = libelf_cvt32_DYN_tof, .tom32 = libelf_cvt32_DYN_tom,
-
        .tof64 = libelf_cvt64_DYN_tof, .tom64 = libelf_cvt64_DYN_tom },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_EHDR] = {
-
        .tof32 = libelf_cvt32_EHDR_tof, .tom32 = libelf_cvt32_EHDR_tom,
-
        .tof64 = libelf_cvt64_EHDR_tof, .tom64 = libelf_cvt64_EHDR_tom },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_HALF] = {
-
        .tof32 = libelf_cvt_HALF_tof, .tom32 = libelf_cvt_HALF_tom,
-
        .tof64 = libelf_cvt_HALF_tof, .tom64 = libelf_cvt_HALF_tom },
-
#endif
-
#if	__FreeBSD_version >= 700025
-
    [ELF_T_LWORD] = {
-
        .tof32 = libelf_cvt_LWORD_tof, .tom32 = libelf_cvt_LWORD_tom,
-
        .tof64 = libelf_cvt_LWORD_tof, .tom64 = libelf_cvt_LWORD_tom },
-
#endif
-
#if	__FreeBSD_version >= 700025
-
    [ELF_T_MOVE] = {
-
        .tof32 = libelf_cvt32_MOVE_tof, .tom32 = libelf_cvt32_MOVE_tom,
-
        .tof64 = libelf_cvt64_MOVE_tof, .tom64 = libelf_cvt64_MOVE_tom },
-
#endif
-
#if	__FreeBSD_version >= 700025
-
    [ELF_T_MOVEP] = {
-
        .tof32 = NULL, .tom32 = NULL,
-
        .tof64 = NULL, .tom64 = NULL },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_OFF] = {
-
        .tof32 = libelf_cvt_OFF32_tof, .tom32 = libelf_cvt_OFF32_tom,
-
        .tof64 = libelf_cvt_OFF64_tof, .tom64 = libelf_cvt_OFF64_tom },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_PHDR] = {
-
        .tof32 = libelf_cvt32_PHDR_tof, .tom32 = libelf_cvt32_PHDR_tom,
-
        .tof64 = libelf_cvt64_PHDR_tof, .tom64 = libelf_cvt64_PHDR_tom },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_REL] = {
-
        .tof32 = libelf_cvt32_REL_tof, .tom32 = libelf_cvt32_REL_tom,
-
        .tof64 = libelf_cvt64_REL_tof, .tom64 = libelf_cvt64_REL_tom },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_RELA] = {
-
        .tof32 = libelf_cvt32_RELA_tof, .tom32 = libelf_cvt32_RELA_tom,
-
        .tof64 = libelf_cvt64_RELA_tof, .tom64 = libelf_cvt64_RELA_tom },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_SHDR] = {
-
        .tof32 = libelf_cvt32_SHDR_tof, .tom32 = libelf_cvt32_SHDR_tom,
-
        .tof64 = libelf_cvt64_SHDR_tof, .tom64 = libelf_cvt64_SHDR_tom },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_SWORD] = {
-
        .tof32 = libelf_cvt_SWORD_tof, .tom32 = libelf_cvt_SWORD_tom,
-
        .tof64 = libelf_cvt_SWORD_tof, .tom64 = libelf_cvt_SWORD_tom },
-
#endif
-
#if	__FreeBSD_version >= 700009
-
    [ELF_T_SXWORD] = {
-
        .tof32 = NULL, .tom32 = NULL,
-
        .tof64 = libelf_cvt_SXWORD_tof, .tom64 = libelf_cvt_SXWORD_tom },
-
#endif
-
#if	__FreeBSD_version >= 700025
-
    [ELF_T_SYMINFO] = {
-
        .tof32 = libelf_cvt32_SYMINFO_tof, .tom32 = libelf_cvt32_SYMINFO_tom,
-
        .tof64 = libelf_cvt64_SYMINFO_tof, .tom64 = libelf_cvt64_SYMINFO_tom },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_SYM] = {
-
        .tof32 = libelf_cvt32_SYM_tof, .tom32 = libelf_cvt32_SYM_tom,
-
        .tof64 = libelf_cvt64_SYM_tof, .tom64 = libelf_cvt64_SYM_tom },
-
#endif
-
#if	__FreeBSD_version >= 700009
-
    [ELF_T_VDEF] = {
-
        .tof32 = libelf_cvt32_VDEF_tof, .tom32 = libelf_cvt32_VDEF_tom,
-
        .tof64 = libelf_cvt64_VDEF_tof, .tom64 = libelf_cvt64_VDEF_tom },
-
#endif
-
#if	__FreeBSD_version >= 700009
-
    [ELF_T_VNEED] = {
-
        .tof32 = libelf_cvt32_VNEED_tof, .tom32 = libelf_cvt32_VNEED_tom,
-
        .tof64 = libelf_cvt64_VNEED_tof, .tom64 = libelf_cvt64_VNEED_tom },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_WORD] = {
-
        .tof32 = libelf_cvt_WORD_tof, .tom32 = libelf_cvt_WORD_tom,
-
        .tof64 = libelf_cvt_WORD_tof, .tom64 = libelf_cvt_WORD_tom },
-
#endif
-
#if	__FreeBSD_version >= 700009
-
    [ELF_T_XWORD] = {
-
        .tof32 = NULL, .tom32 = NULL,
-
        .tof64 = libelf_cvt_XWORD_tof, .tom64 = libelf_cvt_XWORD_tom },
-
#endif
-

-

-
	/*
-
	 * Types that needs hand-coded converters follow.
-
	 */
-

-
	[ELF_T_BYTE] = {
-
		.tof32 = libelf_cvt_BYTE_tox,
-
		.tom32 = libelf_cvt_BYTE_tox,
-
		.tof64 = libelf_cvt_BYTE_tox,
-
		.tom64 = libelf_cvt_BYTE_tox
-
	},
-

-
#if	__FreeBSD_version >= 800062
-
	[ELF_T_GNUHASH] = {
-
		.tof32 = libelf_cvt32_GNUHASH_tof,
-
		.tom32 = libelf_cvt32_GNUHASH_tom,
-
		.tof64 = libelf_cvt64_GNUHASH_tof,
-
		.tom64 = libelf_cvt64_GNUHASH_tom
-
	},
-
#endif
-

-
	[ELF_T_NOTE] = {
-
		.tof32 = libelf_cvt_NOTE_tof,
-
		.tom32 = libelf_cvt_NOTE_tom,
-
		.tof64 = libelf_cvt_NOTE_tof,
-
		.tom64 = libelf_cvt_NOTE_tom
-
	}
-
};
-

-
int (*_libelf_get_translator(Elf_Type t, int direction, int elfclass))
-
 (char *_dst, size_t dsz, char *_src, size_t _cnt, int _byteswap)
-
{
-
	assert(elfclass == ELFCLASS32 || elfclass == ELFCLASS64);
-
	assert(direction == ELF_TOFILE || direction == ELF_TOMEMORY);
-

-
	if (t >= ELF_T_NUM ||
-
	    (elfclass != ELFCLASS32 && elfclass != ELFCLASS64) ||
-
	    (direction != ELF_TOFILE && direction != ELF_TOMEMORY))
-
		return (NULL);
-

-
	return ((elfclass == ELFCLASS32) ?
-
	    (direction == ELF_TOFILE ? cvt[t].tof32 : cvt[t].tom32) :
-
	    (direction == ELF_TOFILE ? cvt[t].tof64 : cvt[t].tom64));
-
}
modified external/libelf/libelf_convert.m4
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006-2008 Joseph Koshy
+
 * Copyright (c) 2006-2011 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,32 +25,522 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_convert.m4 219126 2011-03-01 11:47:51Z brucec $");
-

-
#include <sys/types.h>
-
#include <sys/elf32.h>
-
#include <sys/elf64.h>

#include <assert.h>
#include <libelf.h>
-
#include <osreldate.h>
#include <string.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: libelf_convert.m4 2361 2011-12-28 12:03:05Z jkoshy $");
+

/* WARNING: GENERATED FROM __file__. */

+
divert(-1)
+

+
# Generate conversion routines for converting between in-memory and
+
# file representations of Elf data structures.
+
#
+
# These conversions use the type information defined in `elf_types.m4'.
+

+
include(SRCDIR`/elf_types.m4')
+

+
# For the purposes of generating conversion code, ELF types may be
+
# classified according to the following characteristics:
+
#
+
# 1. Whether the ELF type can be directly mapped to an integral C
+
#    language type.  For example, the ELF_T_WORD type maps directly to
+
#    a 'uint32_t', but ELF_T_GNUHASH lacks a matching C type.
+
#
+
# 2. Whether the type has word size dependent variants.  For example,
+
#    ELT_T_EHDR is represented using C types Elf32_Ehdr and El64_Ehdr,
+
#    and the ELF_T_ADDR and ELF_T_OFF types have integral C types that
+
#    can be 32- or 64- bit wide.
+
#
+
# 3. Whether the ELF types has a fixed representation or not.  For
+
#    example, the ELF_T_SYM type has a fixed size file representation,
+
#    some types like ELF_T_NOTE and ELF_T_GNUHASH use a variable size
+
#    representation.
+
#
+
# We use m4 macros to generate conversion code for ELF types that have
+
# a fixed size representation.  Conversion functions for the remaining
+
# types are coded by hand.
+
#
+
#* Handling File and Memory Representations
+
#
+
# `In-memory' representations of an Elf data structure use natural
+
# alignments and native byte ordering.  This allows pointer arithmetic
+
# and casting to work as expected.  On the other hand, the `file'
+
# representation of an ELF data structure could possibly be packed
+
# tighter than its `in-memory' representation, and could be of a
+
# differing byte order.  Reading ELF objects that are members of `ar'
+
# archives present an additional complication: `ar' pads file data to
+
# even addresses, so file data structures in an archive member
+
# residing inside an `ar' archive could be at misaligned memory
+
# addresses when brought into memory.
+
#
+
# In summary, casting the `char *' pointers that point to memory
+
# representations (i.e., source pointers for the *_tof() functions and
+
# the destination pointers for the *_tom() functions), is safe, as
+
# these pointers should be correctly aligned for the memory type
+
# already.  However, pointers to file representations have to be
+
# treated as being potentially unaligned and no casting can be done.
+

+
# NOCVT(TYPE) -- Do not generate the cvt[] structure entry for TYPE
+
define(`NOCVT',`define(`NOCVT_'$1,1)')
+

+
# NOFUNC(TYPE) -- Do not generate a conversion function for TYPE
+
define(`NOFUNC',`define(`NOFUNC_'$1,1)')
+

+
# IGNORE(TYPE) -- Completely ignore the type.
+
define(`IGNORE',`NOCVT($1)NOFUNC($1)')
+

+
# Mark ELF types that should not be processed by the M4 macros below.
+

+
# Types for which we use functions with non-standard names.
+
IGNORE(`BYTE')			# Uses a wrapper around memcpy().
+
IGNORE(`NOTE')			# Not a fixed size type.
+

+
# Types for which we supply hand-coded functions.
+
NOFUNC(`GNUHASH')		# A type with complex internal structure.
+
NOFUNC(`VDEF')			# See MAKE_VERSION_CONVERTERS below.
+
NOFUNC(`VNEED')			# ..
+

+
# Unimplemented types.
+
IGNORE(`MOVEP')
+

+
# ELF types that don't exist in a 32-bit world.
+
NOFUNC(`XWORD32')
+
NOFUNC(`SXWORD32')
+

+
# `Primitive' ELF types are those that are an alias for an integral
+
# type.  As they have no internal structure, they can be copied using
+
# a `memcpy()', and byteswapped in straightforward way.
+
#
+
# Mark all ELF types that directly map to integral C types.
+
define(`PRIM_ADDR',	1)
+
define(`PRIM_BYTE',	1)
+
define(`PRIM_HALF',	1)
+
define(`PRIM_LWORD',	1)
+
define(`PRIM_OFF',	1)
+
define(`PRIM_SWORD',	1)
+
define(`PRIM_SXWORD',	1)
+
define(`PRIM_WORD',	1)
+
define(`PRIM_XWORD',	1)
+

+
# Note the primitive types that are size-dependent.
+
define(`SIZEDEP_ADDR',	1)
+
define(`SIZEDEP_OFF',	1)
+

+
# Generate conversion functions for primitive types.
+
#
+
# Macro use: MAKEPRIMFUNCS(ELFTYPE,CTYPE,TYPESIZE,SYMSIZE)
+
# `$1': Name of the ELF type.
+
# `$2': C structure name suffix.
+
# `$3': ELF class specifier for types, one of [`32', `64'].
+
# `$4': Additional ELF class specifier, one of [`', `32', `64'].
+
#
+
# Generates a pair of conversion functions.
+
define(`MAKEPRIMFUNCS',`
+
static int
+
_libelf_cvt_$1$4_tof(char *dst, size_t dsz, char *src, size_t count,
+
    int byteswap)
+
{
+
	Elf$3_$2 t, *s = (Elf$3_$2 *) (uintptr_t) src;
+
	size_t c;
+

+
	(void) dsz;
+

+
	if (!byteswap) {
+
		(void) memcpy(dst, src, count * sizeof(*s));
+
		return (1);
+
	}
+

+
	for (c = 0; c < count; c++) {
+
		t = *s++;
+
		SWAP_$1$4(t);
+
		WRITE_$1$4(dst,t);
+
	}
+

+
	return (1);
+
}
+

+
static int
+
_libelf_cvt_$1$4_tom(char *dst, size_t dsz, char *src, size_t count,
+
    int byteswap)
+
{
+
	Elf$3_$2 t, *d = (Elf$3_$2 *) (uintptr_t) dst;
+
	size_t c;
+

+
	if (dsz < count * sizeof(Elf$3_$2))
+
		return (0);
+

+
	if (!byteswap) {
+
		(void) memcpy(dst, src, count * sizeof(*d));
+
		return (1);
+
	}
+

+
	for (c = 0; c < count; c++) {
+
		READ_$1$4(src,t);
+
		SWAP_$1$4(t);
+
		*d++ = t;
+
	}
+

+
	return (1);
+
}
+
')
+

+
#
+
# Handling composite ELF types
+
#
+

+
# SWAP_FIELD(FIELDNAME,ELFTYPE) -- Generate code to swap one field.
+
define(`SWAP_FIELD',
+
  `ifdef(`SIZEDEP_'$2,
+
    `SWAP_$2'SZ()`(t.$1);
+
			',
+
    `SWAP_$2(t.$1);
+
			')')
+

+
# SWAP_MEMBERS(STRUCT) -- Iterate over a structure definition.
+
define(`SWAP_MEMBERS',
+
  `ifelse($#,1,`/**/',
+
     `SWAP_FIELD($1)SWAP_MEMBERS(shift($@))')')
+

+
# SWAP_STRUCT(CTYPE,SIZE) -- Generate code to swap an ELF structure.
+
define(`SWAP_STRUCT',
+
  `pushdef(`SZ',$2)/* Swap an Elf$2_$1 */
+
			SWAP_MEMBERS(Elf$2_$1_DEF)popdef(`SZ')')
+

+
# WRITE_FIELD(ELFTYPE,FIELDNAME) -- Generate code to write one field.
+
define(`WRITE_FIELD',
+
  `ifdef(`SIZEDEP_'$2,
+
    `WRITE_$2'SZ()`(dst,t.$1);
+
		',
+
    `WRITE_$2(dst,t.$1);
+
		')')
+

+
# WRITE_MEMBERS(ELFTYPELIST) -- Iterate over a structure definition.
+
define(`WRITE_MEMBERS',
+
  `ifelse($#,1,`/**/',
+
    `WRITE_FIELD($1)WRITE_MEMBERS(shift($@))')')
+

+
# WRITE_STRUCT(CTYPE,SIZE) -- Generate code to write out an ELF structure.
+
define(`WRITE_STRUCT',
+
  `pushdef(`SZ',$2)/* Write an Elf$2_$1 */
+
		WRITE_MEMBERS(Elf$2_$1_DEF)popdef(`SZ')')
+

+
# READ_FIELD(ELFTYPE,CTYPE) -- Generate code to read one field.
+
define(`READ_FIELD',
+
  `ifdef(`SIZEDEP_'$2,
+
    `READ_$2'SZ()`(s,t.$1);
+
		',
+
    `READ_$2(s,t.$1);
+
		')')
+

+
# READ_MEMBERS(ELFTYPELIST) -- Iterate over a structure definition.
+
define(`READ_MEMBERS',
+
  `ifelse($#,1,`/**/',
+
    `READ_FIELD($1)READ_MEMBERS(shift($@))')')
+

+
# READ_STRUCT(CTYPE,SIZE) -- Generate code to read an ELF structure.
+
define(`READ_STRUCT',
+
  `pushdef(`SZ',$2)/* Read an Elf$2_$1 */
+
		READ_MEMBERS(Elf$2_$1_DEF)popdef(`SZ')')
+

+

+
# MAKECOMPFUNCS -- Generate converters for composite ELF structures.
+
#
+
# When converting data to file representation, the source pointer will
+
# be naturally aligned for a data structure's in-memory
+
# representation.  When converting data to memory, the destination
+
# pointer will be similarly aligned.
+
#
+
# For in-place conversions, when converting to file representations,
+
# the source buffer is large enough to hold `file' data.  When
+
# converting from file to memory, we need to be careful to work
+
# `backwards', to avoid overwriting unconverted data.
+
#
+
# Macro use:
+
# `$1': Name of the ELF type.
+
# `$2': C structure name suffix.
+
# `$3': ELF class specifier, one of [`', `32', `64']
+
define(`MAKECOMPFUNCS', `ifdef(`NOFUNC_'$1$3,`',`
+
static int
+
_libelf_cvt_$1$3_tof(char *dst, size_t dsz, char *src, size_t count,
+
    int byteswap)
+
{
+
	Elf$3_$2	t, *s;
+
	size_t c;
+

+
	(void) dsz;
+

+
	s = (Elf$3_$2 *) (uintptr_t) src;
+
	for (c = 0; c < count; c++) {
+
		t = *s++;
+
		if (byteswap) {
+
			SWAP_STRUCT($2,$3)
+
		}
+
		WRITE_STRUCT($2,$3)
+
	}
+

+
	return (1);
+
}
+

+
static int
+
_libelf_cvt_$1$3_tom(char *dst, size_t dsz, char *src, size_t count,
+
    int byteswap)
+
{
+
	Elf$3_$2	 t, *d;
+
	char		*s,*s0;
+
	size_t		fsz;
+

+
	fsz = elf$3_fsize(ELF_T_$1, (size_t) 1, EV_CURRENT);
+
	d   = ((Elf$3_$2 *) (uintptr_t) dst) + (count - 1);
+
	s0  = (char *) src + (count - 1) * fsz;
+

+
	if (dsz < count * sizeof(Elf$3_$2))
+
		return (0);
+

+
	while (count--) {
+
		s = s0;
+
		READ_STRUCT($2,$3)
+
		if (byteswap) {
+
			SWAP_STRUCT($2,$3)
+
		}
+
		*d-- = t; s0 -= fsz;
+
	}
+

+
	return (1);
+
}
+
')')
+

+
# MAKE_TYPE_CONVERTER(ELFTYPE,CTYPE)
+
#
+
# Make type convertor functions from the type definition
+
# of the ELF type:
+
# - Skip convertors marked as `NOFUNC'.
+
# - Invoke `MAKEPRIMFUNCS' or `MAKECOMPFUNCS' as appropriate.
+
define(`MAKE_TYPE_CONVERTER',
+
  `ifdef(`NOFUNC_'$1,`',
+
    `ifdef(`PRIM_'$1,
+
      `ifdef(`SIZEDEP_'$1,
+
	`MAKEPRIMFUNCS($1,$2,32,32)dnl
+
	 MAKEPRIMFUNCS($1,$2,64,64)',
+
	`MAKEPRIMFUNCS($1,$2,64)')',
+
      `MAKECOMPFUNCS($1,$2,32)dnl
+
       MAKECOMPFUNCS($1,$2,64)')')')
+

+
# MAKE_TYPE_CONVERTERS(ELFTYPELIST) -- Generate conversion functions.
+
define(`MAKE_TYPE_CONVERTERS',
+
  `ifelse($#,1,`',
+
    `MAKE_TYPE_CONVERTER($1)MAKE_TYPE_CONVERTERS(shift($@))')')
+

+

+
#
+
# Macros to generate entries for the table of convertors.
+
#
+

+
# CONV(ELFTYPE,SIZE,DIRECTION)
+
#
+
# Generate the name of a convertor function.
+
define(`CONV',
+
  `ifdef(`NOFUNC_'$1$2,
+
    `.$3$2 = NULL',
+
    `ifdef(`PRIM_'$1,
+
      `ifdef(`SIZEDEP_'$1,
+
	`.$3$2 = _libelf_cvt_$1$2_$3',
+
	`.$3$2 = _libelf_cvt_$1_$3')',
+
      `.$3$2 = _libelf_cvt_$1$2_$3')')')
+

+
# CONVERTER_NAME(ELFTYPE)
+
#
+
# Generate the contents of one `struct cvt' instance.
+
define(`CONVERTER_NAME',
+
  `ifdef(`NOCVT_'$1,`',
+
    `	[ELF_T_$1] = {
+
		CONV($1,32,tof),
+
		CONV($1,32,tom),
+
		CONV($1,64,tof),
+
		CONV($1,64,tom)
+
	},
+

+
')')
+

+
# CONVERTER_NAMES(ELFTYPELIST)
+
#
+
# Generate the `struct cvt[]' array.
+
define(`CONVERTER_NAMES',
+
  `ifelse($#,1,`',
+
    `CONVERTER_NAME($1)CONVERTER_NAMES(shift($@))')')
+

+
#
+
# Handling ELF version sections.
+
#
+

+
# _FSZ(FIELD,BASETYPE) - return the file size for a field.
+
define(`_FSZ',
+
  `ifelse($2,`HALF',2,
+
     $2,`WORD',4)')
+

+
# FSZ(STRUCT) - determine the file size of a structure.
+
define(`FSZ',
+
  `ifelse($#,1,0,
+
    `eval(_FSZ($1) + FSZ(shift($@)))')')
+

+
# MAKE_VERSION_CONVERTERS(TYPE,BASE,AUX,PFX) -- Generate conversion
+
# functions for versioning structures.
+
define(`MAKE_VERSION_CONVERTERS',
+
  `MAKE_VERSION_CONVERTER($1,$2,$3,$4,32)
+
   MAKE_VERSION_CONVERTER($1,$2,$3,$4,64)')
+

+
# MAKE_VERSION_CONVERTOR(TYPE,CBASE,CAUX,PFX,SIZE) -- Generate a
+
# conversion function.
+
define(`MAKE_VERSION_CONVERTER',`
+
static int
+
_libelf_cvt_$1$5_tof(char *dst, size_t dsz, char *src, size_t count,
+
    int byteswap)
+
{
+
	Elf$5_$2	t;
+
	Elf$5_$3	a;
+
	const size_t	verfsz = FSZ(Elf$5_$2_DEF);
+
	const size_t	auxfsz = FSZ(Elf$5_$3_DEF);
+
	const size_t	vermsz = sizeof(Elf$5_$2);
+
	const size_t	auxmsz = sizeof(Elf$5_$3);
+
	char * const	dstend = dst + dsz;
+
	char * const	srcend = src + count;
+
	char		*dtmp, *dstaux, *srcaux;
+
	Elf$5_Word	aux, anext, cnt, vnext;
+

+
	for (dtmp = dst, vnext = ~0;
+
	     vnext != 0 && dtmp + verfsz <= dstend && src + vermsz <= srcend;
+
	     dtmp += vnext, src += vnext) {
+

+
		/* Read in an Elf$5_$2 structure. */
+
		t = *((Elf$5_$2 *) (uintptr_t) src);
+

+
		aux = t.$4_aux;
+
		cnt = t.$4_cnt;
+
		vnext = t.$4_next;
+

+
		if (byteswap) {
+
			SWAP_STRUCT($2, $5)
+
		}
+

+
		dst = dtmp;
+
		WRITE_STRUCT($2, $5)
+

+
		if (aux < verfsz)
+
			return (0);
+

+
		/* Process AUX entries. */
+
		for (anext = ~0, dstaux = dtmp + aux, srcaux = src + aux;
+
		     cnt != 0 && anext != 0 && dstaux + auxfsz <= dstend &&
+
			srcaux + auxmsz <= srcend;
+
		     dstaux += anext, srcaux += anext, cnt--) {
+

+
			/* Read in an Elf$5_$3 structure. */
+
			a = *((Elf$5_$3 *) (uintptr_t) srcaux);
+
			anext = a.$4a_next;
+

+
			if (byteswap) {
+
				pushdef(`t',`a')SWAP_STRUCT($3, $5)popdef(`t')
+
			}
+

+
			dst = dstaux;
+
			pushdef(`t',`a')WRITE_STRUCT($3, $5)popdef(`t')
+
		}
+

+
		if (anext || cnt)
+
			return (0);
+
	}
+

+
	if (vnext)
+
		return (0);
+

+
	return (1);
+
}
+

+
static int
+
_libelf_cvt_$1$5_tom(char *dst, size_t dsz, char *src, size_t count,
+
    int byteswap)
+
{
+
	Elf$5_$2	t, *dp;
+
	Elf$5_$3	a, *ap;
+
	const size_t	verfsz = FSZ(Elf$5_$2_DEF);
+
	const size_t	auxfsz = FSZ(Elf$5_$3_DEF);
+
	const size_t	vermsz = sizeof(Elf$5_$2);
+
	const size_t	auxmsz = sizeof(Elf$5_$3);
+
	char * const	dstend = dst + dsz;
+
	char * const	srcend = src + count;
+
	char		*dstaux, *s, *srcaux, *stmp;
+
	Elf$5_Word	aux, anext, cnt, vnext;
+

+
	for (stmp = src, vnext = ~0;
+
	     vnext != 0 && stmp + verfsz <= srcend && dst + vermsz <= dstend;
+
	     stmp += vnext, dst += vnext) {
+

+
		/* Read in a $1 structure. */
+
		s = stmp;
+
		READ_STRUCT($2, $5)
+
		if (byteswap) {
+
			SWAP_STRUCT($2, $5)
+
		}
+

+
		dp = (Elf$5_$2 *) (uintptr_t) dst;
+
		*dp = t;
+

+
		aux = t.$4_aux;
+
		cnt = t.$4_cnt;
+
		vnext = t.$4_next;
+

+
		if (aux < vermsz)
+
			return (0);
+

+
		/* Process AUX entries. */
+
		for (anext = ~0, dstaux = dst + aux, srcaux = stmp + aux;
+
		     cnt != 0 && anext != 0 && dstaux + auxmsz <= dstend &&
+
			srcaux + auxfsz <= srcend;
+
		     dstaux += anext, srcaux += anext, cnt--) {
+

+
			s = srcaux;
+
			pushdef(`t',`a')READ_STRUCT($3, $5)popdef(`t')
+

+
			if (byteswap) {
+
				pushdef(`t',`a')SWAP_STRUCT($3, $5)popdef(`t')
+
			}
+

+
			anext = a.$4a_next;
+

+
			ap = ((Elf$5_$3 *) (uintptr_t) dstaux);
+
			*ap = a;
+
		}
+

+
		if (anext || cnt)
+
			return (0);
+
	}
+

+
	if (vnext)
+
		return (0);
+

+
	return (1);
+
}')
+

+
divert(0)
+

/*
-
 * Macros to swap various integral quantities.
+
 * C macros to byte swap integral quantities.
 */

-
#define	SWAP_HALF(X) 	do {						\
+
#define	SWAP_BYTE(X)	do { (void) (X); } while (0)
+
#define	SWAP_IDENT(X)	do { (void) (X); } while (0)
+
#define	SWAP_HALF(X)	do {						\
		uint16_t _x = (uint16_t) (X);				\
		uint16_t _t = _x & 0xFF;				\
		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
		(X) = _t;						\
	} while (0)
-
#define	SWAP_WORD(X) 	do {						\
+
#define	SWAP_WORD(X)	do {						\
		uint32_t _x = (uint32_t) (X);				\
		uint32_t _t = _x & 0xFF;				\
		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
@@ -80,9 +570,12 @@ __FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_convert.m4 219126 2011-03-01 11
#define	SWAP_XWORD(X)	SWAP_WORD64(X)

/*
-
 * Write out various integral values.  The destination pointer could
-
 * be unaligned.  Values are written out in native byte order.  The
-
 * destination pointer is incremented after the write.
+
 * C macros to write out various integral values.
+
 *
+
 * Note:
+
 * - The destination pointer could be unaligned.
+
 * - Values are written out in native byte order.
+
 * - The destination pointer is incremented after the write.
 */
#define	WRITE_BYTE(P,X) do {						\
		char *const _p = (char *) (P);	\
@@ -95,7 +588,7 @@ __FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_convert.m4 219126 2011-03-01 11
		const char *const _q = (char *) &_t;	\
		_p[0]		= _q[0];				\
		_p[1]		= _q[1];				\
-
		(P) 		= _p + 2;				\
+
		(P)		= _p + 2;				\
	} while (0)
#define	WRITE_WORD(P,X)	do {						\
		uint32_t _t	= (X);					\
@@ -135,9 +628,12 @@ __FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_convert.m4 219126 2011-03-01 11
	} while (0)

/*
-
 * Read in various integral values.  The source pointer could be
-
 * unaligned.  Values are read in native byte order.  The source
-
 * pointer is incremented appropriately.
+
 * C macros to read in various integral values.
+
 *
+
 * Note:
+
 * - The source pointer could be unaligned.
+
 * - Values are read in native byte order.
+
 * - The source pointer is incremented appropriately.
 */

#define	READ_BYTE(P,X)	do {						\
@@ -199,294 +695,11 @@ __FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_convert.m4 219126 2011-03-01 11

#define	ROUNDUP2(V,N)	(V) = ((((V) + (N) - 1)) & ~((N) - 1))

-
divert(-1)
-

-
/*
-
 * Generate conversion routines for converting between in-memory and
-
 * file representations of Elf data structures.
-
 *
-
 * `In-memory' representations of an Elf data structure use natural
-
 * alignments and native byte ordering.  This allows arithmetic and
-
 * casting to work as expected.  On the other hand the `file'
-
 * representation of an ELF data structure could be packed tighter
-
 * than its `in-memory' representation, and could be of a differing
-
 * byte order.  An additional complication is that `ar' only pads data
-
 * to even addresses and so ELF archive member data being read from
-
 * inside an `ar' archive could end up at misaligned memory addresses.
-
 *
-
 * Consequently, casting the `char *' pointers that point to memory
-
 * representations (i.e., source pointers for the *_tof() functions
-
 * and the destination pointers for the *_tom() functions), is safe,
-
 * as these pointers should be correctly aligned for the memory type
-
 * already.  However, pointers to file representations have to be
-
 * treated as being potentially unaligned and no casting can be done.
-
 */
-

-
include(SRCDIR`/elf_types.m4')
-

-
/*
-
 * `IGNORE'_* flags turn off generation of template code.
-
 */
-

-
define(`IGNORE',
-
  `define(IGNORE_$1`'32,	1)
-
   define(IGNORE_$1`'64,	1)')
-

-
IGNORE(MOVEP)
-
IGNORE(NOTE)
-
IGNORE(GNUHASH)
-

-
define(IGNORE_BYTE,		1)	/* 'lator, leave 'em bytes alone */
-
define(IGNORE_GNUHASH,		1)
-
define(IGNORE_NOTE,		1)
-
define(IGNORE_SXWORD32,		1)
-
define(IGNORE_XWORD32,		1)
-

-
/*
-
 * `BASE'_XXX flags cause class agnostic template functions
-
 * to be generated.
-
 */
-

-
define(`BASE_BYTE',	1)
-
define(`BASE_HALF',	1)
-
define(`BASE_NOTE',	1)
-
define(`BASE_WORD',	1)
-
define(`BASE_LWORD',	1)
-
define(`BASE_SWORD',	1)
-
define(`BASE_XWORD',	1)
-
define(`BASE_SXWORD',	1)
-

-
/*
-
 * `SIZEDEP'_XXX flags cause 32/64 bit variants to be generated
-
 * for each primitive type.
-
 */
-

-
define(`SIZEDEP_ADDR',	1)
-
define(`SIZEDEP_OFF',	1)
-

-
/*
-
 * `Primitive' ELF types are those that are an alias for an integral
-
 * type.  They have no internal structure. These can be copied using
-
 * a `memcpy()', and byteswapped in straightforward way.
-
 *
-
 * Macro use:
-
 * `$1': Name of the ELF type.
-
 * `$2': C structure name suffix
-
 * `$3': ELF class specifier for symbols, one of [`', `32', `64']
-
 * `$4': ELF class specifier for types, one of [`32', `64']
-
 */
-
define(`MAKEPRIM_TO_F',`
-
static int
-
libelf_cvt_$1$3_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf$4_$2 t, *s = (Elf$4_$2 *) (uintptr_t) src;
-
	size_t c;
-

-
	(void) dsz;
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*s));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		SWAP_$1$3(t);
-
		WRITE_$1$3(dst,t);
-
	}
-

-
	return (1);
-
}
-
')
-

-
define(`MAKEPRIM_TO_M',`
-
static int
-
libelf_cvt_$1$3_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf$4_$2 t, *d = (Elf$4_$2 *) (uintptr_t) dst;
-
	size_t c;
-

-
	if (dsz < count * sizeof(Elf$4_$2))
-
		return (0);
-

-
	if (!byteswap) {
-
		(void) memcpy(dst, src, count * sizeof(*d));
-
		return (1);
-
	}
-

-
	for (c = 0; c < count; c++) {
-
		READ_$1$3(src,t);
-
		SWAP_$1$3(t);
-
		*d++ = t;
-
	}
-

-
	return (1);
-
}
-
')
-

-
define(`SWAP_FIELD',
-
  `ifdef(`IGNORE_'$2,`',
-
    `ifelse(BASE_$2,1,
-
      `SWAP_$2(t.$1);
-
			',
-
      `ifelse($2,BYTE,`',
-
        `ifelse($2,IDENT,`',
-
          `SWAP_$2'SZ()`(t.$1);
-
			')')')')')
-
define(`SWAP_MEMBERS',
-
  `ifelse($#,1,`/**/',
-
     `SWAP_FIELD($1)SWAP_MEMBERS(shift($@))')')
-

-
define(`SWAP_STRUCT',
-
  `pushdef(`SZ',$2)/* Swap an Elf$2_$1 */
-
			SWAP_MEMBERS(Elf$2_$1_DEF)popdef(`SZ')')
-

-
define(`WRITE_FIELD',
-
  `ifelse(BASE_$2,1,
-
    `WRITE_$2(dst,t.$1);
-
		',
-
    `ifelse($2,IDENT,
-
      `WRITE_$2(dst,t.$1);
-
		',
-
      `WRITE_$2'SZ()`(dst,t.$1);
-
		')')')
-
define(`WRITE_MEMBERS',
-
  `ifelse($#,1,`/**/',
-
    `WRITE_FIELD($1)WRITE_MEMBERS(shift($@))')')
-

-
define(`WRITE_STRUCT',
-
  `pushdef(`SZ',$2)/* Write an Elf$2_$1 */
-
		WRITE_MEMBERS(Elf$2_$1_DEF)popdef(`SZ')')
-

-
define(`READ_FIELD',
-
  `ifelse(BASE_$2,1,
-
    `READ_$2(s,t.$1);
-
		',
-
    `ifelse($2,IDENT,
-
      `READ_$2(s,t.$1);
-
		',
-
      `READ_$2'SZ()`(s,t.$1);
-
		')')')
-

-
define(`READ_MEMBERS',
-
  `ifelse($#,1,`/**/',
-
    `READ_FIELD($1)READ_MEMBERS(shift($@))')')
-

-
define(`READ_STRUCT',
-
  `pushdef(`SZ',$2)/* Read an Elf$2_$1 */
-
		READ_MEMBERS(Elf$2_$1_DEF)popdef(`SZ')')
-

-
/*
-
 * Converters for non-integral ELF data structures.
-
 *
-
 * When converting data to file representation, the source pointer
-
 * will be naturally aligned for a data structure's in-memory
-
 * representation.  When converting data to memory, the destination
-
 * pointer will be similarly aligned.
-
 *
-
 * For in-place conversions, when converting to file representations,
-
 * the source buffer is large enough to hold `file' data.  When
-
 * converting from file to memory, we need to be careful to work
-
 * `backwards', to avoid overwriting unconverted data.
-
 *
-
 * Macro use:
-
 * `$1': Name of the ELF type.
-
 * `$2': C structure name suffix.
-
 * `$3': ELF class specifier, one of [`', `32', `64']
-
 */
-

-
define(`MAKE_TO_F',
-
  `ifdef(`IGNORE_'$1$3,`',`
-
static int
-
libelf_cvt$3_$1_tof(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf$3_$2	t, *s;
-
	size_t c;
-

-
	(void) dsz;
-

-
	s = (Elf$3_$2 *) (uintptr_t) src;
-
	for (c = 0; c < count; c++) {
-
		t = *s++;
-
		if (byteswap) {
-
			SWAP_STRUCT($2,$3)
-
		}
-
		WRITE_STRUCT($2,$3)
-
	}
-

-
	return (1);
-
}
-
')')
-

-
define(`MAKE_TO_M',
-
  `ifdef(`IGNORE_'$1$3,`',`
-
static int
-
libelf_cvt$3_$1_tom(char *dst, size_t dsz, char *src, size_t count,
-
    int byteswap)
-
{
-
	Elf$3_$2	 t, *d;
-
	char		*s,*s0;
-
	size_t		fsz;
-

-
	fsz = elf$3_fsize(ELF_T_$1, (size_t) 1, EV_CURRENT);
-
	d   = ((Elf$3_$2 *) (uintptr_t) dst) + (count - 1);
-
	s0  = (char *) src + (count - 1) * fsz;
-

-
	if (dsz < count * sizeof(Elf$3_$2))
-
		return (0);
-

-
	while (count--) {
-
		s = s0;
-
		READ_STRUCT($2,$3)
-
		if (byteswap) {
-
			SWAP_STRUCT($2,$3)
-
		}
-
		*d-- = t; s0 -= fsz;
-
	}
-

-
	return (1);
-
}
-
')')
-

-
/*
-
 * Make type convertor functions from the type definition
-
 * of the ELF type:
-
 * - if the type is a base (i.e., `primitive') type:
-
 *   - if it is marked as to be ignored (i.e., `IGNORE_'TYPE)
-
 *     is defined, we skip the code generation step.
-
 *   - if the type is declared as `SIZEDEP', then 32 and 64 bit
-
 *     variants of the conversion functions are generated.
-
 *   - otherwise a 32 bit variant is generated.
-
 * - if the type is a structure type, we generate 32 and 64 bit
-
 *   variants of the conversion functions.
-
 */
-

-
define(`MAKE_TYPE_CONVERTER',
-
  `#if	__FreeBSD_version >= $3 /* $1 */
-
ifdef(`BASE'_$1,
-
    `ifdef(`IGNORE_'$1,`',
-
      `MAKEPRIM_TO_F($1,$2,`',64)
-
       MAKEPRIM_TO_M($1,$2,`',64)')',
-
    `ifdef(`SIZEDEP_'$1,
-
      `MAKEPRIM_TO_F($1,$2,32,32)dnl
-
       MAKEPRIM_TO_M($1,$2,32,32)dnl
-
       MAKEPRIM_TO_F($1,$2,64,64)dnl
-
       MAKEPRIM_TO_M($1,$2,64,64)',
-
      `MAKE_TO_F($1,$2,32)dnl
-
       MAKE_TO_F($1,$2,64)dnl
-
       MAKE_TO_M($1,$2,32)dnl
-
       MAKE_TO_M($1,$2,64)')')
-
#endif /* $1 */
-
')
-

-
define(`MAKE_TYPE_CONVERTERS',
-
  `ifelse($#,1,`',
-
    `MAKE_TYPE_CONVERTER($1)MAKE_TYPE_CONVERTERS(shift($@))')')
-

-
divert(0)
+
/*[*/
+
MAKE_TYPE_CONVERTERS(ELF_TYPE_LIST)
+
MAKE_VERSION_CONVERTERS(VDEF,Verdef,Verdaux,vd)
+
MAKE_VERSION_CONVERTERS(VNEED,Verneed,Vernaux,vn)
+
/*]*/

/*
 * Sections of type ELF_T_BYTE are never byteswapped, consequently a
@@ -494,7 +707,7 @@ divert(0)
 */

static int
-
libelf_cvt_BYTE_tox(char *dst, size_t dsz, char *src, size_t count,
+
_libelf_cvt_BYTE_tox(char *dst, size_t dsz, char *src, size_t count,
    int byteswap)
{
	(void) byteswap;
@@ -505,9 +718,6 @@ libelf_cvt_BYTE_tox(char *dst, size_t dsz, char *src, size_t count,
	return (1);
}

-
MAKE_TYPE_CONVERTERS(ELF_TYPE_LIST)
-

-
#if	__FreeBSD_version >= 800062
/*
 * Sections of type ELF_T_GNUHASH start with a header containing 4 32-bit
 * words.  Bloom filter data comes next, followed by hash buckets and the
@@ -522,23 +732,23 @@ MAKE_TYPE_CONVERTERS(ELF_TYPE_LIST)
 */

static int
-
libelf_cvt32_GNUHASH_tom(char *dst, size_t dsz, char *src, size_t srcsz,
+
_libelf_cvt_GNUHASH32_tom(char *dst, size_t dsz, char *src, size_t srcsz,
    int byteswap)
{
-
	return (libelf_cvt_WORD_tom(dst, dsz, src, srcsz / sizeof(uint32_t),
-
	        byteswap));
+
	return (_libelf_cvt_WORD_tom(dst, dsz, src, srcsz / sizeof(uint32_t),
+
		byteswap));
}

static int
-
libelf_cvt32_GNUHASH_tof(char *dst, size_t dsz, char *src, size_t srcsz,
+
_libelf_cvt_GNUHASH32_tof(char *dst, size_t dsz, char *src, size_t srcsz,
    int byteswap)
{
-
	return (libelf_cvt_WORD_tof(dst, dsz, src, srcsz / sizeof(uint32_t),
-
	        byteswap));
+
	return (_libelf_cvt_WORD_tof(dst, dsz, src, srcsz / sizeof(uint32_t),
+
		byteswap));
}

static int
-
libelf_cvt64_GNUHASH_tom(char *dst, size_t dsz, char *src, size_t srcsz,
+
_libelf_cvt_GNUHASH64_tom(char *dst, size_t dsz, char *src, size_t srcsz,
    int byteswap)
{
	size_t sz;
@@ -576,7 +786,7 @@ libelf_cvt64_GNUHASH_tom(char *dst, size_t dsz, char *src, size_t srcsz,
	gh->gh_symndx    = symndx;
	gh->gh_maskwords = maskwords;
	gh->gh_shift2    = shift2;
-
	
+

	dsz -= sizeof(Elf_GNU_Hash_Header);
	dst += sizeof(Elf_GNU_Hash_Header);

@@ -608,7 +818,7 @@ libelf_cvt64_GNUHASH_tom(char *dst, size_t dsz, char *src, size_t srcsz,
	srcsz -= sz;

	if (dsz < srcsz)	/* Destination lacks space. */
-
	        return (0);
+
		return (0);

	nchains = srcsz / sizeof(uint32_t);
	chains = (uint32_t *) (uintptr_t) dst;
@@ -624,7 +834,7 @@ libelf_cvt64_GNUHASH_tom(char *dst, size_t dsz, char *src, size_t srcsz,
}

static int
-
libelf_cvt64_GNUHASH_tof(char *dst, size_t dsz, char *src, size_t srcsz,
+
_libelf_cvt_GNUHASH64_tof(char *dst, size_t dsz, char *src, size_t srcsz,
    int byteswap)
{
	uint32_t *s32;
@@ -654,7 +864,7 @@ libelf_cvt64_GNUHASH_tof(char *dst, size_t dsz, char *src, size_t srcsz,
	if (srcsz < sz || dsz < sz)
		return (0);

-
 	/* Write out the header. */
+
	/* Write out the header. */
	if (byteswap) {
		SWAP_WORD(t0);
		SWAP_WORD(t1);
@@ -701,7 +911,6 @@ libelf_cvt64_GNUHASH_tof(char *dst, size_t dsz, char *src, size_t srcsz,

	return (1);
}
-
#endif

/*
 * Elf_Note structures comprise a fixed size header followed by variable
@@ -712,7 +921,7 @@ libelf_cvt64_GNUHASH_tof(char *dst, size_t dsz, char *src, size_t srcsz,
 * The destination buffer needs to be at least `count' bytes in size.
 */
static int
-
libelf_cvt_NOTE_tom(char *dst, size_t dsz, char *src, size_t count, 
+
_libelf_cvt_NOTE_tom(char *dst, size_t dsz, char *src, size_t count,
    int byteswap)
{
	uint32_t namesz, descsz, type;
@@ -774,7 +983,7 @@ libelf_cvt_NOTE_tom(char *dst, size_t dsz, char *src, size_t count,
}

static int
-
libelf_cvt_NOTE_tof(char *dst, size_t dsz, char *src, size_t count,
+
_libelf_cvt_NOTE_tof(char *dst, size_t dsz, char *src, size_t count,
    int byteswap)
{
	uint32_t namesz, descsz, type;
@@ -835,60 +1044,28 @@ struct converters {
		    int byteswap);
};

-
divert(-1)
-
define(`CONV',
-
  `ifdef(`IGNORE_'$1$2,
-
    `.$3$2 = NULL',
-
    `ifdef(`BASE_'$1,
-
      `.$3$2 = libelf_cvt_$1_$3',
-
      `ifdef(`SIZEDEP_'$1,
-
        `.$3$2 = libelf_cvt_$1$2_$3',
-
        `.$3$2 = libelf_cvt$2_$1_$3')')')')
-

-
define(`CONVERTER_NAME',
-
  `ifdef(`IGNORE_'$1,`',
-
    `#if	__FreeBSD_version >= $3
-
    [ELF_T_$1] = {
-
        CONV($1,32,tof), CONV($1,32,tom),
-
        CONV($1,64,tof), CONV($1,64,tom) },
-
#endif
-
')')
-

-
define(`CONVERTER_NAMES',
-
  `ifelse($#,1,`',
-
    `CONVERTER_NAME($1)CONVERTER_NAMES(shift($@))')')
-

-
undefine(`IGNORE_BYTE32', `IGNORE_BYTE64')
-
divert(0)

static struct converters cvt[ELF_T_NUM] = {
+
	/*[*/
CONVERTER_NAMES(ELF_TYPE_LIST)
+
	/*]*/

	/*
-
	 * Types that needs hand-coded converters follow.
+
	 * Types that need hand-coded converters follow.
	 */

	[ELF_T_BYTE] = {
-
		.tof32 = libelf_cvt_BYTE_tox,
-
		.tom32 = libelf_cvt_BYTE_tox,
-
		.tof64 = libelf_cvt_BYTE_tox,
-
		.tom64 = libelf_cvt_BYTE_tox
-
	},
-

-
#if	__FreeBSD_version >= 800062
-
	[ELF_T_GNUHASH] = {
-
		.tof32 = libelf_cvt32_GNUHASH_tof,
-
		.tom32 = libelf_cvt32_GNUHASH_tom,
-
		.tof64 = libelf_cvt64_GNUHASH_tof,
-
		.tom64 = libelf_cvt64_GNUHASH_tom
+
		.tof32 = _libelf_cvt_BYTE_tox,
+
		.tom32 = _libelf_cvt_BYTE_tox,
+
		.tof64 = _libelf_cvt_BYTE_tox,
+
		.tom64 = _libelf_cvt_BYTE_tox
	},
-
#endif

	[ELF_T_NOTE] = {
-
		.tof32 = libelf_cvt_NOTE_tof,
-
		.tom32 = libelf_cvt_NOTE_tom,
-
		.tof64 = libelf_cvt_NOTE_tof,
-
		.tom64 = libelf_cvt_NOTE_tom
+
		.tof32 = _libelf_cvt_NOTE_tof,
+
		.tom32 = _libelf_cvt_NOTE_tom,
+
		.tof64 = _libelf_cvt_NOTE_tof,
+
		.tom64 = _libelf_cvt_NOTE_tom
	}
};

modified external/libelf/libelf_data.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,13 +25,13 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: head/lib/libelf/libelf_data.c 233524 2012-03-26 21:31:57Z gonzo $");

#include <libelf.h>
-
#include <osreldate.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: libelf_data.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

int
_libelf_xlate_shtype(uint32_t sht)
{
@@ -42,10 +42,10 @@ _libelf_xlate_shtype(uint32_t sht)
		return (ELF_T_SYM);
	case SHT_FINI_ARRAY:
		return (ELF_T_ADDR);
-
#if	__FreeBSD_version >= 800062
	case SHT_GNU_HASH:
		return (ELF_T_GNUHASH);
-
#endif
+
	case SHT_GNU_LIBLIST:
+
		return (ELF_T_WORD);
	case SHT_GROUP:
		return (ELF_T_WORD);
	case SHT_HASH:
@@ -70,28 +70,18 @@ _libelf_xlate_shtype(uint32_t sht)
		return (ELF_T_SYM);
	case SHT_SYMTAB_SHNDX:
		return (ELF_T_WORD);
-
#if	__FreeBSD_version >= 700025
-
	case SHT_GNU_verdef:	/* == SHT_SUNW_verdef */
-
		return (ELF_T_VDEF);
-
	case SHT_GNU_verneed:	/* == SHT_SUNW_verneed */
-
		return (ELF_T_VNEED);
-
	case SHT_GNU_versym:	/* == SHT_SUNW_versym */
-
		return (ELF_T_HALF);
+
	case SHT_SUNW_dof:
+
		return (ELF_T_BYTE);
	case SHT_SUNW_move:
		return (ELF_T_MOVE);
	case SHT_SUNW_syminfo:
		return (ELF_T_SYMINFO);
-
	case SHT_SUNW_dof:
-
		return (ELF_T_BYTE);
-
#endif
-
	case SHT_MIPS_DWARF:
-
		/* FALLTHROUGH */
-
	case SHT_MIPS_REGINFO:
-
		/* FALLTHROUGH */
-
	case SHT_MIPS_OPTIONS:
-
		/* FALLTHROUGH */
-
	case SHT_AMD64_UNWIND:	/* == SHT_IA_64_UNWIND */
-
		return (ELF_T_BYTE);
+
	case SHT_SUNW_verdef:	/* == SHT_GNU_verdef */
+
		return (ELF_T_VDEF);
+
	case SHT_SUNW_verneed:	/* == SHT_GNU_verneed */
+
		return (ELF_T_VNEED);
+
	case SHT_SUNW_versym:	/* == SHT_GNU_versym */
+
		return (ELF_T_HALF);
	default:
		return (-1);
	}
modified external/libelf/libelf_ehdr.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -22,12 +22,9 @@
 * 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: releng/9.1/lib/libelf/libelf_ehdr.c 210338 2010-07-21 10:25:02Z kaiw $
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_ehdr.c 210338 2010-07-21 10:25:02Z kaiw $");

#include <assert.h>
#include <gelf.h>
@@ -36,6 +33,8 @@ __FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_ehdr.c 210338 2010-07-21 10:25:

#include "_libelf.h"

+
ELFTC_VCSID("$Id: libelf_ehdr.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

/*
 * Retrieve counts for sections, phdrs and the section string table index
 * from section header #0 of the ELF object.
modified external/libelf/libelf_extended.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,13 +25,14 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_extended.c 165535 2006-12-25 02:22:22Z jkoshy $");

#include <assert.h>
#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: libelf_extended.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

/*
 * Retrieve section #0, allocating a new section if needed.
 */
@@ -133,4 +134,3 @@ _libelf_setphnum(Elf *e, void *eh, int ec, size_t phnum)

	return (1);
}
-

deleted external/libelf/libelf_fsize.c
@@ -1,139 +0,0 @@
-
/*-
-
 * Copyright (c) 2006 Joseph Koshy
-
 * 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.
-
 *
-
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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: releng/9.1/lib/libelf/libelf_fsize.m4 210340 2010-07-21 10:39:29Z kaiw $
-
 */
-

-
#include <libelf.h>
-
#include <osreldate.h>
-

-
#include "_libelf.h"
-

-
/*
-
 * Create an array of file sizes from the elf_type definitions
-
 */
-

-

-

-
struct fsize {
-
	size_t fsz32;
-
	size_t fsz64;
-
};
-

-
static struct fsize fsize[ELF_T_NUM] = {
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_ADDR] = { .fsz32 = sizeof(Elf32_Addr), .fsz64 = sizeof(Elf64_Addr) },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_BYTE] = { .fsz32 = 1, .fsz64 = 1 },
-
#endif
-
#if	__FreeBSD_version >= 700025
-
    [ELF_T_CAP] = { .fsz32 = sizeof(Elf32_Word)+sizeof(Elf32_Word)+0, .fsz64 = sizeof(Elf64_Xword)+sizeof(Elf64_Xword)+0 },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_DYN] = { .fsz32 = sizeof(Elf32_Sword)+sizeof(Elf32_Word)+0, .fsz64 = sizeof(Elf64_Sxword)+sizeof(Elf64_Xword)+0 },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_EHDR] = { .fsz32 = EI_NIDENT+sizeof(Elf32_Half)+sizeof(Elf32_Half)+sizeof(Elf32_Word)+sizeof(Elf32_Addr)+sizeof(Elf32_Off)+sizeof(Elf32_Off)+sizeof(Elf32_Word)+sizeof(Elf32_Half)+sizeof(Elf32_Half)+sizeof(Elf32_Half)+sizeof(Elf32_Half)+sizeof(Elf32_Half)+sizeof(Elf32_Half)+0, .fsz64 = EI_NIDENT+sizeof(Elf64_Half)+sizeof(Elf64_Half)+sizeof(Elf64_Word)+sizeof(Elf64_Addr)+sizeof(Elf64_Off)+sizeof(Elf64_Off)+sizeof(Elf64_Word)+sizeof(Elf64_Half)+sizeof(Elf64_Half)+sizeof(Elf64_Half)+sizeof(Elf64_Half)+sizeof(Elf64_Half)+sizeof(Elf64_Half)+0 },
-
#endif
-
#if	__FreeBSD_version >= 800062
-
    [ELF_T_GNUHASH] = { .fsz32 = 1, .fsz64 = 1 },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_HALF] = { .fsz32 = sizeof(Elf32_Half), .fsz64 = sizeof(Elf64_Half) },
-
#endif
-
#if	__FreeBSD_version >= 700025
-
    [ELF_T_LWORD] = { .fsz32 = sizeof(Elf32_Lword), .fsz64 = sizeof(Elf64_Lword) },
-
#endif
-
#if	__FreeBSD_version >= 700025
-
    [ELF_T_MOVE] = { .fsz32 = sizeof(Elf32_Lword)+sizeof(Elf32_Word)+sizeof(Elf32_Word)+sizeof(Elf32_Half)+sizeof(Elf32_Half)+0, .fsz64 = sizeof(Elf64_Lword)+sizeof(Elf64_Xword)+sizeof(Elf64_Xword)+sizeof(Elf64_Half)+sizeof(Elf64_Half)+0 },
-
#endif
-
#if	__FreeBSD_version >= 700025
-
    [ELF_T_MOVEP] = { .fsz32 = 0, .fsz64 = 0 },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_NOTE] = { .fsz32 = 1, .fsz64 = 1 },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_OFF] = { .fsz32 = sizeof(Elf32_Off), .fsz64 = sizeof(Elf64_Off) },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_PHDR] = { .fsz32 = sizeof(Elf32_Word)+sizeof(Elf32_Off)+sizeof(Elf32_Addr)+sizeof(Elf32_Addr)+sizeof(Elf32_Word)+sizeof(Elf32_Word)+sizeof(Elf32_Word)+sizeof(Elf32_Word)+0, .fsz64 = sizeof(Elf64_Word)+sizeof(Elf64_Word)+sizeof(Elf64_Off)+sizeof(Elf64_Addr)+sizeof(Elf64_Addr)+sizeof(Elf64_Xword)+sizeof(Elf64_Xword)+sizeof(Elf64_Xword)+0 },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_REL] = { .fsz32 = sizeof(Elf32_Addr)+sizeof(Elf32_Word)+0, .fsz64 = sizeof(Elf64_Addr)+sizeof(Elf64_Xword)+0 },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_RELA] = { .fsz32 = sizeof(Elf32_Addr)+sizeof(Elf32_Word)+sizeof(Elf32_Sword)+0, .fsz64 = sizeof(Elf64_Addr)+sizeof(Elf64_Xword)+sizeof(Elf64_Sxword)+0 },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_SHDR] = { .fsz32 = sizeof(Elf32_Word)+sizeof(Elf32_Word)+sizeof(Elf32_Word)+sizeof(Elf32_Addr)+sizeof(Elf32_Off)+sizeof(Elf32_Word)+sizeof(Elf32_Word)+sizeof(Elf32_Word)+sizeof(Elf32_Word)+sizeof(Elf32_Word)+0, .fsz64 = sizeof(Elf64_Word)+sizeof(Elf64_Word)+sizeof(Elf64_Xword)+sizeof(Elf64_Addr)+sizeof(Elf64_Off)+sizeof(Elf64_Xword)+sizeof(Elf64_Word)+sizeof(Elf64_Word)+sizeof(Elf64_Xword)+sizeof(Elf64_Xword)+0 },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_SWORD] = { .fsz32 = sizeof(Elf32_Sword), .fsz64 = sizeof(Elf64_Sword) },
-
#endif
-
#if	__FreeBSD_version >= 700009
-
    [ELF_T_SXWORD] = { .fsz32 = 0, .fsz64 = sizeof(Elf64_Sxword) },
-
#endif
-
#if	__FreeBSD_version >= 700025
-
    [ELF_T_SYMINFO] = { .fsz32 = sizeof(Elf32_Half)+sizeof(Elf32_Half)+0, .fsz64 = sizeof(Elf64_Half)+sizeof(Elf64_Half)+0 },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_SYM] = { .fsz32 = sizeof(Elf32_Word)+sizeof(Elf32_Addr)+sizeof(Elf32_Word)+1+1+sizeof(Elf32_Half)+0, .fsz64 = sizeof(Elf64_Word)+1+1+sizeof(Elf64_Half)+sizeof(Elf64_Addr)+sizeof(Elf64_Xword)+0 },
-
#endif
-
#if	__FreeBSD_version >= 700009
-
    [ELF_T_VDEF] = { .fsz32 = sizeof(Elf32_Half)+sizeof(Elf32_Half)+sizeof(Elf32_Half)+sizeof(Elf32_Half)+sizeof(Elf32_Word)+sizeof(Elf32_Word)+sizeof(Elf32_Word)+0, .fsz64 = sizeof(Elf64_Half)+sizeof(Elf64_Half)+sizeof(Elf64_Half)+sizeof(Elf64_Half)+sizeof(Elf64_Word)+sizeof(Elf64_Word)+sizeof(Elf64_Word)+0 },
-
#endif
-
#if	__FreeBSD_version >= 700009
-
    [ELF_T_VNEED] = { .fsz32 = sizeof(Elf32_Half)+sizeof(Elf32_Half)+sizeof(Elf32_Word)+sizeof(Elf32_Word)+sizeof(Elf32_Word)+0, .fsz64 = sizeof(Elf64_Half)+sizeof(Elf64_Half)+sizeof(Elf64_Word)+sizeof(Elf64_Word)+sizeof(Elf64_Word)+0 },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_WORD] = { .fsz32 = sizeof(Elf32_Word), .fsz64 = sizeof(Elf64_Word) },
-
#endif
-
#if	__FreeBSD_version >= 700009
-
    [ELF_T_XWORD] = { .fsz32 = 0, .fsz64 = sizeof(Elf64_Xword) },
-
#endif
-

-
};
-

-
size_t
-
_libelf_fsize(Elf_Type t, int ec, unsigned int v, size_t c)
-
{
-
	size_t sz;
-

-
	sz = 0;
-
	if (v != EV_CURRENT)
-
		LIBELF_SET_ERROR(VERSION, 0);
-
	else if ((int) t < ELF_T_FIRST || t > ELF_T_LAST)
-
		LIBELF_SET_ERROR(ARGUMENT, 0);
-
	else {
-
		sz = ec == ELFCLASS64 ? fsize[t].fsz64 : fsize[t].fsz32;
-
		if (sz == 0)
-
			LIBELF_SET_ERROR(UNIMPL, 0);
-
	}
-

-
	return (sz*c);
-
}
-

modified external/libelf/libelf_fsize.m4
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008-2011 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -22,15 +22,16 @@
 * 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: releng/9.1/lib/libelf/libelf_fsize.m4 210340 2010-07-21 10:39:29Z kaiw $
 */

#include <libelf.h>
-
#include <osreldate.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: libelf_fsize.m4 2225 2011-11-26 18:55:54Z jkoshy $");
+

+
/* WARNING: GENERATED FROM __file__. */
+

/*
 * Create an array of file sizes from the elf_type definitions
 */
@@ -50,6 +51,8 @@ define(`IDENT_SIZE', `EI_NIDENT')
/* Types that have variable length. */
define(`GNUHASH_SIZE',	1)
define(`NOTE_SIZE',	1)
+
define(`VDEF_SIZE',	1)
+
define(`VNEED_SIZE',	1)

/* Currently unimplemented types. */
define(`MOVEP_SIZE',	0)
@@ -118,9 +121,8 @@ DEFINE_ELF_FSIZES(ELF_TYPE_LIST)
DEFINE_ELF_FSIZE(`IDENT',`')	# `IDENT' is a pseudo type

define(`FSIZE',
-
  `#if	__FreeBSD_version >= $3
-
    [ELF_T_$1] = { .fsz32 = $1_SIZE32, .fsz64 = $1_SIZE64 },
-
#endif')
+
  `[ELF_T_$1] = { .fsz32 = $1_SIZE32, .fsz64 = $1_SIZE64 },
+
')
define(`FSIZES',
  `ifelse($#,1,`',
    `FSIZE($1)
@@ -155,4 +157,3 @@ _libelf_fsize(Elf_Type t, int ec, unsigned int v, size_t c)

	return (sz*c);
}
-

added external/libelf/libelf_memory.c
@@ -0,0 +1,96 @@
+
/*-
+
 * Copyright (c) 2011 Joseph Koshy
+
 * 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.
+
 *
+
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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.
+
 */
+

+
#include <ar.h>
+
#include <assert.h>
+
#include <string.h>
+
#include <libelf.h>
+

+
#include "_libelf.h"
+

+
ELFTC_VCSID("$Id: libelf_memory.c 2368 2011-12-29 06:34:28Z jkoshy $");
+

+
/*
+
 * Create an ELF descriptor for a memory image, optionally reporting
+
 * parse errors.
+
 */
+

+
Elf *
+
_libelf_memory(char *image, size_t sz, int reporterror)
+
{
+
	Elf *e;
+
	int e_class;
+
	enum Elf_Error error;
+
	unsigned int e_byteorder, e_version;
+

+
	assert(image != NULL);
+
	assert(sz > 0);
+

+
	if ((e = _libelf_allocate_elf()) == NULL)
+
		return (NULL);
+

+
	e->e_cmd = ELF_C_READ;
+
	e->e_rawfile = image;
+
	e->e_rawsize = sz;
+

+
#undef	LIBELF_IS_ELF
+
#define	LIBELF_IS_ELF(P) ((P)[EI_MAG0] == ELFMAG0 && 		\
+
	(P)[EI_MAG1] == ELFMAG1 && (P)[EI_MAG2] == ELFMAG2 &&	\
+
	(P)[EI_MAG3] == ELFMAG3)
+

+
	if (sz > EI_NIDENT && LIBELF_IS_ELF(image)) {
+
		e_byteorder = image[EI_DATA];
+
		e_class     = image[EI_CLASS];
+
		e_version   = image[EI_VERSION];
+

+
		error = ELF_E_NONE;
+

+
		if (e_version > EV_CURRENT)
+
			error = ELF_E_VERSION;
+
		else if ((e_byteorder != ELFDATA2LSB && e_byteorder !=
+
 		    ELFDATA2MSB) || (e_class != ELFCLASS32 && e_class !=
+
		    ELFCLASS64))
+
			error = ELF_E_HEADER;
+

+
		if (error != ELF_E_NONE) {
+
			if (reporterror) {
+
				LIBELF_PRIVATE(error) = LIBELF_ERROR(error, 0);
+
				(void) _libelf_release_elf(e);
+
				return (NULL);
+
			}
+
		} else {
+
			_libelf_init_elf(e, ELF_K_ELF);
+

+
			e->e_byteorder = e_byteorder;
+
			e->e_class = e_class;
+
			e->e_version = e_version;
+
		}
+
	} else if (sz >= SARMAG &&
+
	    strncmp(image, ARMAG, (size_t) SARMAG) == 0)
+
		return (_libelf_ar_open(e, reporterror));
+

+
	return (e);
+
}
deleted external/libelf/libelf_msize.c
@@ -1,142 +0,0 @@
-
/*-
-
 * Copyright (c) 2006 Joseph Koshy
-
 * 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.
-
 *
-
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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.
-
 */
-

-
#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_msize.m4 210332 2010-07-21 09:56:42Z kaiw $");
-

-
#include <sys/types.h>
-
#include <sys/elf32.h>
-
#include <sys/elf64.h>
-

-
#include <assert.h>
-
#include <libelf.h>
-
#include <osreldate.h>
-
#include <string.h>
-

-
#include "_libelf.h"
-

-
/* WARNING: GENERATED FROM libelf_msize.m4. */
-

-
struct msize {
-
	size_t	msz32;
-
	size_t	msz64;
-
};
-

-

-

-
static struct msize msize[ELF_T_NUM] = {
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_ADDR] = { .msz32 = sizeof(Elf32_Addr), .msz64 = sizeof(Elf64_Addr) },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_BYTE] = { .msz32 = 1, .msz64 = 1 },
-
#endif
-
#if	__FreeBSD_version >= 700025
-
    [ELF_T_CAP] = { .msz32 = sizeof(Elf32_Cap), .msz64 = sizeof(Elf64_Cap) },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_DYN] = { .msz32 = sizeof(Elf32_Dyn), .msz64 = sizeof(Elf64_Dyn) },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_EHDR] = { .msz32 = sizeof(Elf32_Ehdr), .msz64 = sizeof(Elf64_Ehdr) },
-
#endif
-
#if	__FreeBSD_version >= 800062
-
    [ELF_T_GNUHASH] = { .msz32 = 1, .msz64 = 1 },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_HALF] = { .msz32 = sizeof(Elf32_Half), .msz64 = sizeof(Elf64_Half) },
-
#endif
-
#if	__FreeBSD_version >= 700025
-
    [ELF_T_LWORD] = { .msz32 = sizeof(Elf32_Lword), .msz64 = sizeof(Elf64_Lword) },
-
#endif
-
#if	__FreeBSD_version >= 700025
-
    [ELF_T_MOVE] = { .msz32 = sizeof(Elf32_Move), .msz64 = sizeof(Elf64_Move) },
-
#endif
-
#if	__FreeBSD_version >= 700025
-
    [ELF_T_MOVEP] = { .msz32 = 0, .msz64 = 0 },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_NOTE] = { .msz32 = 1, .msz64 = 1 },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_OFF] = { .msz32 = sizeof(Elf32_Off), .msz64 = sizeof(Elf64_Off) },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_PHDR] = { .msz32 = sizeof(Elf32_Phdr), .msz64 = sizeof(Elf64_Phdr) },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_REL] = { .msz32 = sizeof(Elf32_Rel), .msz64 = sizeof(Elf64_Rel) },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_RELA] = { .msz32 = sizeof(Elf32_Rela), .msz64 = sizeof(Elf64_Rela) },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_SHDR] = { .msz32 = sizeof(Elf32_Shdr), .msz64 = sizeof(Elf64_Shdr) },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_SWORD] = { .msz32 = sizeof(Elf32_Sword), .msz64 = sizeof(Elf64_Sword) },
-
#endif
-
#if	__FreeBSD_version >= 700009
-
    [ELF_T_SXWORD] = { .msz32 = 0, .msz64 = sizeof(Elf64_Sxword) },
-
#endif
-
#if	__FreeBSD_version >= 700025
-
    [ELF_T_SYMINFO] = { .msz32 = sizeof(Elf32_Syminfo), .msz64 = sizeof(Elf64_Syminfo) },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_SYM] = { .msz32 = sizeof(Elf32_Sym), .msz64 = sizeof(Elf64_Sym) },
-
#endif
-
#if	__FreeBSD_version >= 700009
-
    [ELF_T_VDEF] = { .msz32 = sizeof(Elf32_Verdef), .msz64 = sizeof(Elf64_Verdef) },
-
#endif
-
#if	__FreeBSD_version >= 700009
-
    [ELF_T_VNEED] = { .msz32 = sizeof(Elf32_Verneed), .msz64 = sizeof(Elf64_Verneed) },
-
#endif
-
#if	__FreeBSD_version >= 600102
-
    [ELF_T_WORD] = { .msz32 = sizeof(Elf32_Word), .msz64 = sizeof(Elf64_Word) },
-
#endif
-
#if	__FreeBSD_version >= 700009
-
    [ELF_T_XWORD] = { .msz32 = 0, .msz64 = sizeof(Elf64_Xword) },
-
#endif
-

-
};
-

-
size_t
-
_libelf_msize(Elf_Type t, int elfclass, unsigned int version)
-
{
-
	size_t sz;
-

-
	assert(elfclass == ELFCLASS32 || elfclass == ELFCLASS64);
-
	assert((signed) t >= ELF_T_FIRST && t <= ELF_T_LAST);
-

-
	if (version != EV_CURRENT) {
-
		LIBELF_SET_ERROR(VERSION, 0);
-
		return (0);
-
	}
-

-
	sz = (elfclass == ELFCLASS32) ? msize[t].msz32 : msize[t].msz64;
-

-
	return (sz);
-
}
modified external/libelf/libelf_msize.m4
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008-2011 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,19 +25,15 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_msize.m4 210332 2010-07-21 09:56:42Z kaiw $");
-

-
#include <sys/types.h>
-
#include <sys/elf32.h>
-
#include <sys/elf64.h>

#include <assert.h>
#include <libelf.h>
-
#include <osreldate.h>
#include <string.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: libelf_msize.m4 2225 2011-11-26 18:55:54Z jkoshy $");
+

/* WARNING: GENERATED FROM __file__. */

struct msize {
@@ -48,9 +44,14 @@ struct msize {
divert(-1)
include(SRCDIR`/elf_types.m4')

+
/*
+
 * ELF types whose memory representations have a variable size.
+
 */
define(BYTE_SIZE,	1)
define(GNUHASH_SIZE,	1)
define(NOTE_SIZE,	1)
+
define(VDEF_SIZE,	1)
+
define(VNEED_SIZE,	1)

/*
 * Unimplemented types.
@@ -75,9 +76,8 @@ define(`DEFINE_ELF_MSIZES',
DEFINE_ELF_MSIZES(ELF_TYPE_LIST)

define(`MSIZE',
-
  `#if	__FreeBSD_version >= $3
-
    [ELF_T_$1] = { .msz32 = $1_SIZE32, .msz64 = $1_SIZE64 },
-
#endif')
+
  `[ELF_T_$1] = { .msz32 = $1_SIZE32, .msz64 = $1_SIZE64 },
+
')
define(`MSIZES',
  `ifelse($#,1,`',
    `MSIZE($1)
added external/libelf/libelf_open.c
@@ -0,0 +1,240 @@
+
/*-
+
 * Copyright (c) 2006,2008-2011 Joseph Koshy
+
 * 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.
+
 *
+
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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.
+
 */
+

+
#include <sys/types.h>
+
#include <sys/stat.h>
+

+
#include <assert.h>
+
#include <errno.h>
+
#include <libelf.h>
+
#include <stdlib.h>
+
#include <unistd.h>
+

+
#include "_libelf.h"
+

+
#if	ELFTC_HAVE_MMAP
+
#include <sys/mman.h>
+
#endif
+

+
ELFTC_VCSID("$Id: libelf_open.c 2364 2011-12-28 17:55:25Z jkoshy $");
+

+
#define	_LIBELF_INITSIZE	(64*1024)
+

+
/*
+
 * Read from a device file, pipe or socket.
+
 */
+
static void *
+
_libelf_read_special_file(int fd, size_t *fsz)
+
{
+
	ssize_t readsz;
+
	size_t bufsz, datasz;
+
	unsigned char *buf, *t;
+

+
	datasz = 0;
+
	readsz = 0;
+
	bufsz = _LIBELF_INITSIZE;
+
	if ((buf = malloc(bufsz)) == NULL)
+
		goto resourceerror;
+

+
	/*
+
	 * Read data from the file descriptor till we reach EOF, or
+
	 * till an error is encountered.
+
	 */
+
	do {
+
		/* Check if we need to expand the data buffer. */
+
		if (datasz == bufsz) {
+
			bufsz *= 2;
+
			if ((t = realloc(buf, bufsz)) == NULL)
+
				goto resourceerror;
+
			buf = t;
+
		}
+

+
		do {
+
			readsz = bufsz - datasz;
+
			t = buf + datasz;
+
			if ((readsz = read(fd, t, readsz)) <= 0)
+
				break;
+
			datasz += readsz;
+
		} while (datasz < bufsz);
+

+
	} while (readsz > 0);
+

+
	if (readsz < 0) {
+
		LIBELF_SET_ERROR(IO, errno);
+
		goto error;
+
	}
+

+
	assert(readsz == 0);
+

+
	/*
+
	 * Free up extra buffer space.
+
	 */
+
	if (bufsz > datasz) {
+
		if (datasz > 0) {
+
			if ((t = realloc(buf, datasz)) == NULL)
+
				goto resourceerror;
+
			buf = t;
+
		} else {	/* Zero bytes read. */
+
			LIBELF_SET_ERROR(ARGUMENT, 0);
+
			free(buf);
+
			buf = NULL;
+
		}
+
	}
+

+
	*fsz = datasz;
+
	return (buf);
+

+
resourceerror:
+
	LIBELF_SET_ERROR(RESOURCE, 0);
+
error:
+
	if (buf != NULL)
+
		free(buf);
+
	return (NULL);
+
}
+

+
/*
+
 * Read the contents of the file referenced by the file descriptor
+
 * 'fd'.
+
 */
+

+
Elf *
+
_libelf_open_object(int fd, Elf_Cmd c, int reporterror)
+
{
+
	Elf *e;
+
	void *m;
+
	mode_t mode;
+
	size_t fsize;
+
	struct stat sb;
+
	unsigned int flags;
+

+
	assert(c == ELF_C_READ || c == ELF_C_RDWR || c == ELF_C_WRITE);
+

+
	if (fstat(fd, &sb) < 0) {
+
		LIBELF_SET_ERROR(IO, errno);
+
		return (NULL);
+
	}
+

+
	mode = sb.st_mode;
+
	fsize = (size_t) sb.st_size;
+

+
	/*
+
	 * Reject unsupported file types.
+
	 */
+
	if (!S_ISREG(mode) && !S_ISCHR(mode) && !S_ISFIFO(mode) &&
+
	    !S_ISSOCK(mode)) {
+
		LIBELF_SET_ERROR(ARGUMENT, 0);
+
		return (NULL);
+
	}
+

+
	/*
+
	 * For ELF_C_WRITE mode, allocate and return a descriptor.
+
	 */
+
	if (c == ELF_C_WRITE) {
+
		if ((e = _libelf_allocate_elf()) != NULL) {
+
			_libelf_init_elf(e, ELF_K_ELF);
+
			e->e_byteorder = LIBELF_PRIVATE(byteorder);
+
			e->e_fd = fd;
+
			e->e_cmd = c;
+
			if (!S_ISREG(mode))
+
				e->e_flags |= LIBELF_F_SPECIAL_FILE;
+
		}
+

+
		return (e);
+
	}
+

+

+
	/*
+
	 * ELF_C_READ and ELF_C_RDWR mode.
+
	 */
+
	m = NULL;
+
	flags = 0;
+
	if (S_ISREG(mode)) {
+
#if	ELFTC_HAVE_MMAP
+
		/*
+
		 * Always map regular files in with 'PROT_READ'
+
		 * permissions.
+
		 *
+
		 * For objects opened in ELF_C_RDWR mode, when
+
		 * elf_update(3) is called, we remove this mapping,
+
		 * write file data out using write(2), and map the new
+
		 * contents back.
+
		 */
+
		m = mmap(NULL, fsize, PROT_READ, MAP_PRIVATE, fd, (off_t) 0);
+

+
		if (m == MAP_FAILED)
+
			m = NULL;
+
		else
+
			flags = LIBELF_F_RAWFILE_MMAP;
+
#endif
+

+
		/*
+
		 * Fallback to a read() if the call to mmap() failed,
+
		 * or if mmap() is not available.
+
		 */
+
		if (m == NULL) {
+
			if ((m = malloc(fsize)) == NULL) {
+
				LIBELF_SET_ERROR(RESOURCE, 0);
+
				return (NULL);
+
			}
+

+
			if (read(fd, m, fsize) != (ssize_t) fsize) {
+
				LIBELF_SET_ERROR(IO, errno);
+
				free(m);
+
				return (NULL);
+
			}
+

+
			flags = LIBELF_F_RAWFILE_MALLOC;
+
		}
+
	} else if ((m = _libelf_read_special_file(fd, &fsize)) != NULL)
+
		flags = LIBELF_F_RAWFILE_MALLOC | LIBELF_F_SPECIAL_FILE;
+
	else
+
		return (NULL);
+

+
	if ((e = _libelf_memory(m, fsize, reporterror)) == NULL) {
+
		assert((flags & LIBELF_F_RAWFILE_MALLOC) ||
+
		    (flags & LIBELF_F_RAWFILE_MMAP));
+
		if (flags & LIBELF_F_RAWFILE_MALLOC)
+
			free(m);
+
#if	ELFTC_HAVE_MMAP
+
		else
+
			(void) munmap(m, fsize);
+
#endif
+
		return (NULL);
+
	}
+

+
	/* ar(1) archives aren't supported in RDWR mode. */
+
	if (c == ELF_C_RDWR && e->e_kind == ELF_K_AR) {
+
		(void) elf_end(e);
+
		LIBELF_SET_ERROR(ARGUMENT, 0);
+
		return (NULL);
+
	}
+

+
	e->e_flags |= flags;
+
	e->e_fd = fd;
+
	e->e_cmd = c;
+

+
	return (e);
+
}
modified external/libelf/libelf_phdr.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -22,12 +22,9 @@
 * 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: releng/9.1/lib/libelf/libelf_phdr.c 210338 2010-07-21 10:25:02Z kaiw $
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_phdr.c 210338 2010-07-21 10:25:02Z kaiw $");

#include <assert.h>
#include <gelf.h>
@@ -36,6 +33,8 @@ __FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_phdr.c 210338 2010-07-21 10:25:

#include "_libelf.h"

+
ELFTC_VCSID("$Id: libelf_phdr.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

void *
_libelf_getphdr(Elf *e, int ec)
{
modified external/libelf/libelf_shdr.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,13 +25,14 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_shdr.c 164190 2006-11-11 17:16:35Z jkoshy $");

#include <gelf.h>
#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: libelf_shdr.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

void *
_libelf_getshdr(Elf_Scn *s, int ec)
{
modified external/libelf/libelf_xlate.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2006 Joseph Koshy
+
 * Copyright (c) 2006,2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
@@ -25,13 +25,14 @@
 */

#include <sys/cdefs.h>
-
__FBSDID("$FreeBSD: releng/9.1/lib/libelf/libelf_xlate.c 210338 2010-07-21 10:25:02Z kaiw $");

#include <assert.h>
#include <libelf.h>

#include "_libelf.h"

+
ELFTC_VCSID("$Id: libelf_xlate.c 2225 2011-11-26 18:55:54Z jkoshy $");
+

/*
 * Translate to/from the file representation of ELF objects.
 *
added external/libelf/os.FreeBSD.mk
@@ -0,0 +1,7 @@
+
#
+
# Building for a FreeBSD target.
+
#
+
# $Id: os.FreeBSD.mk 710 2010-02-17 14:21:38Z jkoshy $
+

+
# Symbol versioning support [FreeBSD 7.X and later]
+
VERSION_MAP=		${.CURDIR}/Version.map
added external/libelf/os.NetBSD.mk
@@ -0,0 +1,7 @@
+
#
+
# Build recipes for NetBSD.
+
#
+
# $Id: os.NetBSD.mk 710 2010-02-17 14:21:38Z jkoshy $
+
#
+

+
MKLINT=		no		# lint dies with a sigbus
modified libpkg/Makefile
@@ -60,7 +60,8 @@ CFLAGS+= -I${.CURDIR} \
		-I${.CURDIR}/../external/uthash

.if defined(WITH_BUNDLED_LIBELF)
-
CFLAGS+=	-I${.CURDIR}/../external/libelf
+
CFLAGS+=	-I${.CURDIR}/../external/libelf \
+
		-DBUNDLED_LIBELF
.endif

LDADD+=		-L${.OBJDIR}/../external/sqlite \
modified libpkg/pkg_elf.c
@@ -27,7 +27,9 @@

#include <sys/endian.h>
#include <sys/types.h>
+
#ifndef BUNDLED_LIBELF
#include <sys/elf_common.h>
+
#endif
#include <sys/stat.h>

#include <assert.h>
@@ -37,7 +39,9 @@
#include <err.h>
#include <fcntl.h>
#include <gelf.h>
+
#ifndef BUNDLED_LIBELF
#include <link.h>
+
#endif
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
modified libpkg/private/elf_tables.h
@@ -32,7 +32,7 @@ struct _elf_corres {

struct _elf_corres mach_corres[] = {
	{ EM_386, "x86" },
-
	{ EM_AMD64, "x86" },
+
	{ EM_X86_64, "x86" },
	{ EM_ARM, "arm" },
	{ EM_MIPS, "mips" },
	{ EM_PPC, "powerpc" },