From 960168409a5f2a6e8adde80cb26ad6ff745a4c21 Mon Sep 17 00:00:00 2001
From: David Shao <davshao@gmail.com>
Date: Mon, 3 Sep 2018 20:34:53 -0700
Subject: [PATCH] synch libelf with FreeBSD 12 current

---
 contrib/elftoolchain/libelf/Makefile          |    2 +-
 contrib/elftoolchain/libelf/_libelf_config.h  |    8 +-
 contrib/elftoolchain/libelf/elf.3             |  611 ++++++
 contrib/elftoolchain/libelf/elf_begin.3       |  315 +++
 contrib/elftoolchain/libelf/elf_cntl.3        |  111 +
 contrib/elftoolchain/libelf/elf_data.c        |   10 +-
 contrib/elftoolchain/libelf/elf_end.3         |   76 +
 contrib/elftoolchain/libelf/elf_errmsg.3      |  107 +
 contrib/elftoolchain/libelf/elf_fill.3        |   52 +
 contrib/elftoolchain/libelf/elf_flagdata.3    |  223 ++
 contrib/elftoolchain/libelf/elf_getarhdr.3    |   97 +
 contrib/elftoolchain/libelf/elf_getarsym.3    |  130 ++
 contrib/elftoolchain/libelf/elf_getbase.3     |   71 +
 contrib/elftoolchain/libelf/elf_getdata.3     |  229 ++
 contrib/elftoolchain/libelf/elf_getident.3    |   83 +
 contrib/elftoolchain/libelf/elf_getphdrnum.3  |   86 +
 contrib/elftoolchain/libelf/elf_getphnum.3    |   93 +
 contrib/elftoolchain/libelf/elf_getscn.3      |  151 ++
 contrib/elftoolchain/libelf/elf_getshdrnum.3  |   78 +
 .../elftoolchain/libelf/elf_getshdrstrndx.3   |   79 +
 contrib/elftoolchain/libelf/elf_getshnum.3    |   84 +
 contrib/elftoolchain/libelf/elf_getshstrndx.3 |   94 +
 contrib/elftoolchain/libelf/elf_hash.3        |   57 +
 contrib/elftoolchain/libelf/elf_kind.3        |   71 +
 contrib/elftoolchain/libelf/elf_memory.3      |  122 ++
 contrib/elftoolchain/libelf/elf_next.3        |   96 +
 contrib/elftoolchain/libelf/elf_open.3        |  121 ++
 contrib/elftoolchain/libelf/elf_rand.3        |  118 ++
 contrib/elftoolchain/libelf/elf_rawfile.3     |   76 +
 contrib/elftoolchain/libelf/elf_strptr.3      |  116 +
 contrib/elftoolchain/libelf/elf_update.3      |  378 ++++
 contrib/elftoolchain/libelf/elf_update.c      |    2 +
 contrib/elftoolchain/libelf/elf_version.3     |   95 +
 contrib/elftoolchain/libelf/gelf.3            |  200 ++
 contrib/elftoolchain/libelf/gelf_checksum.3   |  115 +
 contrib/elftoolchain/libelf/gelf_fsize.3      |   96 +
 contrib/elftoolchain/libelf/gelf_getcap.3     |  121 ++
 contrib/elftoolchain/libelf/gelf_getclass.3   |   61 +
 contrib/elftoolchain/libelf/gelf_getdyn.3     |  123 ++
 contrib/elftoolchain/libelf/gelf_getehdr.3    |  123 ++
 contrib/elftoolchain/libelf/gelf_getmove.3    |  120 ++
 contrib/elftoolchain/libelf/gelf_getphdr.3    |  141 ++
 contrib/elftoolchain/libelf/gelf_getrel.3     |  121 ++
 contrib/elftoolchain/libelf/gelf_getrela.3    |  121 ++
 contrib/elftoolchain/libelf/gelf_getshdr.3    |  115 +
 contrib/elftoolchain/libelf/gelf_getsym.3     |  125 ++
 contrib/elftoolchain/libelf/gelf_getsyminfo.3 |  115 +
 .../elftoolchain/libelf/gelf_getsymshndx.3    |  162 ++
 contrib/elftoolchain/libelf/gelf_newehdr.3    |  194 ++
 contrib/elftoolchain/libelf/gelf_newphdr.3    |  142 ++
 contrib/elftoolchain/libelf/gelf_phdr.c       |   34 +-
 .../elftoolchain/libelf/gelf_update_ehdr.3    |  123 ++
 contrib/elftoolchain/libelf/gelf_xlatetof.3   |  247 +++
 contrib/elftoolchain/libelf/libelf.h          |    5 +-
 contrib/elftoolchain/libelf/libelf_align.c    |    2 +-
 contrib/elftoolchain/libelf/libelf_ar.c       |    4 +-
 contrib/elftoolchain/libelf/libelf_convert.m4 |    3 +-
 contrib/elftoolchain/libelf/libelf_ehdr.c     |   19 +-
 contrib/elftoolchain/libelf/os.FreeBSD.mk     |    7 +
 contrib/elftoolchain/libelf/os.NetBSD.mk      |    7 +
 lib/libelf/Makefile                           |  138 +-
 sys/sys/elf32.h                               |   98 +-
 sys/sys/elf64.h                               |   53 +-
 sys/sys/elf_common.h                          | 1858 +++++++++++------
 sys/sys/elf_generic.h                         |   40 +-
 65 files changed, 8164 insertions(+), 711 deletions(-)
 create mode 100644 contrib/elftoolchain/libelf/elf.3
 create mode 100644 contrib/elftoolchain/libelf/elf_begin.3
 create mode 100644 contrib/elftoolchain/libelf/elf_cntl.3
 create mode 100644 contrib/elftoolchain/libelf/elf_end.3
 create mode 100644 contrib/elftoolchain/libelf/elf_errmsg.3
 create mode 100644 contrib/elftoolchain/libelf/elf_fill.3
 create mode 100644 contrib/elftoolchain/libelf/elf_flagdata.3
 create mode 100644 contrib/elftoolchain/libelf/elf_getarhdr.3
 create mode 100644 contrib/elftoolchain/libelf/elf_getarsym.3
 create mode 100644 contrib/elftoolchain/libelf/elf_getbase.3
 create mode 100644 contrib/elftoolchain/libelf/elf_getdata.3
 create mode 100644 contrib/elftoolchain/libelf/elf_getident.3
 create mode 100644 contrib/elftoolchain/libelf/elf_getphdrnum.3
 create mode 100644 contrib/elftoolchain/libelf/elf_getphnum.3
 create mode 100644 contrib/elftoolchain/libelf/elf_getscn.3
 create mode 100644 contrib/elftoolchain/libelf/elf_getshdrnum.3
 create mode 100644 contrib/elftoolchain/libelf/elf_getshdrstrndx.3
 create mode 100644 contrib/elftoolchain/libelf/elf_getshnum.3
 create mode 100644 contrib/elftoolchain/libelf/elf_getshstrndx.3
 create mode 100644 contrib/elftoolchain/libelf/elf_hash.3
 create mode 100644 contrib/elftoolchain/libelf/elf_kind.3
 create mode 100644 contrib/elftoolchain/libelf/elf_memory.3
 create mode 100644 contrib/elftoolchain/libelf/elf_next.3
 create mode 100644 contrib/elftoolchain/libelf/elf_open.3
 create mode 100644 contrib/elftoolchain/libelf/elf_rand.3
 create mode 100644 contrib/elftoolchain/libelf/elf_rawfile.3
 create mode 100644 contrib/elftoolchain/libelf/elf_strptr.3
 create mode 100644 contrib/elftoolchain/libelf/elf_update.3
 create mode 100644 contrib/elftoolchain/libelf/elf_version.3
 create mode 100644 contrib/elftoolchain/libelf/gelf.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_checksum.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_fsize.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_getcap.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_getclass.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_getdyn.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_getehdr.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_getmove.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_getphdr.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_getrel.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_getrela.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_getshdr.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_getsym.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_getsyminfo.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_getsymshndx.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_newehdr.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_newphdr.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_update_ehdr.3
 create mode 100644 contrib/elftoolchain/libelf/gelf_xlatetof.3
 create mode 100644 contrib/elftoolchain/libelf/os.FreeBSD.mk
 create mode 100644 contrib/elftoolchain/libelf/os.NetBSD.mk

diff --git a/contrib/elftoolchain/libelf/Makefile b/contrib/elftoolchain/libelf/Makefile
index b9e4e13373..df1945a820 100644
--- a/contrib/elftoolchain/libelf/Makefile
+++ b/contrib/elftoolchain/libelf/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile 2605 2012-10-02 17:52:20Z jkoshy $
+# $Id: Makefile 3594 2018-04-11 18:26:50Z jkoshy $
 
 TOP=	${.CURDIR}/..
 
diff --git a/contrib/elftoolchain/libelf/_libelf_config.h b/contrib/elftoolchain/libelf/_libelf_config.h
index 1b8f35b224..d70c04f970 100644
--- a/contrib/elftoolchain/libelf/_libelf_config.h
+++ b/contrib/elftoolchain/libelf/_libelf_config.h
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: _libelf_config.h 3168 2015-02-24 19:17:47Z emaste $
+ * $Id: _libelf_config.h 3566 2017-08-31 02:28:40Z emaste $
  */
 
 #if defined(__APPLE__) || defined(__DragonFly__)
@@ -97,6 +97,12 @@
 #define	LIBELF_BYTEORDER	ELFDATA2MSB
 #define	LIBELF_CLASS		ELFCLASS32
 
+#elif	defined(__riscv) && (__riscv_xlen == 64)
+
+#define	LIBELF_ARCH		EM_RISCV
+#define	LIBELF_BYTEORDER	ELFDATA2LSB
+#define	LIBELF_CLASS		ELFCLASS64
+
 #elif	defined(__sparc__)
 
 #define	LIBELF_ARCH		EM_SPARCV9
diff --git a/contrib/elftoolchain/libelf/elf.3 b/contrib/elftoolchain/libelf/elf.3
new file mode 100644
index 0000000000..20cb944553
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf.3
@@ -0,0 +1,611 @@
+.\" 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 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.3 3195 2015-05-12 17:22:19Z emaste $
+.\"
+.Dd July 28, 2014
+.Os
+.Dt ELF 3
+.Sh NAME
+.Nm elf
+.Nd API for manipulating ELF objects
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Sh DESCRIPTION
+The
+.Lb libelf
+provides functions that allow an application to read and manipulate
+ELF object files, and to read
+.Xr ar 1
+archives.
+The library allows the manipulation of ELF objects in a byte ordering
+and word-size independent way, allowing an application to read and
+create ELF objects for 32 and 64 bit architectures and for little-
+and big-endian machines.
+The library is capable of processing ELF objects that use extended
+section numbering.
+.Pp
+This manual page serves to provide an overview of the functionality in
+the ELF library.
+Further information may found in the manual pages for individual
+.Xr ELF 3
+functions that comprise the library.
+.Ss ELF Concepts
+As described in
+.Xr elf 5 ,
+ELF files contain several data structures that are laid out in a
+specific way.
+ELF files begin with an
+.Dq Executable Header ,
+and may contain an optional
+.Dq Program Header Table ,
+and optional data in the form of ELF
+.Dq sections .
+A
+.Dq Section Header Table
+describes the content of the data in these sections.
+.Pp
+ELF objects have an associated
+.Dq "ELF class"
+which denotes the natural machine word size for the architecture
+the object is associated with.
+Objects for 32 bit architectures have an ELF class of
+.Dv ELFCLASS32 .
+Objects for 64 bit architectures have an ELF class of
+.Dv ELFCLASS64 .
+.Pp
+ELF objects also have an associated
+.Dq endianness
+which denotes the endianness of the machine architecture associated
+with the object.
+This may be
+.Dv ELFDATA2LSB
+for little-endian architectures and
+.Dv ELFDATA2MSB
+for big-endian architectures.
+.Pp
+ELF objects are also associated with an API version number.
+This version number determines the layout of the individual components
+of an ELF file and the semantics associated with these.
+.Ss Data Representation And Translation
+The
+.Xr ELF 3
+library distinguishes between
+.Dq native
+representations of ELF data structures and their
+.Dq file
+representations.
+.Pp
+An application would work with ELF data in its
+.Dq native
+representation, i.e., using the native byteorder and alignment mandated
+by the processor the application is running on.
+The
+.Dq file
+representation of the same data could use a different byte ordering
+and follow different constraints on object alignment than these native
+constraints.
+.Pp
+Accordingly, the
+.Xr ELF 3
+library offers translation facilities
+.Xr ( elf32_xlatetof 3 ,
+.Xr elf32_xlatetom 3 ,
+.Xr elf64_xlatetof 3
+and
+.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.
+.Ss Library Working Version
+Conceptually, there are three version numbers associated with an
+application using the ELF library to manipulate ELF objects:
+.Bl -bullet -compact -offset indent
+.It
+The ELF version that the application was compiled against.
+This version determines the ABI expected by the application.
+.It
+The ELF version of the ELF object being manipulated by the
+application through the ELF library.
+.It
+The ELF version (or set of versions) supported by the ELF library itself.
+.El
+.Pp
+In order to facilitate working with ELF objects of differing versions,
+the ELF library requires the application to call the
+.Fn elf_version
+function before invoking many of its operations, in order to inform
+the library of the application's desired working version.
+.Pp
+In the current implementation, all three versions have to be
+.Dv EV_CURRENT .
+.Ss Namespace use
+The ELF library uses the following prefixes:
+.Bl -tag -width "ELF_F_*"
+.It Dv elf_
+Used for class-independent functions.
+.It Dv elf32_
+Used for functions working with 32 bit ELF objects.
+.It Dv elf64_
+Used for functions working with 64 bit ELF objects.
+.It Dv Elf_
+Used for class-independent data types.
+.It Dv ELF_C_
+Used for command values used in a few functions.
+These symbols are defined as members of the
+.Vt Dv Elf_Cmd
+enumeration.
+.It Dv ELF_E_
+Used for error numbers.
+.It Dv ELF_F_
+Used for flags.
+.It Dv ELF_K_
+These constants define the kind of file associated with an ELF
+descriptor.
+See
+.Xr elf_kind 3 .
+The symbols are defined by the
+.Vt Elf_Kind
+enumeration.
+.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:
+.Bl -tag -width ".Vt Elf_Data"
+.It Vt Elf
+An
+.Vt Elf
+descriptor represents an ELF object or an
+.Xr ar 1
+archive.
+It is allocated using one of the
+.Fn elf_begin
+or
+.Fn elf_memory
+functions.
+An
+.Vt Elf
+descriptor can be used to read and write data to an ELF file.
+An
+.Vt Elf
+descriptor can be associated with zero or more
+.Vt Elf_Scn
+section descriptors.
+.Pp
+Given an ELF descriptor, the application may retrieve the ELF
+object's class-dependent
+.Dq "Executable Header"
+structures using the
+.Fn elf32_getehdr
+or
+.Fn elf64_getehdr
+functions.
+A new Ehdr structure may be allocated using the
+.Fn elf64_newehdr
+or
+.Fn elf64_newehdr
+functions.
+.Pp
+The
+.Dq "Program Header Table"
+associated with an ELF descriptor may be allocated using the
+.Fn elf32_getphdr
+or
+.Fn elf64_getphdr
+functions.
+A new program header table may be allocated or an existing table
+resized using the
+.Fn elf32_newphdr
+or
+.Fn elf64_newphdr
+functions.
+.Pp
+The
+.Vt Elf
+structure is opaque and has no members visible to the
+application.
+.\" TODO describe the Elf_Arhdr and Elf_Arsym structures.
+.It Vt Elf_Data
+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:
+.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 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 within the containing section where this descriptor's data
+would be placed.
+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 "Elf_Type d_type"
+The ELF type (see below) of the data in this descriptor.
+.It Vt "unsigned int d_version"
+The operating version for the data in this buffer.
+.El
+.Pp
+.Vt Elf_Data
+descriptors are usually associated with
+.Vt Elf_Scn
+descriptors.
+Existing data descriptors associated with an ELF section may be
+structures are retrieved using the
+.Fn elf_getdata
+and
+.Fn elf_rawdata
+functions.
+The
+.Fn elf_newdata
+function may be used to attach new data descriptors to an ELF section.
+.It Vt Elf_Scn
+.Vt Elf_Scn
+descriptors represent a section in an ELF object.
+.Pp
+They are retrieved using the
+.Fn elf_getscn
+function.
+An application may iterate through the existing sections of an ELF
+object using the
+.Fn elf_nextscn
+function.
+New sections may be allocated using the
+.Fn elf_newscn
+function.
+.Pp
+The
+.Vt Elf_Scn
+descriptor is opaque and contains no application modifiable fields.
+.El
+.Ss Supported Elf Types
+The following ELF datatypes are supported by the library.
+.Pp
+.Bl -tag -width ".Dv ELF_T_SYMINFO" -compact
+.It Dv ELF_T_ADDR
+Machine addresses.
+.It Dv ELF_T_BYTE
+Byte data.
+The library will not attempt to translate byte data.
+.It Dv ELF_T_CAP
+Software and hardware capability records.
+.It Dv ELF_T_DYN
+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
+64 bit unsigned words.
+.It Dv ELF_T_MOVE
+ELF Move records.
+.\".It Dv ELF_T_MOVEP
+.\" As yet unsupported.
+.It Dv ELF_T_NOTE
+ELF Note structures.
+.It Dv ELF_T_OFF
+File offsets.
+.It Dv ELF_T_PHDR
+ELF program header table entries.
+.It Dv ELF_T_REL
+ELF relocation entries.
+.It Dv ELF_T_RELA
+ELF relocation entries with addends.
+.It Dv ELF_T_SHDR
+ELF section header entries.
+.It Dv ELF_T_SWORD
+Signed 32-bit words.
+.It Dv ELF_T_SXWORD
+Signed 64-bit words.
+.It Dv ELF_T_SYMINFO
+ELF symbol information.
+.It Dv ELF_T_SYM
+ELF symbol table entries.
+.It Dv ELF_T_VDEF
+Symbol version definition records.
+.It Dv ELF_T_VNEED
+Symbol version requirement records.
+.It Dv ELF_T_WORD
+Unsigned 32-bit words.
+.It Dv ELF_T_XWORD
+Unsigned 64-bit words.
+.El
+.Pp
+The symbol
+.Dv ELF_T_NUM
+denotes the number of Elf types known to the library.
+.Pp
+The following table shows the mapping between ELF section types
+defined in
+.Xr elf 5
+and the types supported by the library.
+.Bl -column ".Dv SHT_PREINIT_ARRAY" ".Dv ELF_T_SYMINFO"
+.It Em Section Type Ta Em "Library Type" Ta Em Description
+.It Dv SHT_DYNAMIC Ta Dv ELF_T_DYN Ta Xo
+.Sq .dynamic
+section entries.
+.Xc
+.It Dv SHT_DYNSYM Ta Dv ELF_T_SYM Ta Symbols for dynamic linking.
+.It Dv SHT_FINI_ARRAY Ta Dv ELF_T_ADDR Ta Termination function pointers.
+.It Dv SHT_GNU_HASH Ta Dv ELF_T_GNUHASH Ta GNU hash sections.
+.It Dv SHT_GNU_LIBLIST Ta Dv ELF_T_WORD Ta List of libraries to be pre-linked.
+.It Dv SHT_GNU_verdef Ta Dv ELF_T_VDEF Ta Symbol version definitions.
+.It Dv SHT_GNU_verneed Ta Dv ELF_T_VNEED Ta Symbol versioning requirements.
+.It Dv SHT_GNU_versym Ta Dv ELF_T_HALF Ta Version symbols.
+.It Dv SHT_GROUP Ta Dv ELF_T_WORD Ta Section group marker.
+.It Dv SHT_HASH Ta Dv ELF_T_HASH Ta Symbol hashes.
+.It Dv SHT_INIT_ARRAY Ta Dv ELF_T_ADDR Ta Initialization function pointers.
+.It Dv SHT_NOBITS Ta Dv ELF_T_BYTE Ta Xo
+Empty sections.
+See
+.Xr elf 5 .
+.Xc
+.It Dv SHT_NOTE Ta Dv ELF_T_NOTE Ta ELF note records.
+.It Dv SHT_PREINIT_ARRAY Ta Dv ELF_T_ADDR Ta Pre-initialization function pointers.
+.It Dv SHT_PROGBITS Ta Dv ELF_T_BYTE Ta Machine code.
+.It Dv SHT_REL Ta Dv ELF_T_REL Ta ELF relocation records.
+.It Dv SHT_RELA Ta Dv ELF_T_RELA Ta Relocation records with addends.
+.It Dv SHT_STRTAB Ta Dv ELF_T_BYTE Ta String tables.
+.It Dv SHT_SYMTAB Ta Dv ELF_T_SYM Ta Symbol tables.
+.It Dv SHT_SYMTAB_SHNDX Ta Dv ELF_T_WORD Ta Used with extended section numbering.
+.It Dv SHT_SUNW_dof Ta Dv ELF_T_BYTE Ta Xo
+Used by
+.Xr dtrace 1 .
+.Xc
+.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.
+.It Dv SHT_SUNW_verdef Ta Dv ELF_T_VDEF Ta Xo
+Same as
+.Dv SHT_GNU_verdef .
+.Xc
+.It Dv SHT_SUNW_verneed Ta Dv ELF_T_VNEED Ta Xo
+Same as
+.Dv SHT_GNU_verneed .
+.Xc
+.It Dv SHT_SUNW_versym Ta Dv ELF_T_HALF Ta Xo
+Same as
+.Dv SHT_GNU_versym .
+.Xc
+.El
+.Pp
+Section types in the range
+.Ns [ Dv SHT_LOOS ,
+.Dv SHT_HIUSER ]
+are otherwise considered to be of type
+.Dv ELF_T_BYTE .
+.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 indent
+.It "Archive Access"
+.Bl -tag -compact
+.It Fn elf_getarsym
+Retrieve the archive symbol table.
+.It Fn elf_getarhdr
+Retrieve the archive header for an object.
+.It Fn elf_getbase
+Retrieve the offset of a member inside an archive.
+.It Fn elf_next
+Iterate through an
+.Xr ar 1
+archive.
+.It Fn elf_rand
+Random access inside an
+.Xr ar 1
+archive.
+.El
+.It "Data Structures"
+.Bl -tag -compact
+.It Fn elf_getdata
+Retrieve translated data for an ELF section.
+.It Fn elf_getscn
+Retrieve the section descriptor for a named section.
+.It Fn elf_ndxscn
+Retrieve the index for a section.
+.It Fn elf_newdata
+Add a new
+.Vt Elf_Data
+descriptor to an ELF section.
+.It Fn elf_newscn
+Add a new section descriptor to an ELF descriptor.
+.It Fn elf_nextscn
+Iterate through the sections in an ELF object.
+.It Fn elf_rawdata
+Retrieve untranslated data for an ELF section.
+.It Fn elf_rawfile
+Return a pointer to the untranslated file contents for an ELF object.
+.It Fn elf32_getehdr , Fn elf64_getehdr
+Retrieve the Executable Header in an ELF object.
+.It Fn elf32_getphdr , Fn elf64_getphdr
+Retrieve the Program Header Table in an ELF object.
+.It Fn elf32_getshdr , Fn elf64_getshdr
+Retrieve the ELF section header associated with an
+.Vt Elf_Scn
+descriptor.
+.It Fn elf32_newehdr , Fn elf64_newehdr
+Allocate an Executable Header in an ELF object.
+.It Fn elf32_newphdr , Fn elf64_newphdr
+Allocate or resize the Program Header Table in an ELF object.
+.El
+.It "Data Translation"
+.Bl -tag -compact
+.It Fn elf32_xlatetof , Fn elf64_xlatetof
+Translate an ELF data structure from its native representation to its
+file representation.
+.It Fn elf32_xlatetom , Fn elf64_xlatetom
+Translate an ELF data structure from its file representation to a
+native representation.
+.El
+.It "Error Reporting"
+.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 -compact
+.It Fn elf_begin
+Opens an
+.Xr ar 1
+archive or ELF object given a file descriptor.
+.It Fn elf_end
+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 arena.
+.It Fn elf_version
+Sets the operating version.
+.El
+.It "IO Control"
+.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
+Mark an
+.Vt Elf_Data
+descriptor as dirty.
+.It Fn elf_flagehdr
+Mark the ELF Executable Header in an ELF descriptor as dirty.
+.It Fn elf_flagphdr
+Mark the ELF Program Header Table in an ELF descriptor as dirty.
+.It Fn elf_flagscn
+Mark an
+.Vt Elf_Scn
+descriptor as dirty.
+.It Fn elf_flagshdr
+Mark an ELF Section Header as dirty.
+.It Fn elf_setshstrndx
+Set the index of the section name string table for the ELF object.
+.It Fn elf_update
+Recompute ELF object layout and optionally write the modified object
+back to the underlying file.
+.El
+.It "Queries"
+.Bl -tag -width ".Fn elf_getshstrndx" -compact
+.It Fn elf32_checksum , Fn elf64_checkum
+Compute checksum of an ELF object.
+.It Fn elf_getident
+Retrieve the identification bytes for an ELF object.
+.It Fn elf_getshnum
+Retrieve the number of sections in an ELF object.
+.It Fn elf_getshstrndx
+Retrieve the section index of the section name string table in
+an ELF object.
+.It Fn elf_hash
+Compute the ELF hash value of a string.
+.It Fn elf_kind
+Query the kind of object associated with an ELF descriptor.
+.It Fn elf32_fsize , Fn elf64_fsize
+Return the size of the file representation of an ELF type.
+.El
+.El
+.Ss Controlling ELF Object Layout
+In the usual mode of operation, library will compute section
+offsets and alignments based on the contents of an ELF descriptor's
+sections without need for further intervention by the
+application.
+.Pp
+However, if the application wishes to take complete charge of the
+layout of the ELF file, it may set the
+.Dv ELF_F_LAYOUT
+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
+.Xr elf_update 3
+manual page.
+.Pp
+Gaps in between sections will be filled with the fill character
+set by function
+.Fn elf_fill .
+.Ss Error Handling
+In case an error is encountered, these library functions set an
+internal error number and signal the presence of the error by
+returning an special return value.
+The application can check the
+current error number by calling
+.Xr elf_errno 3 .
+A human readable description of the recorded error is available by
+calling
+.Xr elf_errmsg 3 .
+.Ss Memory Management Rules
+The library keeps track of all
+.Vt Elf_Scn
+and
+.Vt Elf_Data
+descriptors associated with an ELF descriptor and recovers them
+when the descriptor is closed using
+.Xr elf_end 3 .
+Thus the application must not call
+.Xr free 3
+on data structures allocated by the ELF library.
+.Pp
+Conversely the library will not
+free data that it has not allocated.
+As an example, an application may call
+.Xr elf_newdata 3
+to allocate a new
+.Vt Elf_Data
+descriptor and can set the
+.Va d_off
+member of the descriptor to point to a region of memory allocated
+using
+.Xr malloc 3 .
+It is the applications responsibility to free this arena, though the
+library will reclaim the space used by the
+.Vt Elf_Data
+descriptor itself.
+.Sh SEE ALSO
+.Xr gelf 3 ,
+.Xr elf 5
+.Sh HISTORY
+The original ELF(3) API was developed for Unix System V.
+The current implementation of the ELF(3) API appeared in
+.Fx 7.0 .
+.Sh AUTHORS
+The ELF library was written by
+.An Joseph Koshy Aq Mt jkoshy@FreeBSD.org .
diff --git a/contrib/elftoolchain/libelf/elf_begin.3 b/contrib/elftoolchain/libelf/elf_begin.3
new file mode 100644
index 0000000000..e6c11b60e8
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_begin.3
@@ -0,0 +1,315 @@
+.\" 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 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_begin.3 3182 2015-04-10 16:08:10Z emaste $
+.\"
+.Dd December 11, 2011
+.Os
+.Dt ELF_BEGIN 3
+.Sh NAME
+.Nm elf_begin
+.Nd open an ELF file or ar(1) archive
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft "Elf *"
+.Fn elf_begin "int fd" "Elf_Cmd cmd" "Elf *elf"
+.Sh DESCRIPTION
+Function
+.Fn elf_begin
+is used to open ELF files and
+.Xr ar 1
+archives for further processing by other APIs in the
+.Xr elf 3
+library.
+It is also used to access individual ELF members of an
+.Xr ar 1
+archive in combination with the
+.Xr elf_next 3
+and
+.Xr elf_rand 3
+APIs.
+.Pp
+Argument
+.Ar fd
+is an open file descriptor returned from an
+.Xr open 2
+system call.
+Function
+.Fn elf_begin
+uses argument
+.Ar fd
+for reading or writing depending on the value of argument
+.Ar cmd .
+Argument
+.Ar elf
+is primarily used for iterating through archives.
+.Pp
+The argument
+.Ar cmd
+can have the following values:
+.Bl -tag -width "ELF_C_WRITE"
+.It ELF_C_NULL
+Causes
+.Fn elf_begin
+to return NULL.
+Arguments
+.Ar fd
+and
+.Ar elf
+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 the arguments
+.Ar fd
+and
+.Ar elf .
+It can be used for both
+.Xr ar 1
+archives and for ELF objects.
+.Pp
+If argument
+.Ar elf
+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 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
+.Xr ar 1
+archive opened earlier with
+.Fn elf_begin ,
+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
+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
+should have been opened for reading and writing.
+If argument
+.Ar elf
+is NULL, the library will allocate a new ELF descriptor for
+the file being processed.
+If the argument
+.Ar elf
+is non-null, it should point to a descriptor previously
+allocated with
+.Fn elf_begin
+with the same values for arguments
+.Ar fd
+and
+.Ar cmd ;
+in this case the library will increment the activation count for descriptor
+.Ar elf
+and return the same descriptor.
+.Pp
+Changes to the in-memory image of the ELF file may be written back to
+disk using the
+.Xr elf_update 3
+function.
+.It Dv ELF_C_WRITE
+This command is used when the application wishes to create a new ELF
+file.
+Argument
+.Ar fd
+should have been opened for writing.
+Argument
+.Ar elf
+is ignored, and the previous contents of file referenced by argument
+.Ar fd
+are overwritten.
+.El
+.Ss Processing ar(1) archives
+An
+.Xr ar 1
+archive may be opened in read mode (with argument
+.Ar cmd
+set to
+.Dv ELF_C_READ )
+using
+.Fn elf_begin
+or
+.Fn elf_memory .
+The returned ELF descriptor can be passed into to
+subsequent calls to
+.Fn elf_begin
+to access individual members of the archive.
+.Pp
+Random access within an opened archive is possible using
+the
+.Xr elf_next 3
+and
+.Xr elf_rand 3
+functions.
+.Pp
+The symbol table of the archive may be retrieved
+using
+.Xr elf_getarsym 3 .
+.Sh RETURN VALUES
+The function returns a pointer to a ELF descriptor if successful, or NULL
+if an error occurred.
+.Sh EXAMPLES
+To iterate through the members of an
+.Xr ar 1
+archive, use:
+.Bd -literal -offset indent
+Elf_Cmd c;
+Elf *ar_e, *elf_e;
+\&...
+c = ELF_C_READ;
+if ((ar_e = elf_begin(fd, c, (Elf *) 0)) == 0) {
+	\&... handle error in opening the archive ...
+}
+while ((elf_e = elf_begin(fd, c, ar_e)) != 0) {
+	\&... process member referenced by elf_e here ...
+	c = elf_next(elf_e);
+	elf_end(elf_e);
+}
+.Ed
+.Pp
+To create a new ELF file, use:
+.Bd -literal -offset indent
+int fd;
+Elf *e;
+\&...
+if ((fd = open("filename", O_RDWR|O_TRUNC|O_CREAT, 0666)) < 0) {
+	\&... handle the error from open(2) ...
+}
+if ((e = elf_begin(fd, ELF_C_WRITE, (Elf *) 0)) == 0) {
+	\&... handle the error from elf_begin() ...
+}
+\&... create the ELF image using other elf(3) APIs ...
+elf_update(e, ELF_C_WRITE);
+elf_end(e);
+.Ed
+.Sh ERRORS
+Function
+.Fn elf_begin
+can fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARCHIVE
+The archive denoted by argument
+.Ar elf
+could not be parsed.
+.It Bq Er ELF_E_ARGUMENT
+The value in argument
+.Ar cmd
+was unrecognized.
+.It Bq Er ELF_E_ARGUMENT
+A non-null value for argument
+.Ar elf
+was specified when
+.Ar cmd
+was set to
+.Dv ELF_C_RDWR .
+.It Bq Er ELF_E_ARGUMENT
+The value of argument
+.Ar fd
+differs from the one the ELF descriptor
+.Ar elf
+was created with.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar cmd
+differs from the value specified when ELF descriptor
+.Ar elf
+was created.
+.It Bq Er ELF_E_ARGUMENT
+An
+.Xr ar 1
+archive was opened 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
+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
+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 ,
+.Xr elf_end 3 ,
+.Xr elf_errno 3 ,
+.Xr elf_memory 3 ,
+.Xr elf_next 3 ,
+.Xr elf_rand 3 ,
+.Xr elf_update 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/elf_cntl.3 b/contrib/elftoolchain/libelf/elf_cntl.3
new file mode 100644
index 0000000000..257897590d
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_cntl.3
@@ -0,0 +1,111 @@
+.\" 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 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_cntl.3 3181 2015-04-10 13:22:51Z emaste $
+.\"
+.Dd August 9, 2006
+.Os
+.Dt ELF_CNTL 3
+.Sh NAME
+.Nm elf_cntl
+.Nd control an elf file descriptor
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft int
+.Fn elf_cntl "Elf *elf" "Elf_Cmd cmd"
+.Sh DESCRIPTION
+Function
+.Fn elf_cntl
+controls the ELF library's subsequent use of the file descriptor
+used to create ELF descriptor
+.Ar elf .
+.Pp
+Argument
+.Ar cmd
+informs the library of the action to be taken:
+.Bl -tag -width "ELF_C_FDDONE"
+.It Dv ELF_C_FDDONE
+This value instructs the ELF library not to perform any further
+I/O on the file descriptor associated with argument
+.Ar elf .
+For ELF descriptors opened with mode
+.Ar ELF_C_WRITE
+or
+.Ar ELF_C_RDWR
+subsequent
+.Fn elf_update
+operations on the descriptor will fail.
+.It Dv ELF_C_FDREAD
+This value instructs the ELF library to read in all necessary
+data associated with ELF descriptor
+.Ar elf
+into memory so that the underlying file descriptor can be
+safely closed with command
+.Dv ELF_C_FDDONE .
+.El
+.Pp
+Argument
+.Ar elf
+must be an ELF descriptor associated with a file system object
+(e.g., an
+.Xr ar 1
+archive, an ELF file, or other data file).
+.Sh IMPLEMENTATION NOTES
+Due to use of
+.Xr mmap 2
+internally, this function is a no-op for ELF objects opened in
+.Dv ELF_C_READ
+mode.
+.Sh RETURN VALUES
+Function
+.Fn elf_cntl
+returns 0 on success, or -1 if an error was detected.
+.Sh ERRORS
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARCHIVE
+Argument
+.Ar elf
+is a descriptor for an archive member.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar cmd
+was not recognized.
+.It Bq Er ELF_E_MODE
+An
+.Dv ELF_C_FDREAD
+operation was requested on an ELF descriptor opened
+for writing.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_begin 3 ,
+.Xr elf_end 3 ,
+.Xr elf_next 3 ,
+.Xr elf_update 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/elf_data.c b/contrib/elftoolchain/libelf/elf_data.c
index ce80e1c94c..d494eda2de 100644
--- a/contrib/elftoolchain/libelf/elf_data.c
+++ b/contrib/elftoolchain/libelf/elf_data.c
@@ -32,7 +32,7 @@
 
 #include "_libelf.h"
 
-ELFTC_VCSID("$Id: elf_data.c 3177 2015-03-30 18:19:41Z emaste $");
+ELFTC_VCSID("$Id: elf_data.c 3466 2016-05-11 18:35:44Z emaste $");
 
 Elf_Data *
 elf_getdata(Elf_Scn *s, Elf_Data *ed)
@@ -94,7 +94,7 @@ elf_getdata(Elf_Scn *s, Elf_Data *ed)
 
 	if ((elftype = _libelf_xlate_shtype(sh_type)) < ELF_T_FIRST ||
 	    elftype > ELF_T_LAST || (sh_type != SHT_NOBITS &&
-	    sh_offset + sh_size > (uint64_t) e->e_rawsize)) {
+	    (sh_offset > e->e_rawsize || sh_size > e->e_rawsize - sh_offset))) {
 		LIBELF_SET_ERROR(SECTION, 0);
 		return (NULL);
 	}
@@ -253,6 +253,12 @@ elf_rawdata(Elf_Scn *s, Elf_Data *ed)
 		return (NULL);
 	}
 
+	if (sh_type != SHT_NOBITS &&
+	    (sh_offset > e->e_rawsize || sh_size > e->e_rawsize - sh_offset)) {
+		LIBELF_SET_ERROR(SECTION, 0);
+		return (NULL);
+	}
+
 	if ((d = _libelf_allocate_data(s)) == NULL)
 		return (NULL);
 
