Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Dec 2019 13:20:15 +0000 (UTC)
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r355413 - in head: contrib/elftoolchain contrib/elftoolchain/addr2line contrib/elftoolchain/common contrib/elftoolchain/elfcopy contrib/elftoolchain/elfdump contrib/elftoolchain/libdwar...
Message-ID:  <201912051320.xB5DKFok073626@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: emaste
Date: Thu Dec  5 13:20:15 2019
New Revision: 355413
URL: https://svnweb.freebsd.org/changeset/base/355413

Log:
  Update ELF Tool Chain to upstream r3769
  
  This contains many small bugfixes and documentation improvements.
  
  Sponsored by:	The FreeBSD Foundation

Added:
  head/contrib/elftoolchain/.cirrus.yml
     - copied unchanged from r349544, vendor/elftoolchain/dist/.cirrus.yml
  head/contrib/elftoolchain/libelf/os.Linux.mk
     - copied unchanged from r349544, vendor/elftoolchain/dist/libelf/os.Linux.mk
Modified:
  head/contrib/elftoolchain/README.rst
  head/contrib/elftoolchain/addr2line/addr2line.c
  head/contrib/elftoolchain/common/elfdefinitions.h
  head/contrib/elftoolchain/common/native-elf-format
  head/contrib/elftoolchain/elfcopy/ascii.c
  head/contrib/elftoolchain/elfcopy/binary.c
  head/contrib/elftoolchain/elfcopy/elfcopy.h
  head/contrib/elftoolchain/elfcopy/main.c
  head/contrib/elftoolchain/elfcopy/sections.c
  head/contrib/elftoolchain/elfdump/elfdump.c
  head/contrib/elftoolchain/libdwarf/dwarf.h
  head/contrib/elftoolchain/libdwarf/dwarf_dump.c
  head/contrib/elftoolchain/libdwarf/libdwarf_attr.c
  head/contrib/elftoolchain/libdwarf/libdwarf_reloc.c
  head/contrib/elftoolchain/libelf/_libelf.h
  head/contrib/elftoolchain/libelf/_libelf_config.h
  head/contrib/elftoolchain/libelf/elf.3
  head/contrib/elftoolchain/libelf/elf_data.c
  head/contrib/elftoolchain/libelf/elf_end.c
  head/contrib/elftoolchain/libelf/elf_flagdata.3
  head/contrib/elftoolchain/libelf/elf_getdata.3
  head/contrib/elftoolchain/libelf/elf_getident.c
  head/contrib/elftoolchain/libelf/elf_next.3
  head/contrib/elftoolchain/libelf/elf_next.c
  head/contrib/elftoolchain/libelf/elf_open.3
  head/contrib/elftoolchain/libelf/elf_rand.c
  head/contrib/elftoolchain/libelf/elf_rawfile.c
  head/contrib/elftoolchain/libelf/elf_scn.c
  head/contrib/elftoolchain/libelf/elf_update.3
  head/contrib/elftoolchain/libelf/elf_update.c
  head/contrib/elftoolchain/libelf/gelf.3
  head/contrib/elftoolchain/libelf/gelf_cap.c
  head/contrib/elftoolchain/libelf/gelf_dyn.c
  head/contrib/elftoolchain/libelf/gelf_getcap.3
  head/contrib/elftoolchain/libelf/gelf_getdyn.3
  head/contrib/elftoolchain/libelf/gelf_getmove.3
  head/contrib/elftoolchain/libelf/gelf_getrel.3
  head/contrib/elftoolchain/libelf/gelf_getrela.3
  head/contrib/elftoolchain/libelf/gelf_getsym.3
  head/contrib/elftoolchain/libelf/gelf_getsyminfo.3
  head/contrib/elftoolchain/libelf/gelf_getsymshndx.3
  head/contrib/elftoolchain/libelf/gelf_move.c
  head/contrib/elftoolchain/libelf/gelf_newehdr.3
  head/contrib/elftoolchain/libelf/gelf_newphdr.3
  head/contrib/elftoolchain/libelf/gelf_rel.c
  head/contrib/elftoolchain/libelf/gelf_rela.c
  head/contrib/elftoolchain/libelf/gelf_sym.c
  head/contrib/elftoolchain/libelf/gelf_syminfo.c
  head/contrib/elftoolchain/libelf/gelf_symshndx.c
  head/contrib/elftoolchain/libelf/libelf_allocate.c
  head/contrib/elftoolchain/libelf/libelf_ar.c
  head/contrib/elftoolchain/libelf/libelf_convert.m4
  head/contrib/elftoolchain/libelf/libelf_data.c
  head/contrib/elftoolchain/libelf/libelf_ehdr.c
  head/contrib/elftoolchain/libelf/libelf_extended.c
  head/contrib/elftoolchain/libelf/libelf_memory.c
  head/contrib/elftoolchain/libelf/libelf_msize.m4
  head/contrib/elftoolchain/libelf/libelf_phdr.c
  head/contrib/elftoolchain/libelf/libelf_xlate.c
  head/contrib/elftoolchain/libelftc/elftc_bfd_find_target.3
  head/contrib/elftoolchain/libelftc/elftc_string_table.c
  head/contrib/elftoolchain/libelftc/elftc_string_table_create.3
  head/contrib/elftoolchain/libelftc/libelftc.h
  head/contrib/elftoolchain/libelftc/libelftc_bfdtarget.c
  head/contrib/elftoolchain/libelftc/make-toolchain-version
  head/contrib/elftoolchain/nm/nm.c
  head/contrib/elftoolchain/readelf/readelf.1
  head/contrib/elftoolchain/readelf/readelf.c
  head/lib/libelftc/elftc_version.c
Directory Properties:
  head/contrib/elftoolchain/   (props changed)
  head/contrib/elftoolchain/elfdump/   (props changed)