diff --git a/contrib/elftoolchain/libelf/elf_end.3 b/contrib/elftoolchain/libelf/elf_end.3
new file mode 100644
index 0000000000..8649faaa69
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_end.3
@@ -0,0 +1,76 @@
+.\" 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 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_end.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd June 29, 2006
+.Os
+.Dt ELF_END 3
+.Sh NAME
+.Nm elf_end
+.Nd release an ELF descriptor
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft int
+.Fn elf_end "Elf *elf"
+.Sh DESCRIPTION
+Function
+.Fn elf_end
+is used to release the resources associated with an ELF descriptor
+pointed to by argument
+.Ar elf .
+This descriptor must have been allocated by a previous call to
+.Xr elf_begin 3
+or
+.Xr elf_memory 3 .
+For programming convenience, a NULL value is permitted for argument
+.Ar elf .
+.Pp
+A call to
+.Fn elf_end
+decrements the activation count for descriptor
+.Ar elf
+by one.
+The resources associated with the descriptor are only released
+with its activation count goes to zero.
+.Pp
+Once function
+.Fn elf_end
+returns zero, the ELF descriptor
+.Ar elf
+will no longer be valid and should not be used further.
+.Sh RETURN VALUES
+Function
+.Fn elf_end
+returns the current value of the ELF descriptor
+.Ar elf Ap s
+activation count, or zero if argument
+.Ar elf
+was NULL.
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_begin 3 ,
+.Xr elf_memory 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/elf_errmsg.3 b/contrib/elftoolchain/libelf/elf_errmsg.3
new file mode 100644
index 0000000000..822ba6ac89
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_errmsg.3
@@ -0,0 +1,107 @@
+.\" 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 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_errmsg.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd June 11, 2006
+.Os
+.Dt ELF_ERRMSG 3
+.Sh NAME
+.Nm elf_errmsg ,
+.Nm elf_errno
+.Nd ELF library error message handling
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft int
+.Fn elf_errno "void"
+.Ft "const char *"
+.Fn elf_errmsg "int error"
+.Sh DESCRIPTION
+When an error occurs during an ELF library API call, the library
+encodes the error using an error number and stores the error number
+internally for retrieval by the application at a later point of time.
+Error numbers may contain an OS supplied error code in addition to
+an ELF API specific error code.
+An error number value of zero indicates no error.
+.Pp
+Function
+.Fn elf_errno
+is used to retrieve the last error recorded by the ELF library.
+Invoking this function has the side-effect of resetting the
+ELF library's recorded error number to zero.
+.Pp
+The function
+.Fn elf_errmsg
+returns a null-terminated string with a human readable
+description of the error specified in argument
+.Ar error .
+A zero value for argument
+.Ar error
+retrieves the most recent error encountered by the ELF
+library.
+An argument value of -1 behaves identically, except that
+it guarantees a non-NULL return from
+.Fn elf_errmsg .
+.Sh RETURN VALUES
+Function
+.Fn elf_errno
+returns a non-zero value encoding the last error encountered
+by the ELF library, or zero if no error was encountered.
+.Pp
+Function
+.Fn elf_errmsg
+returns a pointer to library local storage for non-zero values
+of argument
+.Ar error .
+With a zero argument, the function will return a NULL pointer if no
+error had been encountered by the library, or will return a pointer to
+library local storage containing an appropriate message otherwise.
+.Sh EXAMPLES
+Clearing the ELF library's recorded error number can be accomplished
+by invoking
+.Fn elf_errno
+and discarding its return value.
+.Bd -literal -offset indent
+/* clear error */
+(void) elf_errno();
+.Ed
+.Pp
+Retrieving a human-readable description of the current error number
+can be done with the following snippet:
+.Bd -literal -offset indent
+int err;
+const char *errmsg;
+\&...
+err = elf_errno();
+if (err != 0)
+	errmsg = elf_errmsg(err);
+.Ed
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr gelf 3
+.Sh BUGS
+Function
+.Fn elf_errmsg
+is not localized.
diff --git a/contrib/elftoolchain/libelf/elf_fill.3 b/contrib/elftoolchain/libelf/elf_fill.3
new file mode 100644
index 0000000000..ab42a4245f
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_fill.3
@@ -0,0 +1,52 @@
+.\" 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 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_fill.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd June 11, 2006
+.Os
+.Dt ELF_FILL 3
+.Sh NAME
+.Nm elf_fill
+.Nd set fill byte for inter-section padding
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft void
+.Fn elf_fill "int fill"
+.Sh DESCRIPTION
+Function
+.Fn elf_fill
+allows an application to specify a fill value for the padding inserted
+between two sections of an ELF file to meet section alignment
+constraints.
+By default the ELF library uses zero bytes for padding.
+.Pp
+The ELF library will only pad bytes if the
+.Dv ELF_F_LAYOUT
+flag is not set for the ELF file.
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_flagelf 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/elf_flagdata.3 b/contrib/elftoolchain/libelf/elf_flagdata.3
new file mode 100644
index 0000000000..de3cfd9731
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_flagdata.3
@@ -0,0 +1,223 @@
+.\" 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 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_flagdata.3 3479 2016-06-25 20:44:33Z jkoshy $
+.\"
+.Dd December 3, 2011
+.Os
+.Dt ELF_FLAGDATA 3
+.Sh NAME
+.Nm elf_flagarhdr ,
+.Nm elf_flagdata ,
+.Nm elf_flagehdr ,
+.Nm elf_flagelf ,
+.Nm elf_flagphdr ,
+.Nm elf_flagscn ,
+.Nm elf_flagshdr
+.Nd manipulate flags associated with ELF(3) data structures
+.Sh LIBRARY
+.Lb libelf
+.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"
+.Ft "unsigned int"
+.Fn elf_flagelf "Elf *elf" "Elf_Cmd cmd" "unsigned int flags"
+.Ft "unsigned int"
+.Fn elf_flagphdr "Elf *elf" "Elf_Cmd cmd" "unsigned int flags"
+.Ft "unsigned int"
+.Fn elf_flagscn "Elf_Scn *scn" "Elf_Cmd cmd" "unsigned int flags"
+.Ft "unsigned int"
+.Fn elf_flagshdr "Elf_Scn *scn" "Elf_Cmd cmd" "unsigned int flags"
+.Sh DESCRIPTION
+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
+Argument
+.Ar cmd
+may have the following values:
+.Bl -tag -width ELF_C_SET
+.It Dv ELF_C_CLR
+The argument
+.Ar flags
+specifies the flags to be cleared.
+.It Dv ELF_C_SET
+The argument
+.Ar flags
+specifies the flags to be set.
+.El
+.Pp
+The argument
+.Ar flags
+is allowed to have the following flags set:
+.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.
+A subsequent call to
+.Xr elf_update 3
+will resynchronize the library's internal data structures.
+.It Dv ELF_F_LAYOUT
+This flag is only valid with the
+.Fn elf_flagelf
+API.
+It informs the library that the application will take
+responsibility for the layout of the file and that the library is
+not to insert any padding in between sections.
+.El
+.Pp
+Marking a given data structure as
+.Dq dirty
+affects all of its contained elements.
+Thus marking an ELF descriptor
+.Ar elf
+with
+.Fn elf_flagelf "elf" "ELF_C_SET" "ELF_F_DIRTY"
+means that the entire contents of the descriptor are
+.Dq dirty .
+.Pp
+Using a value of zero for argument
+.Ar flags
+will return the current set of flags for the data structure being
+queried.
+.Sh RETURN VALUES
+These functions return the updated flags if successful, or 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]"
+.It Bq Er ELF_E_ARGUMENT
+An unsupported value was used for the
+.Ar cmd
+argument.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar flags
+had unsupported flags set.
+.It Bq Er ELF_E_ARGUMENT
+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
+was called without an executable header being allocated.
+.It Bq Er ELF_E_SEQUENCE
+Function
+.Fn elf_flagphdr
+was called without a program header being allocated.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf32_newehdr 3 ,
+.Xr elf32_newphdr 3 ,
+.Xr elf64_newehdr 3 ,
+.Xr elf64_newphdr 3 ,
+.Xr elf_newdata 3 ,
+.Xr elf_update 3 ,
+.Xr gelf 3 ,
+.Xr gelf_newehdr 3 ,
+.Xr gelf_newphdr 3 ,
+.Xr gelf_update_dyn 3 ,
+.Xr gelf_update_move 3 ,
+.Xr gelf_update_rel 3 ,
+.Xr gelf_update_rela 3 ,
+.Xr gelf_update_sym 3 ,
+.Xr gelf_update_syminfo 3
diff --git a/contrib/elftoolchain/libelf/elf_getarhdr.3 b/contrib/elftoolchain/libelf/elf_getarhdr.3
new file mode 100644
index 0000000000..1aab71ce43
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_getarhdr.3
@@ -0,0 +1,97 @@
+.\" 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 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_getarhdr.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd August 15, 2006
+.Os
+.Dt ELF_GETARHDR 3
+.Sh NAME
+.Nm elf_getarhdr
+.Nd retrieve ar(1) header for an archive member
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft "Elf_Arhdr *"
+.Fn elf_getarhdr "Elf *elf"
+.Sh DESCRIPTION
+The
+.Fn elf_getarhdr
+function returns a pointer to an archive member header for
+a descriptor
+.Ar elf .
+This descriptor must have been returned by a prior call to
+.Xr elf_begin 3 ,
+and must be a descriptor for a member inside an
+.Xr ar 1
+archive.
+.Pp
+Structure
+.Vt Elf_Arhdr
+includes the following members:
+.Bl -tag -width indent
+.It Vt "char *" Va ar_name
+A pointer to a null terminated string containing the translated
+name of the archive member.
+.It Vt "char *" Va ar_rawname
+A pointer to a null terminated string containing the untranslated
+name for the archive member, including all
+.Xr ar 1
+formatting characters and trailing white space.
+.It Vt time_t Va ar_date
+The timestamp associated with the member.
+.It Vt uid_t Va ar_uid
+The uid of the creator of the member.
+.It Vt gid_t Va ar_gid
+The gid of the creator of the member.
+.It Vt mode_t Va ar_mode
+The file mode of the member.
+.It Vt size_t Va ar_size
+The size of the member in bytes.
+.El
+.Sh RETURN VALUES
+This function returns a valid pointer to an
+.Vt Elf_Arhdr
+structure if successful, or NULL if an error is encountered.
+.Sh ERRORS
+Function
+.Fn elf_getarhdr
+may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not a descriptor for a member of an
+.Xr ar 1
+archive.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_begin 3 ,
+.Xr elf_getarsym 3 ,
+.Xr elf_memory 3
diff --git a/contrib/elftoolchain/libelf/elf_getarsym.3 b/contrib/elftoolchain/libelf/elf_getarsym.3
new file mode 100644
index 0000000000..cda0511dfd
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_getarsym.3
@@ -0,0 +1,130 @@
+.\" 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 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_getarsym.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd August 15, 2006
+.Os
+.Dt ELF_GETARSYM 3
+.Sh NAME
+.Nm elf_getarsym
+.Nd retrieve the symbol table of an archive
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft "Elf_Arsym *"
+.Fn elf_getarsym "Elf *elf" "size_t *ptr"
+.Sh DESCRIPTION
+The function
+.Fn elf_getarsym
+retrieves the symbol table for an
+.Xr ar 1
+archive, if one is available.
+.Pp
+Argument
+.Ar elf
+should be a descriptor for an
+.Xr ar 1
+archive opened using
+.Fn elf_begin
+or
+.Fn elf_memory .
+.Pp
+If the archive
+.Ar elf
+contains a symbol table with n entries, this function returns a
+pointer to an array of n+1
+.Vt Elf_Arsym
+structures.
+An
+.Vt Elf_Arsym
+structure has the following elements:
+.Bl -tag -width indent -compact
+.It Vt "char *" Va as_name
+This structure member is a pointer to a null-terminated symbol name.
+.It Vt "off_t" Va as_off
+This structure member contains the byte offset from the beginning of the archive to
+the header for the archive member.
+This value is suitable for use with
+.Xr elf_rand 3 .
+.It Vt "unsigned long" Va as_hash
+This structure member contains a portable hash value for the symbol
+name, as computed by
+.Xr elf_hash 3 .
+.El
+.Pp
+The last entry of the returned array will have a NULL value for member
+.Va as_name ,
+a zero value for member
+.Va as_off
+and an illegal value of ~0UL for
+.Va as_hash .
+.Pp
+If argument
+.Ar ptr
+is non-null, the
+.Fn elf_getarsym
+function will store the number of table entries returned (including the
+sentinel entry at the end) into the location it points to.
+.Sh RETURN VALUES
+Function
+.Fn elf_getarsym
+returns a pointer to an array of
+.Vt Elf_Arsym
+structures if successful, or a NULL
+pointer if an error was encountered.
+.Pp
+If argument
+.Ar ptr
+is non-null and there was no error, the library will store the
+number of archive symbol entries returned into the location it
+points to.
+If argument
+.Ar ptr
+is non-null and an error was encountered, the library will
+set the location pointed to by it to zero.
+.Sh ERRORS
+Function
+.Fn elf_getarsym
+may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not a descriptor for an
+.Xr ar 1
+archive.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_begin 3 ,
+.Xr elf_getarhdr 3 ,
+.Xr elf_hash 3 ,
+.Xr elf_memory 3 ,
+.Xr elf_next 3 ,
+.Xr elf_rand 3
diff --git a/contrib/elftoolchain/libelf/elf_getbase.3 b/contrib/elftoolchain/libelf/elf_getbase.3
new file mode 100644
index 0000000000..fa17353941
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_getbase.3
@@ -0,0 +1,71 @@
+.\" Copyright (c) 2006,2008,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 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_getbase.3 978 2010-06-06 12:40:19Z jkoshy $
+.\"
+.Dd June 6, 2010
+.Os
+.Dt ELF_GETBASE 3
+.Sh NAME
+.Nm elf_getbase
+.Nd get the base offset for an object file
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft off_t
+.Fn elf_getbase "Elf *elf"
+.Sh DESCRIPTION
+Function
+.Fn elf_getbase
+returns the file offset to the first byte of the object referenced by ELF
+descriptor
+.Ar elf .
+.Pp
+For descriptors referencing members of archives, the returned offset is
+the file offset of the member in its containing archive.
+For descriptors to regular objects, the returned offset is (vacuously)
+zero.
+.Sh RETURN VALUES
+Function
+.Fn elf_getbase
+returns a valid file offset if successful, or
+.Pq Vt off_t
+.Li -1
+in case of an error.
+.Sh ERRORS
+Function
+.Fn elf_getbase
+may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was NULL.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_getarhdr 3 ,
+.Xr elf_getident 3 ,
+.Xr elf_rawfile 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/elf_getdata.3 b/contrib/elftoolchain/libelf/elf_getdata.3
new file mode 100644
index 0000000000..68b28890b4
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_getdata.3
@@ -0,0 +1,229 @@
+.\" Copyright (c) 2006,2008,2010-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 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_getdata.3 3181 2015-04-10 13:22:51Z emaste $
+.\"
+.Dd January 26, 2011
+.Os
+.Dt ELF_GETDATA 3
+.Sh NAME
+.Nm elf_getdata ,
+.Nm elf_newdata ,
+.Nm elf_rawdata
+.Nd iterate through or allocate section data
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft "Elf_Data *"
+.Fn elf_getdata "Elf_Scn *scn" "Elf_Data *data"
+.Ft "Elf_Data *"
+.Fn elf_newdata "Elf_Scn *scn"
+.Ft "Elf_Data *"
+.Fn elf_rawdata "Elf_Scn *scn" "Elf_Data *data"
+.Sh DESCRIPTION
+These functions are used to access and manipulate data descriptors
+associated with section descriptors.
+Data descriptors used by the ELF library are described in
+.Xr elf 3 .
+.Pp
+Function
+.Fn elf_getdata
+will return the next data descriptor associated with section descriptor
+.Ar scn .
+The returned data descriptor will be setup to contain translated data.
+Argument
+.Ar data
+may be NULL, in which case the function returns the first data descriptor
+associated with section
+.Ar scn .
+If argument
+.Ar data
+is not NULL, it must be a pointer to a data descriptor associated with
+section descriptor
+.Ar scn ,
+and function
+.Fn elf_getdata
+will return a pointer to the next data descriptor for the section,
+or NULL when the end of the section's descriptor list is reached.
+.Pp
+Function
+.Fn elf_newdata
+will allocate a new data descriptor and append it to the list of data
+descriptors associated with section descriptor
+.Ar scn .
+The new data descriptor will be initialized as follows:
+.Bl -tag -width "d_version" -compact -offset indent
+.It Va d_align
+Set to 1.
+.It Va d_buf
+Initialized to NULL.
+.It Va d_off
+Set to (off_t) -1.
+This field is under application control if the
+.Dv ELF_F_LAYOUT
+flag was set on the ELF descriptor.
+.It Va d_size
+Set to zero.
+.It Va d_type
+Initialized to
+.Dv ELF_T_BYTE .
+.It Va d_version
+Set to the current working version of the library, as set by
+.Xr elf_version 3 .
+.El
+The application must set these values as appropriate before
+calling
+.Xr elf_update 3 .
+Section
+.Ar scn
+must be associated with an ELF file opened for writing.
+If the application has not requested full control of layout by
+setting the
+.Dv ELF_F_LAYOUT
+flag on descriptor
+.Ar elf ,
+then the data referenced by the returned descriptor will be positioned
+after the existing content of the section, honoring the file alignment
+specified in member
+.Va d_align .
+On successful completion of a call to
+.Fn elf_newdata ,
+the ELF library will mark the section
+.Ar scn
+as
+.Dq dirty .
+.Pp
+Function
+.Fn elf_rawdata
+is used to step through the data descriptors associated with
+section
+.Ar scn .
+In contrast to function
+.Fn elf_getdata ,
+this function returns untranslated data.
+If argument
+.Ar data
+is NULL, the first data descriptor associated with section
+.Ar scn
+is returned.
+If argument
+.Ar data
+is not NULL, is must be a data descriptor associated with
+section
+.Ar scn ,
+and function
+.Fn elf_rawdata
+will return the next data descriptor in the list, or NULL
+if no further descriptors are present.
+Function
+.Fn elf_rawdata
+always returns
+.Vt Elf_Data
+structures of type
+.Dv ELF_T_BYTE .
+.Ss Special handling of zero-sized and SHT_NOBITS sections
+For sections of type
+.Dv SHT_NOBITS,
+and for zero-sized sections,
+the functions
+.Fn elf_getdata
+and
+.Fn elf_rawdata
+return a pointer to a valid
+.Vt Elf_Data
+structure that has its
+.Va d_buf
+member set to NULL and its
+.Va d_size
+member set to the size of the section.
+.Pp
+If an application wishes to create a section of type
+.Dv SHT_NOBITS ,
+it should add a data buffer to the section using function
+.Fn elf_newdata .
+It should then set the
+.Va d_buf
+and
+.Va d_size
+members of the returned
+.Vt Elf_Data
+structure to NULL and the desired size of the section respectively.
+.Sh RETURN VALUES
+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]"
+.It Bq Er ELF_E_ARGUMENT
+Either of the arguments
+.Ar scn
+or
+.Ar data
+was NULL.
+.It Bq Er ELF_E_ARGUMENT
+The data descriptor referenced by argument
+.Ar data
+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 ,
+.Xr elf_flagdata 3 ,
+.Xr elf_flagscn 3 ,
+.Xr elf_getscn 3 ,
+.Xr elf_getshdr 3 ,
+.Xr elf_newscn 3 ,
+.Xr elf_rawfile 3 ,
+.Xr elf_update 3 ,
+.Xr elf_version 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/elf_getident.3 b/contrib/elftoolchain/libelf/elf_getident.3
new file mode 100644
index 0000000000..01d7f9733a
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_getident.3
@@ -0,0 +1,83 @@
+.\" 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 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_getident.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd July 3, 2006
+.Os
+.Dt ELF_GETIDENT 3
+.Sh NAME
+.Nm elf_getident
+.Nd return the initial bytes of a file
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft char *
+.Fn elf_getident "Elf *elf" "size_t *sz"
+.Sh DESCRIPTION
+Function
+.Fn elf_getident
+returns a pointer to the initial bytes of the file for descriptor
+.Ar elf .
+.Pp
+If argument
+.Ar sz
+is non-null, the size of the identification area returned is written
+to the location pointed to by
+.Ar sz .
+This location is set to zero on errors.
+.Sh RETURN VALUES
+Function
+.Fn elf_getident
+will return a non-NULL pointer to the initial bytes of the file if
+successful, or NULL if an error condition is detected.
+.Sh ERRORS
+Function
+.Fn elf_getident
+can fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+A NULL value was passed in for argument
+.Ar elf .
+.It Bq Er ELF_E_SEQUENCE
+ELF descriptor
+.Ar elf
+was opened for writing and function
+.Fn elf_getident
+was called before a call to
+.Xr elf_update 3 .
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf32_getehdr 3 ,
+.Xr elf64_getehdr 3 ,
+.Xr elf_getarhdr 3 ,
+.Xr elf_getbase 3 ,
+.Xr elf_getflags 3 ,
+.Xr elf_kind 3 ,
+.Xr elf_rawfile 3 ,
+.Xr elf_update 3 ,
+.Xr gelf 3 ,
+.Xr gelf_getclass 3 ,
+.Xr gelf_getehdr 3
diff --git a/contrib/elftoolchain/libelf/elf_getphdrnum.3 b/contrib/elftoolchain/libelf/elf_getphdrnum.3
new file mode 100644
index 0000000000..f0fae5ebb0
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_getphdrnum.3
@@ -0,0 +1,86 @@
+.\" 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 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_getphdrnum.3 467 2009-08-05 18:18:49Z jkoshy $
+.\"
+.Dd August 5, 2009
+.Os
+.Dt ELF_GETPHDRNUM 3
+.Sh NAME
+.Nm elf_getphdrnum
+.Nd return the number of program headers in an ELF file
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft int
+.Fn elf_getphdrnum "Elf *elf" "size_t *phnum"
+.Sh DESCRIPTION
+Function
+.Fn elf_getphdrnum
+retrieves the number of ELF program headers associated with descriptor
+.Ar elf
+and stores it into the location pointed to by argument
+.Ar phnum .
+.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
+returns a zero value if successful, or -1 in case of an error.
+.Sh ERRORS
+Function
+.Fn elf_getphnum
+can fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+A NULL value was passed in for argument
+.Ar elf .
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not for an ELF file.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+lacks an ELF Executable Header.
+.It Bq Er ELF_E_HEADER
+The ELF Executable Header associated with argument
+.Ar elf
+was corrupt.
+.It Bq Er ELF_E_SECTION
+The section header at index
+.Dv SHN_UNDEF
+was corrupt.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf32_getehdr 3 ,
+.Xr elf64_getehdr 3 ,
+.Xr elf_getident 3 ,
+.Xr elf_getshdrnum 3 ,
+.Xr elf_getshdrstrndx 3 ,
+.Xr gelf 3 ,
+.Xr gelf_getehdr 3
diff --git a/contrib/elftoolchain/libelf/elf_getphnum.3 b/contrib/elftoolchain/libelf/elf_getphnum.3
new file mode 100644
index 0000000000..95c75403c3
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_getphnum.3
@@ -0,0 +1,93 @@
+.\" 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 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_getphnum.3 467 2009-08-05 18:18:49Z jkoshy $
+.\"
+.Dd August 5, 2009
+.Os
+.Dt ELF_GETPHNUM 3
+.Sh NAME
+.Nm elf_getphnum
+.Nd return the number of program headers in an ELF file
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft int
+.Fn elf_getphnum "Elf *elf" "size_t *phnum"
+.Sh DESCRIPTION
+This function is deprecated.
+Please use function
+.Xr elf_getphdrnum 3
+instead.
+.Pp
+Function
+.Fn elf_getphnum
+retrieves the number of ELF program headers associated with descriptor
+.Ar elf
+and stores it into the location pointed to by argument
+.Ar phnum .
+.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
+returns a non-zero value if successful, or zero in case of an
+error.
+.Sh ERRORS
+Function
+.Fn elf_getphnum
+can fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+A NULL value was passed in for argument
+.Ar elf .
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not for an ELF file.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+lacks an ELF Executable Header.
+.It Bq Er ELF_E_HEADER
+The ELF Executable Header associated with argument
+.Ar elf
+was corrupt.
+.It Bq Er ELF_E_SECTION
+The section header at index
+.Dv SHN_UNDEF
+was corrupt.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf32_getehdr 3 ,
+.Xr elf64_getehdr 3 ,
+.Xr elf_getident 3 ,
+.Xr elf_getphdrnum 3 ,
+.Xr elf_getshdrnum 3 ,
+.Xr elf_getshdrstrndx 3 ,
+.Xr gelf 3 ,
+.Xr gelf_getehdr 3
diff --git a/contrib/elftoolchain/libelf/elf_getscn.3 b/contrib/elftoolchain/libelf/elf_getscn.3
new file mode 100644
index 0000000000..0afe44340c
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_getscn.3
@@ -0,0 +1,151 @@
+.\" 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 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_getscn.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd October 22, 2007
+.Os
+.Dt ELF_GETSCN 3
+.Sh NAME
+.Nm elf_getscn ,
+.Nm elf_ndxscn ,
+.Nm elf_newscn ,
+.Nm elf_nextscn
+.Nd get/allocate section information for an ELF object
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft "Elf_Scn *"
+.Fn elf_getscn "Elf *elf" "size_t index"
+.Ft size_t
+.Fn elf_ndxscn "Elf_Scn *scn"
+.Ft "Elf_Scn *"
+.Fn elf_newscn "Elf *elf"
+.Ft "Elf_Scn *"
+.Fn elf_nextscn "Elf *elf" "Elf_Scn *scn"
+.Sh DESCRIPTION
+These functions are used to iterate through the sections associated
+with an ELF descriptor.
+.Pp
+Function
+.Fn elf_getscn
+will return a section descriptor for the section at index
+.Ar index
+in the object denoted by ELF descriptor
+.Ar elf .
+An error will be signalled if the specified section does not
+exist.
+.Pp
+Function
+.Fn elf_ndxscn
+returns the section table index associated with section descriptor
+.Ar scn .
+.Pp
+Function
+.Fn elf_newscn
+creates a new section and appends it to the list of sections
+associated with descriptor
+.Ar elf .
+The library will automatically increment the
+.Va e_shnum
+field of the ELF header associated with descriptor
+.Ar elf ,
+and will set the
+.Dv ELF_F_DIRTY
+flag on the returned section descriptor.
+For ELF descriptors opened for writing, the ELF library will
+automatically create an empty section at index zero
+.Dv ( SHN_UNDEF )
+on the first call to
+.Fn elf_newscn .
+.Pp
+Function
+.Fn elf_nextscn
+takes a section descriptor
+.Ar scn
+and returns a pointer to the section descriptor at the next higher
+index.
+Argument
+.Ar scn
+is allowed to be NULL, in which case this function will return a
+pointer to the section descriptor at index 1.
+If no further sections are present, function
+.Fn elf_nextscn
+will return a NULL pointer.
+.Sh RETURN VALUES
+Functions
+.Fn elf_getscn ,
+.Fn elf_newscn
+and
+.Fn elf_nextscn
+return a valid pointer to a section descriptor if successful, or
+NULL if an error occurs.
+.Pp
+Function
+.Fn elf_ndxscn
+returns a valid section table index if successful, or
+.Dv SHN_UNDEF
+if an error occurs.
+.Sh ERRORS
+These functions may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Arguments
+.Ar elf
+or
+.Ar scn
+were NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar index
+exceeded the current number of sections in the ELF object.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not a descriptor for an ELF file.
+.It Bq Er ELF_E_ARGUMENT
+Section descriptor
+.Ar scn
+was not associated with ELF descriptor
+.Ar elf .
+.It Bq Er ELF_E_CLASS
+Descriptor
+.Ar elf
+was of an unknown ELF class.
+.It Bq Er ELF_E_SECTION
+Argument
+.Ar elf
+specified extended section numbering in the ELF header with the section header at
+index
+.Dv SHN_UNDEF
+not being of type
+.Dv SHT_NULL .
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_flagdata 3 ,
+.Xr elf_flagscn 3 ,
+.Xr elf_getdata 3 ,
+.Xr elf_getshdr 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/elf_getshdrnum.3 b/contrib/elftoolchain/libelf/elf_getshdrnum.3
new file mode 100644
index 0000000000..e2bf354bae
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_getshdrnum.3
@@ -0,0 +1,78 @@
+.\" 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 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_getshdrnum.3 467 2009-08-05 18:18:49Z jkoshy $
+.\"
+.Dd August 4, 2009
+.Os
+.Dt ELF_GETSHDRNUM 3
+.Sh NAME
+.Nm elf_getshdrnum
+.Nd return the number of sections in an ELF file
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft int
+.Fn elf_getshdrnum "Elf *elf" "size_t *shnum"
+.Sh DESCRIPTION
+Function
+.Fn elf_getshdrnum
+retrieves the number of ELF sections associated with descriptor
+.Ar elf
+and stores it into the location pointed to by argument
+.Ar shnum .
+.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
+returns zero value if successful, or -1 in case of an error.
+.Sh ERRORS
+Function
+.Fn elf_getshdrnum
+can fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+A NULL value was passed in for argument
+.Ar elf .
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not for an ELF file.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+lacks an ELF Executable header.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf32_getehdr 3 ,
+.Xr elf64_getehdr 3 ,
+.Xr elf_getident 3 ,
+.Xr elf_getphdrnum 3 ,
+.Xr elf_getshdrstrndx 3 ,
+.Xr gelf 3 ,
+.Xr gelf_getehdr 3
diff --git a/contrib/elftoolchain/libelf/elf_getshdrstrndx.3 b/contrib/elftoolchain/libelf/elf_getshdrstrndx.3
new file mode 100644
index 0000000000..b02e715824
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_getshdrstrndx.3
@@ -0,0 +1,79 @@
+.\" 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 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_getshdrstrndx.3 467 2009-08-05 18:18:49Z jkoshy $
+.\"
+.Dd August 5, 2009
+.Os
+.Dt ELF_GETSHDRSTRNDX 3
+.Sh NAME
+.Nm elf_getshdrstrndx
+.Nd retrieve the index of the section name string table
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft int
+.Fn elf_getshdrstrndx "Elf *elf" "size_t *ndxptr"
+.Sh DESCRIPTION
+Function
+.Fn elf_getshdrstrndx
+retrieves the section index of the string table containing section
+names from descriptor
+.Ar elf
+and stores it into the location pointed to by argument
+.Ar ndxptr .
+.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
+These functions can fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+A NULL value was passed in for argument
+.Ar elf .
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not for an ELF file.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+lacks an ELF Executable header.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar ndx
+contained a value in the reserved range of section indices.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf32_getehdr 3 ,
+.Xr elf64_getehdr 3 ,
+.Xr elf_getident 3 ,
+.Xr elf_getphdrnum 3 ,
+.Xr elf_getshdrnum 3 ,
+.Xr gelf 3 ,
+.Xr gelf_getehdr 3
diff --git a/contrib/elftoolchain/libelf/elf_getshnum.3 b/contrib/elftoolchain/libelf/elf_getshnum.3
new file mode 100644
index 0000000000..615aa71faa
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_getshnum.3
@@ -0,0 +1,84 @@
+.\" 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 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_getshnum.3 467 2009-08-05 18:18:49Z jkoshy $
+.\"
+.Dd August 5, 2009
+.Os
+.Dt ELF_GETSHNUM 3
+.Sh NAME
+.Nm elf_getshnum
+.Nd return the number of sections in an ELF file
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft int
+.Fn elf_getshnum "Elf *elf" "size_t *shnum"
+.Sh DESCRIPTION
+This function is deprecated.
+Please use
+.Xr elf_getshdrnum 3
+instead.
+.Pp
+Function
+.Fn elf_getshnum
+retrieves the number of ELF sections associated with descriptor
+.Ar elf
+and stores it into the location pointed to by argument
+.Ar shnum .
+.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
+returns a non-zero value if successful, or zero in case of an
+error.
+.Sh ERRORS
+Function
+.Fn elf_getshnum
+can fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+A NULL value was passed in for argument
+.Ar elf .
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not for an ELF file.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+lacks an ELF Executable header.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf32_getehdr 3 ,
+.Xr elf64_getehdr 3 ,
+.Xr elf_getident 3 ,
+.Xr elf_getphdrnum 3 ,
+.Xr elf_getshdrstrndx 3 ,
+.Xr gelf 3 ,
+.Xr gelf_getehdr 3
diff --git a/contrib/elftoolchain/libelf/elf_getshstrndx.3 b/contrib/elftoolchain/libelf/elf_getshstrndx.3
new file mode 100644
index 0000000000..71c6f9518c
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_getshstrndx.3
@@ -0,0 +1,94 @@
+.\" 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 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_getshstrndx.3 467 2009-08-05 18:18:49Z jkoshy $
+.\"
+.Dd August 5, 2009
+.Os
+.Dt ELF_GETSHSTRNDX 3
+.Sh NAME
+.Nm elf_getshstrndx ,
+.Nm elf_setshstrndx
+.Nd retrieve/update the index of the section name string table
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft int
+.Fn elf_getshstrndx "Elf *elf" "size_t *ndxptr"
+.Ft int
+.Fn elf_setshstrndx "Elf *elf" "size_t ndx"
+.Sh DESCRIPTION
+Function
+.Fn elf_getshstrndx
+retrieves the section index of the string table containing section
+names from descriptor
+.Ar elf
+and stores it into the location pointed to by argument
+.Ar ndxptr .
+Function
+.Fn elf_getshstrndx
+is deprecated.
+Please use
+.Xr elf_getshdrstrndx 3
+instead.
+.Pp
+Function
+.Fn elf_setshstrndx
+sets the index of the section name string table to argument
+.Ar ndx .
+.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.
+.Sh ERRORS
+These functions can fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+A NULL value was passed in for argument
+.Ar elf .
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not for an ELF file.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+lacks an ELF Executable header.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar ndx
+contained a value in the reserved range of section indices.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf32_getehdr 3 ,
+.Xr elf64_getehdr 3 ,
+.Xr elf_getident 3 ,
+.Xr elf_getphdrnum 3 ,
+.Xr elf_getshdrnum 3 ,
+.Xr gelf 3 ,
+.Xr gelf_getehdr 3
diff --git a/contrib/elftoolchain/libelf/elf_hash.3 b/contrib/elftoolchain/libelf/elf_hash.3
new file mode 100644
index 0000000000..f099558570
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_hash.3
@@ -0,0 +1,57 @@
+.\" 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 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_hash.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd August 15, 2006
+.Os
+.Dt ELF_HASH 3
+.Sh NAME
+.Nm elf_hash
+.Nd compute a hash value for a string
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft "unsigned long"
+.Fn elf_hash "const char *name"
+.Sh DESCRIPTION
+Function
+.Fn elf_hash
+computes a portable hash value for the null terminated string
+pointed to by argument
+.Ar name .
+.Pp
+The hash value returned is will be identical across
+machines of different architectures.
+This allows hash tables to be built on one machine and
+correctly used on another of a different architecture.
+The hash value returned is also guaranteed
+.Em not
+to be the bit pattern of all ones (~0UL).
+.Sh IMPLEMENTATION NOTES
+The library internally uses unsigned 32 bit arithmetic to compute
+the hash value.
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/elf_kind.3 b/contrib/elftoolchain/libelf/elf_kind.3
new file mode 100644
index 0000000000..a5bbf9df45
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_kind.3
@@ -0,0 +1,71 @@
+.\" 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 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_kind.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd June 1, 2006
+.Os
+.Dt ELF_KIND 3
+.Sh NAME
+.Nm elf_kind
+.Nd determine ELF file type
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft Elf_Kind
+.Fn elf_kind "Elf *elf"
+.Sh DESCRIPTION
+The
+.Fn elf_kind
+function identifies the kind of file associated with its argument
+.Ar elf .
+The argument
+.Ar elf
+is allowed to be NULL.
+.Sh RETURN VALUES
+The
+.Fn elf_kind
+function returns one of the following values:
+.Bl -tag -width indent
+.It Dv ELF_K_AR
+The file associated with argument
+.Ar elf
+is an archive.
+.It Dv ELF_K_ELF
+The file associated with argument
+.Ar elf
+is an ELF file.
+.It Dv ELF_K_NONE
+The argument
+.Ar elf
+was NULL, or the ELF library could not determine the type of the file
+associated with argument
+.Ar elf ,
+or an error occurred when processing.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_begin 3 ,
+.Xr elf_getident 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/elf_memory.3 b/contrib/elftoolchain/libelf/elf_memory.3
new file mode 100644
index 0000000000..bcb888ff8d
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_memory.3
@@ -0,0 +1,122 @@
+.\" 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 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_memory.3 2314 2011-12-11 06:19:51Z jkoshy $
+.\"
+.Dd June 28, 2006
+.Os
+.Dt ELF_MEMORY 3
+.Sh NAME
+.Nm elf_memory
+.Nd process an ELF or ar(1) archive mapped into memory
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft "Elf *"
+.Fn elf_memory "char *image" "size_t size"
+.Sh DESCRIPTION
+Function
+.Fn elf_memory
+is used to process an ELF file or
+.Xr ar 1
+archive whose image is present in memory.
+.Pp
+Argument
+.Ar image
+points to the start of the memory image of the file or archive.
+Argument
+.Ar size
+contains the size in bytes of the memory image.
+.Pp
+The ELF descriptor is created for reading (i.e., analogous to the
+use of
+.Xr elf_begin 3
+with a command argument value of
+.Dv ELF_C_READ Ns ).
+.Sh RETURN VALUES
+Function
+.Fn elf_memory
+returns a pointer to a new ELF descriptor if successful, or NULL if an
+error occurred.
+.Pp
+The return value may be queried for the file type using
+.Xr elf_kind 3 .
+.Sh EXAMPLES
+To read parse an elf file, use:
+.Bd -literal -offset indent
+int fd;
+void *p;
+struct stat sb;
+Elf *e;
+\&...
+if ((fd = open("./elf-file", O_RDONLY)) < 0 ||
+    fstat(fd, &sb) < 0 ||
+    (p = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, (off_t) 0)) ==
+    MAP_FAILED) {
+	... handle system error ...
+}
+
+if ((e = elf_memory(p, sb.st_size)) == NULL) {
+	... handle elf(3) error ...
+}
+\&... use ELF descriptor "e" here ...
+.Ed
+.Sh ERRORS
+Function
+.Fn elf_memory
+can fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+A NULL value was used for argument
+.Ar image
+or the value of argument
+.Ar sz
+was zero.
+.It Bq Er ELF_E_HEADER
+The header of the ELF object contained an unsupported value in its
+.Va e_ident[EI_CLASS]
+field.
+.It Bq Er ELF_E_HEADER
+The header of the ELF object contained an unsupported value in its
+.Va e_ident[EI_DATA]
+field.
+.It Bq Er ELF_E_RESOURCE
+An out of memory condition was detected.
+.It Bq Er ELF_E_SEQUENCE
+Function
+.Fn elf_memory
+was called before a working version was set using
+.Xr elf_version 3 .
+.It Bq Er ELF_E_VERSION
+The ELF object referenced by argument
+.Ar image
+was of an unsupported ELF version.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_begin 3 ,
+.Xr elf_end 3 ,
+.Xr elf_errno 3 ,
+.Xr elf_kind 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/elf_next.3 b/contrib/elftoolchain/libelf/elf_next.3
new file mode 100644
index 0000000000..859d06cccd
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_next.3
@@ -0,0 +1,96 @@
+.\" 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 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_next.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd June 17, 2006
+.Os
+.Dt ELF_NEXT 3
+.Sh NAME
+.Nm elf_next
+.Nd provide sequential access to the next archive member
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft Elf_Cmd
+.Fn elf_next "Elf *elf"
+.Sh DESCRIPTION
+The
+.Fn elf_next
+function causes the ELF archive descriptor corresponding to argument
+.Ar elf
+to be adjusted to provide access to the next member in
+the archive on a subsequent call to
+.Fn elf_begin .
+.Pp
+The return value of
+.Fn elf_next
+is suitable for use in a loop invoking
+.Fn elf_begin .
+.Sh RETURN VALUES
+If successful, function
+.Fn elf_next
+returns the value
+.Dv ELF_C_READ .
+Otherwise, if argument
+.Ar elf
+was not associated with an archive, or if it was
+.Dv NULL ,
+or if any other error occurred, the value
+.Dv ELF_C_NULL
+is returned.
+.Sh EXAMPLES
+To process all the members of an archive use:
+.Bd -literal -offset indent
+Elf_Cmd cmd;
+Elf *archive, *e;
+\&...
+cmd = ELF_C_READ;
+archive = elf_begin(fd, cmd, NULL);
+while ((e = elf_begin(fd, cmd, archive)) != (Elf *) 0)
+{
+	... process `e' here ...
+
+	cmd = elf_next(e);
+	elf_end(e);
+}
+elf_end(archive);
+.Ed
+.Sh ERRORS
+Function
+.Fn elf_next
+may fail with the following error:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not associated with a containing
+.Xr ar 1
+archive.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_begin 3 ,
+.Xr elf_end 3 ,
+.Xr elf_rand 3
diff --git a/contrib/elftoolchain/libelf/elf_open.3 b/contrib/elftoolchain/libelf/elf_open.3
new file mode 100644
index 0000000000..3dd1e36a03
--- /dev/null
+++ b/contrib/elftoolchain/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 3181 2015-04-10 13:22:51Z emaste $
+.\"
+.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
diff --git a/contrib/elftoolchain/libelf/elf_rand.3 b/contrib/elftoolchain/libelf/elf_rand.3
new file mode 100644
index 0000000000..e5affd6a3f
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_rand.3
@@ -0,0 +1,118 @@
+.\" 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 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_rand.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd June 17, 2006
+.Os
+.Dt ELF_RAND 3
+.Sh NAME
+.Nm elf_rand
+.Nd provide sequential access to the next archive member
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft off_t
+.Fn elf_rand "Elf *archive" "off_t offset"
+.Sh DESCRIPTION
+The
+.Fn elf_rand
+function causes the ELF descriptor
+.Ar archive
+to be adjusted so that the next call to
+.Xr elf_begin 3
+will provide access to the archive member at byte offset
+.Ar offset
+in the archive.
+Argument
+.Ar offset
+is the byte offset from the start of the archive to the beginning of
+the archive header for the desired member.
+.Pp
+Archive member offsets may be retrieved using the
+.Xr elf_getarsym 3
+function.
+.Sh RETURN VALUES
+Function
+.Fn elf_rand
+returns
+.Ar offset
+if successful or zero in case of an error.
+.Sh EXAMPLES
+To process all the members of an archive use:
+.Bd -literal -offset indent
+off_t off;
+Elf *archive, *e;
+\&...
+cmd = ELF_C_READ;
+archive = elf_begin(fd, cmd, NULL);
+while ((e = elf_begin(fd, cmd, archive)) != (Elf *) 0)
+{
+	... process `e' here ...
+	elf_end(e);
+
+	off = ...new value...;
+	if (elf_rand(archive, off) != off) {
+		... process error ...
+	}
+}
+elf_end(archive);
+.Ed
+.Pp
+To rewind an archive, use:
+.Bd -literal -offset indent
+Elf *archive;
+\&...
+if (elf_rand(archive, SARMAG) != SARMAG) {
+	... error ...
+}
+.Ed
+.Sh ERRORS
+Function
+.Fn elf_rand
+may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar archive
+was null.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar archive
+was not a descriptor for an
+.Xr ar 1
+archive.
+.It Bq Er ELF_E_ARCHIVE
+Argument
+.Ar offset
+did not correspond to the start of an archive member header.
+.El
+.Sh SEE ALSO
+.Xr ar 1 ,
+.Xr elf 3 ,
+.Xr elf_begin 3 ,
+.Xr elf_end 3 ,
+.Xr elf_getarsym 3 ,
+.Xr elf_next 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/elf_rawfile.3 b/contrib/elftoolchain/libelf/elf_rawfile.3
new file mode 100644
index 0000000000..a713b42953
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_rawfile.3
@@ -0,0 +1,76 @@
+.\" 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 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_rawfile.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd July 3, 2006
+.Os
+.Dt ELF_RAWFILE 3
+.Sh NAME
+.Nm elf_rawfile
+.Nd return uninterpreted contents of an ELF file
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft char *
+.Fn elf_rawfile "Elf *elf" "size_t *sz"
+.Sh DESCRIPTION
+Function
+.Fn elf_rawfile
+returns the uninterpreted contents of the file referenced by ELF descriptor
+.Ar elf .
+.Pp
+If argument
+.Ar sz
+is non-null, the function stores the file's size in bytes
+in the location to which it points.
+A value of zero is written to this location if an error is
+encountered.
+.Sh RETURN VALUES
+Function
+.Fn elf_rawfile
+returns a valid pointer if successful or NULL if an error occurs.
+.Sh ERRORS
+Function
+.Fn elf_rawfile
+may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was NULL.
+.It Bq Er ELF_E_SEQUENCE
+Argument
+.Ar elf
+was opened for writing and function
+.Fn elf_rawfile
+was invoked before
+.Xr elf_update 3 .
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_getdata 3 ,
+.Xr elf_getident 3 ,
+.Xr elf_kind 3 ,
+.Xr elf_update 3
diff --git a/contrib/elftoolchain/libelf/elf_strptr.3 b/contrib/elftoolchain/libelf/elf_strptr.3
new file mode 100644
index 0000000000..31e0f830a0
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_strptr.3
@@ -0,0 +1,116 @@
+.\" 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 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_strptr.3 1081 2010-08-14 02:23:48Z jkoshy $
+.\"
+.Dd December 16, 2006
+.Os
+.Dt ELF_STRPTR 3
+.Sh NAME
+.Nm elf_strptr
+.Nd retrieve a string pointer in a string table
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft "char *"
+.Fn elf_strptr "Elf *elf" "size_t scndx" "size_t stroffset"
+.Sh DESCRIPTION
+Function
+.Fn elf_strptr
+allows an application to convert a string table offset to a string
+pointer, correctly translating the offset in the presence
+of multiple
+.Vt Elf_Data
+descriptors covering the contents of the section.
+.Pp
+Argument
+.Ar elf
+is a descriptor for an ELF object.
+Argument
+.Ar scndx
+is the section index for an ELF string table.
+Argument
+.Ar stroffset
+is the index of the desired string in the string
+table.
+.Sh RETURN VALUES
+Function
+.Fn elf_strptr
+returns a valid pointer on success or NULL in case an error was
+encountered.
+.Sh ERRORS
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was NULL
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not a descriptor for an ELF object.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar scndx
+was not the section index for a string table.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar stroffset
+exceeded the size of the string table.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar stroffset
+index an unallocated region of the string table.
+.It Bq Er ELF_E_DATA
+Offset
+.Ar stroffset
+indexed a region that was not covered by any Elf_Data
+descriptor.
+.It Bq Er ELF_E_DATA
+An erroneous
+.Vt Elf_Data
+descriptor was part of the section specified by argument
+.Ar scndx .
+.It Bq Er ELF_E_HEADER
+ELF descriptor
+.Ar elf
+contained an invalid section header.
+.It Bq Er ELF_E_RESOURCE
+An out of memory condition was detected.
+.It Bq Er ELF_E_SECTION
+Section
+.Ar scndx
+contained a malformed section header.
+.It Bq Er ELF_E_SECTION
+The ELF descriptor in argument
+.Ar elf
+did not adhere to the conventions used for extended numbering.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf32_getshdr 3 ,
+.Xr elf64_getshdr 3 ,
+.Xr elf_getdata 3 ,
+.Xr elf_rawdata 3 ,
+.Xr gelf 3 ,
+.Xr gelf_getshdr 3
diff --git a/contrib/elftoolchain/libelf/elf_update.3 b/contrib/elftoolchain/libelf/elf_update.3
new file mode 100644
index 0000000000..40a1e40c2d
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_update.3
@@ -0,0 +1,378 @@
+.\" 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
+.\" 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_update.3 1729 2011-08-14 09:13:00Z jkoshy $
+.\"
+.Dd August 14, 2011
+.Os
+.Dt ELF_UPDATE 3
+.Sh NAME
+.Nm elf_update
+.Nd update an ELF descriptor
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft off_t
+.Fn elf_update "Elf *elf" "Elf_Cmd cmd"
+.Sh DESCRIPTION
+Function
+.Fn elf_update
+causes the library to recalculate the structure of an ELF
+object and optionally write out the image of the object
+to file.
+.Pp
+Argument
+.Ar elf
+should reference a valid ELF descriptor.
+.Pp
+Argument
+.Ar cmd
+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 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
+.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 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
+.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 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
+To be set to the desired entry address for executables.
+.It Va e_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]"
+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
+To be set to the desired machine architecture, one of the
+.Dv EM_*
+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.
+.It Va e_shoff
+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
+To be set to the index of the string table containing
+section names.
+.It Va e_type
+To be set to the type of the ELF object, one of the
+.Dv ET_*
+values in the header file
+.In elfdefinitions.h .
+.It Va e_version
+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 need to be
+set by the application.
+.It "Section Header"
+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
+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 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
+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 are known to the library.
+.It Va sh_flags
+To be set to the desired section flags.
+.It Va sh_info
+To be set as described in
+.Xr elf 5 .
+.It Va sh_link
+To be set as described in
+.Xr elf 5 .
+.It Va sh_name
+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.
+.It Va sh_size
+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
+To be set to the type of the section.
+.El
+.It "Section Data"
+The
+.Vt Elf_Data
+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
+returns the total size of the file image if successful, or -1 if an
+error occurred.
+.Sh ERRORS
+This function may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was null.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar cmd
+was not recognized.
+.It Bq Er ELF_E_ARGUMENT
+The argument
+.Ar elf
+was not a descriptor for an ELF object.
+.It Bq Er ELF_E_CLASS
+The
+.Va e_ident[EI_CLASS]
+field of the executable header of argument
+.Ar elf
+did not match the class of the file.
+.It Bq Er ELF_E_DATA
+An
+.Vt Elf_Data
+descriptor contained in argument
+.Ar elf
+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
+requested a different byte order from the byte order already
+associated with the file.
+.It Bq Er ELF_E_IO
+An I/O error was encountered.
+.It Bq Er ELF_E_LAYOUT
+An
+.Vt Elf_Data
+descriptor contained in argument
+.Ar elf
+specified an alignment incompatible with its containing section.
+.It Bq Er ELF_E_LAYOUT
+Argument
+.Ar elf
+contained section descriptors that overlapped in extent.
+.It Bq Er ELF_E_LAYOUT
+Argument
+.Ar elf
+contained section descriptors that were incorrectly aligned or were
+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 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
+operation was requested with an ELF descriptor that was not opened for
+writing or updating.
+.It Bq Er ELF_E_SECTION
+Argument
+.Ar elf
+contained a section with an unrecognized type.
+.It Bq Er ELF_E_SECTION
+The section header at index
+.Dv SHN_UNDEF
+had an illegal section type.
+.It Bq Er ELF_E_SEQUENCE
+An
+.Dv ELF_C_WRITE
+operation was requested after a prior call to
+.Fn elf_cntl elf ELF_C_FDDONE
+disassociated the ELF descriptor
+.Ar elf
+from its underlying file.
+.It Bq Er ELF_E_VERSION
+Argument
+.Ar elf
+had an unsupported version or contained an
+.Vt Elf_Data
+descriptor with an unsupported version.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf32_getehdr 3 ,
+.Xr elf32_getphdr 3 ,
+.Xr elf32_newehdr 3 ,
+.Xr elf32_newphdr 3 ,
+.Xr elf64_getehdr 3 ,
+.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 ,
+.Xr elf_flagelf 3 ,
+.Xr elf_getdata 3 ,
+.Xr elf_getscn 3 ,
+.Xr elf_newdata 3 ,
+.Xr elf_newscn 3 ,
+.Xr elf_rawdata 3 ,
+.Xr gelf 3 ,
+.Xr gelf_newehdr 3 ,
+.Xr gelf_newphdr 3 ,
+.Xr elf 5
diff --git a/contrib/elftoolchain/libelf/elf_update.c b/contrib/elftoolchain/libelf/elf_update.c
index 6cc109daaf..9f5230d1df 100644
--- a/contrib/elftoolchain/libelf/elf_update.c
+++ b/contrib/elftoolchain/libelf/elf_update.c
@@ -808,6 +808,7 @@ _libelf_write_scn(Elf *e, unsigned char *nf, struct _Elf_Extent *ex)
 
 		assert(d->d_buf != NULL);
 		assert(d->d_version == e->e_version);