Copied: head/contrib/elftoolchain/.cirrus.yml (from r349544, vendor/elftoolchain/dist/.cirrus.yml)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/contrib/elftoolchain/.cirrus.yml	Thu Dec  5 13:20:15 2019	(r355413, copy of r349544, vendor/elftoolchain/dist/.cirrus.yml)
@@ -0,0 +1,22 @@
+freebsd_11_task:
+  freebsd_instance:
+    image: freebsd-11-2-release-amd64
+  install_script: pkg install -y git py27-yaml
+  script:
+    - fetch http://tetworks.opengroup.org/downloads/38/software/Sources/3.8/tet3.8-src.tar.gz
+    - tar -x -C test/tet -f tet3.8-src.tar.gz
+    - make
+
+debian_stable_task:
+  container:
+    image: debian:stable
+  setup_script:
+    - apt-get update
+    - apt-get install -y
+      binutils bison bmake curl flex g++ gcc git
+      libarchive-dev libbsd-dev libc6-dev libexpat1-dev lsb-release
+      m4 perl python-yaml sharutils zlib1g-dev
+  script:
+    - curl -O http://tetworks.opengroup.org/downloads/38/software/Sources/3.8/tet3.8-src.tar.gz
+    - tar -x -C test/tet -z -f tet3.8-src.tar.gz
+    - bmake

Modified: head/contrib/elftoolchain/README.rst
==============================================================================
--- head/contrib/elftoolchain/README.rst	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/README.rst	Thu Dec  5 13:20:15 2019	(r355413)
@@ -62,12 +62,12 @@ The project uses subversion_ for its version control s
 The subversion branch for the current set of sources may be accessed
 at the following URL::
 
-    https://elftoolchain.svn.sourceforge.net/svnroot/elftoolchain/trunk
+    https://sourceforge.net/p/elftoolchain/code/HEAD/tree/trunk/
 
 The project's source tree may be checked out from its repository by
 using the ``svn checkout`` command::
 
-    % svn checkout https://elftoolchain.svn.sourceforge.net/svnroot/elftoolchain/trunk
+    % svn checkout https://svn.code.sf.net/p/elftoolchain/code/trunk
 
 Checked-out sources may be kept upto-date by running ``svn update``
 inside the source directory::
@@ -105,10 +105,10 @@ The project's developers may be contacted using the ma
 Reporting Bugs
 --------------
 
-Please use our `Trac instance`_ for viewing existing bug reports and
+Please use our `bug tracker`_ for viewing existing bug reports and
 for submitting new bug reports.
 
-.. _`Trac instance`: http://sourceforge.net/apps/trac/elftoolchain/report
+.. _`bug tracker`: https://sourceforge.net/p/elftoolchain/tickets/
 
 
 Additional Information
@@ -119,7 +119,7 @@ website`_.
 
 .. _project website:  http://elftoolchain.sourceforge.net/
 
-.. $Id: README.rst 3656 2018-12-26 09:46:24Z jkoshy $
+.. $Id: README.rst 3677 2019-02-11 09:37:09Z jkoshy $
 
 .. Local Variables:
 .. mode: rst

Modified: head/contrib/elftoolchain/addr2line/addr2line.c
==============================================================================
--- head/contrib/elftoolchain/addr2line/addr2line.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/addr2line/addr2line.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -42,7 +42,7 @@
 #include "uthash.h"
 #include "_elftc.h"
 
-ELFTC_VCSID("$Id: addr2line.c 3544 2017-06-05 14:51:44Z emaste $");
+ELFTC_VCSID("$Id: addr2line.c 3499 2016-11-25 16:06:29Z emaste $");
 
 struct Func {
 	char *name;

Modified: head/contrib/elftoolchain/common/elfdefinitions.h
==============================================================================
--- head/contrib/elftoolchain/common/elfdefinitions.h	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/common/elfdefinitions.h	Thu Dec  5 13:20:15 2019	(r355413)
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: elfdefinitions.h 3515 2017-01-24 22:04:22Z emaste $
+ * $Id: elfdefinitions.h 3769 2019-06-29 15:15:02Z emaste $
  */
 
 /*
@@ -72,7 +72,39 @@ _ELF_DEFINE_DF(DF_TEXTREL,          0x4,			\
 _ELF_DEFINE_DF(DF_BIND_NOW,         0x8,			\
 	"process relocation entries at load time")		\
 _ELF_DEFINE_DF(DF_STATIC_TLS,       0x10,			\
-	"uses static thread-local storage")
+	"uses static thread-local storage")			\
+_ELF_DEFINE_DF(DF_1_BIND_NOW,       0x1,			\
+	"process relocation entries at load time")		\
+_ELF_DEFINE_DF(DF_1_GLOBAL,         0x2,			\
+	"unused")						\
+_ELF_DEFINE_DF(DF_1_GROUP,          0x4,			\
+	"object is a member of a group")			\
+_ELF_DEFINE_DF(DF_1_NODELETE,       0x8,			\
+	"object cannot be deleted from a process")		\
+_ELF_DEFINE_DF(DF_1_LOADFLTR,       0x10,			\
+	"immediate load filtees")				\
+_ELF_DEFINE_DF(DF_1_INITFIRST,      0x20,			\
+	"initialize object first")				\
+_ELF_DEFINE_DF(DF_1_NOOPEN,         0x40,			\
+	"disallow dlopen()")					\
+_ELF_DEFINE_DF(DF_1_ORIGIN,         0x80,			\
+	"object being loaded may refer to $ORIGIN")		\
+_ELF_DEFINE_DF(DF_1_DIRECT,         0x100,			\
+	"direct bindings enabled")				\
+_ELF_DEFINE_DF(DF_1_INTERPOSE,      0x400,			\
+	"object is interposer")					\
+_ELF_DEFINE_DF(DF_1_NODEFLIB,       0x800,			\
+	"ignore default library search path")			\
+_ELF_DEFINE_DF(DF_1_NODUMP,         0x1000,			\
+	"disallow dldump()")					\
+_ELF_DEFINE_DF(DF_1_CONFALT,        0x2000,			\
+	"object is a configuration alternative")		\
+_ELF_DEFINE_DF(DF_1_ENDFILTEE,      0x4000,			\
+	"filtee terminates filter search")			\
+_ELF_DEFINE_DF(DF_1_DISPRELDNE,     0x8000,			\
+	"displacement relocation done")				\
+_ELF_DEFINE_DF(DF_1_DISPRELPND,     0x10000,			\
+	"displacement relocation pending")
 #undef	_ELF_DEFINE_DF
 #define	_ELF_DEFINE_DF(N, V, DESCR)	N = V ,
 enum {
@@ -2464,7 +2496,10 @@ _ELF_DEFINE_NT(NT_PSTATUS,	10,	"Linux process status")
 _ELF_DEFINE_NT(NT_FPREGS,	12,	"Linux floating point regset")	\
 _ELF_DEFINE_NT(NT_PSINFO,	13,	"Linux process information")	\
 _ELF_DEFINE_NT(NT_LWPSTATUS,	16,	"Linux lwpstatus_t type")	\
-_ELF_DEFINE_NT(NT_LWPSINFO,	17,	"Linux lwpinfo_t type")
+_ELF_DEFINE_NT(NT_LWPSINFO,	17,	"Linux lwpinfo_t type")		\
+_ELF_DEFINE_NT(NT_FREEBSD_NOINIT_TAG,	2,	"FreeBSD no .init tag")	\
+_ELF_DEFINE_NT(NT_FREEBSD_ARCH_TAG,	3,	"FreeBSD arch tag")	\
+_ELF_DEFINE_NT(NT_FREEBSD_FEATURE_CTL,	4,	"FreeBSD feature control")
 
 #undef	_ELF_DEFINE_NT
 #define	_ELF_DEFINE_NT(N, V, DESCR)	N = V ,
@@ -2822,7 +2857,8 @@ typedef struct {
 
 #define ELF64_R_SYM(I)		((I) >> 32)
 #define ELF64_R_TYPE(I)		((I) & 0xFFFFFFFFUL)
-#define ELF64_R_INFO(S,T)	(((S) << 32) + ((T) & 0xFFFFFFFFUL))
+#define ELF64_R_INFO(S,T)	\
+	(((Elf64_Xword) (S) << 32) + ((T) & 0xFFFFFFFFUL))
 
 /*
  * Symbol versioning structures.

Modified: head/contrib/elftoolchain/common/native-elf-format
==============================================================================
--- head/contrib/elftoolchain/common/native-elf-format	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/common/native-elf-format	Thu Dec  5 13:20:15 2019	(r355413)
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $Id: native-elf-format 3650 2018-11-25 12:06:28Z jkoshy $
+# $Id: native-elf-format 3735 2019-04-25 19:44:47Z jkoshy $
 #
 # Find the native ELF format for a host platform by compiling a
 # test object and examining the resulting object.
@@ -37,6 +37,8 @@ $1 ~ "Machine:" {
             elfarch = "EM_MIPS";
         } else if (match($0, ".*[xX]86[-_]64")) {
             elfarch = "EM_X86_64";
+        } else if (match($0, "PowerPC64")) {
+            elfarch = "EM_PPC64";
         } else {
             elfarch = "unknown";
         }

Modified: head/contrib/elftoolchain/elfcopy/ascii.c
==============================================================================
--- head/contrib/elftoolchain/elfcopy/ascii.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/elfcopy/ascii.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -36,7 +36,7 @@
 
 #include "elfcopy.h"
 
-ELFTC_VCSID("$Id: ascii.c 3487 2016-08-24 18:12:08Z emaste $");
+ELFTC_VCSID("$Id: ascii.c 3757 2019-06-28 01:15:28Z emaste $");
 
 static void append_data(struct section *s, const void *buf, size_t sz);
 static char hex_digit(uint8_t n);

Modified: head/contrib/elftoolchain/elfcopy/binary.c
==============================================================================
--- head/contrib/elftoolchain/elfcopy/binary.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/elfcopy/binary.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -36,7 +36,7 @@
 
 #include "elfcopy.h"
 
-ELFTC_VCSID("$Id: binary.c 3611 2018-04-16 21:35:18Z jkoshy $");
+ELFTC_VCSID("$Id: binary.c 3757 2019-06-28 01:15:28Z emaste $");
 
 /*
  * Convert ELF object to `binary'. Sections with SHF_ALLOC flag set

Modified: head/contrib/elftoolchain/elfcopy/elfcopy.h
==============================================================================
--- head/contrib/elftoolchain/elfcopy/elfcopy.h	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/elfcopy/elfcopy.h	Thu Dec  5 13:20:15 2019	(r355413)
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: elfcopy.h 3615 2018-05-17 04:12:24Z kaiwang27 $
+ * $Id: elfcopy.h 3757 2019-06-28 01:15:28Z emaste $
  */
 
 #include <sys/queue.h>

Modified: head/contrib/elftoolchain/elfcopy/main.c
==============================================================================
--- head/contrib/elftoolchain/elfcopy/main.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/elfcopy/main.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -39,7 +39,7 @@
 
 #include "elfcopy.h"
 
-ELFTC_VCSID("$Id: main.c 3577 2017-09-14 02:19:42Z emaste $");
+ELFTC_VCSID("$Id: main.c 3757 2019-06-28 01:15:28Z emaste $");
 
 enum options
 {

Modified: head/contrib/elftoolchain/elfcopy/sections.c
==============================================================================
--- head/contrib/elftoolchain/elfcopy/sections.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/elfcopy/sections.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -34,7 +34,7 @@
 
 #include "elfcopy.h"
 
-ELFTC_VCSID("$Id: sections.c 3646 2018-10-27 02:25:39Z emaste $");
+ELFTC_VCSID("$Id: sections.c 3758 2019-06-28 01:16:50Z emaste $");
 
 static void	add_gnu_debuglink(struct elfcopy *ecp);
 static uint32_t calc_crc32(const char *p, size_t len, uint32_t crc);

Modified: head/contrib/elftoolchain/elfdump/elfdump.c
==============================================================================
--- head/contrib/elftoolchain/elfdump/elfdump.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/elfdump/elfdump.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -50,7 +50,7 @@
 
 #include "_elftc.h"
 
-ELFTC_VCSID("$Id: elfdump.c 3584 2017-11-05 20:51:43Z jkoshy $");
+ELFTC_VCSID("$Id: elfdump.c 3762 2019-06-28 21:06:24Z emaste $");
 
 #if defined(ELFTC_NEED_ELF_NOTE_DEFINITION)
 #include "native-elf-format.h"

Modified: head/contrib/elftoolchain/libdwarf/dwarf.h
==============================================================================
--- head/contrib/elftoolchain/libdwarf/dwarf.h	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libdwarf/dwarf.h	Thu Dec  5 13:20:15 2019	(r355413)
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: dwarf.h 3494 2016-09-20 17:16:13Z emaste $
+ * $Id: dwarf.h 3749 2019-06-28 01:10:44Z emaste $
  */
 
 #ifndef	_DWARF_H_

Modified: head/contrib/elftoolchain/libdwarf/dwarf_dump.c
==============================================================================
--- head/contrib/elftoolchain/libdwarf/dwarf_dump.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libdwarf/dwarf_dump.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -27,7 +27,7 @@
 
 #include "_libdwarf.h"
 
-ELFTC_VCSID("$Id: dwarf_dump.c 3494 2016-09-20 17:16:13Z emaste $");
+ELFTC_VCSID("$Id: dwarf_dump.c 3749 2019-06-28 01:10:44Z emaste $");
 
 int
 dwarf_get_ACCESS_name(unsigned access, const char **s)
@@ -605,7 +605,7 @@ dwarf_get_DS_name(unsigned ds, const char **s)
 	case DW_DS_leading_separate:
 		*s = "DW_DS_leading_separate"; break;
 	case DW_DS_trailing_separate:
-		*s = "DW_DS_trailing_separate";
+		*s = "DW_DS_trailing_separate"; break;
 	default:
 		return (DW_DLV_NO_ENTRY);
 	}