+		assert(msz != 0);
 		assert(d->d_size % msz == 0);
 
 		nobjects = (size_t) (d->d_size / msz);
@@ -1211,5 +1212,6 @@ elf_update(Elf *e, Elf_Cmd c)
 
 done:
 	_libelf_release_extents(&extents);
+	e->e_flags &= ~LIBELF_F_SHDRS_LOADED;
 	return (rc);
 }
diff --git a/contrib/elftoolchain/libelf/elf_version.3 b/contrib/elftoolchain/libelf/elf_version.3
new file mode 100644
index 0000000000..b09fb479cf
--- /dev/null
+++ b/contrib/elftoolchain/libelf/elf_version.3
@@ -0,0 +1,95 @@
+.\" 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 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_version.3 2123 2011-11-09 15:40:09Z jkoshy $
+.\"
+.Dd November 9, 2011
+.Os
+.Dt ELF_VERSION 3
+.Sh NAME
+.Nm elf_version
+.Nd retrieve or set ELF library operating version
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft unsigned int
+.Fn elf_version "unsigned int version"
+.Sh DESCRIPTION
+The
+.Fn elf_version
+function is used to query the current operating version of the ELF
+library, and to inform the ELF library about the application's desired
+operating version.
+.Pp
+If the argument
+.Ar version
+is
+.Dv EV_NONE ,
+the
+.Fn elf_version
+function returns the currently configured operating version for the
+ELF library.
+.Pp
+If the argument
+.Ar version
+is not
+.Dv EV_NONE ,
+and if argument
+.Ar version
+is supported by the ELF library, function
+.Fn elf_version
+sets the library's operating version to
+.Ar version ,
+and returns the previous value of the operating version.
+If argument
+.Ar version
+cannot be supported, then the
+.Fn elf_version
+function returns
+.Dv EV_NONE .
+.Sh RETURN VALUES
+The
+.Fn elf_version
+function returns the currently configured ELF library version, or
+.Dv EV_NONE
+if an unsupported version is requested.
+.Sh EXAMPLES
+An application program would inform the ELF library about its desired
+operating version and check for an error using the following code
+snippet:
+.Bd -literal -offset indent
+if (elf_version(EV_CURRENT) == EV_NONE)
+	err(EXIT_FAILURE, "ELF library too old");
+.Ed
+.Sh ERRORS
+Function
+.Fn elf_version
+may fail with the following error:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er "ELF_E_VERSION"
+An unsupported library version number was requested.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/gelf.3 b/contrib/elftoolchain/libelf/gelf.3
new file mode 100644
index 0000000000..d00d5b3309
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf.3
@@ -0,0 +1,200 @@
+.\" 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 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: gelf.3 3195 2015-05-12 17:22:19Z emaste $
+.\"
+.Dd September 1, 2006
+.Os
+.Dt GELF 3
+.Sh NAME
+.Nm GElf
+.Nd class-independent API for ELF manipulation
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In gelf.h
+.Sh DESCRIPTION
+This manual page describes a class independent API for manipulating
+ELF objects.
+This API allows an application to operate on ELF descriptors without
+needing to the know the ELF class of the descriptor.
+.Pp
+The GElf API may be used alongside the ELF API without restriction.
+.Ss GElf Data Structures
+The GElf API defines the following class-independent data structures:
+.Bl -tag -width GElf_Sxword
+.It Vt GElf_Addr
+A representation of ELF addresses.
+.It Vt GElf_Dyn
+A class-independent representation of ELF
+.Sy .dynamic
+section entries.
+.It Vt GElf_Ehdr
+A class-independent representation of an ELF Executable Header.
+.It Vt GElf_Half
+An unsigned 16 bit quantity.
+.It Vt GElf_Off
+A class-independent representation of a ELF offset.
+.It Vt GElf_Phdr
+A class-independent representation of an ELF Program Header Table
+entry.
+.It Vt GElf_Rel
+A class-independent representation of an ELF relocation entry.
+.It Vt GElf_Rela
+A class-independent representation of an ELF relocation entry with
+addend.
+.It Vt GElf_Shdr
+A class-independent representation of an ELF Section Header Table
+entry.
+.It Vt GElf_Sword
+A signed 32 bit quantity.
+.It Vt GElf_Sxword
+A signed 64 bit quantity.
+.It Vt GElf_Sym
+A class-independent representation of an ELF symbol table entry.
+.It Vt GElf_Word
+An unsigned 32 bit quantity.
+.It Vt GElf_Xword
+An unsigned 64 bit quantity.
+.El
+.Pp
+These data structures are sized to be compatible with the
+corresponding 64 bit ELF structures, and have the same internal
+structure as their 64 bit class-dependent counterparts.
+Class-dependent ELF structures are described in
+.Xr elf 5 .
+.Ss GElf Programming Model
+GElf functions always return a
+.Em copy
+of the underlying (class-dependent) ELF data structure.
+The programming model with GElf is as follows:
+.Bl -enum
+.It
+An application will retrieve data from an ELF descriptor using a
+.Fn gelf_get_*
+function.
+This will copy out data into a private
+.Vt GElf_*
+data structure.
+.It
+The application will work with its private copy of the GElf
+structure.
+.It
+Once done, the application copies the new values back to the
+underlying ELF data structure using the
+.Fn gelf_update_*
+functions.
+.It
+The application will then use the
+.Fn elf_flag*
+APIs to indicate to the ELF library that an ELF data structure is dirty.
+.El
+.Pp
+When updating an underlying 32 bit ELF data structure, the GElf
+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
+.It GElf_*
+Class-independent data types.
+.It gelf_*
+For functions defined in the API set.
+.El
+.Ss GElf Programming APIs
+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
+.It "Allocating ELF Data Structures"
+.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 -compact
+.It Fn gelf_xlatetof
+Translate the native representation of an ELF data structure to its
+file representation.
+.It Fn gelf_xlatetom
+Translate from the file representation of an ELF data structure to a
+native representation.
+.El
+.It "Retrieving ELF Data"
+.Bl -tag -compact
+.It Fn gelf_getdyn
+Retrieve an ELF
+.Sy .dynamic
+table entry.
+.It Fn gelf_getehdr
+Retrieve an ELF Executable Header from the underlying ELF descriptor.
+.It Fn gelf_getphdr
+Retrieve an ELF Program Header Table entry from the underlying ELF descriptor.
+.It Fn gelf_getrel
+Retrieve an ELF relocation entry.
+.It Fn gelf_getrela
+Retrieve an ELF relocation entry with addend.
+.It Fn gelf_getshdr
+Retrieve an ELF Section Header Table entry from the underlying ELF descriptor.
+.It Fn gelf_getsym
+Retrieve an ELF symbol table entry.
+.El
+.It Queries
+.Bl -tag -compact
+.It Fn gelf_checksum
+Retrieves the ELF checksum for an ELF descriptor.
+.It Fn gelf_fsize
+Retrieves the size of the file representation of an ELF type.
+.It Fn gelf_getclass
+Retrieves the ELF class of an ELF descriptor.
+.El
+.It "Updating ELF Data"
+.Bl -tag -compact -width ".Fn gelf_update_shdr"
+.It Fn gelf_update_dyn
+Copy back an ELF
+.Sy .dynamic
+Table entry.
+.It Fn gelf_update_phdr
+Copy back an ELF Program Header Table entry.
+.It Fn gelf_update_rel
+Copy back an ELF relocation entry.
+.It Fn gelf_update_rela
+Copy back an ELF relocation with addend entry.
+.It Fn gelf_update_shdr
+Copy back an ELF Section Header Table entry.
+.It Fn gelf_update_sym
+Copy back an ELF symbol table entry.
+.El
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf 5
+.Sh HISTORY
+The GELF(3) API first appeared in System V Release 4.
+This implementation of the API first appeared in
+.Fx 7.0 .
+.Sh AUTHORS
+The GElf API was implemented by
+.An Joseph Koshy Aq Mt jkoshy@FreeBSD.org .
diff --git a/contrib/elftoolchain/libelf/gelf_checksum.3 b/contrib/elftoolchain/libelf/gelf_checksum.3
new file mode 100644
index 0000000000..e5f845f6c9
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_checksum.3
@@ -0,0 +1,115 @@
+.\" 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 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: gelf_checksum.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd August 29, 2006
+.Os
+.Dt GELF_CHECKSUM 3
+.Sh NAME
+.Nm elf32_checksum ,
+.Nm elf64_checksum ,
+.Nm gelf_checksum
+.Nd return the checksum of an ELF object
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft long
+.Fn elf32_checksum "Elf *elf"
+.Ft long
+.Fn elf64_checksum "Elf *elf"
+.In gelf.h
+.Ft long
+.Fn gelf_checksum "Elf *elf"
+.Sh DESCRIPTION
+These functions return a simple checksum of the ELF object described
+by their argument
+.Ar elf .
+The checksum is computed in way that allows its value to remain
+unchanged in presence of modifications to the ELF object by utilities
+like
+.Xr strip 1 .
+.Pp
+Function
+.Fn elf32_checksum
+returns a checksum for an ELF descriptor
+.Ar elf
+of class
+.Dv ELFCLASS32 .
+.Pp
+Function
+.Fn elf64_checksum
+returns a checksum for an ELF descriptor
+.Ar elf
+of class
+.Dv ELFCLASS64 .
+.Pp
+Function
+.Fn gelf_checksum
+provides a class-independent way retrieving the checksum
+for ELF object
+.Ar elf .
+.Sh RETURN VALUES
+These functions return the checksum of the ELF object, or zero in case
+an error was encountered.
+.Sh ERRORS
+These functions may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not a descriptor for an ELF file.
+.It Bq Er ELF_E_ARGUMENT
+The ELF descriptor
+.Ar elf
+was not opened for reading or updating.
+.It Bq Er ELF_E_CLASS
+For functions
+.Fn elf32_checksum
+and
+.Fn elf64_checksum ,
+ELF descriptor
+.Ar elf
+did not match the class of the called function.
+.It Bq Er ELF_E_HEADER
+The ELF object specified by argument
+.Ar elf
+had a malformed executable header.
+.It Bq Er ELF_E_RESOURCE
+An out of memory condition was detected during processing.
+.It Bq Er ELF_E_SECTION
+The ELF object specified by argument
+.Ar elf
+contained a section with a malformed section header.
+.It Bq Er ELF_E_VERSION
+The ELF object was of an unsupported version.
+.El
+.Sh SEE ALSO
+.Xr strip 1 ,
+.Xr elf 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/gelf_fsize.3 b/contrib/elftoolchain/libelf/gelf_fsize.3
new file mode 100644
index 0000000000..ac7996f929
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_fsize.3
@@ -0,0 +1,96 @@
+.\" 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 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: gelf_fsize.3 317 2009-03-06 17:29:22Z jkoshy $
+.\"
+.Dd February 5, 2008
+.Os
+.Dt GELF_FSIZE 3
+.Sh NAME
+.Nm gelf_fsize ,
+.Nm elf32_fsize ,
+.Nm elf64_fsize
+.Nd return the size of a file type
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft size_t
+.Fn elf32_fsize "Elf_Type type" "size_t count" "unsigned int version"
+.Ft size_t
+.Fn elf64_fsize "Elf_Type type" "size_t count" "unsigned int version"
+.In gelf.h
+.Ft size_t
+.Fn gelf_fsize "Elf *elf" "Elf_Type type" "size_t count" "unsigned int version"
+.Sh DESCRIPTION
+These functions return the size in bytes of the file representation of
+.Ar count
+numbers of objects of ELF type
+.Ar type .
+For ELF types that are of variable length, these functions return a
+size of one byte.
+.Pp
+Functions
+.Fn elf32_fsize
+and
+.Fn elf64_fsize
+return sizes for files of class
+.Dv ELFCLASS32
+and
+.Dv ELFCLASS64
+respectively.
+Function
+.Fn gelf_fsize
+returns the size for the class of ELF descriptor
+.Ar elf .
+.Sh RETURN VALUES
+These functions return a non-zero value in case of success, or zero in
+case of an error.
+.Sh ERRORS
+These functions may fail with:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was NULL in a call to
+.Fn gelf_fsize .
+.It Bq Er ELF_E_ARGUMENT
+ELF descriptor
+.Ar elf
+had an unknown ELF class.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar type
+contained an illegal value.
+.It Bq Er ELF_E_UNIMPL
+Support for ELF type
+.Ar type
+has not been implemented.
+.It Bq Er ELF_E_VERSION
+Argument
+.Ar version
+is not a supported version.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/gelf_getcap.3 b/contrib/elftoolchain/libelf/gelf_getcap.3
new file mode 100644
index 0000000000..ed8eb02758
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_getcap.3
@@ -0,0 +1,121 @@
+.\" 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 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: gelf_getcap.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd August 29, 2006
+.Os
+.Dt GELF_GETCAP 3
+.Sh NAME
+.Nm gelf_getcap ,
+.Nm gelf_update_cap
+.Nd read and update ELF capability information
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In gelf.h
+.Ft "GElf_Cap *"
+.Fn gelf_getcap "Elf_Data *data" "int ndx" "GElf_Cap *cap"
+.Ft int
+.Fn gelf_update_cap "Elf_Data *data" "int ndx" "GElf_Cap *cap"
+.Sh DESCRIPTION
+These convenience functions are used to retrieve and update class-dependent
+.Vt Elf32_Cap
+or
+.Vt Elf64_Cap
+information.
+.Pp
+Argument
+.Ar data
+is an
+.Vt Elf_Data
+descriptor associated with a section of type
+.Dv SHT_SUNW_cap .
+Argument
+.Ar ndx
+is the index of the entry being retrieved or updated.
+The class-independent
+.Vt GElf_Cap
+structure is described in
+.Xr gelf 3 .
+.Pp
+Function
+.Fn gelf_getcap
+retrieves the class-dependent entry at index
+.Ar ndx
+in data buffer
+.Ar data
+and copies it to the destination pointed to by argument
+.Ar cap
+after translation to class-independent form.
+.Pp
+Function
+.Fn gelf_update_cap
+converts the class-independent entry pointed to
+by argument
+.Ar cap
+to class-dependent form, and writes it to the entry at index
+.Ar ndx
+in the data buffer described by argument
+.Ar data .
+Function
+.Fn gelf_update_cap
+signals an error if any of the values in the class-independent
+representation exceeds the representable limits of the target
+type.
+.Sh RETURN VALUES
+Function
+.Fn gelf_getcap
+returns the value of argument
+.Ar cap
+if successful, or NULL in case of an error.
+Function
+.Fn gelf_update_cap
+returns a non-zero value if successful, or zero in case of an error.
+.Sh ERRORS
+These functions may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Arguments
+.Ar data
+or
+.Ar cap
+were NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar ndx
+was less than zero or larger than the number of entries in the data
+descriptor.
+.It Bq Er ELF_E_ARGUMENT
+Data descriptor
+.Ar data
+was not associated with a section of type
+.Dv SHT_SUNW_cap .
+.It Bq Er ELF_E_RANGE
+A value was not representable in the target type.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_getdata 3 ,
+.Xr elf_getscn 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/gelf_getclass.3 b/contrib/elftoolchain/libelf/gelf_getclass.3
new file mode 100644
index 0000000000..3504569fd1
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_getclass.3
@@ -0,0 +1,61 @@
+.\" 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 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: gelf_getclass.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd July 3, 2006
+.Os
+.Dt GELF_GETCLASS 3
+.Sh NAME
+.Nm gelf_getclass
+.Nd retrieve the class of an ELF descriptor
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In gelf.h
+.Ft int
+.Fn gelf_getclass "Elf *elf"
+.Sh DESCRIPTION
+Function
+.Fn gelf_getclass
+returns the ELF class of the descriptor supplied in argument
+.Ar elf .
+.Sh RETURN VALUES
+Function
+.Fn gelf_getclass
+will return one of
+.Dv ELFCLASS32
+or
+.Dv ELFCLASS64
+if the argument
+.Ar elf
+is a descriptor for an ELF file.
+The value
+.Dv ELFCLASSNONE
+is returned if argument
+.Ar elf
+was null, or if it was not a descriptor for an ELF file.
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_kind 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/gelf_getdyn.3 b/contrib/elftoolchain/libelf/gelf_getdyn.3
new file mode 100644
index 0000000000..f8c177876d
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_getdyn.3
@@ -0,0 +1,123 @@
+.\" 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 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: gelf_getdyn.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd August 29, 2006
+.Os
+.Dt GELF_GETDYN 3
+.Sh NAME
+.Nm gelf_getdyn ,
+.Nm gelf_update_dyn
+.Nd read and update ELF dynamic entries
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In gelf.h
+.Ft "GElf_Dyn *"
+.Fn gelf_getdyn "Elf_Data *data" "int ndx" "GElf_Dyn *dyn"
+.Ft int
+.Fn gelf_update_dyn "Elf_Data *data" "int ndx" "GElf_Dyn *dyn"
+.Sh DESCRIPTION
+These convenience functions are used to retrieve and update class-dependent
+.Vt Elf32_Dyn
+or
+.Vt Elf64_Dyn
+information in the
+.Sy dynamic
+table of an ELF object.
+.Pp
+Argument
+.Ar data
+is an
+.Vt Elf_Data
+descriptor associated with a section of type
+.Dv SHT_DYNAMIC .
+Argument
+.Ar ndx
+is the index of the entry being retrieved or updated.
+The class-independent
+.Vt GElf_Dyn
+structure is described in
+.Xr gelf 3 .
+.Pp
+Function
+.Fn gelf_getdyn
+retrieves the class-dependent entry at index
+.Ar ndx
+in data buffer
+.Ar data
+and copies it to the destination pointed to by argument
+.Ar dyn
+after translation to class-independent form.
+.Pp
+Function
+.Fn gelf_update_dyn
+converts the class-independent entry pointed to
+by argument
+.Ar dyn
+to class-dependent form, and writes it to the entry at index
+.Ar ndx
+in the data buffer described by argument
+.Ar data .
+Function
+.Fn gelf_update_dyn
+signals an error if any of the values in the class-independent
+representation exceeds the representable limits of the target
+type.
+.Sh RETURN VALUES
+Function
+.Fn gelf_getdyn
+returns the value of argument
+.Ar dyn
+if successful, or NULL in case of an error.
+Function
+.Fn gelf_update_dyn
+returns a non-zero value if successful, or zero in case of an error.
+.Sh ERRORS
+These functions may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Arguments
+.Ar data
+or
+.Ar dyn
+were NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar ndx
+was less than zero or larger than the number of entries in the data
+descriptor.
+.It Bq Er ELF_E_ARGUMENT
+Data descriptor
+.Ar data
+was not associated with a section of type
+.Dv SHT_DYNAMIC .
+.It Bq Er ELF_E_RANGE
+A value was not representable in the target type.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_getdata 3 ,
+.Xr elf_getscn 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/gelf_getehdr.3 b/contrib/elftoolchain/libelf/gelf_getehdr.3
new file mode 100644
index 0000000000..56bdcd4056
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_getehdr.3
@@ -0,0 +1,123 @@
+.\" 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 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: gelf_getehdr.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd December 16, 2006
+.Os
+.Dt GELF_GETEHDR 3
+.Sh NAME
+.Nm elf32_getehdr ,
+.Nm elf64_getehdr ,
+.Nm gelf_getehdr
+.Nd retrieve the object file header
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft "Elf32_Ehdr *"
+.Fn elf32_getehdr "Elf *elf"
+.Ft "Elf64_Ehdr *"
+.Fn elf64_getehdr "Elf *elf"
+.In gelf.h
+.Ft "GElf_Ehdr *"
+.Fn gelf_getehdr "Elf *elf" "GElf_Ehdr *dst"
+.Sh DESCRIPTION
+These functions retrieve the ELF object file
+header from the ELF descriptor
+.Ar elf
+and return a translated header descriptor to their callers.
+.Pp
+Functions
+.Fn elf32_getehdr
+and
+.Fn elf64_getehdr
+return a pointer to the appropriate class-specific header descriptor
+if it exists in the file referenced by descriptor
+.Ar elf .
+These functions return
+.Dv NULL
+if an ELF header was not found in file
+.Ar elf .
+.Pp
+Function
+.Fn gelf_getehdr
+stores a translated copy of the header for ELF file
+.Ar elf
+into the descriptor pointed to by argument
+.Ar dst .
+It returns argument
+.Ar dst
+if successful or
+.Dv NULL
+in case of failure.
+.Sh RETURN VALUES
+These functions return a pointer to a translated header descriptor
+if successful, or NULL on failure.
+.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 elf
+was null.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not a descriptor for an ELF file.
+.It Bq Er ELF_E_ARGUMENT
+The elf class of descriptor
+.Ar elf
+was not recognized.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar dst
+was null.
+.It Bq Er ELF_E_CLASS
+The ELF class of descriptor
+.Ar elf
+did not match that of the API function being called.
+.It Bq Er ELF_E_HEADER
+ELF descriptor
+.Ar elf
+does not have an associated header.
+.It Bq Er ELF_E_RESOURCE
+An out of memory condition was detected during execution.
+.It Bq Er ELF_E_SECTION
+The ELF descriptor in argument
+.Ar elf
+did not adhere to the conventions used for extended numbering.
+.It Bq Er ELF_E_VERSION
+The ELF descriptor
+.Ar elf
+had an unsupported ELF version number.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf32_newehdr 3 ,
+.Xr elf64_newehdr 3 ,
+.Xr elf_flagehdr 3 ,
+.Xr elf_getident 3 ,
+.Xr gelf 3 ,
+.Xr gelf_newehdr 3 ,
+.Xr elf 5
diff --git a/contrib/elftoolchain/libelf/gelf_getmove.3 b/contrib/elftoolchain/libelf/gelf_getmove.3
new file mode 100644
index 0000000000..871a040ad4
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_getmove.3
@@ -0,0 +1,120 @@
+.\" 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 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: gelf_getmove.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd August 29, 2006
+.Os
+.Dt GELF_GETMOVE 3
+.Sh NAME
+.Nm gelf_getmove ,
+.Nm gelf_update_move
+.Nd read and update Elf Move information
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In gelf.h
+.Ft "GElf_Move *"
+.Fn gelf_getmove "Elf_Data *data" "int ndx" "GElf_Move *move"
+.Ft int
+.Fn gelf_update_move "Elf_Data *data" "int ndx" "GElf_Move *move"
+.Sh DESCRIPTION
+These convenience functions are used to retrieve and update class-dependent
+.Vt Elf32_Move
+and
+.Vt Elf64_Move
+structures in an ELF object.
+.Pp
+Argument
+.Ar data
+is an
+.Vt Elf_Data
+descriptor associated with a section of type
+.Dv SHT_SUNW_move .
+Argument
+.Ar ndx
+is the index of the move record being retrieved or updated.
+The class-independent
+.Vt GElf_Move
+structure is described in
+.Xr gelf 3 .
+.Pp
+Function
+.Fn gelf_getmove
+retrieves class-dependent move record at index
+.Ar ndx
+in data buffer
+.Ar data
+and copies it to the destination pointed to by argument
+.Ar move
+after translation to class-independent form.
+.Pp
+Function
+.Fn gelf_update_move
+converts the class-independent move information pointed to
+by argument
+.Ar move
+to class-dependent form, and writes it to the move record at index
+.Ar ndx
+in the data buffer described by argument
+.Ar data .
+Function
+.Fn gelf_update_move
+signals an error if any of the values in the class-independent
+representation exceeds the representable limits of the target
+type.
+.Sh RETURN VALUES
+Function
+.Fn gelf_getmove
+returns the value of argument
+.Ar move
+if successful, or NULL in case of an error.
+Function
+.Fn gelf_update_move
+returns a non-zero value if successful, or zero in case of an error.
+.Sh ERRORS
+These functions may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Arguments
+.Ar data
+or
+.Ar move
+were NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar ndx
+was less than zero or larger than the number of records in the data
+descriptor.
+.It Bq Er ELF_E_ARGUMENT
+Data descriptor
+.Ar data
+was not associated with a section containing move information.
+.It Bq Er ELF_E_RANGE
+A value was not representable in the target type.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_getdata 3 ,
+.Xr elf_getscn 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/gelf_getphdr.3 b/contrib/elftoolchain/libelf/gelf_getphdr.3
new file mode 100644
index 0000000000..f2d38aa831
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_getphdr.3
@@ -0,0 +1,141 @@
+.\" 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 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: gelf_getphdr.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd October 21, 2007
+.Os
+.Dt GELF_GETPHDR 3
+.Sh NAME
+.Nm elf32_getphdr ,
+.Nm elf64_getphdr ,
+.Nm gelf_getphdr
+.Nd retrieve an ELF program header table
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft "Elf32_Phdr *"
+.Fn elf32_getphdr "Elf *elf"
+.Ft "Elf64_Phdr *"
+.Fn elf64_getphdr "Elf *elf"
+.In gelf.h
+.Ft "GElf_Phdr *"
+.Fn gelf_getphdr "Elf *elf" "int index" "GElf_Phdr *dst"
+.Sh DESCRIPTION
+These functions retrieve and translate ELF program header information
+from an ELF descriptor, if this information exists.
+.Pp
+Functions
+.Fn elf32_getphdr
+and
+.Fn elf64_getphdr
+return a pointer to an array of translated
+.Vt Elf32_Phdr
+and
+.Vt Elf64_Phdr
+descriptors respectively.
+These descriptors are described in
+.Xr elf 5 .
+The number of entries in this array may be determined using the
+.Xr elf_getphnum 3
+function.
+.Pp
+Function
+.Fn gelf_getphdr
+will retrieve the program header table entry at index
+.Ar index
+from ELF descriptor
+.Ar elf.
+The translated program header table entry will be written to the
+address pointed to be argument
+.Ar dst .
+.Pp
+Applications may inform the library of modifications to a program header table entry
+by using the
+.Xr elf_flagphdr 3
+API.
+Applications using the
+.Xr gelf 3
+interface need to use the
+.Xr gelf_update_phdr 3
+API to copy modifications to a program header entry back to the underlying
+ELF descriptor.
+.Sh RETURN VALUES
+The functions a valid pointer if successful, or NULL in case an error
+was encountered.
+.Sh ERRORS
+These functions may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not a descriptor for an ELF object.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar dst
+was NULL.
+.It Bq Er ELF_E_ARGUMENT
+Index
+.Ar index
+was out of range.
+.It Bq Er ELF_E_CLASS
+The class of ELF descriptor
+.Ar elf
+did not match the expected class of the function being called.
+.It Bq Er ELF_E_HEADER
+ELF descriptor
+.Ar elf
+did not possess an executable header.
+.It Bq Er ELF_E_HEADER
+ELF descriptor
+.Ar elf
+had a corrupt executable header.
+.It Bq Er ELF_E_RESOURCE
+An out of memory condition was detected.
+.It Bq Er ELF_E_SECTION
+The ELF descriptor in argument
+.Ar elf
+did not adhere to the conventions used for extended numbering.
+.It Bq Er ELF_VERSION
+ELF descriptor
+.Ar elf
+was of an unsupported version.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf32_getehdr 3 ,
+.Xr elf32_newphdr 3 ,
+.Xr elf64_getehdr 3 ,
+.Xr elf64_newphdr 3 ,
+.Xr elf_flagphdr 3 ,
+.Xr elf_getphnum 3 ,
+.Xr gelf 3 ,
+.Xr gelf_getehdr 3 ,
+.Xr gelf_newphdr 3 ,
+.Xr gelf_update_phdr 3 ,
+.Xr elf 5
diff --git a/contrib/elftoolchain/libelf/gelf_getrel.3 b/contrib/elftoolchain/libelf/gelf_getrel.3
new file mode 100644
index 0000000000..c7566e64e6
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_getrel.3
@@ -0,0 +1,121 @@
+.\" 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 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: gelf_getrel.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd August 29, 2006
+.Os
+.Dt GELF_GETREL 3
+.Sh NAME
+.Nm gelf_getrel ,
+.Nm gelf_update_rel
+.Nd read and update ELF relocation entries
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In gelf.h
+.Ft "GElf_Rel *"
+.Fn gelf_getrel "Elf_Data *data" "int ndx" "GElf_Rel *rel"
+.Ft int
+.Fn gelf_update_rel "Elf_Data *data" "int ndx" "GElf_Rel *rel"
+.Sh DESCRIPTION
+These convenience functions are used to retrieve and update class-dependent
+.Vt Elf32_Rel
+or
+.Vt Elf64_Rel
+structures in an ELF object.
+.Pp
+Argument
+.Ar data
+is an
+.Vt Elf_Data
+descriptor associated with a section of type
+.Dv SHT_REL .
+Argument
+.Ar ndx
+is the index of the entry being retrieved or updated.
+The class-independent
+.Vt GElf_Rel
+structure is described in
+.Xr gelf 3 .
+.Pp
+Function
+.Fn gelf_getrel
+retrieves the class-dependent entry at index
+.Ar ndx
+in data buffer
+.Ar data
+and copies it to the destination pointed to by argument
+.Ar rel
+after translation to class-independent form.
+.Pp
+Function
+.Fn gelf_update_rel
+converts the class-independent entry pointed to
+by argument
+.Ar rel
+to class-dependent form, and writes it to the entry at index
+.Ar ndx
+in the data buffer described by argument
+.Ar data .
+Function
+.Fn gelf_update_rel
+signals an error if any of the values in the class-independent
+representation exceeds the representable limits of the target
+type.
+.Sh RETURN VALUES
+Function
+.Fn gelf_getrel
+returns the value of argument
+.Ar rel
+if successful, or NULL in case of an error.
+Function
+.Fn gelf_update_rel
+returns a non-zero value if successful, or zero in case of an error.
+.Sh ERRORS
+These functions may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Arguments
+.Ar data
+or
+.Ar rel
+were NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar ndx
+was less than zero or larger than the number of entries in the data
+descriptor.
+.It Bq Er ELF_E_ARGUMENT
+Data descriptor
+.Ar data
+was not associated with a section of type
+.Dv SHT_REL .
+.It Bq Er ELF_E_RANGE
+A value was not representable in the target type.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_getdata 3 ,
+.Xr elf_getscn 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/gelf_getrela.3 b/contrib/elftoolchain/libelf/gelf_getrela.3
new file mode 100644
index 0000000000..c77d52a402
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_getrela.3
@@ -0,0 +1,121 @@
+.\" 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 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: gelf_getrela.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd August 29, 2006
+.Os
+.Dt GELF_GETRELA 3
+.Sh NAME
+.Nm gelf_getrela ,
+.Nm gelf_update_rela
+.Nd read and update ELF relocation entries with addends
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In gelf.h
+.Ft "GElf_Rela *"
+.Fn gelf_getrela "Elf_Data *data" "int ndx" "GElf_Rela *rela"
+.Ft int
+.Fn gelf_update_rela "Elf_Data *data" "int ndx" "GElf_Rela *rela"
+.Sh DESCRIPTION
+These convenience functions are used to retrieve and update class-dependent
+.Vt Elf32_Rela
+or
+.Vt Elf64_Rela
+structures in an ELF object.
+.Pp
+Argument
+.Ar data
+is an
+.Vt Elf_Data
+descriptor associated with a section of type
+.Dv SHT_RELA .
+Argument
+.Ar ndx
+is the index of the entry being retrieved or updated.
+The class-independent
+.Vt GElf_Rela
+structure is described in
+.Xr gelf 3 .
+.Pp
+Function
+.Fn gelf_getrela
+retrieves the class-dependent entry at index
+.Ar ndx
+in data buffer
+.Ar data
+and copies it to the destination pointed to by argument
+.Ar rela
+after translation to class-independent form.
+.Pp
+Function
+.Fn gelf_update_rela
+converts the class-independent entry pointed to
+by argument
+.Ar rela
+to class-dependent form, and writes it to the entry at index
+.Ar ndx
+in the data buffer described by argument
+.Ar data .
+Function
+.Fn gelf_update_rela
+signals an error if any of the values in the class-independent
+representation exceeds the representable limits of the target
+type.
+.Sh RETURN VALUES
+Function
+.Fn gelf_getrela
+returns the value of argument
+.Ar rela
+if successful, or NULL in case of an error.
+Function
+.Fn gelf_update_rela
+returns a non-zero value if successful, or zero in case of an error.
+.Sh ERRORS
+These functions may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Arguments
+.Ar data
+or
+.Ar rela
+were NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar ndx
+was less than zero or larger than the number of entries in the data
+descriptor.
+.It Bq Er ELF_E_ARGUMENT
+Data descriptor
+.Ar data
+was not associated with a section of type
+.Dv SHT_RELA .
+.It Bq Er ELF_E_RANGE
+A value was not representable in the target type.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_getdata 3 ,
+.Xr elf_getscn 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/gelf_getshdr.3 b/contrib/elftoolchain/libelf/gelf_getshdr.3
new file mode 100644
index 0000000000..e92d414371
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_getshdr.3
@@ -0,0 +1,115 @@
+.\" 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 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: gelf_getshdr.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd August 27, 2006
+.Os
+.Dt GELF_GETSHDR 3
+.Sh NAME
+.Nm elf32_getshdr ,
+.Nm elf64_getshdr ,
+.Nm gelf_getshdr
+.Nd retrieve the class-dependent section header
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft "Elf32_Shdr *"
+.Fn elf32_getshdr "Elf_Scn *scn"
+.Ft "Elf64_Shdr *"
+.Fn elf64_getshdr "Elf_Scn *scn"
+.In gelf.h
+.Ft "GElf_Shdr *"
+.Fn gelf_getshdr "Elf_Scn *scn" "GElf_Shdr *shdr"
+.Sh DESCRIPTION
+These functions return a pointer to the ELF Section Header data
+structure associated with section descriptor
+.Ar scn .
+.Pp
+Function
+.Fn elf32_getshdr
+retrieves a pointer to an
+.Vt Elf32_Shdr
+structure.
+Section descriptor
+.Ar scn
+must be associated with an ELF descriptor of class
+.Dv ELFCLASS32 .
+.Pp
+Function
+.Fn elf64_getshdr
+retrieves a pointer to an
+.Vt Elf64_Shdr
+structure.
+Section descriptor
+.Ar scn
+must be associated with an ELF descriptor of class
+.Dv ELFCLASS64 .
+.Pp
+Function
+.Fn gelf_getshdr
+copies the values in the section header associated with argument
+.Ar scn
+to the structure pointed to be argument
+.Ar dst .
+The
+.Vt GElf_Shdr
+data structure is described in
+.Xr gelf 3 .
+.Sh RETURN VALUES
+Functions
+.Fn elf32_getshdr
+and
+.Fn elf64_getshdr
+return a valid pointer to the appropriate section header on success
+or NULL if an error was encountered.
+.Pp
+Function
+.Fn gelf_getshdr
+returns argument
+.Ar dst
+if successful, or NULL if an error was encountered.
+.Sh ERRORS
+These functions may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Arguments
+.Ar scn
+or
+.Ar shdr
+were NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar scn
+was not associated a descriptor for an ELF object.
+.It Bq Er ELF_E_CLASS
+The ELF class associated with the section descriptor
+.Ar scn
+did not match the class expected by the API.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_getscn 3 ,
+.Xr gelf 3 ,
+.Xr gelf_update_shdr 3
diff --git a/contrib/elftoolchain/libelf/gelf_getsym.3 b/contrib/elftoolchain/libelf/gelf_getsym.3
new file mode 100644
index 0000000000..98d886f882
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_getsym.3
@@ -0,0 +1,125 @@
+.\" 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 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: gelf_getsym.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd August 29, 2006
+.Os
+.Dt GELF_GETSYM 3
+.Sh NAME
+.Nm gelf_getsym ,
+.Nm gelf_update_sym
+.Nd read and update symbol information
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In gelf.h
+.Ft "GElf_Sym *"
+.Fn gelf_getsym "Elf_Data *data" "int ndx" "GElf_Sym *sym"
+.Ft int
+.Fn gelf_update_sym "Elf_Data *data" "int ndx" "GElf_Sym *sym"
+.Sh DESCRIPTION
+These convenience functions are used to retrieve and update class-dependent
+.Vt Elf32_Sym
+and
+.Vt Elf64_Sym
+structures in an ELF object.
+.Pp
+Argument
+.Ar data
+is an
+.Vt Elf_Data
+descriptor associated with a section of type
+.Dv SHT_SYMTAB ,
+.Dv SHT_DYNSYM
+or
+.Dv SHT_GNU_versym .
+Argument
+.Ar ndx
+is the index of the symbol being retrieved or updated.
+The class-independent
+.Vt GElf_Sym
+structure is described in
+.Xr gelf 3 .
+.Pp
+Function
+.Fn gelf_getsym
+retrieves class-dependent symbol information at index
+.Ar ndx
+in data buffer
+.Ar data
+and copies it to the destination pointed to by argument
+.Ar sym
+after translation to class-independent form.
+.Pp
+Function
+.Fn gelf_update_sym
+converts the class-independent symbol information pointed to
+by argument
+.Ar sym
+to class-dependent form, and writes it to the symbol entry at index
+.Ar ndx
+in the data buffer described by argument
+.Ar data .
+Function
+.Fn gelf_update_sym
+signals an error if any of the values in the class-independent
+representation exceeds the representable limits of the target
+type.
+.Sh RETURN VALUES
+Function
+.Fn gelf_getsym
+returns the value of argument
+.Ar sym
+if successful, or NULL in case of an error.
+Function
+.Fn gelf_update_sym
+returns a non-zero value if successful, or zero in case of an error.
+.Sh ERRORS
+These functions may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Arguments
+.Ar data
+or
+.Ar sym
+were NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar ndx
+was less than zero or larger than the number of symbols in the data
+descriptor.
+.It Bq Er ELF_E_ARGUMENT
+Data descriptor
+.Ar data
+was not associated with a section containing symbol information.
+.It Bq Er ELF_E_RANGE
+A value was not representable in the target type.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_getdata 3 ,
+.Xr elf_getscn 3 ,
+.Xr gelf 3 ,
+.Xr gelf_getsyminfo 3 ,
+.Xr gelf_update_syminfo 3
diff --git a/contrib/elftoolchain/libelf/gelf_getsyminfo.3 b/contrib/elftoolchain/libelf/gelf_getsyminfo.3
new file mode 100644
index 0000000000..a1169f80dc
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_getsyminfo.3
@@ -0,0 +1,115 @@
+.\" 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 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: gelf_getsyminfo.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd August 29, 2006
+.Os
+.Dt GELF_GETSYMINFO 3
+.Sh NAME
+.Nm gelf_getsyminfo ,
+.Nm gelf_update_syminfo
+.Nd read and update symbol information
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In gelf.h
+.Ft "GElf_Syminfo *"
+.Fn gelf_getsyminfo "Elf_Data *data" "int ndx" "GElf_Syminfo *syminfo"
+.Ft int
+.Fn gelf_update_syminfo "Elf_Data *data" "int ndx" "GElf_Syminfo *syminfo"
+.Sh DESCRIPTION
+These convenience functions are used to retrieve and update class-dependent
+.Vt Elf32_Syminfo
+and
+.Vt Elf64_Syminfo
+records in an ELF object.
+.Pp
+Argument
+.Ar data
+is an
+.Vt Elf_Data
+descriptor associated with a section of type
+.Dv SHT_SUNW_syminfo .
+Argument
+.Ar ndx
+is the index of the record being retrieved or updated.
+The class-independent
+.Vt GElf_Syminfo
+structure is described in
+.Xr gelf 3 .
+.Pp
+Function
+.Fn gelf_getsyminfo
+retrieves class-dependent record at index
+.Ar ndx
+in data buffer
+.Ar data
+and copies it to the destination pointed to by argument
+.Ar syminfo
+after translation to class-independent form.
+.Pp
+Function
+.Fn gelf_update_syminfo
+converts the class-independent record pointed to
+by argument
+.Ar syminfo
+to class-dependent form, and writes it to the record at index
+.Ar ndx
+in the data buffer described by argument
+.Ar data .
+.Sh RETURN VALUES
+Function
+.Fn gelf_getsyminfo
+returns the value of argument
+.Ar syminfo
+if successful, or NULL in case of an error.
+Function
+.Fn gelf_update_syminfo
+returns a non-zero value if successful, or zero in case of an error.
+.Sh ERRORS
+These functions may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Arguments
+.Ar data
+or
+.Ar syminfo
+were NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar ndx
+was less than zero or larger than the number of symbols in the data
+descriptor.
+.It Bq Er ELF_E_ARGUMENT
+Data descriptor
+.Ar data
+was not associated with a section containing symbol information.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_getdata 3 ,
+.Xr elf_getscn 3 ,
+.Xr gelf 3 ,
+.Xr gelf_getsym 3 ,
+.Xr gelf_update_sym 3
diff --git a/contrib/elftoolchain/libelf/gelf_getsymshndx.3 b/contrib/elftoolchain/libelf/gelf_getsymshndx.3
new file mode 100644
index 0000000000..b635aac6d5
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_getsymshndx.3
@@ -0,0 +1,162 @@
+.\" 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 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: gelf_getsymshndx.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd November 5, 2006
+.Os
+.Dt GELF_GETSYMSHNDX 3
+.Sh NAME
+.Nm gelf_getsymshndx ,
+.Nm gelf_update_symshndx
+.Nd read and update symbol information using extended section indices
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In gelf.h
+.Ft "GElf_Sym *"
+.Fo gelf_getsymshndx
+.Fa "Elf_Data *symdata"
+.Fa "Elf_Data *xndxdata"
+.Fa "int ndx"
+.Fa "GElf_Sym *sym"
+.Fa "Elf32_Word *xndxptr"
+.Fc
+.Ft int
+.Fo gelf_update_symshndx
+.Fa "Elf_Data *symdata"
+.Fa "Elf_Data *xndxdata"
+.Fa "int ndx"
+.Fa "GElf_Sym *sym"
+.Fa "Elf32_Word xndx"
+.Fc
+.Sh DESCRIPTION
+These functions are analogous to
+.Fn gelf_getsym
+and
+.Fn gelf_update_sym
+respectively, but are capable of handling symbol tables using extended
+section numbering.
+.Pp
+Argument
+.Ar symdata
+is an
+.Vt Elf_Data
+descriptor associated with a section of type
+.Dv SHT_SYMTAB .
+Argument
+.Ar xndxdata
+is an
+.Vt Elf_Data
+descriptor associated with a section of type
+.Dv SHT_SYMTAB_SHNDX .
+Argument
+.Ar ndx
+is the index of the symbol table entry being retrieved or updated.
+Argument
+.Ar sym
+is a pointer to a class-independent
+.Vt GElf_Sym
+structure.
+.Vt GElf_Sym
+structures are described in detail in
+.Xr gelf 3 .
+.Pp
+Function
+.Fn gelf_getsymshndx
+retrieves symbol information at index
+.Ar ndx
+from the data descriptor specified by argument
+.Ar symdata
+and stores in class-independent form in argument
+.Ar sym .
+In addition it retrieves the extended section index for the
+symbol from data buffer
+.Ar xndxdata
+and stores it into the location pointed to by argument
+.Ar xndxptr .
+.Pp
+Function
+.Fn gelf_update_symshndx
+updates the underlying symbol table entry in data
+descriptor
+.Ar symdata
+with the information in argument
+.Ar sym .
+In addition it sets the extended section index in
+data buffer
+.Ar xndxdata
+to the value of argument
+.Ar xndx .
+.Sh RETURN VALUES
+Function
+.Fn gelf_getsymshndx
+returns the value of argument
+.Ar sym
+if successful, or NULL in case of an error.
+.Pp
+Function
+.Fn gelf_update_symshndx
+returns a non-zero value if successful, or zero in case of an error.
+.Sh ERRORS
+These functions may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Arguments
+.Ar symdata ,
+.Ar xndxdata ,
+.Ar xndxptr
+or
+.Ar sym
+were NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar ndx
+was less than zero, or too large for either of descriptors
+.Ar symdata
+or
+.Ar xndxdata .
+.It Bq Er ELF_E_ARGUMENT
+Data descriptor
+.Ar symdata
+was not associated with a section of type
+.Dv SHT_SYMTAB .
+.It Bq Er ELF_E_ARGUMENT
+Data descriptor
+.Ar xndxdata
+was not associated with a section of type
+.Dv SHT_SYMTAB_SHNDX .
+.It Bq Er ELF_E_ARGUMENT
+Data descriptor
+.Ar symdata
+and
+.Ar xndxdata
+were associated with different ELF objects.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_getdata 3 ,
+.Xr elf_getscn 3 ,
+.Xr gelf 3 ,
+.Xr gelf_getsym 3 ,
+.Xr gelf_update_sym 3
diff --git a/contrib/elftoolchain/libelf/gelf_newehdr.3 b/contrib/elftoolchain/libelf/gelf_newehdr.3
new file mode 100644
index 0000000000..cba9de0c8f
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_newehdr.3
@@ -0,0 +1,194 @@
+.\" 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 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: gelf_newehdr.3 3500 2016-12-04 11:08:44Z jkoshy $
+.\"
+.Dd October 22, 2007
+.Os
+.Dt GELF_NEWEHDR 3
+.Sh NAME
+.Nm elf32_newehdr ,
+.Nm elf64_newehdr ,
+.Nm gelf_newehdr
+.Nd retrieve or allocate the object file header
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft "Elf32_Ehdr *"
+.Fn elf32_newehdr "Elf *elf"
+.Ft "Elf64_Ehdr *"
+.Fn elf64_newehdr "Elf *elf"
+.In gelf.h
+.Ft "void *"
+.Fn gelf_newehdr "Elf *elf" "int elfclass"
+.Sh DESCRIPTION
+These functions retrieve the ELF header from the ELF descriptor
+.Ar elf ,
+allocating a new header if needed.
+File data structures are translated to their in-memory representations
+as described in
+.Xr elf 3 .
+.Pp
+Function
+.Fn elf32_newehdr
+returns a pointer to a 32 bit
+.Vt Elf32_Ehdr
+structure.
+Function
+.Fn elf64_newehdr
+returns a pointer to a 64 bit
+.Vt Elf64_Ehdr structure.
+.Pp
+When argument
+.Ar elfclass
+has value
+.Dv ELFCLASS32 ,
+function
+.Fn gelf_newehdr
+returns the value returned by
+.Fn elf32_newehdr "elf" .
+When argument
+.Ar elfclass
+has value
+.Dv ELFCLASS64
+it returns the value returned by
+.Fn elf64_newehdr "elf" .
+.Pp
+If a fresh header structure is allocated, the members of the
+structure are initialized as follows:
+.Bl -tag -width indent
+.It Va "e_ident[EI_MAG0..EI_MAG3]"
+Identification bytes at offsets
+.Dv EI_MAG0 ,
+.Dv EI_MAG1 ,
+.Dv EI_MAG2
+and
+.Dv EI_MAG3
+are set to the ELF signature.
+.It Va "e_ident[EI_CLASS]"
+The identification byte at offset
+.Dv EI_CLASS
+is set to the ELF class associated with the function being called
+or to argument
+.Ar elfclass
+for function
+.Fn gelf_newehdr .
+.It Va "e_ident[EI_DATA]"
+The identification byte at offset
+.Dv EI_DATA
+is set to
+.Dv ELFDATANONE .
+.It Va "e_ident[EI_VERSION]"
+The identification byte at offset
+.Dv EI_VERSION
+is set to the ELF library's operating version set by a prior call to
+.Xr elf_version 3 .
+.It Va e_machine
+is set to
+.Dv EM_NONE .
+.It Va e_type
+is set to
+.Dv ELF_K_NONE .
+.It Va e_version
+is set to the ELF library's operating version set by a prior call to
+.Xr elf_version 3 .
+.El
+.Pp
+Other members of the header are set to zero.
+The application is responsible for changing these values
+as needed before calling
+.Fn elf_update .
+.Pp
+If successful, these three functions set the
+.Dv ELF_F_DIRTY
+flag on ELF descriptor
+.Ar elf .
+.Sh RETURN VALUES
+These functions return a pointer to a translated header descriptor
+if successful, or NULL on failure.
+.Sh COMPATIBILITY
+The
+.Fn gelf_newehdr
+function uses a type of
+.Ft "void *"
+for its returned value.
+This differs from some other implementations of the ELF(3) API, which use an
+.Ft "unsigned long"
+return type.
+.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 elf
+was null.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not a descriptor for an ELF object.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elfclass
+had an unsupported value.
+.It Bq Er ELF_E_ARGUMENT
+The class of the ELF descriptor
+.Ar elf
+did not match that of the requested operation.
+.It Bq Er ELF_E_ARGUMENT
+For function
+.Fn gelf_newehdr ,
+the class of argument
+.Ar elf
+was not
+.Dv ELFCLASSNONE
+and did not match the argument
+.Ar elfclass .
+.It Bq Er ELF_E_CLASS
+The ELF class of descriptor
+.Ar elf
+did not match that of the API function being called.
+.It Bq Er ELF_E_HEADER
+A malformed ELF header was detected.
+.It Bq Er ELF_E_RESOURCE
+An out of memory condition was detected during execution.
+.It Bq Er ELF_E_SECTION
+The ELF descriptor in argument
+.Ar elf
+did not adhere to the conventions used for extended numbering.
+.It Bq Er ELF_E_VERSION
+The ELF descriptor
+.Ar elf
+had an unsupported ELF version number.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf32_getehdr 3 ,
+.Xr elf64_getehdr 3 ,
+.Xr elf_flagdata 3 ,
+.Xr elf_getident 3 ,
+.Xr elf_update 3 ,
+.Xr elf_version 3 ,
+.Xr gelf 3 ,
+.Xr gelf_getehdr 3 ,
+.Xr elf 5
diff --git a/contrib/elftoolchain/libelf/gelf_newphdr.3 b/contrib/elftoolchain/libelf/gelf_newphdr.3
new file mode 100644
index 0000000000..27e561d010
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_newphdr.3
@@ -0,0 +1,142 @@
+.\" 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 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: gelf_newphdr.3 3500 2016-12-04 11:08:44Z jkoshy $
+.\"
+.Dd October 22, 2007
+.Os
+.Dt GELF_NEWPHDR 3
+.Sh NAME
+.Nm elf32_newphdr ,
+.Nm elf64_newphdr ,
+.Nm gelf_newphdr
+.Nd allocate an ELF program header table
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft "Elf32_Phdr *"
+.Fn elf32_newphdr "Elf *elf" "size_t count"
+.Ft "Elf64_Phdr *"
+.Fn elf64_newphdr "Elf *elf" "size_t count"
+.In gelf.h
+.Ft "void *"
+.Fn gelf_newphdr "Elf *elf" "size_t count"
+.Sh DESCRIPTION
+These functions allocate an ELF Program Header table
+for an ELF descriptor.
+.Vt Elf32_Phdr
+and
+.Vt Elf64_Phdr
+descriptors are described further in
+.Xr elf 5 .
+.Pp
+Functions
+.Fn elf32_newphdr
+and
+.Fn elf64_newphdr
+allocate a table of
+.Ar count
+.Vt Elf32_Phdr
+and
+.Vt Elf64_Phdr
+descriptors respectively,
+discarding any existing program header table
+already present in the ELF descriptor
+.Ar elf .
+A value of zero for argument
+.Ar count
+may be used to delete an existing program header table
+from an ELF descriptor.
+.Pp
+Function
+.Fn gelf_newphdr
+will return a table of
+.Vt Elf32_Phdr
+or
+.Vt Elf64_Phdr
+with
+.Ar count
+elements depending on the ELF class of ELF descriptor
+.Ar elf .
+.Pp
+The functions set the
+.Dv ELF_F_DIRTY
+flag on the program header table.
+All members of the returned array of Phdr structures
+will be initialized to zero.
+.Pp
+After a successful call to these functions, the pointer returned
+by a prior call to
+.Fn elf32_getphdr
+or
+.Fn elf64_getphdr
+on the same descriptor
+.Ar elf
+will no longer be valid.
+.Sh RETURN VALUES
+The functions a valid pointer if successful, or NULL in case an error
+was encountered.
+.Sh COMPATIBILITY
+The
+.Fn gelf_newphdr
+function uses a type of
+.Ft "void *"
+for its returned value.
+This differs from some other implementations of the ELF(3) API, which use an
+.Ft "unsigned long"
+return type.
+.Sh ERRORS
+These functions may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not a descriptor for an ELF object.
+.It Bq Er ELF_E_CLASS
+ELF descriptor
+.Ar elf
+was of an unrecognized class.
+.It Bq Er ELF_E_RESOURCE
+An out of memory condition was detected.
+.It Bq Er ELF_E_SEQUENCE
+An executable header was not allocated for ELF descriptor
+.Ar elf
+before using these APIs.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf32_getphdr 3 ,
+.Xr elf32_newehdr 3 ,
+.Xr elf64_getphdr 3 ,
+.Xr elf64_newehdr 3 ,
+.Xr elf_flagphdr 3 ,
+.Xr elf_getphnum 3 ,
+.Xr gelf 3 ,
+.Xr gelf_getphdr 3 ,
+.Xr gelf_newehdr 3 ,
+.Xr elf 5
diff --git a/contrib/elftoolchain/libelf/gelf_phdr.c b/contrib/elftoolchain/libelf/gelf_phdr.c
index 31e20b0680..0916ccf345 100644
--- a/contrib/elftoolchain/libelf/gelf_phdr.c
+++ b/contrib/elftoolchain/libelf/gelf_phdr.c
@@ -31,7 +31,7 @@
 
 #include "_libelf.h"
 
-ELFTC_VCSID("$Id: gelf_phdr.c 3177 2015-03-30 18:19:41Z emaste $");
+ELFTC_VCSID("$Id: gelf_phdr.c 3576 2017-09-14 02:15:29Z emaste $");
 
 Elf32_Phdr *
 elf32_getphdr(Elf *e)
@@ -53,10 +53,17 @@ gelf_getphdr(Elf *e, int index, GElf_Phdr *d)
 	Elf64_Ehdr *eh64;
 	Elf32_Phdr *ep32;
 	Elf64_Phdr *ep64;
+	size_t phnum;
 
 	if (d == NULL || e == NULL ||
 	    ((ec = e->e_class) != ELFCLASS32 && ec != ELFCLASS64) ||
-	    (e->e_kind != ELF_K_ELF) || index < 0) {
+	    (e->e_kind != ELF_K_ELF) || index < 0 ||
+	    elf_getphdrnum(e, &phnum) < 0) {
+		LIBELF_SET_ERROR(ARGUMENT, 0);
+		return (NULL);
+	}
+
+	if ((size_t)index >= phnum) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (NULL);
 	}
@@ -66,11 +73,6 @@ gelf_getphdr(Elf *e, int index, GElf_Phdr *d)
 		    ((ep32 = _libelf_getphdr(e, ELFCLASS32)) == NULL))
 			return (NULL);
 
-		if (index >= eh32->e_phnum) {
-			LIBELF_SET_ERROR(ARGUMENT, 0);
-			return (NULL);
-		}
-
 		ep32 += index;
 
 		d->p_type   = ep32->p_type;
@@ -87,11 +89,6 @@ gelf_getphdr(Elf *e, int index, GElf_Phdr *d)
 		    (ep64 = _libelf_getphdr(e, ELFCLASS64)) == NULL)
 			return (NULL);
 
-		if (index >= eh64->e_phnum) {
-			LIBELF_SET_ERROR(ARGUMENT, 0);
-			return (NULL);
-		}
-
 		ep64 += index;
 
 		*d = *ep64;
@@ -125,13 +122,15 @@ gelf_newphdr(Elf *e, size_t count)
 int
 gelf_update_phdr(Elf *e, int ndx, GElf_Phdr *s)
 {
-	int ec, phnum;
+	int ec;
+	size_t phnum;
 	void *ehdr;
 	Elf32_Phdr *ph32;
 	Elf64_Phdr *ph64;
 
 	if (s == NULL || e == NULL || e->e_kind != ELF_K_ELF ||
-	    ((ec = e->e_class) != ELFCLASS32 && ec != ELFCLASS64)) {
+	    ((ec = e->e_class) != ELFCLASS32 && ec != ELFCLASS64) ||
+	    elf_getphdrnum(e, &phnum) < 0) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (0);
 	}
@@ -144,12 +143,7 @@ gelf_update_phdr(Elf *e, int ndx, GElf_Phdr *s)
 	if ((ehdr = _libelf_ehdr(e, ec, 0)) == NULL)
 		return (0);
 
-	if (ec == ELFCLASS32)
-		phnum = ((Elf32_Ehdr *) ehdr)->e_phnum;
-	else
-		phnum = ((Elf64_Ehdr *) ehdr)->e_phnum;
-
-	if (ndx < 0 || ndx > phnum) {
+	if (ndx < 0 || (size_t)ndx > phnum) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (0);
 	}
diff --git a/contrib/elftoolchain/libelf/gelf_update_ehdr.3 b/contrib/elftoolchain/libelf/gelf_update_ehdr.3
new file mode 100644
index 0000000000..f5e041d797
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_update_ehdr.3
@@ -0,0 +1,123 @@
+.\" 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 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: gelf_update_ehdr.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd August 27, 2006
+.Os
+.Dt GELF_UPDATE_EHDR 3
+.Sh NAME
+.Nm gelf_update_ehdr ,
+.Nm gelf_update_phdr ,
+.Nm gelf_update_shdr
+.Nd update underlying ELF data structures
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In gelf.h
+.Ft int
+.Fn gelf_update_ehdr "Elf *elf" "GElf_Ehdr *ehdr"
+.Ft int
+.Fn gelf_update_phdr "Elf *elf" "int ndx" "GElf_Phdr *phdr"
+.Ft int
+.Fn gelf_update_shdr "Elf_Scn *scn" "GElf_Shdr *shdr"
+.Sh DESCRIPTION
+These functions are used to update ELF data structures on the underlying
+ELF descriptor.
+Class-dependent data structures in the underlying ELF descriptor
+are updated using the data in the class-independent GElf descriptors
+and the underlying ELF data structures are marked
+.Dq dirty .
+The conversion process signals an error if the values being copied
+to the target ELF data structure would exceed representation
+limits.
+GElf descriptors are described in
+.Xr gelf 3 .
+.Pp
+Function
+.Fn gelf_update_ehdr
+updates the ELF Executable Header with the values in the
+class-independent executable header
+.Ar ehdr .
+.Pp
+Function
+.Fn gelf_update_phdr
+updates the ELF Program Header structure at index
+.Ar ndx
+with the values in the class-independent program header
+.Ar phdr .
+.Pp
+Function
+.Fn gelf_update_shdr
+updates the ELF Section Header structure associated with section
+descriptor
+.Ar scn
+with the values in argument
+.Ar shdr .
+.Sh RETURN VALUES
+These functions return a non-zero integer on success, or zero in case
+of an error.
+.Sh ERRORS
+These functions may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+Arguments
+.Ar elf ,
+.Ar ehdr ,
+.Ar phdr ,
+.Ar scn ,
+or
+.Ar shdr
+were NULL.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+was not a descriptor for an ELF object.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar elf
+had an unsupported ELF class.
+.It Bq Er ELF_E_ARGUMENT
+Argument
+.Ar ndx
+exceeded the number of entries in the program header table.
+.It Bq Er ELF_E_ARGUMENT
+Section descriptor
+.Ar scn
+was not associated with an ELF descriptor.
+.It Bq Er ELF_E_MODE
+ELF descriptor
+.Ar elf
+was not opened for writing or updating.
+.It Bq Er ELF_E_RESOURCE
+An out of memory condition was detected.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_flagelf 3 ,
+.Xr elf_flagphdr 3 ,
+.Xr elf_flagshdr 3 ,
+.Xr gelf 3 ,
+.Xr gelf_getehdr 3 ,
+.Xr gelf_getphdr 3 ,
+.Xr gelf_getshdr 3
diff --git a/contrib/elftoolchain/libelf/gelf_xlatetof.3 b/contrib/elftoolchain/libelf/gelf_xlatetof.3
new file mode 100644
index 0000000000..ca90002096
--- /dev/null
+++ b/contrib/elftoolchain/libelf/gelf_xlatetof.3
@@ -0,0 +1,247 @@
+.\" 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 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: gelf_xlatetof.3 189 2008-07-20 10:38:08Z jkoshy $
+.\"
+.Dd July 24, 2006
+.Os
+.Dt GELF_XLATETOF 3
+.Sh NAME
+.Nm elf32_xlate ,
+.Nm elf64_xlate ,
+.Nm gelf_xlate
+.Nd translate data between files and memory
+.Sh LIBRARY
+.Lb libelf
+.Sh SYNOPSIS
+.In libelf.h
+.Ft "Elf_Data *"
+.Fn elf32_xlatetof "Elf_Data *dst" "Elf_Data *src" "unsigned int encode"
+.Ft "Elf_Data *"
+.Fn elf32_xlatetom "Elf_Data *dst" "Elf_Data *src" "unsigned int encode"
+.Ft "Elf_Data *"
+.Fn elf64_xlatetof "Elf_Data *dst" "Elf_Data *src" "unsigned int encode"
+.Ft "Elf_Data *"
+.Fn elf64_xlatetom "Elf_Data *dst" "Elf_Data *src" "unsigned int encode"
+.In gelf.h
+.Ft "Elf_Data *"
+.Fo gelf_xlatetof
+.Fa "Elf *elf"
+.Fa "Elf_Data *dst"
+.Fa "Elf_Data *src"
+.Fa "unsigned int encode"
+.Fc
+.Ft "Elf_Data *"
+.Fo gelf_xlatetom
+.Fa "Elf *elf"
+.Fa "Elf_Data *dst"
+.Fa "Elf_Data *src"
+.Fa "unsigned int encode"
+.Fc
+.Sh DESCRIPTION
+These functions translate between the file and memory representations
+of ELF data structures.
+The in-memory representation of an ELF data structure would confirm to
+the byte ordering and data alignment restrictions dictated by the host
+processor.
+A file representation of the same data structure could use a non-native byte
+ordering and in addition may be laid out differently with the file.
+.Pp
+Functions
+.Fn elf32_xlatetom ,
+.Fn elf64_xlatetom ,
+and
+.Fn gelf_xlatetom
+translate data from file representations to native, in-memory representations.
+Functions
+.Fn elf32_xlatetof ,
+.Fn elf64_xlatetof ,
+and
+.Fn gelf_xlatetof
+translate data from in-memory representations to file representations.
+.Pp
+Argument
+.Ar src
+denotes an
+.Vt Elf_Data
+descriptor describing the source to be translated.
+The following elements of the descriptor need to be set before
+invoking these functions:
+.Bl -hang -offset indent
+.It Va d_buf
+Set to a valid pointer value denoting the beginning of the data area
+to be translated.
+.It Va d_size
+Set to the total size in bytes of the source data area to be
+translated.
+.It Va d_type
+Set to the type of the source data being translated.
+This value is one of the values defined in the
+.Vt Elf_Type
+enumeration.
+The
+.Vt Elf_Type
+enumeration is described in
+.Xr elf 3 .
+.It Va d_version
+Set to the version number of the ELF data structures being
+translated.
+Currently only version
+.Dv EV_CURRENT
+is supported.
+.El
+.Pp
+Argument
+.Ar dst
+describes the destination buffer.
+The following elements of the
+.Vt Elf_Data
+descriptor need to be set before invoking these functions:
+.Bl -hang -offset indent
+.It Va d_buf
+Set to a valid pointer value that denotes the start of the destination
+buffer that will hold translated data.
+This value may be the same as that of the source buffer, in which case
+an in-place conversion will be attempted.
+.It Va d_size
+Set to the size of the destination buffer in bytes.
+This value will be modified if the function call succeeds.
+.It Va d_version
+Set to the desired version number of the destination.
+Currently only version
+.Dv EV_CURRENT
+is supported.
+.El
+.Pp
+These translations routines allow the source and destination buffers
+to coincide, in which case an in-place translation will be done
+if the destination is large enough to hold the translated data.
+Other kinds of overlap between the source and destination buffers
+are not permitted.
+.Pp
+On successful completion of the translation request the following
+fields of the
+.Ar dst
+descriptor would be modified:
+.Bl -hang -offset indent
+.It Va d_size
+Set to the size in bytes of the translated data.
+.It Va d_type
+Set to the
+.Va d_type
+value of the source data descriptor.
+.El
+.Pp
+Argument
+.Ar encode
+specifies the encoding in which the file objects are represented.
+It must be one of:
+.Bl -hang -offset indent
+.It Dv ELFDATANONE
+File objects use the library's native byte ordering.
+.It Dv ELFDATA2LSB
+File objects use a little-endian ordering.
+.It Dv ELFDATA2MSB
+File objects use a big-endian ordering.
+.El
+.Pp
+The functions
+.Fn gelf_xlatetof
+and
+.Fn gelf_xlatetom
+select the appropriate 32 or 64 bit translations based on the class of argument
+.Ar elf .
+.Sh RETURN VALUES
+These functions return argument
+.Ar dst
+if successful, or NULL in case of an error.
+.Sh EXAMPLES
+TODO
+.Sh ERRORS
+These functions may fail with the following errors:
+.Bl -tag -width "[ELF_E_RESOURCE]"
+.It Bq Er ELF_E_ARGUMENT
+One of arguments
+.Ar src ,
+.Ar dst
+or
+.Ar elf
+was NULL.
+.It Bq Er ELF_E_ARGUMENT
+Arguments
+.Ar src
+and
+.Ar dst
+were equal.
+.It Bq Er ELF_E_ARGUMENT
+The desired encoding parameter was not one of
+.Dv ELFDATANONE ,
+.Dv ELFDATA2LSB
+or
+.Dv ELFDATA2MSB .
+.It Bq Er ELF_E_ARGUMENT
+The
+.Ar d_type
+field of argument
+.Ar src
+specified an unsupported type.
+.It Bq Er ELF_E_DATA
+The
+.Ar src
+argument specified a buffer size that was not an integral multiple of
+its underlying type.
+.It Bq Er ELF_E_DATA
+The
+.Ar dst
+argument specified a buffer size that was too small.
+.It Bq Er ELF_E_DATA
+Argument
+.Ar dst
+specified a destination buffer that overlaps with the source
+buffer.
+.It Bq Er ELF_E_DATA
+The destination buffer for a conversion to memory had an alignment
+inappropriate for the underlying ELF type.
+.It Bq Er ELF_E_DATA
+The source buffer for a conversion to file had an alignment
+inappropriate for the underlying ELF type.
+.It Bq Er ELF_E_UNIMPL
+The version numbers for arguments
+.Ar dst
+and
+.Ar src
+were not identical.
+.It Bq Er ELF_E_UNIMPL
+The argument
+.Ar src
+requested conversion for a type which is not currently
+supported.
+.It Bq Er ELF_E_VERSION
+Argument
+.Ar src
+specified an unsupported version number.
+.El
+.Sh SEE ALSO
+.Xr elf 3 ,
+.Xr elf_getdata 3 ,
+.Xr gelf 3
diff --git a/contrib/elftoolchain/libelf/libelf.h b/contrib/elftoolchain/libelf/libelf.h
index 47c11b9015..7b312d38e7 100644
--- a/contrib/elftoolchain/libelf/libelf.h
+++ b/contrib/elftoolchain/libelf/libelf.h
@@ -30,8 +30,9 @@
 #define	_LIBELF_H_
 
 #include <sys/types.h>