Modified: head/contrib/elftoolchain/libdwarf/libdwarf_attr.c
==============================================================================
--- head/contrib/elftoolchain/libdwarf/libdwarf_attr.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libdwarf/libdwarf_attr.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -27,7 +27,7 @@
 
 #include "_libdwarf.h"
 
-ELFTC_VCSID("$Id: libdwarf_attr.c 3064 2014-06-06 19:35:55Z kaiwang27 $");
+ELFTC_VCSID("$Id: libdwarf_attr.c 3748 2019-06-28 01:11:13Z emaste $");
 
 int
 _dwarf_attr_alloc(Dwarf_Die die, Dwarf_Attribute *atp, Dwarf_Error *error)

Modified: head/contrib/elftoolchain/libdwarf/libdwarf_reloc.c
==============================================================================
--- head/contrib/elftoolchain/libdwarf/libdwarf_reloc.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libdwarf/libdwarf_reloc.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -26,7 +26,7 @@
 
 #include "_libdwarf.h"
 
-ELFTC_VCSID("$Id: libdwarf_reloc.c 3578 2017-09-14 02:21:28Z emaste $");
+ELFTC_VCSID("$Id: libdwarf_reloc.c 3741 2019-06-07 06:32:01Z jkoshy $");
 
 Dwarf_Unsigned
 _dwarf_get_reloc_type(Dwarf_P_Debug dbg, int is64)

Modified: head/contrib/elftoolchain/libelf/_libelf.h
==============================================================================
--- head/contrib/elftoolchain/libelf/_libelf.h	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/_libelf.h	Thu Dec  5 13:20:15 2019	(r355413)
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: _libelf.h 3632 2018-10-10 21:12:43Z jkoshy $
+ * $Id: _libelf.h 3738 2019-05-05 21:49:06Z jkoshy $
  */
 
 #ifndef	__LIBELF_H_
@@ -94,7 +94,7 @@ struct _Elf {
 	Elf_Kind	e_kind;		/* ELF_K_* */
 	Elf		*e_parent; 	/* non-NULL for archive members */
 	unsigned char	*e_rawfile;	/* uninterpreted bytes */
-	size_t		e_rawsize;	/* size of uninterpreted bytes */
+	off_t		e_rawsize;	/* size of uninterpreted bytes */
 	unsigned int	e_version;	/* file version */
 
 	/*
@@ -233,7 +233,7 @@ Elf	*_libelf_open_object(int _fd, Elf_Cmd _c, int _rep
 Elf64_Xword _libelf_mips64el_r_info_tof(Elf64_Xword r_info);
 Elf64_Xword _libelf_mips64el_r_info_tom(Elf64_Xword r_info);
 struct _Libelf_Data *_libelf_release_data(struct _Libelf_Data *_d);
-Elf	*_libelf_release_elf(Elf *_e);
+void	_libelf_release_elf(Elf *_e);
 Elf_Scn	*_libelf_release_scn(Elf_Scn *_s);
 int	_libelf_setphnum(Elf *_e, void *_eh, int _elfclass, size_t _phnum);
 int	_libelf_setshnum(Elf *_e, void *_eh, int _elfclass, size_t _shnum);

Modified: head/contrib/elftoolchain/libelf/_libelf_config.h
==============================================================================
--- head/contrib/elftoolchain/libelf/_libelf_config.h	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/_libelf_config.h	Thu Dec  5 13:20:15 2019	(r355413)
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: _libelf_config.h 3566 2017-08-31 02:28:40Z emaste $
+ * $Id: _libelf_config.h 3764 2019-06-28 21:44:46Z emaste $
  */
 
 #if defined(__APPLE__) || defined(__DragonFly__)
@@ -98,6 +98,12 @@
 #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(__riscv64)
 
 #define	LIBELF_ARCH		EM_RISCV
 #define	LIBELF_BYTEORDER	ELFDATA2LSB

Modified: head/contrib/elftoolchain/libelf/elf.3
==============================================================================
--- head/contrib/elftoolchain/libelf/elf.3	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/elf.3	Thu Dec  5 13:20:15 2019	(r355413)
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2006-2008,2011 Joseph Koshy.  All rights reserved.
+.\" Copyright (c) 2006-2008,2011,2019 Joseph Koshy.  All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
 .\" modification, are permitted provided that the following conditions
@@ -21,9 +21,9 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $Id: elf.3 3643 2018-10-14 21:09:24Z jkoshy $
+.\" $Id: elf.3 3743 2019-06-12 19:36:30Z jkoshy $
 .\"
-.Dd October 10, 2018
+.Dd June 12, 2019
 .Dt ELF 3
 .Os
 .Sh NAME
@@ -266,36 +266,43 @@ The operating version for the data in this buffer.
 .El
 .Pp
 .Vt Elf_Data
-descriptors are usually associated with
+descriptors are usually used in conjunction 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.
+descriptors represent sections in an ELF object.
+These descriptors are opaque and contain no application modifiable
+fields.
 .Pp
-They are retrieved using the
+The
+.Vt Elf_Scn
+descriptor for a specific section in an ELF object can be
+retrieved using the
 .Fn elf_getscn
 function.
-An application may iterate through the existing sections of an ELF
-object using the
+The sections contained in an ELF object can be traversed using the
 .Fn elf_nextscn
 function.
-New sections may be allocated using the
+New sections are allocated using the
 .Fn elf_newscn
 function.
 .Pp
 The
-.Vt Elf_Scn
-descriptor is opaque and contains no application modifiable fields.
+.Vt Elf_Data
+descriptors associated with a given section can be retrieved
+using the
+.Fn elf_getdata
+function.
+New data descriptors can be added to a section
+descriptor using the
+.Fn elf_newdata
+function.
+The untranslated
+.Dq file
+representation of data in a section can be retrieved using the
+.Fn elf_rawdata
+function.
 .El
 .Ss Supported Elf Types
 The following ELF datatypes are supported by the library.
@@ -608,8 +615,11 @@ descriptor itself.
 .Xr ar 5 ,
 .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
+The original
+.Nm
+API was developed for
+.At V .
+The current implementation of the API appeared in
 .Fx 7.0 .
 .Sh AUTHORS
 The ELF library was written by

Modified: head/contrib/elftoolchain/libelf/elf_data.c
==============================================================================
--- head/contrib/elftoolchain/libelf/elf_data.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/elf_data.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -32,7 +32,7 @@
 
 #include "_libelf.h"
 
-ELFTC_VCSID("$Id: elf_data.c 3632 2018-10-10 21:12:43Z jkoshy $");
+ELFTC_VCSID("$Id: elf_data.c 3732 2019-04-22 11:08:38Z jkoshy $");
 
 Elf_Data *
 elf_getdata(Elf_Scn *s, Elf_Data *ed)
@@ -42,7 +42,7 @@ elf_getdata(Elf_Scn *s, Elf_Data *ed)
 	int elfclass, elftype;
 	size_t count, fsz, msz;
 	struct _Libelf_Data *d;
-	uint64_t sh_align, sh_offset, sh_size;
+	uint64_t sh_align, sh_offset, sh_size, raw_size;
 	_libelf_translator_function *xlate;
 
 	d = (struct _Libelf_Data *) ed;
@@ -59,7 +59,8 @@ elf_getdata(Elf_Scn *s, Elf_Data *ed)
 		return (&d->d_data);
 
 	if (d != NULL)
-		return (&STAILQ_NEXT(d, d_next)->d_data);
+		return (STAILQ_NEXT(d, d_next) ?
+		    &STAILQ_NEXT(d, d_next)->d_data : NULL);
 
 	if (e->e_rawfile == NULL) {
 		/*
@@ -91,9 +92,10 @@ elf_getdata(Elf_Scn *s, Elf_Data *ed)
 		return (NULL);
 	}
 
+	raw_size = (uint64_t) e->e_rawsize;
 	if ((elftype = _libelf_xlate_shtype(sh_type)) < ELF_T_FIRST ||
 	    elftype > ELF_T_LAST || (sh_type != SHT_NOBITS &&
-	    (sh_offset > e->e_rawsize || sh_size > e->e_rawsize - sh_offset))) {
+	    (sh_offset > raw_size || sh_size > raw_size - sh_offset))) {
 		LIBELF_SET_ERROR(SECTION, 0);
 		return (NULL);
 	}
@@ -116,7 +118,8 @@ elf_getdata(Elf_Scn *s, Elf_Data *ed)
 
 	count = (size_t) (sh_size / fsz);
 
-	msz = _libelf_msize(elftype, elfclass, e->e_version);
+	if ((msz = _libelf_msize(elftype, elfclass, e->e_version)) == 0)
+		return (NULL);
 
 	if (count > 0 && msz > SIZE_MAX / count) {
 		LIBELF_SET_ERROR(RANGE, 0);
@@ -215,7 +218,7 @@ elf_rawdata(Elf_Scn *s, Elf_Data *ed)
 	int elf_class;
 	uint32_t sh_type;
 	struct _Libelf_Data *d;
-	uint64_t sh_align, sh_offset, sh_size;
+	uint64_t sh_align, sh_offset, sh_size, raw_size;
 
 	if (s == NULL || (e = s->s_elf) == NULL || e->e_rawfile == NULL) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
@@ -253,8 +256,9 @@ elf_rawdata(Elf_Scn *s, Elf_Data *ed)
 		return (NULL);
 	}
 
+	raw_size = (uint64_t) e->e_rawsize;
 	if (sh_type != SHT_NOBITS &&
-	    (sh_offset > e->e_rawsize || sh_size > e->e_rawsize - sh_offset)) {
+	    (sh_offset > raw_size || sh_size > raw_size - sh_offset)) {
 		LIBELF_SET_ERROR(SECTION, 0);
 		return (NULL);
 	}

Modified: head/contrib/elftoolchain/libelf/elf_end.c
==============================================================================
--- head/contrib/elftoolchain/libelf/elf_end.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/elf_end.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -34,7 +34,7 @@
 #include <sys/mman.h>
 #endif
 
-ELFTC_VCSID("$Id: elf_end.c 3174 2015-03-27 17:13:41Z emaste $");
+ELFTC_VCSID("$Id: elf_end.c 3738 2019-05-05 21:49:06Z jkoshy $");
 
 int
 elf_end(Elf *e)
@@ -80,14 +80,14 @@ elf_end(Elf *e)
 				free(e->e_rawfile);
 #if	ELFTC_HAVE_MMAP
 			else if (e->e_flags & LIBELF_F_RAWFILE_MMAP)
-				(void) munmap(e->e_rawfile, e->e_rawsize);
+				(void) munmap(e->e_rawfile, (size_t) e->e_rawsize);
 #endif
 		}
 
 		sv = e;
 		if ((e = e->e_parent) != NULL)
 			e->e_u.e_ar.e_nchildren--;
-		sv = _libelf_release_elf(sv);
+		_libelf_release_elf(sv);
 	}
 
 	return (0);

Modified: head/contrib/elftoolchain/libelf/elf_flagdata.3
==============================================================================
--- head/contrib/elftoolchain/libelf/elf_flagdata.3	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/elf_flagdata.3	Thu Dec  5 13:20:15 2019	(r355413)
@@ -21,9 +21,9 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $Id: elf_flagdata.3 3639 2018-10-14 14:07:02Z jkoshy $
+.\" $Id: elf_flagdata.3 3743 2019-06-12 19:36:30Z jkoshy $
 .\"
-.Dd December 3, 2011
+.Dd June 12, 2019
 .Dt ELF_FLAGDATA 3
 .Os
 .Sh NAME
@@ -34,7 +34,7 @@
 .Nm elf_flagphdr ,
 .Nm elf_flagscn ,
 .Nm elf_flagshdr
-.Nd manipulate flags associated with ELF(3) data structures
+.Nd manipulate flags associated with ELF data structures
 .Sh LIBRARY
 .Lb libelf
 .Sh SYNOPSIS
@@ -65,7 +65,9 @@ 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:
+functions in the
+.Xr elf 3
+API set:
 .Bl -bullet -compact
 .It
 Argument
@@ -175,7 +177,9 @@ function and the
 .Dv ELF_F_ARCHIVE
 and
 .Dv ELF_F_ARCHIVE_SYSV
-flags are an extension to the ELF(3) API.
+flags are an extension to the
+.Xr elf 3
+API.
 .Sh ERRORS
 These functions may fail with the following errors:
 .Bl -tag -width "[ELF_E_RESOURCE]"

Modified: head/contrib/elftoolchain/libelf/elf_getdata.3
==============================================================================
--- head/contrib/elftoolchain/libelf/elf_getdata.3	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/elf_getdata.3	Thu Dec  5 13:20:15 2019	(r355413)
@@ -21,9 +21,9 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $Id: elf_getdata.3 3643 2018-10-14 21:09:24Z jkoshy $
+.\" $Id: elf_getdata.3 3734 2019-04-22 14:10:49Z jkoshy $
 .\"
-.Dd January 26, 2011
+.Dd April 22, 2019
 .Dt ELF_GETDATA 3
 .Os
 .Sh NAME
@@ -214,7 +214,12 @@ is incorrect.
 .It Bq Er ELF_E_UNIMPL
 The section type associated with section
 .Ar scn
-is currently unsupported by the library.
+is not supported.
+.It Bq Er ELF_E_VERSION
+Section
+.Ar scn
+was associated with an ELF object with an unsupported
+version.
 .El
 .Sh SEE ALSO
 .Xr elf 3 ,

Modified: head/contrib/elftoolchain/libelf/elf_getident.c
==============================================================================
--- head/contrib/elftoolchain/libelf/elf_getident.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/elf_getident.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -30,7 +30,7 @@
 
 #include "_libelf.h"
 
-ELFTC_VCSID("$Id: elf_getident.c 3174 2015-03-27 17:13:41Z emaste $");
+ELFTC_VCSID("$Id: elf_getident.c 3712 2019-03-16 22:23:34Z jkoshy $");
 
 char *
 elf_getident(Elf *e, size_t *sz)
@@ -54,7 +54,7 @@ elf_getident(Elf *e, size_t *sz)
 		else if (e->e_kind == ELF_K_ELF)
 			*sz = EI_NIDENT;
 		else
-			*sz = e->e_rawsize;
+			*sz = (size_t) e->e_rawsize;
 	}
 
 	return ((char *) e->e_rawfile);

Modified: head/contrib/elftoolchain/libelf/elf_next.3
==============================================================================
--- head/contrib/elftoolchain/libelf/elf_next.3	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/elf_next.3	Thu Dec  5 13:20:15 2019	(r355413)
@@ -21,9 +21,9 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $Id: elf_next.3 3639 2018-10-14 14:07:02Z jkoshy $
+.\" $Id: elf_next.3 3698 2019-02-28 06:34:42Z jkoshy $
 .\"
-.Dd June 17, 2006
+.Dd February 27, 2019
 .Dt ELF_NEXT 3
 .Os
 .Sh NAME
@@ -88,6 +88,9 @@ Argument
 was not associated with a containing
 .Xr ar 1
 archive.
+.It Bq Er ELF_E_ARGUMENT
+An error was encountered while parsing the archive containing argument
+.Ar elf .
 .El
 .Sh SEE ALSO
 .Xr elf 3 ,

Modified: head/contrib/elftoolchain/libelf/elf_next.c
==============================================================================
--- head/contrib/elftoolchain/libelf/elf_next.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/elf_next.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -30,7 +30,7 @@
 
 #include "_libelf.h"
 
-ELFTC_VCSID("$Id: elf_next.c 3174 2015-03-27 17:13:41Z emaste $");
+ELFTC_VCSID("$Id: elf_next.c 3710 2019-03-12 09:42:35Z jkoshy $");
 
 Elf_Cmd
 elf_next(Elf *e)
@@ -59,6 +59,20 @@ elf_next(Elf *e)
 	 */
 	parent->e_u.e_ar.e_next = (next >= (off_t) parent->e_rawsize) ?
 	    (off_t) 0 : next;
+
+	/*
+	 * Return an error if the 'e_next' field falls outside the current
+	 * file.
+	 *
+	 * This check is performed after updating the parent descriptor's
+	 * 'e_next' field so that the next call to elf_begin(3) will terminate
+	 * traversal of a too-small archive even if client code forgets to
+	 * check the return value from elf_next(3).
+	 */
+	if (next > (off_t) parent->e_rawsize) {
+		LIBELF_SET_ERROR(ARGUMENT, 0);
+		return (ELF_C_NULL);
+	}
 
 	return (ELF_C_READ);
 }

Modified: head/contrib/elftoolchain/libelf/elf_open.3
==============================================================================
--- head/contrib/elftoolchain/libelf/elf_open.3	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/elf_open.3	Thu Dec  5 13:20:15 2019	(r355413)
@@ -21,9 +21,9 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $Id: elf_open.3 3643 2018-10-14 21:09:24Z jkoshy $
+.\" $Id: elf_open.3 3743 2019-06-12 19:36:30Z jkoshy $
 .\"
-.Dd May 31, 2012
+.Dd June 12, 2019
 .Dt ELF_OPEN 3
 .Os
 .Sh NAME
@@ -43,7 +43,9 @@ The functions
 .Fn elf_open
 and
 .Fn elf_openmemory
-are extensions to the ELF(3) API, for the internal use of the
+are extensions to the
+.Xr elf 3
+API, for the internal use of the
 Elftoolchain project.
 Portable applications should not use these functions.
 .Pp
@@ -71,7 +73,9 @@ specifies the size of the memory area in bytes.
 The function returns a pointer to a ELF descriptor if successful, or
 NULL if an error occurred.
 .Sh COMPATIBILITY
-These functions are non-standard extensions to the ELF(3) API set.
+These functions are non-standard extensions to the
+.Xr elf 3
+API set.
 .Pp
 The behavior of these functions differs from their counterparts
 .Xr elf_begin 3

Modified: head/contrib/elftoolchain/libelf/elf_rand.c
==============================================================================
--- head/contrib/elftoolchain/libelf/elf_rand.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/elf_rand.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -29,16 +29,25 @@
 
 #include "_libelf.h"
 
-ELFTC_VCSID("$Id: elf_rand.c 3174 2015-03-27 17:13:41Z emaste $");
+ELFTC_VCSID("$Id: elf_rand.c 3716 2019-03-18 22:01:01Z jkoshy $");
 
 off_t
 elf_rand(Elf *ar, off_t offset)
 {
 	struct ar_hdr *arh;
+	off_t offset_of_member;
 
 	if (ar == NULL || ar->e_kind != ELF_K_AR ||
 	    (offset & 1) || offset < SARMAG ||
-	    (size_t) offset + sizeof(struct ar_hdr) >= ar->e_rawsize) {
+	    offset >= ar->e_rawsize) {
+		LIBELF_SET_ERROR(ARGUMENT, 0);
+		return 0;
+	}
+
+	offset_of_member = offset + (off_t) sizeof(struct ar_hdr);
+
+	if (offset_of_member <= 0 || /* Numeric overflow. */
+	    offset_of_member >= ar->e_rawsize) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return 0;
 	}

Modified: head/contrib/elftoolchain/libelf/elf_rawfile.c
==============================================================================
--- head/contrib/elftoolchain/libelf/elf_rawfile.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/elf_rawfile.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -28,15 +28,13 @@
 
 #include "_libelf.h"
 
-ELFTC_VCSID("$Id: elf_rawfile.c 3174 2015-03-27 17:13:41Z emaste $");
+ELFTC_VCSID("$Id: elf_rawfile.c 3712 2019-03-16 22:23:34Z jkoshy $");
 
 char *
 elf_rawfile(Elf *e, size_t *sz)
 {
-	size_t size;
 	unsigned char *ptr;
 
-	size = e ? e->e_rawsize : 0;
 	ptr = NULL;
 
 	if (e == NULL)
@@ -45,7 +43,7 @@ elf_rawfile(Elf *e, size_t *sz)
 		LIBELF_SET_ERROR(SEQUENCE, 0);
 
 	if (sz)
-		*sz = size;
+		*sz = e ? (size_t) e->e_rawsize : 0;
 
 	return ((char *) ptr);
 }

Modified: head/contrib/elftoolchain/libelf/elf_scn.c
==============================================================================
--- head/contrib/elftoolchain/libelf/elf_scn.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/elf_scn.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -36,7 +36,7 @@
 
 #include "_libelf.h"
 
-ELFTC_VCSID("$Id: elf_scn.c 3632 2018-10-10 21:12:43Z jkoshy $");
+ELFTC_VCSID("$Id: elf_scn.c 3712 2019-03-16 22:23:34Z jkoshy $");
 
 static int
 elfscn_cmp(struct _Elf_Scn *s1, struct _Elf_Scn *s2)
@@ -71,10 +71,11 @@ _libelf_load_section_headers(Elf *e, void *ehdr)
 	assert((e->e_flags & LIBELF_F_SHDRS_LOADED) == 0);
 
 #define	CHECK_EHDR(E,EH)	do {				\
-		if (shoff > e->e_rawsize ||			\
+		uintmax_t rawsize = (uintmax_t) e->e_rawsize;	\
+		if (shoff > (uintmax_t) e->e_rawsize ||		\
 		    fsz != (EH)->e_shentsize ||			\
 		    shnum > SIZE_MAX / fsz ||			\
-		    fsz * shnum > e->e_rawsize - shoff) {	\
+		    fsz * shnum > rawsize - shoff) {		\
 			LIBELF_SET_ERROR(HEADER, 0);		\
 			return (0);				\
 		}						\

Modified: head/contrib/elftoolchain/libelf/elf_update.3
==============================================================================
--- head/contrib/elftoolchain/libelf/elf_update.3	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/elf_update.3	Thu Dec  5 13:20:15 2019	(r355413)
@@ -21,9 +21,9 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $Id: elf_update.3 3639 2018-10-14 14:07:02Z jkoshy $
+.\" $Id: elf_update.3 3734 2019-04-22 14:10:49Z jkoshy $
 .\"
-.Dd August 14, 2011
+.Dd April 22, 2019
 .Dt ELF_UPDATE 3
 .Os
 .Sh NAME
@@ -345,6 +345,10 @@ operation was requested after a prior call to
 disassociated the ELF descriptor
 .Ar elf
 from its underlying file.
+.It Bq Er ELF_E_UNIMPL
+Argument
+.Ar elf
+contained a section with an unsupported ELF type.
 .It Bq Er ELF_E_VERSION
 Argument
 .Ar elf

Modified: head/contrib/elftoolchain/libelf/elf_update.c
==============================================================================
--- head/contrib/elftoolchain/libelf/elf_update.c	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/elf_update.c	Thu Dec  5 13:20:15 2019	(r355413)
@@ -41,7 +41,7 @@
 #include <sys/mman.h>
 #endif
 
-ELFTC_VCSID("$Id: elf_update.c 3632 2018-10-10 21:12:43Z jkoshy $");
+ELFTC_VCSID("$Id: elf_update.c 3763 2019-06-28 21:43:27Z emaste $");
 
 /*
  * Layout strategy:
@@ -142,7 +142,7 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, of
 	assert(sh_type != SHT_NULL && sh_type != SHT_NOBITS);
 
 	elftype = _libelf_xlate_shtype(sh_type);
-	if (elftype > ELF_T_LAST) {
+	if (elftype < ELF_T_FIRST || elftype > ELF_T_LAST) {
 		LIBELF_SET_ERROR(SECTION, 0);
 		return (0);
 	}
@@ -222,10 +222,16 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, of
 		}
 
 		/*
+		 * The data buffer's ELF type, ELF class and ELF version
+		 * should be supported.
+		 */
+		if ((msz = _libelf_msize(d->d_type, ec, e->e_version)) == 0)
+			return (0);
+
+		/*
 		 * The buffer's size should be a multiple of the
 		 * memory size of the underlying type.
 		 */
-		msz = _libelf_msize(d->d_type, ec, e->e_version);
 		if (d->d_size % msz) {
 			LIBELF_SET_ERROR(DATA, 0);
 			return (0);
@@ -802,7 +808,8 @@ _libelf_write_scn(Elf *e, unsigned char *nf, struct _E
 
 		d = &ld->d_data;
 
-		msz = _libelf_msize(d->d_type, ec, e->e_version);
+		if ((msz = _libelf_msize(d->d_type, ec, e->e_version)) == 0)
+			return ((off_t) -1);
 
 		if ((uint64_t) rc < sh_off + d->d_off)
 			(void) memset(nf + rc,
@@ -813,8 +820,8 @@ _libelf_write_scn(Elf *e, unsigned char *nf, struct _E
 
 		assert(d->d_buf != NULL);
 		assert(d->d_version == e->e_version);
-		assert(msz != 0);
 		assert(d->d_size % msz == 0);
+		assert(msz != 0);
 
 		nobjects = (size_t) (d->d_size / msz);
 
@@ -854,7 +861,8 @@ _libelf_write_ehdr(Elf *e, unsigned char *nf, struct _
 	assert(ehdr != NULL);
 
 	fsz = _libelf_fsize(ELF_T_EHDR, ec, e->e_version, (size_t) 1);
-	msz = _libelf_msize(ELF_T_EHDR, ec, e->e_version);
+	if ((msz = _libelf_msize(ELF_T_EHDR, ec, e->e_version)) == 0)
+		return ((off_t) -1);
 
 	em = _libelf_elfmachine(e);
 
@@ -888,15 +896,17 @@ _libelf_write_phdr(Elf *e, unsigned char *nf, struct _
 	Elf32_Ehdr *eh32;
 	Elf64_Ehdr *eh64;
 	Elf_Data dst, src;
-	size_t fsz, phnum;
+	size_t fsz, msz, phnum;
 	uint64_t phoff;
 
 	assert(ex->ex_type == ELF_EXTENT_PHDR);
 
 	ec = e->e_class;
+
 	ehdr = _libelf_ehdr(e, ec, 0);
-	phnum = e->e_u.e_elf.e_nphdr;
+	assert(ehdr != NULL);
 
+	phnum = e->e_u.e_elf.e_nphdr;
 	assert(phnum > 0);
 
 	if (ec == ELFCLASS32) {
@@ -916,14 +926,15 @@ _libelf_write_phdr(Elf *e, unsigned char *nf, struct _
 	(void) memset(&dst, 0, sizeof(dst));
 	(void) memset(&src, 0, sizeof(src));
 
+	if ((msz = _libelf_msize(ELF_T_PHDR, ec, e->e_version)) == 0)
+		return ((off_t) -1);
 	fsz = _libelf_fsize(ELF_T_PHDR, ec, e->e_version, phnum);
 	assert(fsz > 0);
 
 	src.d_buf = _libelf_getphdr(e, ec);
 	src.d_version = dst.d_version = e->e_version;
 	src.d_type = ELF_T_PHDR;
-	src.d_size = phnum * _libelf_msize(ELF_T_PHDR, ec,
-	    e->e_version);
+	src.d_size = phnum * msz;
 
 	dst.d_size = fsz;
 	dst.d_buf = nf + ex->ex_start;
@@ -948,13 +959,16 @@ _libelf_write_shdr(Elf *e, unsigned char *nf, struct _
 	uint64_t shoff;
 	Elf32_Ehdr *eh32;
 	Elf64_Ehdr *eh64;
-	size_t fsz, nscn;
+	size_t fsz, msz, nscn;
 	Elf_Data dst, src;
 
 	assert(ex->ex_type == ELF_EXTENT_SHDR);
 
 	ec = e->e_class;
+
 	ehdr = _libelf_ehdr(e, ec, 0);
+	assert(ehdr != NULL);
+
 	nscn = e->e_u.e_elf.e_nscn;
 
 	if (ec == ELFCLASS32) {
@@ -974,8 +988,11 @@ _libelf_write_shdr(Elf *e, unsigned char *nf, struct _
 	(void) memset(&dst, 0, sizeof(dst));
 	(void) memset(&src, 0, sizeof(src));
 
+	if ((msz = _libelf_msize(ELF_T_SHDR, ec, e->e_version)) == 0)
+		return ((off_t) -1);
+
 	src.d_type = ELF_T_SHDR;
-	src.d_size = _libelf_msize(ELF_T_SHDR, ec, e->e_version);
+	src.d_size = msz;
 	src.d_version = dst.d_version = e->e_version;
 
 	fsz = _libelf_fsize(ELF_T_SHDR, ec, e->e_version, (size_t) 1);
@@ -1087,7 +1104,7 @@ _libelf_write_elf(Elf *e, off_t newsize, struct _Elf_E
 		if (e->e_flags & LIBELF_F_RAWFILE_MMAP) {
 			assert(e->e_rawfile != NULL);
 			assert(e->e_cmd == ELF_C_RDWR);
-			if (munmap(e->e_rawfile, e->e_rawsize) < 0) {
+			if (munmap(e->e_rawfile, (size_t) e->e_rawsize) < 0) {
 				LIBELF_SET_ERROR(IO, errno);
 				goto error;
 			}
@@ -1112,12 +1129,14 @@ _libelf_write_elf(Elf *e, off_t newsize, struct _Elf_E
 		assert((e->e_flags & LIBELF_F_RAWFILE_MALLOC) ||
 		    (e->e_flags & LIBELF_F_RAWFILE_MMAP));
 		if (e->e_flags & LIBELF_F_RAWFILE_MALLOC) {
+			assert((e->e_flags & LIBELF_F_RAWFILE_MMAP) == 0);
 			free(e->e_rawfile);
 			e->e_rawfile = newfile;
 			newfile = NULL;
 		}
 #if	ELFTC_HAVE_MMAP
 		else if (e->e_flags & LIBELF_F_RAWFILE_MMAP) {
+			assert((e->e_flags & LIBELF_F_RAWFILE_MALLOC) == 0);
 			if ((e->e_rawfile = mmap(NULL, (size_t) newsize,
 			    PROT_READ, MAP_PRIVATE, e->e_fd, (off_t) 0)) ==
 			    MAP_FAILED) {
@@ -1128,7 +1147,7 @@ _libelf_write_elf(Elf *e, off_t newsize, struct _Elf_E
 #endif	/* ELFTC_HAVE_MMAP */
 
 		/* Record the new size of the file. */
-		e->e_rawsize = (size_t) newsize;
+		e->e_rawsize = newsize;
 	} else {
 		/* File opened in ELF_C_WRITE mode. */
 		assert(e->e_rawfile == NULL);

Modified: head/contrib/elftoolchain/libelf/gelf.3
==============================================================================
--- head/contrib/elftoolchain/libelf/gelf.3	Thu Dec  5 04:52:19 2019	(r355412)
+++ head/contrib/elftoolchain/libelf/gelf.3	Thu Dec  5 13:20:15 2019	(r355413)

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201912051320.xB5DKFok073626>