-
-#include <elfdefinitions.h>
+// #include <elfdefinitions.h>
+#include <sys/elf32.h>
+#include <sys/elf64.h>
 
 /* Library private data structures */
 typedef struct _Elf Elf;
diff --git a/contrib/elftoolchain/libelf/libelf_align.c b/contrib/elftoolchain/libelf/libelf_align.c
index 5afb98bb41..ea6a601e3b 100644
--- a/contrib/elftoolchain/libelf/libelf_align.c
+++ b/contrib/elftoolchain/libelf/libelf_align.c
@@ -107,7 +107,7 @@ static struct align falign[ELF_T_NUM] = {
 	[ELF_T_LWORD]	= FALIGN(8,8),
 	[ELF_T_MOVE]	= FALIGN(8,8),
 	[ELF_T_MOVEP] 	= UNSUPPORTED(),
-	[ELF_T_NOTE]	= FALIGN(4,4),
+	[ELF_T_NOTE]	= FALIGN(1,1),
 	[ELF_T_OFF]	= FALIGN(4,8),
 	[ELF_T_PHDR]	= FALIGN(4,8),
 	[ELF_T_REL]	= FALIGN(4,8),
diff --git a/contrib/elftoolchain/libelf/libelf_ar.c b/contrib/elftoolchain/libelf/libelf_ar.c
index faeec2c607..8fce741972 100644
--- a/contrib/elftoolchain/libelf/libelf_ar.c
+++ b/contrib/elftoolchain/libelf/libelf_ar.c
@@ -33,7 +33,7 @@
 #include "_libelf.h"
 #include "_libelf_ar.h"
 
-ELFTC_VCSID("$Id: libelf_ar.c 3174 2015-03-27 17:13:41Z emaste $");
+ELFTC_VCSID("$Id: libelf_ar.c 3446 2016-05-03 01:31:17Z emaste $");
 
 #define	LIBELF_NALLOC_SIZE	16
 
@@ -64,7 +64,7 @@ ELFTC_VCSID("$Id: libelf_ar.c 3174 2015-03-27 17:13:41Z emaste $");
  * 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
+ * In the BSD format, file names can be up to 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
diff --git a/contrib/elftoolchain/libelf/libelf_convert.m4 b/contrib/elftoolchain/libelf/libelf_convert.m4
index 9f99f1ead8..ec395902a1 100644
--- a/contrib/elftoolchain/libelf/libelf_convert.m4
+++ b/contrib/elftoolchain/libelf/libelf_convert.m4
@@ -30,7 +30,7 @@
 
 #include "_libelf.h"
 
-ELFTC_VCSID("$Id: libelf_convert.m4 3174 2015-03-27 17:13:41Z emaste $");
+ELFTC_VCSID("$Id: libelf_convert.m4 3429 2016-03-12 04:12:39Z emaste $");
 
 /* WARNING: GENERATED FROM __file__. */
 
@@ -1019,6 +1019,7 @@ _libelf_cvt_NOTE_tof(unsigned char *dst, size_t dsz, unsigned char *src,
 		WRITE_WORD(dst, type);
 
 		src += sizeof(Elf_Note);
+		count -= sizeof(Elf_Note);
 
 		if (count < sz)
 			sz = count;
diff --git a/contrib/elftoolchain/libelf/libelf_ehdr.c b/contrib/elftoolchain/libelf/libelf_ehdr.c
index d375fb3002..6630e6eba7 100644
--- a/contrib/elftoolchain/libelf/libelf_ehdr.c
+++ b/contrib/elftoolchain/libelf/libelf_ehdr.c
@@ -31,7 +31,7 @@
 
 #include "_libelf.h"
 
-ELFTC_VCSID("$Id: libelf_ehdr.c 3174 2015-03-27 17:13:41Z emaste $");
+ELFTC_VCSID("$Id: libelf_ehdr.c 3575 2017-09-14 02:13:36Z emaste $");
 
 /*
  * Retrieve counts for sections, phdrs and the section string table index
@@ -170,10 +170,6 @@ _libelf_ehdr(Elf *e, int ec, int allocate)
 	(*xlator)((unsigned char*) ehdr, msz, e->e_rawfile, (size_t) 1,
 	    e->e_byteorder != LIBELF_PRIVATE(byteorder));
 
-	/*
-	 * If extended numbering is being used, read the correct
-	 * number of sections and program header entries.
-	 */
 	if (ec == ELFCLASS32) {
 		phnum = ((Elf32_Ehdr *) ehdr)->e_phnum;
 		shnum = ((Elf32_Ehdr *) ehdr)->e_shnum;
@@ -193,12 +189,19 @@ _libelf_ehdr(Elf *e, int ec, int allocate)
 		return (NULL);
 	}
 
-	if (shnum != 0 || shoff == 0LL) { /* not using extended numbering */
+	/*
+	 * If extended numbering is being used, read the correct
+	 * number of sections and program header entries.
+	 */
+	if ((shnum == 0 && shoff != 0) || phnum == PN_XNUM || strndx == SHN_XINDEX) {
+		if (_libelf_load_extended(e, ec, shoff, phnum, strndx) == 0)
+			return (NULL);
+	} else {
+		/* not using extended numbering */
 		e->e_u.e_elf.e_nphdr = phnum;
 		e->e_u.e_elf.e_nscn = shnum;
 		e->e_u.e_elf.e_strndx = strndx;
-	} else if (_libelf_load_extended(e, ec, shoff, phnum, strndx) == 0)
-		return (NULL);
+	}
 
 	return (ehdr);
 }
diff --git a/contrib/elftoolchain/libelf/os.FreeBSD.mk b/contrib/elftoolchain/libelf/os.FreeBSD.mk
new file mode 100644
index 0000000000..72834b757b
--- /dev/null
+++ b/contrib/elftoolchain/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
diff --git a/contrib/elftoolchain/libelf/os.NetBSD.mk b/contrib/elftoolchain/libelf/os.NetBSD.mk
new file mode 100644
index 0000000000..96b833596d
--- /dev/null
+++ b/contrib/elftoolchain/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
diff --git a/lib/libelf/Makefile b/lib/libelf/Makefile
index 312d154d71..46b67e17e2 100644
--- a/lib/libelf/Makefile
+++ b/lib/libelf/Makefile
@@ -1,17 +1,18 @@
 # ELF library is a component of ELF Tool Chain (replacement for binutils)
-# For now, do not expose this library.  It is needed for execinfo library.
+# It is needed for execinfo library.
 
+PACKAGE=lib${LIB}
+SHLIBDIR?= /lib
 
-LIB=			elf
-INTERNALLIB=		yes
-INTERNALLIBPROF=	yes
-INSTALL_PIC_ARCHIVE=	yes
-TOOLCHAINDIR=		${.CURDIR}/../../contrib/elftoolchain
-SRCDIR=			${TOOLCHAINDIR}/libelf
-COMMON=			${TOOLCHAINDIR}/common
-CFLAGS+=		-I. -I${SRCDIR} -I${COMMON}
+.include <bsd.own.mk>
+
+ELFTCDIR=${.CURDIR}/../../contrib/elftoolchain
+SRCDIR=	${ELFTCDIR}/libelf
+
+.PATH:	${SRCDIR}
 
-.PATH:			${SRCDIR}
+LIB=	elf
+INSTALL_PIC_ARCHIVE=	yes
 
 # verbatim from vendor sourcefile
 SRCS=	elf.c							\
@@ -69,29 +70,128 @@ SRCS=	elf.c							\
 	libelf_xlate.c						\
 	${GENSRCS}
 
-GENSRCS=	libelf_fsize.c libelf_msize.c libelf_convert.c
-
-libelf_convert.c:	elf_types.m4 libelf_convert.m4
-libelf_fsize.c:		elf_types.m4 libelf_fsize.m4
-libelf_msize.c:		elf_types.m4 libelf_msize.m4
+INCS=		libelf.h gelf.h
 
 # Copy correct headers over to object directory
-
+# We need to link against the correct version of these files. One
+# solution is to include ../../sys in the include path. This causes
+# problems when a header file in sys depends on a file in another
+# part of the tree, e.g. a machine dependent header.
+#
 ELFHEAD=	sys/elf32.h sys/elf64.h sys/elf_common.h
 SRCS+=		${ELFHEAD}
 
+GENSRCS=	libelf_fsize.c libelf_msize.c libelf_convert.c
+CLEANFILES=	${GENSRCS}
+CLEANDIRS=	sys
+CFLAGS+=	-I. -I${SRCDIR} -I${ELFTCDIR}/common
+
 ${.OBJDIR}/sys:
 	mkdir -p ${.TARGET}
 
 ${ELFHEAD}: ${.OBJDIR}/sys ${.CURDIR}/../../sys/${.TARGET}
 	ln -sf ${.CURDIR}/../../sys/${.TARGET} ${.TARGET}
 
-CLEANFILES=	${GENSRCS}
-CLEANDIRS=	sys
+SHLIB_MAJOR=	2
+
+MAN=	elf.3							\
+	elf_begin.3						\
+	elf_cntl.3						\
+	elf_end.3						\
+	elf_errmsg.3						\
+	elf_fill.3						\
+	elf_flagdata.3						\
+	elf_getarhdr.3						\
+	elf_getarsym.3						\
+	elf_getbase.3						\
+	elf_getdata.3						\
+	elf_getident.3						\
+	elf_getscn.3						\
+	elf_getphdrnum.3					\
+	elf_getphnum.3						\
+	elf_getshdrnum.3					\
+	elf_getshnum.3						\
+	elf_getshdrstrndx.3					\
+	elf_getshstrndx.3					\
+	elf_hash.3						\
+	elf_kind.3						\
+	elf_memory.3						\
+	elf_next.3						\
+	elf_open.3						\
+	elf_rawfile.3						\
+	elf_rand.3						\
+	elf_strptr.3						\
+	elf_update.3						\
+	elf_version.3						\
+	gelf.3							\
+	gelf_checksum.3						\
+	gelf_fsize.3						\
+	gelf_getcap.3						\
+	gelf_getclass.3						\
+	gelf_getdyn.3						\
+	gelf_getehdr.3						\
+	gelf_getmove.3						\
+	gelf_getphdr.3						\
+	gelf_getrel.3						\
+	gelf_getrela.3						\
+	gelf_getshdr.3						\
+	gelf_getsym.3						\
+	gelf_getsyminfo.3					\
+	gelf_getsymshndx.3					\
+	gelf_newehdr.3						\
+	gelf_newphdr.3						\
+	gelf_update_ehdr.3					\
+	gelf_xlatetof.3
+
+MLINKS+= \
+	elf_errmsg.3 elf_errno.3		\
+	elf_flagdata.3 elf_flagarhdr.3		\
+	elf_flagdata.3 elf_flagehdr.3		\
+	elf_flagdata.3 elf_flagelf.3		\
+	elf_flagdata.3 elf_flagphdr.3		\
+	elf_flagdata.3 elf_flagscn.3		\
+	elf_flagdata.3 elf_flagshdr.3		\
+	elf_getdata.3 elf_newdata.3		\
+	elf_getdata.3 elf_rawdata.3		\
+	elf_getscn.3 elf_ndxscn.3		\
+	elf_getscn.3 elf_newscn.3		\
+	elf_getscn.3 elf_nextscn.3		\
+	elf_getshstrndx.3 elf_setshstrndx.3	\
+	elf_open.3 elf_openmemory.3             \
+	gelf_getcap.3 gelf_update_cap.3		\
+	gelf_getdyn.3 gelf_update_dyn.3		\
+	gelf_getmove.3 gelf_update_move.3	\
+	gelf_getrel.3 gelf_update_rel.3		\
+	gelf_getrela.3 gelf_update_rela.3	\
+	gelf_getsym.3 gelf_update_sym.3		\
+	gelf_getsyminfo.3 gelf_update_syminfo.3	\
+	gelf_getsymshndx.3 gelf_update_symshndx.3 \
+	gelf_update_ehdr.3 gelf_update_phdr.3	\
+	gelf_update_ehdr.3 gelf_update_shdr.3	\
+	gelf_xlatetof.3 gelf_xlatetom.3
+
+.for E in 32 64
+MLINKS+= \
+	gelf_checksum.3	elf${E}_checksum.3 	\
+	gelf_fsize.3	elf${E}_fsize.3 	\
+	gelf_getehdr.3	elf${E}_getehdr.3	\
+	gelf_getphdr.3	elf${E}_getphdr.3	\
+	gelf_getshdr.3	elf${E}_getshdr.3	\
+	gelf_newehdr.3	elf${E}_newehdr.3	\
+	gelf_newphdr.3	elf${E}_newphdr.3	\
+	gelf_xlatetof.3	elf${E}_xlatetof.3	\
+	gelf_xlatetof.3	elf${E}_xlatetom.3
+.endfor
+
+# VERSION_MAP=           ${SRCDIR}/Version.map
+
+libelf_convert.c:	elf_types.m4 libelf_convert.m4
+libelf_fsize.c:		elf_types.m4 libelf_fsize.m4
+libelf_msize.c:		elf_types.m4 libelf_msize.m4
 
 .include <bsd.lib.mk>
 
-# Keep the .SUFFIXES line after the include of <bsd.lib.mk>
+# Keep the .SUFFIXES line after the include of bsd.lib.mk
 .SUFFIXES:	.m4 .c
 .m4.c:
 	m4 -D SRCDIR=${SRCDIR} ${M4FLAGS} ${.IMPSRC} > ${.TARGET}
diff --git a/sys/sys/elf32.h b/sys/sys/elf32.h
index 8f89193585..69f1c61dd3 100644
--- a/sys/sys/elf32.h
+++ b/sys/sys/elf32.h
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 1996-1998 John D. Polstra.
  * All rights reserved.
  *
@@ -23,30 +25,34 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/sys/elf32.h,v 1.7 1999/08/28 00:51:41 peter Exp $
+ * $FreeBSD$
  */
 
 #ifndef _SYS_ELF32_H_
-#define _SYS_ELF32_H_
+#define _SYS_ELF32_H_ 1
 
 #ifndef _SYS_TYPES_H_
 #include <sys/types.h>
 #endif
-#ifndef _SYS_ELF_COMMON_H_
+
 #include <sys/elf_common.h>
-#endif
 
 /*
  * ELF definitions common to all 32-bit architectures.
  */
 
-typedef u_int32_t	Elf32_Addr;
-typedef u_int16_t	Elf32_Half;
-typedef u_int32_t	Elf32_Off;
+typedef uint32_t	Elf32_Addr;
+typedef uint16_t	Elf32_Half;
+typedef uint32_t	Elf32_Off;
 typedef int32_t		Elf32_Sword;
-typedef u_int32_t	Elf32_Word;
-typedef u_int32_t	Elf32_Size;
-typedef Elf32_Off	Elf32_Hashelt;
+typedef uint32_t	Elf32_Word;
+typedef uint64_t	Elf32_Lword;
+
+typedef Elf32_Word	Elf32_Hashelt;
+
+/* Non-standard class-dependent datatype used for abstraction. */
+typedef Elf32_Word	Elf32_Size;
+typedef Elf32_Sword	Elf32_Ssize;
 
 /*
  * ELF header.
@@ -69,6 +75,18 @@ typedef struct {
 	Elf32_Half	e_shstrndx;	/* Section name strings section. */
 } Elf32_Ehdr;
 
+/*
+ * Shared object information, found in SHT_MIPS_LIBLIST.
+ */
+
+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;
+
 /*
  * Section header.
  */
@@ -80,11 +98,11 @@ typedef struct {
 	Elf32_Word	sh_flags;	/* Section flags. */
 	Elf32_Addr	sh_addr;	/* Address in memory image. */
 	Elf32_Off	sh_offset;	/* Offset in file. */
-	Elf32_Size	sh_size;	/* Size in bytes. */
+	Elf32_Word	sh_size;	/* Size in bytes. */
 	Elf32_Word	sh_link;	/* Index of a related section. */
 	Elf32_Word	sh_info;	/* Depends on section type. */
-	Elf32_Size	sh_addralign;	/* Alignment in bytes. */
-	Elf32_Size	sh_entsize;	/* Size of each entry in section. */
+	Elf32_Word	sh_addralign;	/* Alignment in bytes. */
+	Elf32_Word	sh_entsize;	/* Size of each entry in section. */
 } Elf32_Shdr;
 
 /*
@@ -96,10 +114,10 @@ typedef struct {
 	Elf32_Off	p_offset;	/* File offset of contents. */
 	Elf32_Addr	p_vaddr;	/* Virtual address in memory image. */
 	Elf32_Addr	p_paddr;	/* Physical address (not used). */
-	Elf32_Size	p_filesz;	/* Size of contents in file. */
-	Elf32_Size	p_memsz;	/* Size of contents in memory. */
+	Elf32_Word	p_filesz;	/* Size of contents in file. */
+	Elf32_Word	p_memsz;	/* Size of contents in memory. */
 	Elf32_Word	p_flags;	/* Access permission flags. */
-	Elf32_Size	p_align;	/* Alignment in memory and file. */
+	Elf32_Word	p_align;	/* Alignment in memory and file. */
 } Elf32_Phdr;
 
 /*
@@ -109,7 +127,7 @@ typedef struct {
 typedef struct {
 	Elf32_Sword	d_tag;		/* Entry type. */
 	union {
-		Elf32_Size	d_val;	/* Integer value. */
+		Elf32_Word	d_val;	/* Integer value. */
 		Elf32_Addr	d_ptr;	/* Address value. */
 	} d_un;
 } Elf32_Dyn;
@@ -138,6 +156,44 @@ typedef struct {
 /* Macro for constructing r_info from field values. */
 #define ELF32_R_INFO(sym, type)	(((sym) << 8) + (unsigned char)(type))
 
+/*
+ *	Note entry header
+ */
+typedef Elf_Note Elf32_Nhdr;
+
+/*
+ *	Move entry
+ */
+typedef struct {
+	Elf32_Lword	m_value;	/* symbol value */
+	Elf32_Word 	m_info;		/* size + index */
+	Elf32_Word	m_poffset;	/* symbol offset */
+	Elf32_Half	m_repeat;	/* repeat count */
+	Elf32_Half	m_stride;	/* stride info */
+} Elf32_Move;
+
+/*
+ *	The macros compose and decompose values for Move.r_info
+ *
+ *	sym = ELF32_M_SYM(M.m_info)
+ *	size = ELF32_M_SIZE(M.m_info)
+ *	M.m_info = ELF32_M_INFO(sym, size)
+ */
+#define	ELF32_M_SYM(info)	((info)>>8)
+#define	ELF32_M_SIZE(info)	((unsigned char)(info))
+#define	ELF32_M_INFO(sym, size)	(((sym)<<8)+(unsigned char)(size))
+
+/*
+ *	Hardware/Software capabilities entry
+ */
+typedef struct {
+	Elf32_Word	c_tag;		/* how to interpret value */
+	union {
+		Elf32_Word	c_val;
+		Elf32_Addr	c_ptr;
+	} c_un;
+} Elf32_Cap;
+
 /*
  * Symbol table entries.
  */
@@ -145,7 +201,7 @@ typedef struct {
 typedef struct {
 	Elf32_Word	st_name;	/* String table index of name. */
 	Elf32_Addr	st_value;	/* Symbol value. */
-	Elf32_Size	st_size;	/* Size of associated object. */
+	Elf32_Word	st_size;	/* Size of associated object. */
 	unsigned char	st_info;	/* Type and binding information. */
 	unsigned char	st_other;	/* Reserved (not used). */
 	Elf32_Half	st_shndx;	/* Section index of symbol. */
@@ -204,4 +260,10 @@ typedef struct {
 	Elf32_Half	si_flags;	/* per symbol flags */
 } Elf32_Syminfo;
 
+typedef struct {
+	Elf32_Word	ch_type;
+	Elf32_Word	ch_size;
+	Elf32_Word	ch_addralign;
+} Elf32_Chdr;
+
 #endif /* !_SYS_ELF32_H_ */
diff --git a/sys/sys/elf64.h b/sys/sys/elf64.h
index 5a352798b7..b788dc57d8 100644
--- a/sys/sys/elf64.h
+++ b/sys/sys/elf64.h
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 1996-1998 John D. Polstra.
  * All rights reserved.
  *
@@ -23,19 +25,17 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/sys/elf64.h,v 1.17 2006/10/17 05:43:30 jkoshy Exp $
- * $DragonFly: src/sys/sys/elf64.h,v 1.10 2008/08/30 17:07:17 swildner Exp $
+ * $FreeBSD$
  */
 
 #ifndef _SYS_ELF64_H_
-#define _SYS_ELF64_H_
+#define _SYS_ELF64_H_ 1
 
 #ifndef _SYS_TYPES_H_
 #include <sys/types.h>
 #endif
-#ifndef _SYS_ELF_COMMON_H_
+
 #include <sys/elf_common.h>
-#endif
 
 /*
  * ELF definitions common to all 64-bit architectures.
@@ -84,6 +84,18 @@ typedef struct {
 	Elf64_Half	e_shstrndx;	/* Section name strings section. */
 } Elf64_Ehdr;
 
+/*
+ * Shared object information, found in SHT_MIPS_LIBLIST.
+ */
+
+typedef struct {
+	Elf64_Word l_name;		/* The name of a shared object. */
+	Elf64_Word l_time_stamp;	/* 64-bit timestamp. */
+	Elf64_Word l_checksum;		/* Checksum of visible symbols, sizes. */
+	Elf64_Word l_version;		/* Interface version string index. */
+	Elf64_Word l_flags;		/* Flags (LL_*). */
+} Elf64_Lib;
+
 /*
  * Section header.
  */
@@ -147,28 +159,28 @@ typedef struct {
 } Elf64_Rela;
 
 /* Macros for accessing the fields of r_info. */
-#define ELF64_R_SYM(info)	((info) >> 32)
-#define ELF64_R_TYPE(info)	((info) & 0xffffffffL)
+#define	ELF64_R_SYM(info)	((info) >> 32)
+#define	ELF64_R_TYPE(info)	((info) & 0xffffffffL)
 
 /* Macro for constructing r_info from field values. */
-#define ELF64_R_INFO(sym, type)	(((sym) << 32) + ((type) & 0xffffffffL))
+#define	ELF64_R_INFO(sym, type)	(((sym) << 32) + ((type) & 0xffffffffL))
 
 #define	ELF64_R_TYPE_DATA(info)	(((Elf64_Xword)(info)<<32)>>40)
 #define	ELF64_R_TYPE_ID(info)	(((Elf64_Xword)(info)<<56)>>56)
 #define	ELF64_R_TYPE_INFO(data, type)	\
-		(((Elf64_Xword)(data)<<8)+(Elf64_Xword)(type))
+				(((Elf64_Xword)(data)<<8)+(Elf64_Xword)(type))
 
 /*
- * Note entry header
+ *	Note entry header
  */
 typedef Elf_Note Elf64_Nhdr;
 
 /*
- * Move entry
+ *	Move entry
  */
 typedef struct {
 	Elf64_Lword	m_value;	/* symbol value */
-	Elf64_Xword	m_info;		/* size + index */
+	Elf64_Xword 	m_info;		/* size + index */
 	Elf64_Xword	m_poffset;	/* symbol offset */
 	Elf64_Half	m_repeat;	/* repeat count */
 	Elf64_Half	m_stride;	/* stride info */
@@ -179,7 +191,7 @@ typedef struct {
 #define	ELF64_M_INFO(sym, size)	(((sym)<<8)+(unsigned char)(size))
 
 /*
- * Hardware/Software capabilities entry
+ *	Hardware/Software capabilities entry
  */
 typedef struct {
 	Elf64_Xword	c_tag;		/* how to interpret value */
@@ -203,14 +215,14 @@ typedef struct {
 } Elf64_Sym;
 
 /* Macros for accessing the fields of st_info. */
-#define ELF64_ST_BIND(info)		((info) >> 4)
-#define ELF64_ST_TYPE(info)		((info) & 0xf)
+#define	ELF64_ST_BIND(info)		((info) >> 4)
+#define	ELF64_ST_TYPE(info)		((info) & 0xf)
 
 /* Macro for constructing st_info from field values. */
-#define ELF64_ST_INFO(bind, type)	(((bind) << 4) + ((type) & 0xf))
+#define	ELF64_ST_INFO(bind, type)	(((bind) << 4) + ((type) & 0xf))
 
 /* Macro for accessing the fields of st_other. */
-#define ELF64_ST_VISIBILITY(oth)	((oth) & 0x3)
+#define	ELF64_ST_VISIBILITY(oth)	((oth) & 0x3)
 
 /* Structures used by Sun & GNU-style symbol versioning. */
 typedef struct {
@@ -251,4 +263,11 @@ typedef struct {
 	Elf64_Half	si_flags;	/* per symbol flags */
 } Elf64_Syminfo;
 
+typedef struct {
+	Elf64_Word	ch_type;
+	Elf64_Word	ch_reserved;
+	Elf64_Xword	ch_size;
+	Elf64_Xword	ch_addralign;
+} Elf64_Chdr;
+
 #endif /* !_SYS_ELF64_H_ */
diff --git a/sys/sys/elf_common.h b/sys/sys/elf_common.h
index 05caf78f03..5927ec41fe 100644
--- a/sys/sys/elf_common.h
+++ b/sys/sys/elf_common.h
@@ -1,4 +1,8 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2017, 2018 Dell EMC
+ * Copyright (c) 2000, 2001, 2008, 2011, David E. O'Brien
  * Copyright (c) 1998 John D. Polstra.
  * All rights reserved.
  *
@@ -22,10 +26,12 @@
  * 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$
  */
 
 #ifndef _SYS_ELF_COMMON_H_
-#define _SYS_ELF_COMMON_H_
+#define	_SYS_ELF_COMMON_H_ 1
 
 #ifndef _SYS_TYPES_H_
 #include <sys/types.h>
@@ -51,663 +57,1315 @@ typedef struct {
 } Elf_Note;
 typedef Elf_Note Elf_Nhdr;
 
+/*
+ * Option kinds.
+ */
+#define	ODK_NULL	0	/* undefined */
+#define	ODK_REGINFO	1	/* register usage info */
+#define	ODK_EXCEPTIONS	2	/* exception processing info */
+#define	ODK_PAD		3	/* section padding */
+#define	ODK_HWPATCH	4	/* hardware patch applied */
+#define	ODK_FILL	5	/* fill value used by the linker */
+#define	ODK_TAGS	6	/* reserved space for tools */
+#define	ODK_HWAND	7	/* hardware AND patch applied */
+#define	ODK_HWOR	8	/* hardware OR patch applied */
+#define	ODK_GP_GROUP	9	/* GP group for text/data sections */
+#define	ODK_IDENT	10	/* ID information */
+#define	ODK_PAGESIZE	11	/* page size information */
+
+/*
+ * ODK_EXCEPTIONS info field masks.
+ */
+#define	OEX_FPU_MIN	0x0000001f	/* min FPU exception required */
+#define	OEX_FPU_MAX	0x00001f00	/* max FPU exception allowed */
+#define	OEX_PAGE0	0x00010000	/* page zero must be mapped */
+#define	OEX_SMM		0x00020000	/* run in sequential memory mode */
+#define	OEX_PRECISEFP	0x00040000	/* run in precise FP exception mode */
+#define	OEX_DISMISS	0x00080000	/* dismiss invalid address traps */
+
+/*
+ * ODK_PAD info field masks.
+ */
+#define	OPAD_PREFIX	0x0001
+#define	OPAD_POSTFIX	0x0002
+#define	OPAD_SYMBOL	0x0004
+
+/*
+ * ODK_HWPATCH info field masks.
+ */
+#define	OHW_R4KEOP	0x00000001	/* patch for R4000 branch at end-of-page bug */
+#define	OHW_R8KPFETCH	0x00000002	/* R8000 prefetch bug may occur */
+#define	OHW_R5KEOP	0x00000004	/* patch for R5000 branch at end-of-page bug */
+#define	OHW_R5KCVTL	0x00000008	/* R5000 cvt.[ds].l bug: clean == 1 */
+#define	OHW_R10KLDL	0x00000010UL	/* need patch for R10000 misaligned load */
+
+/*
+ * ODK_HWAND/ODK_HWOR info field and hwp_flags[12] masks.
+ */
+#define	OHWA0_R4KEOP_CHECKED	0x00000001	/* object checked for R4000 end-of-page bug */
+#define	OHWA0_R4KEOP_CLEAN	0x00000002	/* object verified clean for R4000 end-of-page bug */
+#define	OHWO0_FIXADE		0x00000001	/* object requires call to fixade */
+
+/*
+ * ODK_IDENT/ODK_GP_GROUP info field masks.
+ */
+#define	OGP_GROUP	0x0000ffff	/* GP group number */
+#define	OGP_SELF	0x00010000	/* GP group is self-contained */
+
+/*
+ * The header for GNU-style hash sections.
+ */
+
+typedef struct {
+	u_int32_t	gh_nbuckets;	/* Number of hash buckets. */
+	u_int32_t	gh_symndx;	/* First visible symbol in .dynsym. */
+	u_int32_t	gh_maskwords;	/* #maskwords used in bloom filter. */
+	u_int32_t	gh_shift2;	/* Bloom filter shift count. */
+} Elf_GNU_Hash_Header;
+
 /* Indexes into the e_ident array.  Keep synced with
    http://www.sco.com/developers/gabi/latest/ch4.eheader.html */
-#define EI_MAG0		0	/* Magic number, byte 0. */
-#define EI_MAG1		1	/* Magic number, byte 1. */
-#define EI_MAG2		2	/* Magic number, byte 2. */
-#define EI_MAG3		3	/* Magic number, byte 3. */
-#define EI_CLASS	4	/* Class of machine. */
-#define EI_DATA		5	/* Data format. */
-#define EI_VERSION	6	/* ELF format version. */
-#define EI_OSABI	7	/* Operating system / ABI identification */
-#define EI_ABIVERSION	8	/* ABI version */
-#define EI_PAD		9	/* Start of padding (per SVR4 ABI). */
-#define EI_NIDENT	16	/* Size of e_ident array. */
+#define	EI_MAG0		0	/* Magic number, byte 0. */
+#define	EI_MAG1		1	/* Magic number, byte 1. */
+#define	EI_MAG2		2	/* Magic number, byte 2. */
+#define	EI_MAG3		3	/* Magic number, byte 3. */
+#define	EI_CLASS	4	/* Class of machine. */
+#define	EI_DATA		5	/* Data format. */
+#define	EI_VERSION	6	/* ELF format version. */
+#define	EI_OSABI	7	/* Operating system / ABI identification */
+#define	EI_ABIVERSION	8	/* ABI version */
+#define	OLD_EI_BRAND	8	/* Start of architecture identification. */
+#define	EI_PAD		9	/* Start of padding (per SVR4 ABI). */
+#define	EI_NIDENT	16	/* Size of e_ident array. */
 
 /* Values for the magic number bytes. */
-#define ELFMAG0		0x7f
-#define ELFMAG1		'E'
-#define ELFMAG2		'L'
-#define ELFMAG3		'F'
-#define ELFMAG		"\177ELF"	/* magic string */
-#define SELFMAG		4		/* magic string size */
+#define	ELFMAG0		0x7f
+#define	ELFMAG1		'E'
+#define	ELFMAG2		'L'
+#define	ELFMAG3		'F'
+#define	ELFMAG		"\177ELF"	/* magic string */
+#define	SELFMAG		4		/* magic string size */
 
 /* Values for e_ident[EI_VERSION] and e_version. */
-#define EV_NONE		0
-#define EV_CURRENT	1
+#define	EV_NONE		0
+#define	EV_CURRENT	1
 
 /* Values for e_ident[EI_CLASS]. */
-#define ELFCLASSNONE	0	/* Unknown class. */
-#define ELFCLASS32	1	/* 32-bit architecture. */
-#define ELFCLASS64	2	/* 64-bit architecture. */
+#define	ELFCLASSNONE	0	/* Unknown class. */
+#define	ELFCLASS32	1	/* 32-bit architecture. */
+#define	ELFCLASS64	2	/* 64-bit architecture. */
 
 /* Values for e_ident[EI_DATA]. */
-#define ELFDATANONE	0	/* Unknown data format. */
-#define ELFDATA2LSB	1	/* 2's complement little-endian. */
-#define ELFDATA2MSB	2	/* 2's complement big-endian. */
+#define	ELFDATANONE	0	/* Unknown data format. */
+#define	ELFDATA2LSB	1	/* 2's complement little-endian. */
+#define	ELFDATA2MSB	2	/* 2's complement big-endian. */
 
 /* Values for e_ident[EI_OSABI]. */
-#define ELFOSABI_SYSV		0	/* symbol used in old spec */
-#define ELFOSABI_NONE		0	/* UNIX System V ABI */
-#define ELFOSABI_HPUX		1	/* HP-UX operating system */
-#define ELFOSABI_NETBSD 	2	/* NetBSD */
-#define ELFOSABI_GNU		3	/* GNU */
-#define ELFOSABI_LINUX		3	/* Alias for ELFOSABI_GNU */
-#define ELFOSABI_SOLARIS	6	/* Solaris */
-#define ELFOSABI_AIX		7	/* AIX */
-#define ELFOSABI_IRIX		8	/* IRIX */
-#define ELFOSABI_FREEBSD	9	/* FreeBSD */
-#define ELFOSABI_TRU64		10	/* TRU64 UNIX */
-#define ELFOSABI_MODESTO	11	/* Novell Modesto */
-#define ELFOSABI_OPENBSD	12	/* OpenBSD */
-#define ELFOSABI_OPENVMS	13	/* OpenVMS */
-#define ELFOSABI_NSK		14	/* Hewlett-Packard Non-Stop Kernel */
-#define ELFOSABI_AROS		15	/* AROS */
-#define ELFOSABI_FENIXOS	16	/* FenixOS */
-#define ELFOSABI_C6000_ELFABI	64	/* Bare-metal TMS320C6000 */
-#define ELFOSABI_C6000_LINUX	65	/* Linux TMS320C6000 */
-#define ELFOSABI_ARM		97	/* ARM */
-#define ELFOSABI_STANDALONE	255	/* Standalone (embedded) application */
+#define	ELFOSABI_NONE		0	/* UNIX System V ABI */
+#define	ELFOSABI_HPUX		1	/* HP-UX operating system */
+#define	ELFOSABI_NETBSD		2	/* NetBSD */
+#define	ELFOSABI_LINUX		3	/* GNU/Linux */
+#define	ELFOSABI_HURD		4	/* GNU/Hurd */
+#define	ELFOSABI_86OPEN		5	/* 86Open common IA32 ABI */
+#define	ELFOSABI_SOLARIS	6	/* Solaris */
+#define	ELFOSABI_AIX		7	/* AIX */
+#define	ELFOSABI_IRIX		8	/* IRIX */
+#define	ELFOSABI_FREEBSD	9	/* FreeBSD */
+#define	ELFOSABI_TRU64		10	/* TRU64 UNIX */
+#define	ELFOSABI_MODESTO	11	/* Novell Modesto */
+#define	ELFOSABI_OPENBSD	12	/* OpenBSD */
+#define	ELFOSABI_OPENVMS	13	/* Open VMS */
+#define	ELFOSABI_NSK		14	/* HP Non-Stop Kernel */
+#define	ELFOSABI_AROS		15	/* Amiga Research OS */
+#define	ELFOSABI_FENIXOS	16	/* FenixOS */
+#define	ELFOSABI_CLOUDABI	17	/* Nuxi CloudABI */
+#define	ELFOSABI_ARM_AEABI	64	/* ARM EABI */
+#define	ELFOSABI_ARM		97	/* ARM */
+#define	ELFOSABI_STANDALONE	255	/* Standalone (embedded) application */
+
+#define	ELFOSABI_SYSV		ELFOSABI_NONE	/* symbol used in old spec */
+#define	ELFOSABI_MONTEREY	ELFOSABI_AIX	/* Monterey */
+#define	ELFOSABI_GNU		ELFOSABI_LINUX
 
 /* e_ident */
-#define IS_ELF(ehdr)	((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
+#define	IS_ELF(ehdr)	((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
 			 (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
 			 (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
 			 (ehdr).e_ident[EI_MAG3] == ELFMAG3)
 
-/* Values for e_type, which identifies the object file type.  */
-
-#define ET_NONE 	0	/* No file type */
-#define ET_REL		1	/* Relocatable file */
-#define ET_EXEC 	2	/* Executable file */
-#define ET_DYN		3	/* Shared object file */
-#define ET_CORE 	4	/* Core file */
-#define ET_LOOS 	0xFE00	/* Operating system-specific */
-#define ET_HIOS 	0xFEFF	/* Operating system-specific */
-#define ET_LOPROC	0xFF00	/* Processor-specific */
-#define ET_HIPROC	0xFFFF	/* Processor-specific */
-
-/* Values for e_machine, which identifies the architecture.  These numbers
-   are officially assigned by registry@sco.com.  See below for a list of
-   ad-hoc numbers used during initial development.  */
-
-#define EM_NONE 	  0	/* No machine */
-#define EM_M32		  1	/* AT&T WE 32100 */
-#define EM_SPARC	  2	/* SUN SPARC */
-#define EM_386		  3	/* Intel 80386 */
-#define EM_68K		  4	/* Motorola m68k family */
-#define EM_88K		  5	/* Motorola m88k family */
-#define EM_486		  6	/* Intel 80486 *//* Reserved for future use */
-#define EM_860		  7	/* Intel 80860 */
-#define EM_MIPS 	  8	/* MIPS R3000 (officially, big-endian only) */
-#define EM_S370 	  9	/* IBM System/370 */
-#define EM_MIPS_RS3_LE	 10	/* MIPS R3000 little-endian (Oct 4 1999 Draft) Deprecated */
-#define EM_res011	 11	/* Reserved */
-#define EM_res012	 12	/* Reserved */
-#define EM_res013	 13	/* Reserved */
-#define EM_res014	 14	/* Reserved */
-#define EM_PARISC	 15	/* HPPA */
-#define EM_res016	 16	/* Reserved */
-#define EM_VPP550	 17	/* Fujitsu VPP500 */
-#define EM_SPARC32PLUS	 18	/* Sun's "v8plus" */
-#define EM_960		 19	/* Intel 80960 */
-#define EM_PPC		 20	/* PowerPC */
-#define EM_PPC64	 21	/* 64-bit PowerPC */
-#define EM_S390 	 22	/* IBM S/390 */
-#define EM_SPU		 23	/* Sony/Toshiba/IBM SPU */
-#define EM_res024	 24	/* Reserved */
-#define EM_res025	 25	/* Reserved */
-#define EM_res026	 26	/* Reserved */
-#define EM_res027	 27	/* Reserved */
-#define EM_res028	 28	/* Reserved */
-#define EM_res029	 29	/* Reserved */
-#define EM_res030	 30	/* Reserved */
-#define EM_res031	 31	/* Reserved */
-#define EM_res032	 32	/* Reserved */
-#define EM_res033	 33	/* Reserved */
-#define EM_res034	 34	/* Reserved */
-#define EM_res035	 35	/* Reserved */
-#define EM_V800 	 36	/* NEC V800 series */
-#define EM_FR20 	 37	/* Fujitsu FR20 */
-#define EM_RH32 	 38	/* TRW RH32 */
-#define EM_MCORE	 39	/* Motorola M*Core */ /* May also be taken by Fujitsu MMA */
-#define EM_RCE		 39	/* Old name for MCore */
-#define EM_ARM		 40	/* ARM */
-#define EM_OLD_ALPHA	 41	/* Digital Alpha */
-#define EM_SH		 42	/* Renesas (formerly Hitachi) / SuperH SH */
-#define EM_SPARCV9	 43	/* SPARC v9 64-bit */
-#define EM_TRICORE	 44	/* Siemens Tricore embedded processor */
-#define EM_ARC		 45	/* ARC Cores */
-#define EM_H8_300	 46	/* Renesas (formerly Hitachi) H8/300 */
-#define EM_H8_300H	 47	/* Renesas (formerly Hitachi) H8/300H */
-#define EM_H8S		 48	/* Renesas (formerly Hitachi) H8S */
-#define EM_H8_500	 49	/* Renesas (formerly Hitachi) H8/500 */
-#define EM_IA_64	 50	/* Intel IA-64 Processor */
-#define EM_MIPS_X	 51	/* Stanford MIPS-X */
-#define EM_COLDFIRE	 52	/* Motorola Coldfire */
-#define EM_68HC12	 53	/* Motorola M68HC12 */
-#define EM_MMA		 54	/* Fujitsu Multimedia Accelerator */
-#define EM_PCP		 55	/* Siemens PCP */
-#define EM_NCPU 	 56	/* Sony nCPU embedded RISC processor */
-#define EM_NDR1 	 57	/* Denso NDR1 microprocessor */
-#define EM_STARCORE	 58	/* Motorola Star*Core processor */
-#define EM_ME16 	 59	/* Toyota ME16 processor */
-#define EM_ST100	 60	/* STMicroelectronics ST100 processor */
-#define EM_TINYJ	 61	/* Advanced Logic Corp. TinyJ embedded processor */
-#define EM_X86_64	 62	/* Advanced Micro Devices X86-64 processor */
-#define EM_AMD64	 62	/* Advanced Micro Devices X86-64 (compat) */
-#define EM_PDSP 	 63	/* Sony DSP Processor */
-#define EM_PDP10	 64	/* Digital Equipment Corp. PDP-10 */
-#define EM_PDP11	 65	/* Digital Equipment Corp. PDP-11 */
-#define EM_FX66 	 66	/* Siemens FX66 microcontroller */
-#define EM_ST9PLUS	 67	/* STMicroelectronics ST9+ 8/16 bit microcontroller */
-#define EM_ST7		 68	/* STMicroelectronics ST7 8-bit microcontroller */
-#define EM_68HC16	 69	/* Motorola MC68HC16 Microcontroller */
-#define EM_68HC11	 70	/* Motorola MC68HC11 Microcontroller */
-#define EM_68HC08	 71	/* Motorola MC68HC08 Microcontroller */
-#define EM_68HC05	 72	/* Motorola MC68HC05 Microcontroller */
-#define EM_SVX		 73	/* Silicon Graphics SVx */
-#define EM_ST19 	 74	/* STMicroelectronics ST19 8-bit cpu */
-#define EM_VAX		 75	/* Digital VAX */
-#define EM_CRIS 	 76	/* Axis Communications 32-bit embedded processor */
-#define EM_JAVELIN	 77	/* Infineon Technologies 32-bit embedded cpu */
-#define EM_FIREPATH	 78	/* Element 14 64-bit DSP processor */
-#define EM_ZSP		 79	/* LSI Logic's 16-bit DSP processor */
-#define EM_MMIX 	 80	/* Donald Knuth's educational 64-bit processor */
-#define EM_HUANY	 81	/* Harvard's machine-independent format */
-#define EM_PRISM	 82	/* SiTera Prism */
-#define EM_AVR		 83	/* Atmel AVR 8-bit microcontroller */
-#define EM_FR30 	 84	/* Fujitsu FR30 */
-#define EM_D10V 	 85	/* Mitsubishi D10V */
-#define EM_D30V 	 86	/* Mitsubishi D30V */
-#define EM_V850 	 87	/* Renesas V850 (formerly NEC V850) */
-#define EM_M32R 	 88	/* Renesas M32R (formerly Mitsubishi M32R) */
-#define EM_MN10300	 89	/* Matsushita MN10300 */
-#define EM_MN10200	 90	/* Matsushita MN10200 */
-#define EM_PJ		 91	/* picoJava */
-#define EM_OPENRISC	 92	/* OpenRISC 32-bit embedded processor */
-#define EM_ARC_A5	 93	/* ARC Cores Tangent-A5 */
-#define EM_XTENSA	 94	/* Tensilica Xtensa Architecture */
-#define EM_VIDEOCORE	 95	/* Alphamosaic VideoCore processor */
-#define EM_TMM_GPP	 96	/* Thompson Multimedia General Purpose Processor */
-#define EM_NS32K	 97	/* National Semiconductor 32000 series */
-#define EM_TPC		 98	/* Tenor Network TPC processor */
-#define EM_SNP1K	 99	/* Trebia SNP 1000 processor */
-#define EM_ST200	100	/* STMicroelectronics ST200 microcontroller */
-#define EM_IP2K 	101	/* Ubicom IP2022 micro controller */
-#define EM_MAX		102	/* MAX Processor */
-#define EM_CR		103	/* National Semiconductor CompactRISC */
-#define EM_F2MC16	104	/* Fujitsu F2MC16 */
-#define EM_MSP430	105	/* TI msp430 micro controller */
-#define EM_BLACKFIN	106	/* ADI Blackfin */
-#define EM_SE_C33	107	/* S1C33 Family of Seiko Epson processors */
-#define EM_SEP		108	/* Sharp embedded microprocessor */
-#define EM_ARCA 	109	/* Arca RISC Microprocessor */
-#define EM_UNICORE	110	/* Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University */
-#define EM_EXCESS	111	/* eXcess: 16/32/64-bit configurable embedded CPU */
-#define EM_DXP		112	/* Icera Semiconductor Inc. Deep Execution Processor */
-#define EM_ALTERA_NIOS2	113	/* Altera Nios II soft-core processor */
-#define EM_CRX		114	/* National Semiconductor CRX */
-#define EM_XGATE	115	/* Motorola XGATE embedded processor */
-#define EM_C166 	116	/* Infineon C16x/XC16x processor */
-#define EM_M16C 	117	/* Renesas M16C series microprocessors */
-#define EM_DSPIC30F	118	/* Microchip Technology dsPIC30F Digital Signal Controller */
-#define EM_CE		119	/* Freescale Communication Engine RISC core */
-#define EM_M32C 	120	/* Renesas M32C series microprocessors */
-#define EM_res121	121	/* Reserved */
-#define EM_res122	122	/* Reserved */
-#define EM_res123	123	/* Reserved */
-#define EM_res124	124	/* Reserved */
-#define EM_res125	125	/* Reserved */
-#define EM_res126	126	/* Reserved */
-#define EM_res127	127	/* Reserved */
-#define EM_res128	128	/* Reserved */
-#define EM_res129	129	/* Reserved */
-#define EM_res130	130	/* Reserved */
-#define EM_TSK3000	131	/* Altium TSK3000 core */
-#define EM_RS08 	132	/* Freescale RS08 embedded processor */
-#define EM_res133	133	/* Reserved */
-#define EM_ECOG2	134	/* Cyan Technology eCOG2 microprocessor */
-#define EM_SCORE	135	/* Sunplus Score */
-#define EM_SCORE7	135	/* Sunplus S+core7 RISC processor */
-#define EM_DSP24	136	/* New Japan Radio (NJR) 24-bit DSP Processor */
-#define EM_VIDEOCORE3	137	/* Broadcom VideoCore III processor */
-#define EM_LATTICEMICO32 138	/* RISC processor for Lattice FPGA architecture */
-#define EM_SE_C17	139	/* Seiko Epson C17 family */
-#define EM_TI_C6000	140	/* Texas Instruments TMS320C6000 DSP family */
-#define EM_TI_C2000	141	/* Texas Instruments TMS320C2000 DSP family */
-#define EM_TI_C5500	142	/* Texas Instruments TMS320C55x DSP family */
-#define EM_res143	143	/* Reserved */
-#define EM_res144	144	/* Reserved */
-#define EM_res145	145	/* Reserved */
-#define EM_res146	146	/* Reserved */
-#define EM_res147	147	/* Reserved */
-#define EM_res148	148	/* Reserved */
-#define EM_res149	149	/* Reserved */
-#define EM_res150	150	/* Reserved */
-#define EM_res151	151	/* Reserved */
-#define EM_res152	152	/* Reserved */
-#define EM_res153	153	/* Reserved */
-#define EM_res154	154	/* Reserved */
-#define EM_res155	155	/* Reserved */
-#define EM_res156	156	/* Reserved */
-#define EM_res157	157	/* Reserved */
-#define EM_res158	158	/* Reserved */
-#define EM_res159	159	/* Reserved */
-#define EM_MMDSP_PLUS	160	/* STMicroelectronics 64bit VLIW Data Signal Processor */
-#define EM_CYPRESS_M8C	161	/* Cypress M8C microprocessor */
-#define EM_R32C 	162	/* Renesas R32C series microprocessors */
-#define EM_TRIMEDIA	163	/* NXP Semiconductors TriMedia architecture family */
-#define EM_QDSP6	164	/* QUALCOMM DSP6 Processor */
-#define EM_8051 	165	/* Intel 8051 and variants */
-#define EM_STXP7X	166	/* STMicroelectronics STxP7x family */
-#define EM_NDS32	167	/* Andes Technology compact code size embedded RISC processor family */
-#define EM_ECOG1	168	/* Cyan Technology eCOG1X family */
-#define EM_ECOG1X	168	/* Cyan Technology eCOG1X family */
-#define EM_MAXQ30	169	/* Dallas Semiconductor MAXQ30 Core Micro-controllers */
-#define EM_XIMO16	170	/* New Japan Radio (NJR) 16-bit DSP Processor */
-#define EM_MANIK	171	/* M2000 Reconfigurable RISC Microprocessor */
-#define EM_CRAYNV2	172	/* Cray Inc. NV2 vector architecture */
-#define EM_RX		173	/* Renesas RX family */
-#define EM_METAG	174	/* Imagination Technologies META processor architecture */
-#define EM_MCST_ELBRUS	175	/* MCST Elbrus general purpose hardware architecture */
-#define EM_ECOG16	176	/* Cyan Technology eCOG16 family */
-#define EM_CR16 	177	/* National Semiconductor CompactRISC 16-bit processor */
-#define EM_ETPU 	178	/* Freescale Extended Time Processing Unit */
-#define EM_SLE9X	179	/* Infineon Technologies SLE9X core */
-#define EM_L1OM 	180	/* Intel L1OM */
-#define EM_K1OM 	181	/* Intel K1OM */
-#define EM_INTEL182	182	/* Reserved by Intel */
-#define EM_res183	183	/* Reserved by ARM */
-#define EM_res184	184	/* Reserved by ARM */
-#define EM_AVR32	185	/* Atmel Corporation 32-bit microprocessor family */
-#define EM_STM8 	186	/* STMicroeletronics STM8 8-bit microcontroller */
-#define EM_TILE64	187	/* Tilera TILE64 multicore architecture family */
-#define EM_TILEPRO	188	/* Tilera TILEPro multicore architecture family */
-#define EM_MICROBLAZE	189	/* Xilinx MicroBlaze 32-bit RISC soft processor core */
-#define EM_CUDA 	190	/* NVIDIA CUDA architecture */
-#define EM_TILEGX	191	/* Tilera TILE-Gx multicore architecture family */
-
-/* Alpha backend magic number.  Written in the absence of an ABI.  */
-#define EM_ALPHA		0x9026
+/* Values for e_type. */
+#define	ET_NONE		0	/* Unknown type. */
+#define	ET_REL		1	/* Relocatable. */
+#define	ET_EXEC		2	/* Executable. */
+#define	ET_DYN		3	/* Shared object. */
+#define	ET_CORE		4	/* Core file. */
+#define	ET_LOOS		0xfe00	/* First operating system specific. */
+#define	ET_HIOS		0xfeff	/* Last operating system-specific. */
+#define	ET_LOPROC	0xff00	/* First processor-specific. */
+#define	ET_HIPROC	0xffff	/* Last processor-specific. */
+
+/* Values for e_machine. */
+#define	EM_NONE		0	/* Unknown machine. */
+#define	EM_M32		1	/* AT&T WE32100. */
+#define	EM_SPARC	2	/* Sun SPARC. */
+#define	EM_386		3	/* Intel i386. */
+#define	EM_68K		4	/* Motorola 68000. */
+#define	EM_88K		5	/* Motorola 88000. */
+#define	EM_IAMCU	6	/* Intel MCU. */
+#define	EM_860		7	/* Intel i860. */
+#define	EM_MIPS		8	/* MIPS R3000 Big-Endian only. */
+#define	EM_S370		9	/* IBM System/370. */
+#define	EM_MIPS_RS3_LE	10	/* MIPS R3000 Little-Endian. */
+#define	EM_PARISC	15	/* HP PA-RISC. */
+#define	EM_VPP500	17	/* Fujitsu VPP500. */
+#define	EM_SPARC32PLUS	18	/* SPARC v8plus. */
+#define	EM_960		19	/* Intel 80960. */
+#define	EM_PPC		20	/* PowerPC 32-bit. */
+#define	EM_PPC64	21	/* PowerPC 64-bit. */
+#define	EM_S390		22	/* IBM System/390. */
+#define	EM_V800		36	/* NEC V800. */
+#define	EM_FR20		37	/* Fujitsu FR20. */
+#define	EM_RH32		38	/* TRW RH-32. */
+#define	EM_RCE		39	/* Motorola RCE. */
+#define	EM_ARM		40	/* ARM. */
+#define	EM_SH		42	/* Hitachi SH. */
+#define	EM_SPARCV9	43	/* SPARC v9 64-bit. */
+#define	EM_TRICORE	44	/* Siemens TriCore embedded processor. */
+#define	EM_ARC		45	/* Argonaut RISC Core. */
+#define	EM_H8_300	46	/* Hitachi H8/300. */
+#define	EM_H8_300H	47	/* Hitachi H8/300H. */
+#define	EM_H8S		48	/* Hitachi H8S. */
+#define	EM_H8_500	49	/* Hitachi H8/500. */
+#define	EM_IA_64	50	/* Intel IA-64 Processor. */
+#define	EM_MIPS_X	51	/* Stanford MIPS-X. */
+#define	EM_COLDFIRE	52	/* Motorola ColdFire. */
+#define	EM_68HC12	53	/* Motorola M68HC12. */
+#define	EM_MMA		54	/* Fujitsu MMA. */
+#define	EM_PCP		55	/* Siemens PCP. */
+#define	EM_NCPU		56	/* Sony nCPU. */
+#define	EM_NDR1		57	/* Denso NDR1 microprocessor. */
+#define	EM_STARCORE	58	/* Motorola Star*Core processor. */
+#define	EM_ME16		59	/* Toyota ME16 processor. */
+#define	EM_ST100	60	/* STMicroelectronics ST100 processor. */
+#define	EM_TINYJ	61	/* Advanced Logic Corp. TinyJ processor. */
+#define	EM_X86_64	62	/* Advanced Micro Devices x86-64 */
+#define	EM_AMD64	EM_X86_64	/* Advanced Micro Devices x86-64 (compat) */
+#define	EM_PDSP		63	/* Sony DSP Processor. */
+#define	EM_FX66		66	/* Siemens FX66 microcontroller. */
+#define	EM_ST9PLUS	67	/* STMicroelectronics ST9+ 8/16
+				   microcontroller. */
+#define	EM_ST7		68	/* STmicroelectronics ST7 8-bit
+				   microcontroller. */
+#define	EM_68HC16	69	/* Motorola MC68HC16 microcontroller. */
+#define	EM_68HC11	70	/* Motorola MC68HC11 microcontroller. */
+#define	EM_68HC08	71	/* Motorola MC68HC08 microcontroller. */
+#define	EM_68HC05	72	/* Motorola MC68HC05 microcontroller. */
+#define	EM_SVX		73	/* Silicon Graphics SVx. */
+#define	EM_ST19		74	/* STMicroelectronics ST19 8-bit mc. */
+#define	EM_VAX		75	/* Digital VAX. */
+#define	EM_CRIS		76	/* Axis Communications 32-bit embedded
+				   processor. */
+#define	EM_JAVELIN	77	/* Infineon Technologies 32-bit embedded
+				   processor. */
+#define	EM_FIREPATH	78	/* Element 14 64-bit DSP Processor. */
+#define	EM_ZSP		79	/* LSI Logic 16-bit DSP Processor. */
+#define	EM_MMIX		80	/* Donald Knuth's educational 64-bit proc. */
+#define	EM_HUANY	81	/* Harvard University machine-independent
+				   object files. */
+#define	EM_PRISM	82	/* SiTera Prism. */
+#define	EM_AVR		83	/* Atmel AVR 8-bit microcontroller. */
+#define	EM_FR30		84	/* Fujitsu FR30. */
+#define	EM_D10V		85	/* Mitsubishi D10V. */
+#define	EM_D30V		86	/* Mitsubishi D30V. */
+#define	EM_V850		87	/* NEC v850. */
+#define	EM_M32R		88	/* Mitsubishi M32R. */
+#define	EM_MN10300	89	/* Matsushita MN10300. */
+#define	EM_MN10200	90	/* Matsushita MN10200. */
+#define	EM_PJ		91	/* picoJava. */
+#define	EM_OPENRISC	92	/* OpenRISC 32-bit embedded processor. */
+#define	EM_ARC_A5	93	/* ARC Cores Tangent-A5. */
+#define	EM_XTENSA	94	/* Tensilica Xtensa Architecture. */
+#define	EM_VIDEOCORE	95	/* Alphamosaic VideoCore processor. */
+#define	EM_TMM_GPP	96	/* Thompson Multimedia General Purpose
+				   Processor. */
+#define	EM_NS32K	97	/* National Semiconductor 32000 series. */
+#define	EM_TPC		98	/* Tenor Network TPC processor. */
+#define	EM_SNP1K	99	/* Trebia SNP 1000 processor. */
+#define	EM_ST200	100	/* STMicroelectronics ST200 microcontroller. */
+#define	EM_IP2K		101	/* Ubicom IP2xxx microcontroller family. */
+#define	EM_MAX		102	/* MAX Processor. */
+#define	EM_CR		103	/* National Semiconductor CompactRISC
+				   microprocessor. */
+#define	EM_F2MC16	104	/* Fujitsu F2MC16. */
+#define	EM_MSP430	105	/* Texas Instruments embedded microcontroller
+				   msp430. */
+#define	EM_BLACKFIN	106	/* Analog Devices Blackfin (DSP) processor. */
+#define	EM_SE_C33	107	/* S1C33 Family of Seiko Epson processors. */
+#define	EM_SEP		108	/* Sharp embedded microprocessor. */
+#define	EM_ARCA		109	/* Arca RISC Microprocessor. */
+#define	EM_UNICORE	110	/* Microprocessor series from PKU-Unity Ltd.
+				   and MPRC of Peking University */
+#define	EM_AARCH64	183	/* AArch64 (64-bit ARM) */
+#define	EM_RISCV	243	/* RISC-V */
+
+/* Non-standard or deprecated. */
+#define	EM_486		6	/* Intel i486. */
+#define	EM_MIPS_RS4_BE	10	/* MIPS R4000 Big-Endian */
+#define	EM_ALPHA_STD	41	/* Digital Alpha (standard value). */
+#define	EM_ALPHA	0x9026	/* Alpha (written in the absence of an ABI) */
+
+/**
+ * e_flags
+ */
+#define	EF_ARM_RELEXEC	0x1
+#define	EF_ARM_HASENTRY	0x2
+#define	EF_ARM_SYMSARESORTED	0x4
+#define	EF_ARM_DYNSYMSUSESEGIDX	0x8
+#define	EF_ARM_MAPSYMSFIRST	0x10
+#define	EF_ARM_LE8		0x00400000
+#define	EF_ARM_BE8		0x00800000
+#define	EF_ARM_EABIMASK		0xFF000000
+#define	EF_ARM_EABI_UNKNOWN	0x00000000
+#define	EF_ARM_EABI_VER1	0x01000000
+#define	EF_ARM_EABI_VER2	0x02000000
+#define	EF_ARM_EABI_VER3	0x03000000
+#define	EF_ARM_EABI_VER4	0x04000000
+#define	EF_ARM_EABI_VER5	0x05000000
+#define	EF_ARM_INTERWORK	0x00000004
+#define	EF_ARM_APCS_26		0x00000008
+#define	EF_ARM_APCS_FLOAT	0x00000010
+#define	EF_ARM_PIC		0x00000020
+#define	EF_ARM_ALIGN8		0x00000040
+#define	EF_ARM_NEW_ABI		0x00000080
+#define	EF_ARM_OLD_ABI		0x00000100
+#define	EF_ARM_ABI_FLOAT_SOFT	0x00000200
+#define	EF_ARM_SOFT_FLOAT	EF_ARM_ABI_FLOAT_SOFT /* Pre-V5 ABI name */
+#define	EF_ARM_ABI_FLOAT_HARD	0x00000400
+#define	EF_ARM_VFP_FLOAT	EF_ARM_ABI_FLOAT_HARD /* Pre-V5 ABI name */
+#define	EF_ARM_MAVERICK_FLOAT	0x00000800
+
+#define	EF_MIPS_NOREORDER	0x00000001
+#define	EF_MIPS_PIC		0x00000002	/* Contains PIC code */
+#define	EF_MIPS_CPIC		0x00000004	/* STD PIC calling sequence */
+#define	EF_MIPS_UCODE		0x00000010
+#define	EF_MIPS_ABI2		0x00000020	/* N32 */
+#define	EF_MIPS_OPTIONS_FIRST	0x00000080
+#define	EF_MIPS_ABI		0x0000F000
+#define	EF_MIPS_ABI_O32		0x00001000
+#define	EF_MIPS_ABI_O64		0x00002000
+#define	EF_MIPS_ABI_EABI32	0x00003000
+#define	EF_MIPS_ABI_EABI64	0x00004000
+#define	EF_MIPS_ARCH_ASE	0x0F000000	/* Architectural extensions */
+#define	EF_MIPS_ARCH_ASE_MDMX	0x08000000	/* MDMX multimedia extension */
+#define	EF_MIPS_ARCH_ASE_M16	0x04000000	/* MIPS-16 ISA extensions */
+#define	EF_MIPS_ARCH		0xF0000000	/* Architecture field */
+#define	EF_MIPS_ARCH_1		0x00000000	/* -mips1 code */
+#define	EF_MIPS_ARCH_2		0x10000000	/* -mips2 code */
+#define	EF_MIPS_ARCH_3		0x20000000	/* -mips3 code */
+#define	EF_MIPS_ARCH_4		0x30000000	/* -mips4 code */
+#define	EF_MIPS_ARCH_5		0x40000000	/* -mips5 code */
+#define	EF_MIPS_ARCH_32		0x50000000	/* -mips32 code */
+#define	EF_MIPS_ARCH_64		0x60000000	/* -mips64 code */
+#define	EF_MIPS_ARCH_32R2	0x70000000	/* -mips32r2 code */
+#define	EF_MIPS_ARCH_64R2	0x80000000	/* -mips64r2 code */
+
+#define	EF_PPC_EMB		0x80000000
+#define	EF_PPC_RELOCATABLE	0x00010000
+#define	EF_PPC_RELOCATABLE_LIB	0x00008000
+
+#define	EF_SPARC_EXT_MASK	0x00ffff00
+#define	EF_SPARC_32PLUS		0x00000100
+#define	EF_SPARC_SUN_US1	0x00000200
+#define	EF_SPARC_HAL_R1		0x00000200
+#define	EF_SPARC_SUN_US3	0x00000800
+
+#define	EF_SPARCV9_MM		0x00000003
+#define	EF_SPARCV9_TSO		0x00000000
+#define	EF_SPARCV9_PSO		0x00000001
+#define	EF_SPARCV9_RMO		0x00000002
 
 /* Special section indexes. */
+#define	SHN_UNDEF	     0		/* Undefined, missing, irrelevant. */
+#define	SHN_LORESERVE	0xff00		/* First of reserved range. */
+#define	SHN_LOPROC	0xff00		/* First processor-specific. */
+#define	SHN_HIPROC	0xff1f		/* Last processor-specific. */
+#define	SHN_LOOS	0xff20		/* First operating system-specific. */
+#define	SHN_FBSD_CACHED	SHN_LOOS	/* Transient, for sys/kern/link_elf_obj
+					   linker only: Cached global in local
+					   symtab. */
+#define	SHN_HIOS	0xff3f		/* Last operating system-specific. */
+#define	SHN_ABS		0xfff1		/* Absolute values. */
+#define	SHN_COMMON	0xfff2		/* Common data. */
+#define	SHN_XINDEX	0xffff		/* Escape -- index stored elsewhere. */
+#define	SHN_HIRESERVE	0xffff		/* Last of reserved range. */
+
+/* sh_type */
+#define	SHT_NULL		0	/* inactive */
+#define	SHT_PROGBITS		1	/* program defined information */
+#define	SHT_SYMTAB		2	/* symbol table section */
+#define	SHT_STRTAB		3	/* string table section */
+#define	SHT_RELA		4	/* relocation section with addends */
+#define	SHT_HASH		5	/* symbol hash table section */
+#define	SHT_DYNAMIC		6	/* dynamic section */
+#define	SHT_NOTE		7	/* note section */
+#define	SHT_NOBITS		8	/* no space section */
+#define	SHT_REL			9	/* relocation section - no addends */
+#define	SHT_SHLIB		10	/* reserved - purpose unknown */
+#define	SHT_DYNSYM		11	/* dynamic symbol table section */
+#define	SHT_INIT_ARRAY		14	/* Initialization function pointers. */
+#define	SHT_FINI_ARRAY		15	/* Termination function pointers. */
+#define	SHT_PREINIT_ARRAY	16	/* Pre-initialization function ptrs. */
+#define	SHT_GROUP		17	/* Section group. */
+#define	SHT_SYMTAB_SHNDX	18	/* Section indexes (see SHN_XINDEX). */
+#define	SHT_LOOS		0x60000000	/* First of OS specific semantics */
+#define	SHT_LOSUNW		0x6ffffff4
+#define	SHT_SUNW_dof		0x6ffffff4
+#define	SHT_SUNW_cap		0x6ffffff5
+#define	SHT_GNU_ATTRIBUTES	0x6ffffff5
+#define	SHT_SUNW_SIGNATURE	0x6ffffff6
+#define	SHT_GNU_HASH		0x6ffffff6
+#define	SHT_GNU_LIBLIST		0x6ffffff7
+#define	SHT_SUNW_ANNOTATE	0x6ffffff7
+#define	SHT_SUNW_DEBUGSTR	0x6ffffff8
+#define	SHT_SUNW_DEBUG		0x6ffffff9
+#define	SHT_SUNW_move		0x6ffffffa
+#define	SHT_SUNW_COMDAT		0x6ffffffb
+#define	SHT_SUNW_syminfo	0x6ffffffc
+#define	SHT_SUNW_verdef		0x6ffffffd
+#define	SHT_GNU_verdef		0x6ffffffd	/* Symbol versions provided */
+#define	SHT_SUNW_verneed	0x6ffffffe
+#define	SHT_GNU_verneed		0x6ffffffe	/* Symbol versions required */
+#define	SHT_SUNW_versym		0x6fffffff
+#define	SHT_GNU_versym		0x6fffffff	/* Symbol version table */
+#define	SHT_HISUNW		0x6fffffff
+#define	SHT_HIOS		0x6fffffff	/* Last of OS specific semantics */
+#define	SHT_LOPROC		0x70000000	/* reserved range for processor */
+#define	SHT_X86_64_UNWIND	0x70000001	/* unwind information */
+#define	SHT_AMD64_UNWIND	SHT_X86_64_UNWIND 
+
+#define	SHT_ARM_EXIDX		0x70000001	/* Exception index table. */
+#define	SHT_ARM_PREEMPTMAP	0x70000002	/* BPABI DLL dynamic linking 
+						   pre-emption map. */
+#define	SHT_ARM_ATTRIBUTES	0x70000003	/* Object file compatibility 
+						   attributes. */
+#define	SHT_ARM_DEBUGOVERLAY	0x70000004	/* See DBGOVL for details. */
+#define	SHT_ARM_OVERLAYSECTION	0x70000005	/* See DBGOVL for details. */
+#define	SHT_MIPS_LIBLIST	0x70000000
+#define	SHT_MIPS_MSYM		0x70000001
+#define	SHT_MIPS_CONFLICT	0x70000002
+#define	SHT_MIPS_GPTAB		0x70000003
+#define	SHT_MIPS_UCODE		0x70000004
+#define	SHT_MIPS_DEBUG		0x70000005
+#define	SHT_MIPS_REGINFO	0x70000006
+#define	SHT_MIPS_PACKAGE	0x70000007
+#define	SHT_MIPS_PACKSYM	0x70000008
+#define	SHT_MIPS_RELD		0x70000009
+#define	SHT_MIPS_IFACE		0x7000000b
+#define	SHT_MIPS_CONTENT	0x7000000c
+#define	SHT_MIPS_OPTIONS	0x7000000d
+#define	SHT_MIPS_DELTASYM	0x7000001b
+#define	SHT_MIPS_DELTAINST	0x7000001c
+#define	SHT_MIPS_DELTACLASS	0x7000001d
+#define	SHT_MIPS_DWARF		0x7000001e	/* MIPS gcc uses MIPS_DWARF */
+#define	SHT_MIPS_DELTADECL	0x7000001f
+#define	SHT_MIPS_SYMBOL_LIB	0x70000020
+#define	SHT_MIPS_EVENTS		0x70000021
+#define	SHT_MIPS_TRANSLATE	0x70000022
+#define	SHT_MIPS_PIXIE		0x70000023
+#define	SHT_MIPS_XLATE		0x70000024
+#define	SHT_MIPS_XLATE_DEBUG	0x70000025
+#define	SHT_MIPS_WHIRL		0x70000026
+#define	SHT_MIPS_EH_REGION	0x70000027
+#define	SHT_MIPS_XLATE_OLD	0x70000028
+#define	SHT_MIPS_PDR_EXCEPTION	0x70000029
+#define	SHT_MIPS_ABIFLAGS	0x7000002a
+
+#define	SHT_SPARC_GOTDATA	0x70000000
+
+#define	SHTORDERED
+#define	SHT_HIPROC		0x7fffffff	/* specific section header types */
+#define	SHT_LOUSER		0x80000000	/* reserved range for application */
+#define	SHT_HIUSER		0xffffffff	/* specific indexes */
+
+/* Flags for sh_flags. */
+#define	SHF_WRITE		0x1	/* Section contains writable data. */
+#define	SHF_ALLOC		0x2	/* Section occupies memory. */
+#define	SHF_EXECINSTR		0x4	/* Section contains instructions. */
+#define	SHF_MERGE		0x10	/* Section may be merged. */
+#define	SHF_STRINGS		0x20	/* Section contains strings. */
+#define	SHF_INFO_LINK		0x40	/* sh_info holds section index. */
+#define	SHF_LINK_ORDER		0x80	/* Special ordering requirements. */
+#define	SHF_OS_NONCONFORMING	0x100	/* OS-specific processing required. */
+#define	SHF_GROUP		0x200	/* Member of section group. */
+#define	SHF_TLS			0x400	/* Section contains TLS data. */
+#define	SHF_COMPRESSED		0x800	/* Section contains compressed data. */
+#define	SHF_MASKOS	0x0ff00000	/* OS-specific semantics. */
+#define	SHF_MASKPROC	0xf0000000	/* Processor-specific semantics. */
+
+/* Flags for section groups. */
+#define	GRP_COMDAT	0x1	/* COMDAT semantics. */
 
-#define SHN_UNDEF	     0		/* Undefined, missing, irrelevant. */
-#define SHN_LORESERVE	0xff00		/* First of reserved range. */
-#define SHN_LOPROC	0xff00		/* First processor-specific. */
-#define SHN_HIPROC	0xff1f		/* Last processor-specific. */
-#define SHN_LOOS	0xff20		/* First operating system-specific. */
-#define SHN_HIOS	0xff3f		/* Last operating system-specific. */
-#define SHN_ABS 	0xfff1		/* Absolute values. */
-#define SHN_COMMON	0xfff2		/* Common data. */
-#define SHN_XINDEX	0xffff		/* Escape -- index stored elsewhere. */
-#define SHN_HIRESERVE	0xffff		/* Last of reserved range. */
-
-/* Values for program header, p_type field. */
-
-#define PT_NULL 	0		/* Program header table entry unused */
-#define PT_LOAD 	1		/* Loadable program segment */
-#define PT_DYNAMIC	2		/* Dynamic linking information */
-#define PT_INTERP	3		/* Program interpreter */
-#define PT_NOTE 	4		/* Auxiliary information */
-#define PT_SHLIB	5		/* Reserved, unspecified semantics */
-#define PT_PHDR 	6		/* Entry for header table itself */
-#define PT_TLS		7		/* Thread local storage segment */
-#define PT_LOOS 	0x60000000	/* OS-specific */
-#define PT_HIOS 	0x6fffffff	/* OS-specific */
-#define PT_LOPROC	0x70000000	/* Processor-specific */
-#define PT_HIPROC	0x7FFFFFFF	/* Processor-specific */
-
-#define PT_GNU_EH_FRAME (PT_LOOS + 0x474e550) /* Frame unwind information */
-#define PT_SUNW_EH_FRAME PT_GNU_EH_FRAME      /* Solaris uses the same value */
-#define PT_GNU_STACK    (PT_LOOS + 0x474e551) /* Stack flags */
-#define PT_GNU_RELRO    (PT_LOOS + 0x474e552) /* Read-only after relocation */
-
-/* Program segment permissions, in program header p_flags field.  */
-
-#define PF_X		0x1		/* Segment is executable */
-#define PF_W		0x2		/* Segment is writable */
-#define PF_R		0x4		/* Segment is readable */
-#define PF_MASKOS	0x0FF00000	/* New value, Oct 4, 1999 Draft */
-#define PF_MASKPROC	0xF0000000	/* Processor-specific reserved bits */
-
-/* Values for section header, sh_type field.  */
-
-#define SHT_NULL		 0	/* Section header table entry unused */
-#define SHT_PROGBITS		 1	/* Program specific (private) data */
-#define SHT_SYMTAB		 2	/* Link editing symbol table */
-#define SHT_STRTAB		 3	/* A string table */
-#define SHT_RELA		 4	/* Relocation entries with addends */
-#define SHT_HASH		 5	/* A symbol hash table */
-#define SHT_DYNAMIC		 6	/* Information for dynamic linking */
-#define SHT_NOTE		 7	/* Information that marks file */
-#define SHT_NOBITS		 8	/* Section occupies no space in file */
-#define SHT_REL 		 9	/* Relocation entries, no addends */
-#define SHT_SHLIB		10	/* Reserved, unspecified semantics */
-#define SHT_DYNSYM		11	/* Dynamic linking symbol table */
-
-#define SHT_INIT_ARRAY		14	/* Array of ptrs to init functions */
-#define SHT_FINI_ARRAY		15	/* Array of ptrs to finish functions */
-#define SHT_PREINIT_ARRAY	16	/* Array of ptrs to pre-init funcs */
-#define SHT_GROUP		17	/* Section contains a section group */
-#define SHT_SYMTAB_SHNDX	18	/* Indicies for SHN_XINDEX entries */
-
-#define SHT_LOOS		0x60000000	/* First of OS specific semantics */
-#define SHT_HIOS		0x6fffffff	/* Last of OS specific semantics */
-
-#define SHT_GNU_INCREMENTAL_INPUTS 0x6fff4700	/* incremental build data */
-#define SHT_GNU_ATTRIBUTES	0x6ffffff5	/* Object attributes */
-#define SHT_GNU_HASH		0x6ffffff6	/* GNU style symbol hash table */
-#define SHT_GNU_LIBLIST 	0x6ffffff7	/* List of prelink dependencies */
-
-/* The next three section types are defined by Solaris, and are named
-   SHT_SUNW*.  We use them in GNU code, so we also define SHT_GNU*
-   versions.  */
-#define SHT_SUNW_verdef 	0x6ffffffd	/* Versions defined by file */
-#define SHT_SUNW_verneed	0x6ffffffe	/* Versions needed by file */
-#define SHT_SUNW_versym 	0x6fffffff	/* Symbol versions */
-
-#define SHT_GNU_verdef		SHT_SUNW_verdef
-#define SHT_GNU_verneed 	SHT_SUNW_verneed
-#define SHT_GNU_versym		SHT_SUNW_versym
-
-#define SHT_LOPROC	0x70000000	/* Processor-specific semantics, lo */
-#define SHT_HIPROC	0x7FFFFFFF	/* Processor-specific semantics, hi */
-#define SHT_LOUSER	0x80000000	/* Application-specific semantics */
-#define SHT_HIUSER	0xFFFFFFFF	/* New value, defined in Oct 4, 1999 Draft */
-
-/* Values for section header, sh_flags field.  */
-
-#define SHF_WRITE		0x1	/* Writable data during execution */
-#define SHF_ALLOC		0x2	/* Occupies memory during execution */
-#define SHF_EXECINSTR		0x4	/* Executable machine instructions */
-#define SHF_MERGE		0x10	/* Data in this section can be merged */
-#define SHF_STRINGS		0x20	/* Contains null terminated character strings */
-#define SHF_INFO_LINK		0x40	/* sh_info holds section header table index */
-#define SHF_LINK_ORDER		0x80	/* Preserve section ordering when linking */
-#define SHF_OS_NONCONFORMING	0x100	/* OS specific processing required */
-#define SHF_GROUP		0x200	/* Member of a section group */
-#define SHF_TLS			0x400	/* Thread local storage section */
-
-#define SHF_MASKOS	0x0FF00000	/* New value, Oct 4, 1999 Draft */
-#define SHF_MASKPROC	0xF0000000	/* Processor-specific semantics */
-
-/* Values of note segment descriptor types for core files. */
-
-#define NT_PRSTATUS	1		/* Contains copy of prstatus struct */
-#define NT_FPREGSET	2		/* Contains copy of fpregset struct */
-#define NT_PRPSINFO	3		/* Contains copy of prpsinfo struct */
-#define NT_TASKSTRUCT	4		/* Contains copy of task struct */
-#define NT_AUXV 	6		/* Contains copy of Elfxx_auxv_t */
-
-#define STN_UNDEF	0		/* Undefined symbol index */
-
-#define STB_LOCAL	0		/* Symbol not visible outside obj */
-#define STB_GLOBAL	1		/* Symbol visible outside obj */
-#define STB_WEAK	2		/* Like globals, lower precedence */
-#define STB_LOOS	10		/* OS-specific semantics */
-#define STB_GNU_UNIQUE	10		/* Symbol is unique in namespace */
-#define STB_HIOS	12		/* OS-specific semantics */
-#define STB_LOPROC	13		/* Processor-specific semantics */
-#define STB_HIPROC	15		/* Processor-specific semantics */
-
-#define STT_NOTYPE	0		/* Symbol type is unspecified */
-#define STT_OBJECT	1		/* Symbol is a data object */
-#define STT_FUNC	2		/* Symbol is a code object */
-#define STT_SECTION	3		/* Symbol associated with a section */
-#define STT_FILE	4		/* Symbol gives a file name */
-#define STT_COMMON	5		/* An uninitialised common block */
-#define STT_TLS 	6		/* Thread local data object */
-#define STT_RELC	8		/* Complex relocation expression */
-#define STT_SRELC	9		/* Signed Complex relocation expression */
-#define STT_LOOS	10		/* OS-specific semantics */
-#define STT_GNU_IFUNC	10		/* Symbol is an indirect code object */
-#define STT_HIOS	12		/* OS-specific semantics */
-#define STT_LOPROC	13		/* Processor-specific semantics */
-#define STT_HIPROC	15		/* Processor-specific semantics */
-
-/* The following constants control how a symbol may be accessed once it has
-   become part of an executable or shared library.  */
-
-#define STV_DEFAULT	0		/* Visibility is specified by binding type */
-#define STV_INTERNAL	1		/* OS specific version of STV_HIDDEN */
-#define STV_HIDDEN	2		/* Can only be seen inside currect component */
-#define STV_PROTECTED	3		/* Treat as STB_LOCAL inside current component */
-
-/* Dynamic section tags.  */
-
-#define DT_NULL 	0	/* Terminating entry. */
-#define DT_NEEDED	1	/* String table offset of a needed shared
+/*
+ * Flags / mask for .gnu.versym sections.
+ */
+#define	VERSYM_VERSION	0x7fff
+#define	VERSYM_HIDDEN	0x8000
+
+/* Values for p_type. */
+#define	PT_NULL		0	/* Unused entry. */
+#define	PT_LOAD		1	/* Loadable segment. */
+#define	PT_DYNAMIC	2	/* Dynamic linking information segment. */
+#define	PT_INTERP	3	/* Pathname of interpreter. */
+#define	PT_NOTE		4	/* Auxiliary information. */
+#define	PT_SHLIB	5	/* Reserved (not used). */
+#define	PT_PHDR		6	/* Location of program header itself. */
+#define	PT_TLS		7	/* Thread local storage segment */
+#define	PT_LOOS		0x60000000	/* First OS-specific. */
+#define	PT_SUNW_UNWIND	0x6464e550	/* amd64 UNWIND program header */
+#define	PT_GNU_EH_FRAME	0x6474e550
+#define	PT_GNU_STACK	0x6474e551
+#define	PT_GNU_RELRO	0x6474e552
+#define	PT_DUMP_DELTA	0x6fb5d000	/* va->pa map for kernel dumps
+					   (currently arm). */
+#define	PT_LOSUNW	0x6ffffffa
+#define	PT_SUNWBSS	0x6ffffffa	/* Sun Specific segment */
+#define	PT_SUNWSTACK	0x6ffffffb	/* describes the stack segment */
+#define	PT_SUNWDTRACE	0x6ffffffc	/* private */
+#define	PT_SUNWCAP	0x6ffffffd	/* hard/soft capabilities segment */
+#define	PT_HISUNW	0x6fffffff
+#define	PT_HIOS		0x6fffffff	/* Last OS-specific. */
+#define	PT_LOPROC	0x70000000	/* First processor-specific type. */
+#define	PT_ARM_ARCHEXT	0x70000000	/* ARM arch compat information. */
+#define	PT_ARM_EXIDX	0x70000001	/* ARM exception unwind tables. */
+#define	PT_HIPROC	0x7fffffff	/* Last processor-specific type. */
+
+/* Values for p_flags. */
+#define	PF_X		0x1		/* Executable. */
+#define	PF_W		0x2		/* Writable. */
+#define	PF_R		0x4		/* Readable. */
+#define	PF_MASKOS	0x0ff00000	/* Operating system-specific. */
+#define	PF_MASKPROC	0xf0000000	/* Processor-specific. */
+
+/* Extended program header index. */
+#define	PN_XNUM		0xffff
+
+/* Values for d_tag. */
+#define	DT_NULL		0	/* Terminating entry. */
+#define	DT_NEEDED	1	/* String table offset of a needed shared
 				   library. */
-#define DT_PLTRELSZ	2	/* Total size in bytes of PLT relocations. */
-#define DT_PLTGOT	3	/* Processor-dependent address. */
-#define DT_HASH 	4	/* Address of symbol hash table. */
-#define DT_STRTAB	5	/* Address of string table. */
-#define DT_SYMTAB	6	/* Address of symbol table. */
-#define DT_RELA 	7	/* Address of ElfNN_Rela relocations. */
-#define DT_RELASZ	8	/* Total size of ElfNN_Rela relocations. */
-#define DT_RELAENT	9	/* Size of each ElfNN_Rela relocation entry. */
-#define DT_STRSZ	10	/* Size of string table. */
-#define DT_SYMENT	11	/* Size of each symbol table entry. */
-#define DT_INIT 	12	/* Address of initialization function. */
-#define DT_FINI 	13	/* Address of finalization function. */
-#define DT_SONAME	14	/* String table offset of shared object
+#define	DT_PLTRELSZ	2	/* Total size in bytes of PLT relocations. */
+#define	DT_PLTGOT	3	/* Processor-dependent address. */
+#define	DT_HASH		4	/* Address of symbol hash table. */
+#define	DT_STRTAB	5	/* Address of string table. */
+#define	DT_SYMTAB	6	/* Address of symbol table. */
+#define	DT_RELA		7	/* Address of ElfNN_Rela relocations. */
+#define	DT_RELASZ	8	/* Total size of ElfNN_Rela relocations. */
+#define	DT_RELAENT	9	/* Size of each ElfNN_Rela relocation entry. */
+#define	DT_STRSZ	10	/* Size of string table. */
+#define	DT_SYMENT	11	/* Size of each symbol table entry. */
+#define	DT_INIT		12	/* Address of initialization function. */
+#define	DT_FINI		13	/* Address of finalization function. */
+#define	DT_SONAME	14	/* String table offset of shared object
 				   name. */
-#define DT_RPATH	15	/* String table offset of library path. [sup] */
-#define DT_SYMBOLIC	16	/* Indicates "symbolic" linking. [sup] */
-#define DT_REL		17	/* Address of ElfNN_Rel relocations. */
-#define DT_RELSZ	18	/* Total size of ElfNN_Rel relocations. */
-#define DT_RELENT	19	/* Size of each ElfNN_Rel relocation. */
-#define DT_PLTREL	20	/* Type of relocation used for PLT. */
-#define DT_DEBUG	21	/* Reserved (not used). */
-#define DT_TEXTREL	22	/* Indicates there may be relocations in
+#define	DT_RPATH	15	/* String table offset of library path. [sup] */
+#define	DT_SYMBOLIC	16	/* Indicates "symbolic" linking. [sup] */
+#define	DT_REL		17	/* Address of ElfNN_Rel relocations. */
+#define	DT_RELSZ	18	/* Total size of ElfNN_Rel relocations. */
+#define	DT_RELENT	19	/* Size of each ElfNN_Rel relocation. */
+#define	DT_PLTREL	20	/* Type of relocation used for PLT. */
+#define	DT_DEBUG	21	/* Reserved (not used). */
+#define	DT_TEXTREL	22	/* Indicates there may be relocations in
 				   non-writable segments. [sup] */
-#define DT_JMPREL	23	/* Address of PLT relocations. */
-#define DT_BIND_NOW	24	/* [sup] */
-#define DT_INIT_ARRAY	25	/* Address of the array of pointers to
+#define	DT_JMPREL	23	/* Address of PLT relocations. */
+#define	DT_BIND_NOW	24	/* [sup] */
+#define	DT_INIT_ARRAY	25	/* Address of the array of pointers to
 				   initialization functions */
-#define DT_FINI_ARRAY	26	/* Address of the array of pointers to
+#define	DT_FINI_ARRAY	26	/* Address of the array of pointers to
 				   termination functions */
-#define DT_INIT_ARRAYSZ	27	/* Size in bytes of the array of
+#define	DT_INIT_ARRAYSZ	27	/* Size in bytes of the array of
 				   initialization functions. */
-#define DT_FINI_ARRAYSZ	28	/* Size in bytes of the array of
-				   terminationfunctions. */
-#define DT_RUNPATH	29	/* String table offset of a null-terminated
+#define	DT_FINI_ARRAYSZ	28	/* Size in bytes of the array of
+				   termination functions. */
+#define	DT_RUNPATH	29	/* String table offset of a null-terminated
 				   library search path string. */
-#define DT_FLAGS	30	/* Object specific flag values. */
-#define DT_ENCODING	32	/* Values greater than or equal to DT_ENCODING
+#define	DT_FLAGS	30	/* Object specific flag values. */
+#define	DT_ENCODING	32	/* Values greater than or equal to DT_ENCODING
 				   and less than DT_LOOS follow the rules for
 				   the interpretation of the d_un union
 				   as follows: even == 'd_ptr', odd == 'd_val'
 				   or none */
-#define DT_PREINIT_ARRAY 32	/* Address of the array of pointers to
+#define	DT_PREINIT_ARRAY 32	/* Address of the array of pointers to
 				   pre-initialization functions. */
-#define DT_PREINIT_ARRAYSZ 33	/* Size in bytes of the array of
+#define	DT_PREINIT_ARRAYSZ 33	/* Size in bytes of the array of
 				   pre-initialization functions. */
+#define	DT_MAXPOSTAGS	34	/* number of positive tags */
+#define	DT_LOOS		0x6000000d	/* First OS-specific */
+#define	DT_SUNW_AUXILIARY	0x6000000d	/* symbol auxiliary name */
+#define	DT_SUNW_RTLDINF		0x6000000e	/* ld.so.1 info (private) */
+#define	DT_SUNW_FILTER		0x6000000f	/* symbol filter name */
+#define	DT_SUNW_CAP		0x60000010	/* hardware/software */
+#define	DT_SUNW_ASLR		0x60000023	/* ASLR control */
+#define	DT_HIOS		0x6ffff000	/* Last OS-specific */
 
-#define DT_LOOS		0x6000000d	/* First OS-specific */
-#define DT_HIOS		0x6fff0000	/* Last OS-specific */
+/*
+ * DT_* entries which fall between DT_VALRNGHI & DT_VALRNGLO use the
+ * Dyn.d_un.d_val field of the Elf*_Dyn structure.
+ */
+#define	DT_VALRNGLO	0x6ffffd00
+#define	DT_GNU_PRELINKED	0x6ffffdf5 /* prelinking timestamp */
+#define	DT_GNU_CONFLICTSZ	0x6ffffdf6 /* size of conflict section */
+#define	DT_GNU_LIBLISTSZ	0x6ffffdf7 /* size of library list */
+#define	DT_CHECKSUM	0x6ffffdf8	/* elf checksum */
+#define	DT_PLTPADSZ	0x6ffffdf9	/* pltpadding size */
+#define	DT_MOVEENT	0x6ffffdfa	/* move table entry size */
+#define	DT_MOVESZ	0x6ffffdfb	/* move table size */
+#define	DT_FEATURE	0x6ffffdfc	/* feature holder */
+#define	DT_FEATURE_1	DT_FEATURE
+#define	DT_POSFLAG_1	0x6ffffdfd	/* flags for DT_* entries, effecting */
+					/*	the following DT_* entry. */
+					/*	See DF_P1_* definitions */
+#define	DT_SYMINSZ	0x6ffffdfe	/* syminfo table size (in bytes) */
+#define	DT_SYMINENT	0x6ffffdff	/* syminfo entry size (in bytes) */
+#define	DT_VALRNGHI	0x6ffffdff
 
-/* The next 2 dynamic tag ranges, integer value range (DT_VALRNGLO to
-   DT_VALRNGHI) and virtual address range (DT_ADDRRNGLO to DT_ADDRRNGHI),
-   are used on Solaris.  We support them everywhere.  Note these values
-   lie outside of the (new) range for OS specific values.  This is a
-   deliberate special case and we maintain it for backwards compatibility.
+/*
+ * DT_* entries which fall between DT_ADDRRNGHI & DT_ADDRRNGLO use the
+ * Dyn.d_un.d_ptr field of the Elf*_Dyn structure.
+ *
+ * If any adjustment is made to the ELF object after it has been
+ * built, these entries will need to be adjusted.
  */
-#define DT_VALRNGLO		0x6ffffd00
-#define DT_GNU_PRELINKED	0x6ffffdf5
-#define DT_GNU_CONFLICTSZ	0x6ffffdf6
-#define DT_GNU_LIBLISTSZ	0x6ffffdf7
-#define DT_CHECKSUM	0x6ffffdf8	/* elf checksum */
-#define DT_PLTPADSZ	0x6ffffdf9	/* pltpadding size */
-#define DT_MOVEENT	0x6ffffdfa	/* move table entry size */
-#define DT_MOVESZ	0x6ffffdfb	/* move table size */
-#define DT_FEATURE	0x6ffffdfc	/* feature holder */
-#define DT_POSFLAG_1	0x6ffffdfd	/* flags for DT_* entries, effecting */
-					/*   the following DT_* entry. */
-					/*   See DF_P1_* definitions */
-#define DT_SYMINSZ	0x6ffffdfe	/* syminfo table size (in bytes) */
-#define DT_SYMINENT	0x6ffffdff	/* syminfo entry size (in bytes) */
-#define DT_VALRNGHI	0x6ffffdff
-
-#define DT_ADDRRNGLO	0x6ffffe00
-#define DT_GNU_HASH	0x6ffffef5	/* GNU-style hash table */
-#define DT_TLSDESC_PLT	0x6ffffef6
-#define DT_TLSDESC_GOT	0x6ffffef7
-#define DT_GNU_CONFLICT 0x6ffffef8
-#define DT_GNU_LIBLIST	0x6ffffef9
-#define DT_CONFIG	0x6ffffefa	/* configuration information */
-#define DT_DEPAUDIT	0x6ffffefb	/* dependency auditing */
-#define DT_AUDIT	0x6ffffefc	/* object auditing */
-#define DT_PLTPAD	0x6ffffefd	/* pltpadding (sparcv9) */
-#define DT_MOVETAB	0x6ffffefe	/* move table */
-#define DT_SYMINFO	0x6ffffeff	/* syminfo table */
-#define DT_ADDRRNGHI	0x6ffffeff
-
-#define DT_RELACOUNT	0x6ffffff9	/* number of RELATIVE relocations */
-#define DT_RELCOUNT	0x6ffffffa	/* number of RELATIVE relocations */
-#define DT_FLAGS_1	0x6ffffffb	/* state flags - see DF_1_* defs */
-#define DT_VERDEF	0x6ffffffc	/* Address of verdef section. */
-#define DT_VERDEFNUM	0x6ffffffd	/* Number of elems in verdef section */
-#define DT_VERNEED	0x6ffffffe	/* Address of verneed section. */
-#define DT_VERNEEDNUM	0x6fffffff	/* Number of elems in verneed section */
-
-/* This tag is a GNU extension to the Solaris version scheme.  */
-#define DT_VERSYM	0x6ffffff0
-
-#define DT_LOPROC	0x70000000	/* First processor-specific type. */
-#define DT_HIPROC	0x7fffffff	/* Last processor-specific type. */
-
-/* These section tags are used on Solaris.  We support them
-   everywhere, and hope they do not conflict.  */
-
-#define DT_AUXILIARY	0x7ffffffd	/* shared library auxiliary name */
-#define DT_USED 	0x7ffffffe	/* ignored - same as needed */
-#define DT_FILTER	0x7fffffff	/* shared library filter name */
-
-
-/* Values used in DT_FEATURE .dynamic entry.  */
-#define DTF_1_PARINIT	0x00000001
-/* From
-
-   http://docs.sun.com:80/ab2/coll.45.13/LLM/@Ab2PageView/21165?Ab2Lang=C&Ab2Enc=iso-8859-1
-
-   DTF_1_CONFEXP is the same as DTF_1_PARINIT. It is a typo. The value
-   defined here is the same as the one in <sys/link.h> on Solaris 8.  */
-#define DTF_1_CONFEXP	0x00000002
-
-/* Flag values used in the DT_POSFLAG_1 .dynamic entry.	 */
-#define DF_P1_LAZYLOAD	0x00000001
-#define DF_P1_GROUPPERM 0x00000002
-
-/* Flag value in in the DT_FLAGS_1 .dynamic entry.  */
-#define DF_1_NOW	0x00000001
-#define DF_1_BIND_NOW	0x00000001	/* Same as DF_BIND_NOW */
-#define DF_1_GLOBAL	0x00000002	/* Set the RTLD_GLOBAL for object */
-#define DF_1_GROUP	0x00000004
-#define DF_1_NODELETE	0x00000008	/* Set the RTLD_NODELETE for object */
-#define DF_1_LOADFLTR	0x00000010	/* Immediate loading of filtees */
-#define DF_1_INITFIRST	0x00000020
-#define DF_1_NOOPEN	0x00000040	/* Do not allow loading on dlopen() */
-#define DF_1_ORIGIN	0x00000080	/* Process $ORIGIN */
-#define DF_1_DIRECT	0x00000100
-#define DF_1_TRANS	0x00000200
-#define DF_1_INTERPOSE	0x00000400
-#define DF_1_NODEFLIB	0x00000800
-#define DF_1_NODUMP	0x00001000
-#define DF_1_CONLFAT	0x00002000
-
-/* Flag values for the DT_FLAGS entry. */
-#define DF_ORIGIN	0x1	/* Indicates that the object being loaded may
+#define	DT_ADDRRNGLO	0x6ffffe00
+#define	DT_GNU_HASH	0x6ffffef5	/* GNU-style hash table */
+#define	DT_TLSDESC_PLT	0x6ffffef6	/* loc. of PLT for tlsdesc resolver */
+#define	DT_TLSDESC_GOT	0x6ffffef7	/* loc. of GOT for tlsdesc resolver */
+#define	DT_GNU_CONFLICT	0x6ffffef8	/* address of conflict section */
+#define	DT_GNU_LIBLIST	0x6ffffef9	/* address of library list */
+#define	DT_CONFIG	0x6ffffefa	/* configuration information */
+#define	DT_DEPAUDIT	0x6ffffefb	/* dependency auditing */
+#define	DT_AUDIT	0x6ffffefc	/* object auditing */
+#define	DT_PLTPAD	0x6ffffefd	/* pltpadding (sparcv9) */
+#define	DT_MOVETAB	0x6ffffefe	/* move table */
+#define	DT_SYMINFO	0x6ffffeff	/* syminfo table */
+#define	DT_ADDRRNGHI	0x6ffffeff
+
+#define	DT_VERSYM	0x6ffffff0	/* Address of versym section. */
+#define	DT_RELACOUNT	0x6ffffff9	/* number of RELATIVE relocations */
+#define	DT_RELCOUNT	0x6ffffffa	/* number of RELATIVE relocations */
+#define	DT_FLAGS_1	0x6ffffffb	/* state flags - see DF_1_* defs */
+#define	DT_VERDEF	0x6ffffffc	/* Address of verdef section. */
+#define	DT_VERDEFNUM	0x6ffffffd	/* Number of elems in verdef section */
+#define	DT_VERNEED	0x6ffffffe	/* Address of verneed section. */
+#define	DT_VERNEEDNUM	0x6fffffff	/* Number of elems in verneed section */
+
+#define	DT_LOPROC	0x70000000	/* First processor-specific type. */
+
+#define	DT_ARM_SYMTABSZ			0x70000001
+#define	DT_ARM_PREEMPTMAP		0x70000002
+
+#define	DT_SPARC_REGISTER		0x70000001
+#define	DT_DEPRECATED_SPARC_REGISTER	0x7000001
+
+#define	DT_MIPS_RLD_VERSION		0x70000001
+#define	DT_MIPS_TIME_STAMP		0x70000002
+#define	DT_MIPS_ICHECKSUM		0x70000003
+#define	DT_MIPS_IVERSION		0x70000004
+#define	DT_MIPS_FLAGS			0x70000005
+#define	DT_MIPS_BASE_ADDRESS		0x70000006
+#define	DT_MIPS_CONFLICT		0x70000008
+#define	DT_MIPS_LIBLIST			0x70000009
+#define	DT_MIPS_LOCAL_GOTNO		0x7000000a
+#define	DT_MIPS_CONFLICTNO		0x7000000b
+#define	DT_MIPS_LIBLISTNO		0x70000010
+#define	DT_MIPS_SYMTABNO		0x70000011
+#define	DT_MIPS_UNREFEXTNO		0x70000012
+#define	DT_MIPS_GOTSYM			0x70000013
+#define	DT_MIPS_HIPAGENO		0x70000014
+#define	DT_MIPS_RLD_MAP			0x70000016
+#define	DT_MIPS_DELTA_CLASS		0x70000017
+#define	DT_MIPS_DELTA_CLASS_NO		0x70000018
+#define	DT_MIPS_DELTA_INSTANCE		0x70000019
+#define	DT_MIPS_DELTA_INSTANCE_NO	0x7000001A
+#define	DT_MIPS_DELTA_RELOC		0x7000001B
+#define	DT_MIPS_DELTA_RELOC_NO		0x7000001C
+#define	DT_MIPS_DELTA_SYM		0x7000001D
+#define	DT_MIPS_DELTA_SYM_NO		0x7000001E
+#define	DT_MIPS_DELTA_CLASSSYM		0x70000020
+#define	DT_MIPS_DELTA_CLASSSYM_NO	0x70000021
+#define	DT_MIPS_CXX_FLAGS		0x70000022
+#define	DT_MIPS_PIXIE_INIT		0x70000023
+#define	DT_MIPS_SYMBOL_LIB		0x70000024
+#define	DT_MIPS_LOCALPAGE_GOTIDX	0x70000025
+#define	DT_MIPS_LOCAL_GOTIDX		0x70000026
+#define	DT_MIPS_HIDDEN_GOTIDX		0x70000027
+#define	DT_MIPS_PROTECTED_GOTIDX	0x70000028
+#define	DT_MIPS_OPTIONS			0x70000029
+#define	DT_MIPS_INTERFACE		0x7000002A
+#define	DT_MIPS_DYNSTR_ALIGN		0x7000002B
+#define	DT_MIPS_INTERFACE_SIZE		0x7000002C
+#define	DT_MIPS_RLD_TEXT_RESOLVE_ADDR	0x7000002D
+#define	DT_MIPS_PERF_SUFFIX		0x7000002E
+#define	DT_MIPS_COMPACT_SIZE		0x7000002F
+#define	DT_MIPS_GP_VALUE		0x70000030
+#define	DT_MIPS_AUX_DYNAMIC		0x70000031
+#define	DT_MIPS_PLTGOT			0x70000032
+#define	DT_MIPS_RLD_OBJ_UPDATE		0x70000033
+#define	DT_MIPS_RWPLT			0x70000034
+
+#define	DT_PPC_GOT			0x70000000
+#define	DT_PPC_TLSOPT			0x70000001
+
+#define	DT_PPC64_GLINK			0x70000000
+#define	DT_PPC64_OPD			0x70000001
+#define	DT_PPC64_OPDSZ			0x70000002
+#define	DT_PPC64_TLSOPT			0x70000003
+
+#define	DT_AUXILIARY	0x7ffffffd	/* shared library auxiliary name */
+#define	DT_USED		0x7ffffffe	/* ignored - same as needed */
+#define	DT_FILTER	0x7fffffff	/* shared library filter name */
+#define	DT_HIPROC	0x7fffffff	/* Last processor-specific type. */
+
+/* Values for DT_FLAGS */
+#define	DF_ORIGIN	0x0001	/* Indicates that the object being loaded may
 				   make reference to the $ORIGIN substitution
 				   string */
-#define DF_SYMBOLIC	0x2	/* Indicates "symbolic" linking. */
-#define DF_TEXTREL	0x4	/* Indicates there may be relocations in
+#define	DF_SYMBOLIC	0x0002	/* Indicates "symbolic" linking. */
+#define	DF_TEXTREL	0x0004	/* Indicates there may be relocations in
 				   non-writable segments. */
-#define DF_BIND_NOW	0x8	/* Indicates that the dynamic linker should
+#define	DF_BIND_NOW	0x0008	/* Indicates that the dynamic linker should
 				   process all relocations for the object
 				   containing this entry before transferring
 				   control to the program. */
-#define DF_STATIC_TLS	0x10	/* Indicates that the shared object or
+#define	DF_STATIC_TLS	0x0010	/* Indicates that the shared object or
 				   executable contains code using a static
 				   thread-local storage scheme. */
 
-/* These constants are used for the version number of a Elf32_Verdef
-   structure.  */
-
-#define VER_DEF_NONE		0
-#define VER_DEF_CURRENT 	1
-#define VER_DEF_IDX(x)		VER_NDX(x)
-
-/* These constants appear in the vd_flags field of a Elf32_Verdef
-   structure.
-
-   Cf. the Solaris Linker and Libraries Guide, Ch. 7, Object File Format,
-   Versioning Sections, for a description:
-
-   http://docs.sun.com/app/docs/doc/819-0690/chapter6-93046?l=en&a=view  */
-
-#define VER_FLG_BASE		0x1
-#define VER_FLG_WEAK		0x2
-#define VER_FLG_INFO		0x4
+/* Values for DT_FLAGS_1 */
+#define	DF_1_BIND_NOW	0x00000001	/* Same as DF_BIND_NOW */
+#define	DF_1_GLOBAL	0x00000002	/* Set the RTLD_GLOBAL for object */
+#define	DF_1_NODELETE	0x00000008	/* Set the RTLD_NODELETE for object */
+#define	DF_1_LOADFLTR	0x00000010	/* Immediate loading of filtees */
+#define	DF_1_NOOPEN     0x00000040	/* Do not allow loading on dlopen() */
+#define	DF_1_ORIGIN	0x00000080	/* Process $ORIGIN */
+#define	DF_1_INTERPOSE	0x00000400	/* Interpose all objects but main */
+#define	DF_1_NODEFLIB	0x00000800	/* Do not search default paths */
+
+/* Values for l_flags. */
+#define	LL_NONE			0x0	/* no flags */
+#define	LL_EXACT_MATCH		0x1	/* require an exact match */
+#define	LL_IGNORE_INT_VER	0x2	/* ignore version incompatibilities */
+#define	LL_REQUIRE_MINOR	0x4
+#define	LL_EXPORTS		0x8
+#define	LL_DELAY_LOAD		0x10
+#define	LL_DELTA		0x20
+
+/* Values for n_type used in executables. */
+#define	NT_FREEBSD_ABI_TAG	1
+#define	NT_FREEBSD_NOINIT_TAG	2
+#define	NT_FREEBSD_ARCH_TAG	3
+
+/* Values for n_type.  Used in core files. */
+#define	NT_PRSTATUS	1	/* Process status. */
+#define	NT_FPREGSET	2	/* Floating point registers. */
+#define	NT_PRPSINFO	3	/* Process state info. */
+#define	NT_THRMISC	7	/* Thread miscellaneous info. */
+#define	NT_PROCSTAT_PROC	8	/* Procstat proc data. */
+#define	NT_PROCSTAT_FILES	9	/* Procstat files data. */
+#define	NT_PROCSTAT_VMMAP	10	/* Procstat vmmap data. */
+#define	NT_PROCSTAT_GROUPS	11	/* Procstat groups data. */
+#define	NT_PROCSTAT_UMASK	12	/* Procstat umask data. */
+#define	NT_PROCSTAT_RLIMIT	13	/* Procstat rlimit data. */
+#define	NT_PROCSTAT_OSREL	14	/* Procstat osreldate data. */
+#define	NT_PROCSTAT_PSSTRINGS	15	/* Procstat ps_strings data. */
+#define	NT_PROCSTAT_AUXV	16	/* Procstat auxv data. */
+#define	NT_PTLWPINFO		17	/* Thread ptrace miscellaneous info. */
+#define	NT_PPC_VMX	0x100	/* PowerPC Altivec/VMX registers */
+#define	NT_PPC_VSX	0x102	/* PowerPC VSX registers */
+#define	NT_X86_XSTATE	0x202	/* x86 XSAVE extended state. */
+#define	NT_ARM_VFP	0x400	/* ARM VFP registers */
+
+/* Symbol Binding - ELFNN_ST_BIND - st_info */
+#define	STB_LOCAL	0	/* Local symbol */
+#define	STB_GLOBAL	1	/* Global symbol */
+#define	STB_WEAK	2	/* like global - lower precedence */
+#define	STB_LOOS	10	/* Start of operating system reserved range. */
+#define	STB_GNU_UNIQUE	10	/* Unique symbol (GNU) */
+#define	STB_HIOS	12	/* End of operating system reserved range. */
+#define	STB_LOPROC	13	/* reserved range for processor */
+#define	STB_HIPROC	15	/*   specific semantics. */
+
+/* Symbol type - ELFNN_ST_TYPE - st_info */
+#define	STT_NOTYPE	0	/* Unspecified type. */
+#define	STT_OBJECT	1	/* Data object. */
+#define	STT_FUNC	2	/* Function. */
+#define	STT_SECTION	3	/* Section. */
+#define	STT_FILE	4	/* Source file. */
+#define	STT_COMMON	5	/* Uninitialized common block. */
+#define	STT_TLS		6	/* TLS object. */
+#define	STT_NUM		7
+#define	STT_LOOS	10	/* Reserved range for operating system */
+#define	STT_GNU_IFUNC	10
+#define	STT_HIOS	12	/*   specific semantics. */
+#define	STT_LOPROC	13	/* Start of processor reserved range. */
+#define	STT_SPARC_REGISTER 13	/* SPARC register information. */
+#define	STT_HIPROC	15	/* End of processor reserved range. */
+
+/* Symbol visibility - ELFNN_ST_VISIBILITY - st_other */
+#define	STV_DEFAULT	0x0	/* Default visibility (see binding). */
+#define	STV_INTERNAL	0x1	/* Special meaning in relocatable objects. */
+#define	STV_HIDDEN	0x2	/* Not visible. */
+#define	STV_PROTECTED	0x3	/* Visible but not preemptible. */
+#define	STV_EXPORTED	0x4
+#define	STV_SINGLETON	0x5
+#define	STV_ELIMINATE	0x6
+
+/* Special symbol table indexes. */
+#define	STN_UNDEF	0	/* Undefined symbol index. */
+
+/* Symbol versioning flags. */
+#define	VER_DEF_CURRENT	1
+#define	VER_DEF_IDX(x)	VER_NDX(x)
+
+#define	VER_FLG_BASE	0x01
+#define	VER_FLG_WEAK	0x02
+
+#define	VER_NEED_CURRENT	1
+#define	VER_NEED_WEAK	(1u << 15)
+#define	VER_NEED_HIDDEN	VER_NDX_HIDDEN
+#define	VER_NEED_IDX(x)	VER_NDX(x)
+
+#define	VER_NDX_LOCAL	0
+#define	VER_NDX_GLOBAL	1
+#define	VER_NDX_GIVEN	2
+
+#define	VER_NDX_HIDDEN	(1u << 15)
+#define	VER_NDX(x)	((x) & ~(1u << 15))
+
+#define	CA_SUNW_NULL	0
+#define	CA_SUNW_HW_1	1		/* first hardware capabilities entry */
+#define	CA_SUNW_SF_1	2		/* first software capabilities entry */
 
-/* These special constants can be found in an Elf32_Versym field.  */
-
-#define VER_NDX_LOCAL		0
-#define VER_NDX_GLOBAL		1
-#define VER_NDX_GIVEN		2
-#define VER_NDX_HIDDEN		(1u << 15)
-#define VER_NDX(x)		((x) & ~(1u << 15))
-/* These constants are used for the version number of a Elf32_Verneed
-   structure.  */
-
-#define VER_NEED_NONE		0
-#define VER_NEED_CURRENT	1
-#define VER_NEED_WEAK		(1u << 15)
-#define VER_NEED_HIDDEN 	VER_NDX_HIDDEN
-#define VER_NEED_IDX(x) 	VER_NDX(x)
-
-/* This flag appears in a Versym structure.  It means that the symbol
-   is hidden, and is only visible with an explicit version number.
-   This is a GNU extension.  */
-
-#define VERSYM_HIDDEN		0x8000
+/*
+ * Syminfo flag values
+ */
+#define	SYMINFO_FLG_DIRECT	0x0001	/* symbol ref has direct association */
+					/*	to object containing defn. */
+#define	SYMINFO_FLG_PASSTHRU	0x0002	/* ignored - see SYMINFO_FLG_FILTER */
+#define	SYMINFO_FLG_COPY	0x0004	/* symbol is a copy-reloc */
+#define	SYMINFO_FLG_LAZYLOAD	0x0008	/* object containing defn should be */
+					/*	lazily-loaded */
+#define	SYMINFO_FLG_DIRECTBIND	0x0010	/* ref should be bound directly to */
+					/*	object containing defn. */
+#define	SYMINFO_FLG_NOEXTDIRECT	0x0020	/* don't let an external reference */
+					/*	directly bind to this symbol */
+#define	SYMINFO_FLG_FILTER	0x0002	/* symbol ref is associated to a */
+#define	SYMINFO_FLG_AUXILIARY	0x0040	/* 	standard or auxiliary filter */
 
-/* This is the mask for the rest of the Versym information.  */
+/*
+ * Syminfo.si_boundto values.
+ */
+#define	SYMINFO_BT_SELF		0xffff	/* symbol bound to self */
+#define	SYMINFO_BT_PARENT	0xfffe	/* symbol bound to parent */
+#define	SYMINFO_BT_NONE		0xfffd	/* no special symbol binding */
+#define	SYMINFO_BT_EXTERN	0xfffc	/* symbol defined as external */
+#define	SYMINFO_BT_LOWRESERVE	0xff00	/* beginning of reserved entries */
 
-#define VERSYM_VERSION		0x7fff
+/*
+ * Syminfo version values.
+ */
+#define	SYMINFO_NONE		0	/* Syminfo version */
+#define	SYMINFO_CURRENT		1
+#define	SYMINFO_NUM		2
 
-/* This is a special token which appears as part of a symbol name.  It
-   indictes that the rest of the name is actually the name of a
-   version node, and is not part of the actual name.  This is a GNU
-   extension.  For example, the symbol name `stat@ver2' is taken to
-   mean the symbol `stat' in version `ver2'.  */
+/* Values for ch_type (compressed section headers). */
+#define	ELFCOMPRESS_ZLIB	1	/* ZLIB/DEFLATE */
+#define	ELFCOMPRESS_LOOS	0x60000000	/* OS-specific */
+#define	ELFCOMPRESS_HIOS	0x6fffffff
+#define	ELFCOMPRESS_LOPROC	0x70000000	/* Processor-specific */
+#define	ELFCOMPRESS_HIPROC	0x7fffffff
 
-#define ELF_VER_CHR		'@'
+/*
+ * Relocation types.
+ *
+ * All machine architectures are defined here to allow tools on one to
+ * handle others.
+ */
 
-/* Possible values for si_boundto.  */
+#define	R_386_NONE		0	/* No relocation. */
+#define	R_386_32		1	/* Add symbol value. */
+#define	R_386_PC32		2	/* Add PC-relative symbol value. */
+#define	R_386_GOT32		3	/* Add PC-relative GOT offset. */
+#define	R_386_PLT32		4	/* Add PC-relative PLT offset. */
+#define	R_386_COPY		5	/* Copy data from shared object. */
+#define	R_386_GLOB_DAT		6	/* Set GOT entry to data address. */
+#define	R_386_JMP_SLOT		7	/* Set GOT entry to code address. */
+#define	R_386_RELATIVE		8	/* Add load address of shared object. */
+#define	R_386_GOTOFF		9	/* Add GOT-relative symbol address. */
+#define	R_386_GOTPC		10	/* Add PC-relative GOT table address. */
+#define	R_386_TLS_TPOFF		14	/* Negative offset in static TLS block */
+#define	R_386_TLS_IE		15	/* Absolute address of GOT for -ve static TLS */
+#define	R_386_TLS_GOTIE		16	/* GOT entry for negative static TLS block */
+#define	R_386_TLS_LE		17	/* Negative offset relative to static TLS */
+#define	R_386_TLS_GD		18	/* 32 bit offset to GOT (index,off) pair */
+#define	R_386_TLS_LDM		19	/* 32 bit offset to GOT (index,zero) pair */
+#define	R_386_TLS_GD_32		24	/* 32 bit offset to GOT (index,off) pair */
+#define	R_386_TLS_GD_PUSH	25	/* pushl instruction for Sun ABI GD sequence */
+#define	R_386_TLS_GD_CALL	26	/* call instruction for Sun ABI GD sequence */
+#define	R_386_TLS_GD_POP	27	/* popl instruction for Sun ABI GD sequence */
+#define	R_386_TLS_LDM_32	28	/* 32 bit offset to GOT (index,zero) pair */
+#define	R_386_TLS_LDM_PUSH	29	/* pushl instruction for Sun ABI LD sequence */
+#define	R_386_TLS_LDM_CALL	30	/* call instruction for Sun ABI LD sequence */
+#define	R_386_TLS_LDM_POP	31	/* popl instruction for Sun ABI LD sequence */
+#define	R_386_TLS_LDO_32	32	/* 32 bit offset from start of TLS block */
+#define	R_386_TLS_IE_32		33	/* 32 bit offset to GOT static TLS offset entry */
+#define	R_386_TLS_LE_32		34	/* 32 bit offset within static TLS block */
+#define	R_386_TLS_DTPMOD32	35	/* GOT entry containing TLS index */
+#define	R_386_TLS_DTPOFF32	36	/* GOT entry containing TLS offset */
+#define	R_386_TLS_TPOFF32	37	/* GOT entry of -ve static TLS offset */
+#define	R_386_IRELATIVE		42	/* PLT entry resolved indirectly at runtime */
+
+#define	R_AARCH64_NONE		0	/* No relocation */
+#define	R_AARCH64_ABS64		257	/* Absolute offset */
+#define	R_AARCH64_ABS32		258	/* Absolute, 32-bit overflow check */
+#define	R_AARCH64_ABS16		259	/* Absolute, 16-bit overflow check */
+#define	R_AARCH64_PREL64	260	/* PC relative */
+#define	R_AARCH64_PREL32	261	/* PC relative, 32-bit overflow check */
+#define	R_AARCH64_PREL16	262	/* PC relative, 16-bit overflow check */
+#define	R_AARCH64_COPY		1024	/* Copy data from shared object */
+#define	R_AARCH64_GLOB_DAT	1025	/* Set GOT entry to data address */
+#define	R_AARCH64_JUMP_SLOT	1026	/* Set GOT entry to code address */
+#define	R_AARCH64_RELATIVE 	1027	/* Add load address of shared object */
+#define	R_AARCH64_TLS_DTPREL64	1028
+#define	R_AARCH64_TLS_DTPMOD64	1029
+#define	R_AARCH64_TLS_TPREL64 	1030
+#define	R_AARCH64_TLSDESC 	1031	/* Identify the TLS descriptor */
+#define	R_AARCH64_IRELATIVE	1032
+
+#define	R_ARM_NONE		0	/* No relocation. */
+#define	R_ARM_PC24		1
+#define	R_ARM_ABS32		2
+#define	R_ARM_REL32		3
+#define	R_ARM_PC13		4
+#define	R_ARM_ABS16		5
+#define	R_ARM_ABS12		6
+#define	R_ARM_THM_ABS5		7
+#define	R_ARM_ABS8		8
+#define	R_ARM_SBREL32		9
+#define	R_ARM_THM_PC22		10
+#define	R_ARM_THM_PC8		11
+#define	R_ARM_AMP_VCALL9	12
+#define	R_ARM_SWI24		13
+#define	R_ARM_THM_SWI8		14
+#define	R_ARM_XPC25		15
+#define	R_ARM_THM_XPC22		16
+/* TLS relocations */
+#define	R_ARM_TLS_DTPMOD32	17	/* ID of module containing symbol */
+#define	R_ARM_TLS_DTPOFF32	18	/* Offset in TLS block */
+#define	R_ARM_TLS_TPOFF32	19	/* Offset in static TLS block */
+#define	R_ARM_COPY		20	/* Copy data from shared object. */
+#define	R_ARM_GLOB_DAT		21	/* Set GOT entry to data address. */
+#define	R_ARM_JUMP_SLOT		22	/* Set GOT entry to code address. */
+#define	R_ARM_RELATIVE		23	/* Add load address of shared object. */
+#define	R_ARM_GOTOFF		24	/* Add GOT-relative symbol address. */
+#define	R_ARM_GOTPC		25	/* Add PC-relative GOT table address. */
+#define	R_ARM_GOT32		26	/* Add PC-relative GOT offset. */
+#define	R_ARM_PLT32		27	/* Add PC-relative PLT offset. */
+#define	R_ARM_GNU_VTENTRY	100
+#define	R_ARM_GNU_VTINHERIT	101
+#define	R_ARM_RSBREL32		250
+#define	R_ARM_THM_RPC22		251
+#define	R_ARM_RREL32		252
+#define	R_ARM_RABS32		253
+#define	R_ARM_RPC24		254
+#define	R_ARM_RBASE		255
+
+/*	Name			Value	   Field	Calculation */
+#define	R_IA_64_NONE		0	/* None */
+#define	R_IA_64_IMM14		0x21	/* immediate14	S + A */
+#define	R_IA_64_IMM22		0x22	/* immediate22	S + A */
+#define	R_IA_64_IMM64		0x23	/* immediate64	S + A */
+#define	R_IA_64_DIR32MSB	0x24	/* word32 MSB	S + A */
+#define	R_IA_64_DIR32LSB	0x25	/* word32 LSB	S + A */
+#define	R_IA_64_DIR64MSB	0x26	/* word64 MSB	S + A */
+#define	R_IA_64_DIR64LSB	0x27	/* word64 LSB	S + A */
+#define	R_IA_64_GPREL22		0x2a	/* immediate22	@gprel(S + A) */
+#define	R_IA_64_GPREL64I	0x2b	/* immediate64	@gprel(S + A) */
+#define	R_IA_64_GPREL32MSB	0x2c	/* word32 MSB	@gprel(S + A) */
+#define	R_IA_64_GPREL32LSB	0x2d	/* word32 LSB	@gprel(S + A) */
+#define	R_IA_64_GPREL64MSB	0x2e	/* word64 MSB	@gprel(S + A) */
+#define	R_IA_64_GPREL64LSB	0x2f	/* word64 LSB	@gprel(S + A) */
+#define	R_IA_64_LTOFF22		0x32	/* immediate22	@ltoff(S + A) */
+#define	R_IA_64_LTOFF64I	0x33	/* immediate64	@ltoff(S + A) */
+#define	R_IA_64_PLTOFF22	0x3a	/* immediate22	@pltoff(S + A) */
+#define	R_IA_64_PLTOFF64I	0x3b	/* immediate64	@pltoff(S + A) */
+#define	R_IA_64_PLTOFF64MSB	0x3e	/* word64 MSB	@pltoff(S + A) */
+#define	R_IA_64_PLTOFF64LSB	0x3f	/* word64 LSB	@pltoff(S + A) */
+#define	R_IA_64_FPTR64I		0x43	/* immediate64	@fptr(S + A) */
+#define	R_IA_64_FPTR32MSB	0x44	/* word32 MSB	@fptr(S + A) */
+#define	R_IA_64_FPTR32LSB	0x45	/* word32 LSB	@fptr(S + A) */
+#define	R_IA_64_FPTR64MSB	0x46	/* word64 MSB	@fptr(S + A) */
+#define	R_IA_64_FPTR64LSB	0x47	/* word64 LSB	@fptr(S + A) */
+#define	R_IA_64_PCREL60B	0x48	/* immediate60 form1 S + A - P */
+#define	R_IA_64_PCREL21B	0x49	/* immediate21 form1 S + A - P */
+#define	R_IA_64_PCREL21M	0x4a	/* immediate21 form2 S + A - P */
+#define	R_IA_64_PCREL21F	0x4b	/* immediate21 form3 S + A - P */
+#define	R_IA_64_PCREL32MSB	0x4c	/* word32 MSB	S + A - P */
+#define	R_IA_64_PCREL32LSB	0x4d	/* word32 LSB	S + A - P */
+#define	R_IA_64_PCREL64MSB	0x4e	/* word64 MSB	S + A - P */
+#define	R_IA_64_PCREL64LSB	0x4f	/* word64 LSB	S + A - P */
+#define	R_IA_64_LTOFF_FPTR22	0x52	/* immediate22	@ltoff(@fptr(S + A)) */
+#define	R_IA_64_LTOFF_FPTR64I	0x53	/* immediate64	@ltoff(@fptr(S + A)) */
+#define	R_IA_64_LTOFF_FPTR32MSB	0x54	/* word32 MSB	@ltoff(@fptr(S + A)) */
+#define	R_IA_64_LTOFF_FPTR32LSB	0x55	/* word32 LSB	@ltoff(@fptr(S + A)) */
+#define	R_IA_64_LTOFF_FPTR64MSB	0x56	/* word64 MSB	@ltoff(@fptr(S + A)) */
+#define	R_IA_64_LTOFF_FPTR64LSB	0x57	/* word64 LSB	@ltoff(@fptr(S + A)) */
+#define	R_IA_64_SEGREL32MSB	0x5c	/* word32 MSB	@segrel(S + A) */
+#define	R_IA_64_SEGREL32LSB	0x5d	/* word32 LSB	@segrel(S + A) */
+#define	R_IA_64_SEGREL64MSB	0x5e	/* word64 MSB	@segrel(S + A) */
+#define	R_IA_64_SEGREL64LSB	0x5f	/* word64 LSB	@segrel(S + A) */
+#define	R_IA_64_SECREL32MSB	0x64	/* word32 MSB	@secrel(S + A) */
+#define	R_IA_64_SECREL32LSB	0x65	/* word32 LSB	@secrel(S + A) */
+#define	R_IA_64_SECREL64MSB	0x66	/* word64 MSB	@secrel(S + A) */
+#define	R_IA_64_SECREL64LSB	0x67	/* word64 LSB	@secrel(S + A) */
+#define	R_IA_64_REL32MSB	0x6c	/* word32 MSB	BD + A */
+#define	R_IA_64_REL32LSB	0x6d	/* word32 LSB	BD + A */
+#define	R_IA_64_REL64MSB	0x6e	/* word64 MSB	BD + A */
+#define	R_IA_64_REL64LSB	0x6f	/* word64 LSB	BD + A */
+#define	R_IA_64_LTV32MSB	0x74	/* word32 MSB	S + A */
+#define	R_IA_64_LTV32LSB	0x75	/* word32 LSB	S + A */
+#define	R_IA_64_LTV64MSB	0x76	/* word64 MSB	S + A */
+#define	R_IA_64_LTV64LSB	0x77	/* word64 LSB	S + A */
+#define	R_IA_64_PCREL21BI	0x79	/* immediate21 form1 S + A - P */
+#define	R_IA_64_PCREL22		0x7a	/* immediate22	S + A - P */
+#define	R_IA_64_PCREL64I	0x7b	/* immediate64	S + A - P */
+#define	R_IA_64_IPLTMSB		0x80	/* function descriptor MSB special */
+#define	R_IA_64_IPLTLSB		0x81	/* function descriptor LSB speciaal */
+#define	R_IA_64_SUB		0x85	/* immediate64	A - S */
+#define	R_IA_64_LTOFF22X	0x86	/* immediate22	special */
+#define	R_IA_64_LDXMOV		0x87	/* immediate22	special */
+#define	R_IA_64_TPREL14		0x91	/* imm14	@tprel(S + A) */
+#define	R_IA_64_TPREL22		0x92	/* imm22	@tprel(S + A) */
+#define	R_IA_64_TPREL64I	0x93	/* imm64	@tprel(S + A) */
+#define	R_IA_64_TPREL64MSB	0x96	/* word64 MSB	@tprel(S + A) */
+#define	R_IA_64_TPREL64LSB	0x97	/* word64 LSB	@tprel(S + A) */
+#define	R_IA_64_LTOFF_TPREL22	0x9a	/* imm22	@ltoff(@tprel(S+A)) */
+#define	R_IA_64_DTPMOD64MSB	0xa6	/* word64 MSB	@dtpmod(S + A) */
+#define	R_IA_64_DTPMOD64LSB	0xa7	/* word64 LSB	@dtpmod(S + A) */
+#define	R_IA_64_LTOFF_DTPMOD22	0xaa	/* imm22	@ltoff(@dtpmod(S+A)) */
+#define	R_IA_64_DTPREL14	0xb1	/* imm14	@dtprel(S + A) */
+#define	R_IA_64_DTPREL22	0xb2	/* imm22	@dtprel(S + A) */
+#define	R_IA_64_DTPREL64I	0xb3	/* imm64	@dtprel(S + A) */
+#define	R_IA_64_DTPREL32MSB	0xb4	/* word32 MSB	@dtprel(S + A) */
+#define	R_IA_64_DTPREL32LSB	0xb5	/* word32 LSB	@dtprel(S + A) */
+#define	R_IA_64_DTPREL64MSB	0xb6	/* word64 MSB	@dtprel(S + A) */
+#define	R_IA_64_DTPREL64LSB	0xb7	/* word64 LSB	@dtprel(S + A) */
+#define	R_IA_64_LTOFF_DTPREL22	0xba	/* imm22	@ltoff(@dtprel(S+A)) */
+
+#define	R_MIPS_NONE	0	/* No reloc */
+#define	R_MIPS_16	1	/* Direct 16 bit */
+#define	R_MIPS_32	2	/* Direct 32 bit */
+#define	R_MIPS_REL32	3	/* PC relative 32 bit */
+#define	R_MIPS_26	4	/* Direct 26 bit shifted */
+#define	R_MIPS_HI16	5	/* High 16 bit */
+#define	R_MIPS_LO16	6	/* Low 16 bit */
+#define	R_MIPS_GPREL16	7	/* GP relative 16 bit */
+#define	R_MIPS_LITERAL	8	/* 16 bit literal entry */
+#define	R_MIPS_GOT16	9	/* 16 bit GOT entry */
+#define	R_MIPS_PC16	10	/* PC relative 16 bit */
+#define	R_MIPS_CALL16	11	/* 16 bit GOT entry for function */
+#define	R_MIPS_GPREL32	12	/* GP relative 32 bit */
+#define	R_MIPS_64	18	/* Direct 64 bit */
+#define	R_MIPS_GOT_DISP	19
+#define	R_MIPS_GOT_PAGE	20
+#define	R_MIPS_GOT_OFST	21
+#define	R_MIPS_GOT_HI16	22	/* GOT HI 16 bit */
+#define	R_MIPS_GOT_LO16	23	/* GOT LO 16 bit */
+#define	R_MIPS_SUB	24
+#define	R_MIPS_CALLHI16 30	/* upper 16 bit GOT entry for function */
+#define	R_MIPS_CALLLO16 31	/* lower 16 bit GOT entry for function */
+#define	R_MIPS_JALR	37
+#define	R_MIPS_TLS_GD	42
+#define	R_MIPS_COPY	126
+#define	R_MIPS_JUMP_SLOT	127
+
+#define	R_PPC_NONE		0	/* No relocation. */
+#define	R_PPC_ADDR32		1
+#define	R_PPC_ADDR24		2
+#define	R_PPC_ADDR16		3
+#define	R_PPC_ADDR16_LO		4
+#define	R_PPC_ADDR16_HI		5
+#define	R_PPC_ADDR16_HA		6
+#define	R_PPC_ADDR14		7
+#define	R_PPC_ADDR14_BRTAKEN	8
+#define	R_PPC_ADDR14_BRNTAKEN	9
+#define	R_PPC_REL24		10
+#define	R_PPC_REL14		11
+#define	R_PPC_REL14_BRTAKEN	12
+#define	R_PPC_REL14_BRNTAKEN	13
+#define	R_PPC_GOT16		14
+#define	R_PPC_GOT16_LO		15
+#define	R_PPC_GOT16_HI		16
+#define	R_PPC_GOT16_HA		17
+#define	R_PPC_PLTREL24		18
+#define	R_PPC_COPY		19
+#define	R_PPC_GLOB_DAT		20
+#define	R_PPC_JMP_SLOT		21
+#define	R_PPC_RELATIVE		22
+#define	R_PPC_LOCAL24PC		23
+#define	R_PPC_UADDR32		24
+#define	R_PPC_UADDR16		25
+#define	R_PPC_REL32		26
+#define	R_PPC_PLT32		27
+#define	R_PPC_PLTREL32		28
+#define	R_PPC_PLT16_LO		29
+#define	R_PPC_PLT16_HI		30
+#define	R_PPC_PLT16_HA		31
+#define	R_PPC_SDAREL16		32
+#define	R_PPC_SECTOFF		33
+#define	R_PPC_SECTOFF_LO	34
+#define	R_PPC_SECTOFF_HI	35
+#define	R_PPC_SECTOFF_HA	36
 
-#define SYMINFO_BT_SELF 	0xffff	/* Symbol bound to self */
-#define SYMINFO_BT_PARENT	0xfffe	/* Symbol bound to parent */
-#define SYMINFO_BT_LOWRESERVE	0xff00	/* Beginning of reserved entries */
+/*
+ * 64-bit relocations
+ */
+#define	R_PPC64_ADDR64		38
+#define	R_PPC64_ADDR16_HIGHER	39
+#define	R_PPC64_ADDR16_HIGHERA	40
+#define	R_PPC64_ADDR16_HIGHEST	41
+#define	R_PPC64_ADDR16_HIGHESTA	42
+#define	R_PPC64_UADDR64		43
+#define	R_PPC64_REL64		44
+#define	R_PPC64_PLT64		45
+#define	R_PPC64_PLTREL64	46
+#define	R_PPC64_TOC16		47
+#define	R_PPC64_TOC16_LO	48
+#define	R_PPC64_TOC16_HI	49
+#define	R_PPC64_TOC16_HA	50
+#define	R_PPC64_TOC		51
+#define	R_PPC64_DTPMOD64	68
+#define	R_PPC64_TPREL64		73
+#define	R_PPC64_DTPREL64	78
 
-/* Possible bitmasks for si_flags.  */
+/*
+ * TLS relocations
+ */
+#define	R_PPC_TLS		67
+#define	R_PPC_DTPMOD32		68
+#define	R_PPC_TPREL16		69
+#define	R_PPC_TPREL16_LO	70
+#define	R_PPC_TPREL16_HI	71
+#define	R_PPC_TPREL16_HA	72
+#define	R_PPC_TPREL32		73
+#define	R_PPC_DTPREL16		74
+#define	R_PPC_DTPREL16_LO	75
+#define	R_PPC_DTPREL16_HI	76
+#define	R_PPC_DTPREL16_HA	77
+#define	R_PPC_DTPREL32		78
+#define	R_PPC_GOT_TLSGD16	79
+#define	R_PPC_GOT_TLSGD16_LO	80
+#define	R_PPC_GOT_TLSGD16_HI	81
+#define	R_PPC_GOT_TLSGD16_HA	82
+#define	R_PPC_GOT_TLSLD16	83
+#define	R_PPC_GOT_TLSLD16_LO	84
+#define	R_PPC_GOT_TLSLD16_HI	85
+#define	R_PPC_GOT_TLSLD16_HA	86
+#define	R_PPC_GOT_TPREL16	87
+#define	R_PPC_GOT_TPREL16_LO	88
+#define	R_PPC_GOT_TPREL16_HI	89
+#define	R_PPC_GOT_TPREL16_HA	90
 
-#define SYMINFO_FLG_DIRECT	0x0001	/* Direct bound symbol */
-#define SYMINFO_FLG_PASSTHRU	0x0002	/* Pass-thru symbol for translator */
-#define SYMINFO_FLG_COPY	0x0004	/* Symbol is a copy-reloc */
-#define SYMINFO_FLG_LAZYLOAD	0x0008	/* Symbol bound to object to be lazy loaded */
+/*
+ * The remaining relocs are from the Embedded ELF ABI, and are not in the
+ *  SVR4 ELF ABI.
+ */
 
-/* Syminfo version values.  */
+#define	R_PPC_EMB_NADDR32	101
+#define	R_PPC_EMB_NADDR16	102
+#define	R_PPC_EMB_NADDR16_LO	103
+#define	R_PPC_EMB_NADDR16_HI	104
+#define	R_PPC_EMB_NADDR16_HA	105
+#define	R_PPC_EMB_SDAI16	106
+#define	R_PPC_EMB_SDA2I16	107
+#define	R_PPC_EMB_SDA2REL	108
+#define	R_PPC_EMB_SDA21		109
+#define	R_PPC_EMB_MRKREF	110
+#define	R_PPC_EMB_RELSEC16	111
+#define	R_PPC_EMB_RELST_LO	112
+#define	R_PPC_EMB_RELST_HI	113
+#define	R_PPC_EMB_RELST_HA	114
+#define	R_PPC_EMB_BIT_FLD	115
+#define	R_PPC_EMB_RELSDA	116
 
-#define SYMINFO_NONE		0
-#define SYMINFO_CURRENT 	1
-#define SYMINFO_NUM		2
+/*
+ * RISC-V relocation types.
+ */
 
-/* Section Group Flags.	 */
+/* Relocation types used by the dynamic linker. */
+#define	R_RISCV_NONE		0
+#define	R_RISCV_32		1
+#define	R_RISCV_64		2
+#define	R_RISCV_RELATIVE	3
+#define	R_RISCV_COPY		4
+#define	R_RISCV_JUMP_SLOT	5
+#define	R_RISCV_TLS_DTPMOD32	6
+#define	R_RISCV_TLS_DTPMOD64	7
+#define	R_RISCV_TLS_DTPREL32	8
+#define	R_RISCV_TLS_DTPREL64	9
+#define	R_RISCV_TLS_TPREL32	10
+#define	R_RISCV_TLS_TPREL64	11
+
+/* Relocation types not used by the dynamic linker. */
+#define	R_RISCV_BRANCH		16
+#define	R_RISCV_JAL		17
+#define	R_RISCV_CALL		18
+#define	R_RISCV_CALL_PLT	19
+#define	R_RISCV_GOT_HI20	20
+#define	R_RISCV_TLS_GOT_HI20	21
+#define	R_RISCV_TLS_GD_HI20	22
+#define	R_RISCV_PCREL_HI20	23
+#define	R_RISCV_PCREL_LO12_I	24
+#define	R_RISCV_PCREL_LO12_S	25
+#define	R_RISCV_HI20		26
+#define	R_RISCV_LO12_I		27
+#define	R_RISCV_LO12_S		28
+#define	R_RISCV_TPREL_HI20	29
+#define	R_RISCV_TPREL_LO12_I	30
+#define	R_RISCV_TPREL_LO12_S	31
+#define	R_RISCV_TPREL_ADD	32
+#define	R_RISCV_ADD8		33
+#define	R_RISCV_ADD16		34
+#define	R_RISCV_ADD32		35
+#define	R_RISCV_ADD64		36
+#define	R_RISCV_SUB8		37
+#define	R_RISCV_SUB16		38
+#define	R_RISCV_SUB32		39
+#define	R_RISCV_SUB64		40
+#define	R_RISCV_GNU_VTINHERIT	41
+#define	R_RISCV_GNU_VTENTRY	42
+#define	R_RISCV_ALIGN		43
+#define	R_RISCV_RVC_BRANCH	44
+#define	R_RISCV_RVC_JUMP	45
+
+#define	R_SPARC_NONE		0
+#define	R_SPARC_8		1
+#define	R_SPARC_16		2
+#define	R_SPARC_32		3
+#define	R_SPARC_DISP8		4
+#define	R_SPARC_DISP16		5
+#define	R_SPARC_DISP32		6
+#define	R_SPARC_WDISP30		7
+#define	R_SPARC_WDISP22		8
+#define	R_SPARC_HI22		9
+#define	R_SPARC_22		10
+#define	R_SPARC_13		11
+#define	R_SPARC_LO10		12
+#define	R_SPARC_GOT10		13
+#define	R_SPARC_GOT13		14
+#define	R_SPARC_GOT22		15
+#define	R_SPARC_PC10		16
+#define	R_SPARC_PC22		17
+#define	R_SPARC_WPLT30		18
+#define	R_SPARC_COPY		19
+#define	R_SPARC_GLOB_DAT	20
+#define	R_SPARC_JMP_SLOT	21
+#define	R_SPARC_RELATIVE	22
+#define	R_SPARC_UA32		23
+#define	R_SPARC_PLT32		24
+#define	R_SPARC_HIPLT22		25
+#define	R_SPARC_LOPLT10		26
+#define	R_SPARC_PCPLT32		27
+#define	R_SPARC_PCPLT22		28
+#define	R_SPARC_PCPLT10		29
+#define	R_SPARC_10		30
+#define	R_SPARC_11		31
+#define	R_SPARC_64		32
+#define	R_SPARC_OLO10		33
+#define	R_SPARC_HH22		34
+#define	R_SPARC_HM10		35
+#define	R_SPARC_LM22		36
+#define	R_SPARC_PC_HH22		37
+#define	R_SPARC_PC_HM10		38
+#define	R_SPARC_PC_LM22		39
+#define	R_SPARC_WDISP16		40
+#define	R_SPARC_WDISP19		41
+#define	R_SPARC_GLOB_JMP	42
+#define	R_SPARC_7		43
+#define	R_SPARC_5		44
+#define	R_SPARC_6		45
+#define	R_SPARC_DISP64		46
+#define	R_SPARC_PLT64		47
+#define	R_SPARC_HIX22		48
+#define	R_SPARC_LOX10		49
+#define	R_SPARC_H44		50
+#define	R_SPARC_M44		51
+#define	R_SPARC_L44		52
+#define	R_SPARC_REGISTER	53
+#define	R_SPARC_UA64		54
+#define	R_SPARC_UA16		55
+#define	R_SPARC_TLS_GD_HI22	56
+#define	R_SPARC_TLS_GD_LO10	57
+#define	R_SPARC_TLS_GD_ADD	58
+#define	R_SPARC_TLS_GD_CALL	59
+#define	R_SPARC_TLS_LDM_HI22	60
+#define	R_SPARC_TLS_LDM_LO10	61
+#define	R_SPARC_TLS_LDM_ADD	62
+#define	R_SPARC_TLS_LDM_CALL	63
+#define	R_SPARC_TLS_LDO_HIX22	64
+#define	R_SPARC_TLS_LDO_LOX10	65
+#define	R_SPARC_TLS_LDO_ADD	66
+#define	R_SPARC_TLS_IE_HI22	67
+#define	R_SPARC_TLS_IE_LO10	68
+#define	R_SPARC_TLS_IE_LD	69
+#define	R_SPARC_TLS_IE_LDX	70
+#define	R_SPARC_TLS_IE_ADD	71
+#define	R_SPARC_TLS_LE_HIX22	72
+#define	R_SPARC_TLS_LE_LOX10	73
+#define	R_SPARC_TLS_DTPMOD32	74
+#define	R_SPARC_TLS_DTPMOD64	75
+#define	R_SPARC_TLS_DTPOFF32	76
+#define	R_SPARC_TLS_DTPOFF64	77
+#define	R_SPARC_TLS_TPOFF32	78
+#define	R_SPARC_TLS_TPOFF64	79
+
+#define	R_X86_64_NONE		0	/* No relocation. */
+#define	R_X86_64_64		1	/* Add 64 bit symbol value. */
+#define	R_X86_64_PC32		2	/* PC-relative 32 bit signed sym value. */
+#define	R_X86_64_GOT32		3	/* PC-relative 32 bit GOT offset. */
+#define	R_X86_64_PLT32		4	/* PC-relative 32 bit PLT offset. */
+#define	R_X86_64_COPY		5	/* Copy data from shared object. */
+#define	R_X86_64_GLOB_DAT	6	/* Set GOT entry to data address. */
+#define	R_X86_64_JMP_SLOT	7	/* Set GOT entry to code address. */
+#define	R_X86_64_RELATIVE	8	/* Add load address of shared object. */
+#define	R_X86_64_GOTPCREL	9	/* Add 32 bit signed pcrel offset to GOT. */
+#define	R_X86_64_32		10	/* Add 32 bit zero extended symbol value */
+#define	R_X86_64_32S		11	/* Add 32 bit sign extended symbol value */
+#define	R_X86_64_16		12	/* Add 16 bit zero extended symbol value */
+#define	R_X86_64_PC16		13	/* Add 16 bit signed extended pc relative symbol value */
+#define	R_X86_64_8		14	/* Add 8 bit zero extended symbol value */
+#define	R_X86_64_PC8		15	/* Add 8 bit signed extended pc relative symbol value */
+#define	R_X86_64_DTPMOD64	16	/* ID of module containing symbol */
+#define	R_X86_64_DTPOFF64	17	/* Offset in TLS block */
+#define	R_X86_64_TPOFF64	18	/* Offset in static TLS block */
+#define	R_X86_64_TLSGD		19	/* PC relative offset to GD GOT entry */
+#define	R_X86_64_TLSLD		20	/* PC relative offset to LD GOT entry */
+#define	R_X86_64_DTPOFF32	21	/* Offset in TLS block */
+#define	R_X86_64_GOTTPOFF	22	/* PC relative offset to IE GOT entry */
+#define	R_X86_64_TPOFF32	23	/* Offset in static TLS block */
+#define	R_X86_64_PC64		24	/* PC-relative 64 bit signed sym value. */
+#define	R_X86_64_GOTOFF64	25
+#define	R_X86_64_GOTPC32	26
+#define	R_X86_64_GOT64		27
+#define	R_X86_64_GOTPCREL64	28
+#define	R_X86_64_GOTPC64	29
+#define	R_X86_64_GOTPLT64	30
+#define	R_X86_64_PLTOFF64	31
+#define	R_X86_64_SIZE32		32
+#define	R_X86_64_SIZE64		33
+#define	R_X86_64_GOTPC32_TLSDESC 34
+#define	R_X86_64_TLSDESC_CALL	35
+#define	R_X86_64_TLSDESC	36
+#define	R_X86_64_IRELATIVE	37
 
-#define GRP_COMDAT		0x1	/* A COMDAT group */
 
 #endif /* !_SYS_ELF_COMMON_H_ */
diff --git a/sys/sys/elf_generic.h b/sys/sys/elf_generic.h
index 4d07fb848a..3b8cfc7322 100644
--- a/sys/sys/elf_generic.h
+++ b/sys/sys/elf_generic.h
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 1998 John D. Polstra.
  * All rights reserved.
  *
@@ -23,15 +25,13 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/sys/elf_generic.h,v 1.4 1999/08/28 00:51:42 peter Exp $
+ * $FreeBSD$
  */
 
 #ifndef _SYS_ELF_GENERIC_H_
-#define _SYS_ELF_GENERIC_H_
+#define	_SYS_ELF_GENERIC_H_ 1
 
-#ifndef _SYS_CDEFS_H_
 #include <sys/cdefs.h>
-#endif
 #include <machine/endian.h>
 
 /*
@@ -44,20 +44,20 @@
 #error "__ELF_WORD_SIZE must be defined as 32 or 64"
 #endif
 
-#define ELF_CLASS	__CONCAT(ELFCLASS,__ELF_WORD_SIZE)
+#define	ELF_CLASS	__CONCAT(ELFCLASS,__ELF_WORD_SIZE)
 
-#if _BYTE_ORDER == _LITTLE_ENDIAN
-#define ELF_DATA	ELFDATA2LSB
-#elif _BYTE_ORDER == _BIG_ENDIAN
-#define ELF_DATA	ELFDATA2MSB
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define	ELF_DATA	ELFDATA2LSB
+#elif BYTE_ORDER == BIG_ENDIAN
+#define	ELF_DATA	ELFDATA2MSB
 #else
 #error "Unknown byte order"
 #endif
 
-#define __elfN(x)       __CONCAT(__CONCAT(__CONCAT(elf,__ELF_WORD_SIZE),_),x)
-#define __ElfN(x)	__CONCAT(__CONCAT(__CONCAT(Elf,__ELF_WORD_SIZE),_),x)
-#define __ELFN(x)	__CONCAT(__CONCAT(__CONCAT(ELF,__ELF_WORD_SIZE),_),x)
-#define __ElfType(x)	typedef __ElfN(x) __CONCAT(Elf_,x)
+#define	__elfN(x)	__CONCAT(__CONCAT(__CONCAT(elf,__ELF_WORD_SIZE),_),x)
+#define	__ElfN(x)	__CONCAT(__CONCAT(__CONCAT(Elf,__ELF_WORD_SIZE),_),x)
+#define	__ELFN(x)	__CONCAT(__CONCAT(__CONCAT(ELF,__ELF_WORD_SIZE),_),x)
+#define	__ElfType(x)	typedef __ElfN(x) __CONCAT(Elf_,x)
 
 __ElfType(Addr);
 __ElfType(Half);
@@ -80,13 +80,15 @@ __ElfType(Versym);
 /* Non-standard ELF types. */
 __ElfType(Hashelt);
 __ElfType(Size);
+__ElfType(Ssize);
 
-#define ELF_R_SYM	__ELFN(R_SYM)
-#define ELF_R_TYPE	__ELFN(R_TYPE)
-#define ELF_R_INFO	__ELFN(R_INFO)
-#define ELF_ST_BIND	__ELFN(ST_BIND)
-#define ELF_ST_TYPE	__ELFN(ST_TYPE)
-#define ELF_ST_INFO	__ELFN(ST_INFO)
+#define	ELF_R_SYM	__ELFN(R_SYM)
+#define	ELF_R_TYPE	__ELFN(R_TYPE)
+#define	ELF_R_INFO	__ELFN(R_INFO)
+#define	ELF_ST_BIND	__ELFN(ST_BIND)
+#define	ELF_ST_TYPE	__ELFN(ST_TYPE)
+#define	ELF_ST_INFO	__ELFN(ST_INFO)
+#define	ELF_ST_VISIBILITY	__ELFN(ST_VISIBILITY)
 
 #else
 
-- 
2.18.0

