[rtems-tools commit] rtemstoolkit: Update elftoolchain to the latest code.

Chris Johns chrisj at rtems.org
Mon Apr 30 05:51:41 UTC 2018


Module:    rtems-tools
Branch:    master
Commit:    771e7f162ed5d0576fac476154280347a4bb228b
Changeset: http://git.rtems.org/rtems-tools/commit/?id=771e7f162ed5d0576fac476154280347a4bb228b

Author:    Chris Johns <chrisj at rtems.org>
Date:      Mon Apr 30 14:20:32 2018 +1000

rtemstoolkit: Update elftoolchain to the latest code.

The update is taken from:

 https://svn.code.sf.net/p/elftoolchain/code/trunk

Update #3417

---

 rtemstoolkit/elftoolchain/common/Makefile          |  11 +-
 rtemstoolkit/elftoolchain/common/_elftc.h          | 377 ++++++++++++++++-
 rtemstoolkit/elftoolchain/common/elfdefinitions.h  | 450 ++++++++++++++++++---
 rtemstoolkit/elftoolchain/common/native-elf-format |   9 +-
 rtemstoolkit/elftoolchain/common/os.Linux.mk       |  10 +-
 rtemstoolkit/elftoolchain/common/utarray.h         | 237 +++++++++++
 rtemstoolkit/elftoolchain/common/uthash.h          |  53 ++-
 rtemstoolkit/elftoolchain/libelf/Makefile          |  13 +-
 rtemstoolkit/elftoolchain/libelf/Version.map       |  15 +-
 rtemstoolkit/elftoolchain/libelf/_libelf.h         | 110 +++--
 rtemstoolkit/elftoolchain/libelf/_libelf_ar.h      |  13 +-
 rtemstoolkit/elftoolchain/libelf/_libelf_config.h  |  92 +++--
 rtemstoolkit/elftoolchain/libelf/elf.3             |  44 +-
 rtemstoolkit/elftoolchain/libelf/elf.c             |   2 +-
 rtemstoolkit/elftoolchain/libelf/elf_begin.3       |  10 +-
 rtemstoolkit/elftoolchain/libelf/elf_begin.c       | 189 +--------
 rtemstoolkit/elftoolchain/libelf/elf_cntl.3        |   2 +-
 rtemstoolkit/elftoolchain/libelf/elf_cntl.c        |   2 +-
 rtemstoolkit/elftoolchain/libelf/elf_data.c        | 105 +++--
 rtemstoolkit/elftoolchain/libelf/elf_end.c         |  18 +-
 rtemstoolkit/elftoolchain/libelf/elf_errmsg.c      |   8 +-
 rtemstoolkit/elftoolchain/libelf/elf_errno.c       |   4 +-
 rtemstoolkit/elftoolchain/libelf/elf_fill.c        |   4 +-
 rtemstoolkit/elftoolchain/libelf/elf_flag.c        |  15 +-
 rtemstoolkit/elftoolchain/libelf/elf_flagdata.3    |  43 +-
 rtemstoolkit/elftoolchain/libelf/elf_getarhdr.c    |   4 +-
 rtemstoolkit/elftoolchain/libelf/elf_getarsym.c    |   4 +-
 rtemstoolkit/elftoolchain/libelf/elf_getbase.c     |   4 +-
 rtemstoolkit/elftoolchain/libelf/elf_getdata.3     |   4 +-
 rtemstoolkit/elftoolchain/libelf/elf_getident.c    |   4 +-
 rtemstoolkit/elftoolchain/libelf/elf_hash.c        |   6 +-
 rtemstoolkit/elftoolchain/libelf/elf_kind.c        |   4 +-
 rtemstoolkit/elftoolchain/libelf/elf_memory.3      |   6 +-
 rtemstoolkit/elftoolchain/libelf/elf_memory.c      |  49 +--
 rtemstoolkit/elftoolchain/libelf/elf_next.c        |  14 +-
 rtemstoolkit/elftoolchain/libelf/elf_open.3        | 121 ++++++
 rtemstoolkit/elftoolchain/libelf/elf_open.c        |  67 +++
 rtemstoolkit/elftoolchain/libelf/elf_phnum.c       |   4 +-
 rtemstoolkit/elftoolchain/libelf/elf_rand.c        |   6 +-
 rtemstoolkit/elftoolchain/libelf/elf_rawfile.c     |   8 +-
 rtemstoolkit/elftoolchain/libelf/elf_scn.c         |  27 +-
 rtemstoolkit/elftoolchain/libelf/elf_shnum.c       |   4 +-
 rtemstoolkit/elftoolchain/libelf/elf_shstrndx.c    |   4 +-
 rtemstoolkit/elftoolchain/libelf/elf_strptr.c      |   8 +-
 rtemstoolkit/elftoolchain/libelf/elf_update.c      | 179 ++++----
 rtemstoolkit/elftoolchain/libelf/elf_version.c     |   4 +-
 rtemstoolkit/elftoolchain/libelf/gelf.3            |   5 +-
 rtemstoolkit/elftoolchain/libelf/gelf.h            |  12 +-
 rtemstoolkit/elftoolchain/libelf/gelf_cap.c        |  32 +-
 rtemstoolkit/elftoolchain/libelf/gelf_checksum.c   |   4 +-
 rtemstoolkit/elftoolchain/libelf/gelf_dyn.c        |  35 +-
 rtemstoolkit/elftoolchain/libelf/gelf_ehdr.c       |   6 +-
 rtemstoolkit/elftoolchain/libelf/gelf_fsize.c      |   4 +-
 rtemstoolkit/elftoolchain/libelf/gelf_getclass.c   |   4 +-
 rtemstoolkit/elftoolchain/libelf/gelf_move.c       |  39 +-
 rtemstoolkit/elftoolchain/libelf/gelf_newehdr.3    |  11 +-
 rtemstoolkit/elftoolchain/libelf/gelf_newphdr.3    |  11 +-
 rtemstoolkit/elftoolchain/libelf/gelf_phdr.c       |  38 +-
 rtemstoolkit/elftoolchain/libelf/gelf_rel.c        |  44 +-
 rtemstoolkit/elftoolchain/libelf/gelf_rela.c       |  44 +-
 rtemstoolkit/elftoolchain/libelf/gelf_shdr.c       |   6 +-
 rtemstoolkit/elftoolchain/libelf/gelf_sym.c        |  44 +-
 rtemstoolkit/elftoolchain/libelf/gelf_syminfo.c    |  37 +-
 rtemstoolkit/elftoolchain/libelf/gelf_symshndx.c   |  31 +-
 rtemstoolkit/elftoolchain/libelf/gelf_xlate.c      |   4 +-
 rtemstoolkit/elftoolchain/libelf/libelf.h          |  30 +-
 rtemstoolkit/elftoolchain/libelf/libelf_align.c    |  12 +-
 rtemstoolkit/elftoolchain/libelf/libelf_allocate.c |  24 +-
 rtemstoolkit/elftoolchain/libelf/libelf_ar.c       |  53 +--
 rtemstoolkit/elftoolchain/libelf/libelf_ar_util.c  |  64 +--
 rtemstoolkit/elftoolchain/libelf/libelf_checksum.c |  10 +-
 rtemstoolkit/elftoolchain/libelf/libelf_convert.m4 | 242 +++++------
 rtemstoolkit/elftoolchain/libelf/libelf_data.c     |  19 +-
 rtemstoolkit/elftoolchain/libelf/libelf_ehdr.c     |  37 +-
 rtemstoolkit/elftoolchain/libelf/libelf_extended.c |  16 +-
 rtemstoolkit/elftoolchain/libelf/libelf_fsize.m4   |   2 +-
 rtemstoolkit/elftoolchain/libelf/libelf_memory.c   |  96 +++++
 rtemstoolkit/elftoolchain/libelf/libelf_msize.m4   |   4 +-
 rtemstoolkit/elftoolchain/libelf/libelf_open.c     | 249 ++++++++++++
 rtemstoolkit/elftoolchain/libelf/libelf_phdr.c     |  11 +-
 rtemstoolkit/elftoolchain/libelf/libelf_shdr.c     |   4 +-
 rtemstoolkit/elftoolchain/libelf/libelf_xlate.c    |  12 +-
 rtemstoolkit/win32/sys/cdefs.h                     |   6 -
 rtemstoolkit/wscript                               |  32 +-
 84 files changed, 2582 insertions(+), 1119 deletions(-)

diff --git a/rtemstoolkit/elftoolchain/common/Makefile b/rtemstoolkit/elftoolchain/common/Makefile
index b7b5372..7a74620 100644
--- a/rtemstoolkit/elftoolchain/common/Makefile
+++ b/rtemstoolkit/elftoolchain/common/Makefile
@@ -1,15 +1,18 @@
-# $Id: Makefile 2140 2011-11-10 14:27:03Z jkoshy $
+# $Id: Makefile 3594 2018-04-11 18:26:50Z jkoshy $
 
 TOP=	..
 
-INCS=	elfdefinitions.h
-INCSDIR?=	/usr/include
+INCS=		elfdefinitions.h
+INCSDIR=	/usr/include
 
 .PHONY:	all clean clobber depend obj
 
-all depend obj:
+all depend:
 
 clean clobber:
 	rm -f ${CLEANFILES}
 
+cleandepend:
+	rm -f ${.OBJDIR}/.depend
+
 .include "${TOP}/mk/elftoolchain.inc.mk"
diff --git a/rtemstoolkit/elftoolchain/common/_elftc.h b/rtemstoolkit/elftoolchain/common/_elftc.h
index 9ee8db1..ed4fdbc 100644
--- a/rtemstoolkit/elftoolchain/common/_elftc.h
+++ b/rtemstoolkit/elftoolchain/common/_elftc.h
@@ -23,11 +23,11 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: _elftc.h 2064 2011-10-26 15:12:32Z jkoshy $
+ * $Id: _elftc.h 3446 2016-05-03 01:31:17Z emaste $
  */
 
 /**
- ** Miscellanous definitions needed by multiple components.
+ ** Miscellaneous definitions needed by multiple components.
  **/
 
 #ifndef	_ELFTC_H
@@ -41,23 +41,234 @@
 #define	offsetof(T, M)		((int) &((T*) 0) -> M)
 #endif
 
+/* --QUEUE-MACROS-- [[ */
+
 /*
  * Supply macros missing from <sys/queue.h>
  */
 
+/*
+ * Copyright (c) 1991, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef	LIST_FOREACH_SAFE
+#define	LIST_FOREACH_SAFE(var, head, field, tvar)		\
+	for ((var) = LIST_FIRST((head));			\
+	    (var) && ((tvar) = LIST_NEXT((var), field), 1);	\
+	    (var) = (tvar))
+#endif
+
+#ifndef	SLIST_FOREACH_SAFE
+#define	SLIST_FOREACH_SAFE(var, head, field, tvar)		\
+	for ((var) = SLIST_FIRST((head));			\
+	    (var) && ((tvar) = SLIST_NEXT((var), field), 1);	\
+	    (var) = (tvar))
+#endif
+
+#ifndef	STAILQ_CONCAT
+#define	STAILQ_CONCAT(head1, head2) do {			\
+	if (!STAILQ_EMPTY((head2))) {				\
+		*(head1)->stqh_last = (head2)->stqh_first;	\
+		(head1)->stqh_last = (head2)->stqh_last;	\
+		STAILQ_INIT((head2));				\
+	}							\
+} while (/*CONSTCOND*/0)
+#endif
+
+#ifndef	STAILQ_EMPTY
+#define	STAILQ_EMPTY(head)	((head)->stqh_first == NULL)
+#endif
+
+#ifndef	STAILQ_ENTRY
+#define	STAILQ_ENTRY(type)					\
+struct {							\
+	struct type *stqe_next;	/* next element */		\
+}
+#endif
+
+#ifndef	STAILQ_FIRST
+#define	STAILQ_FIRST(head)	((head)->stqh_first)
+#endif
+
+#ifndef	STAILQ_HEAD
+#define	STAILQ_HEAD(name, type)					\
+struct name {							\
+	struct type *stqh_first; /* first element */		\
+	struct type **stqh_last; /* addr of last next element */ \
+}
+#endif
+
+#ifndef	STAILQ_HEAD_INITIALIZER
+#define	STAILQ_HEAD_INITIALIZER(head)				\
+	{ NULL, &(head).stqh_first }
+#endif
+
+#ifndef	STAILQ_FOREACH
+#define	STAILQ_FOREACH(var, head, field)			\
+	for ((var) = ((head)->stqh_first);			\
+		(var);						\
+		(var) = ((var)->field.stqe_next))
+#endif
+
 #ifndef	STAILQ_FOREACH_SAFE
-#define STAILQ_FOREACH_SAFE(var, head, field, tvar)            \
-       for ((var) = STAILQ_FIRST((head));                      \
-            (var) && ((tvar) = STAILQ_NEXT((var), field), 1);  \
-            (var) = (tvar))
+#define STAILQ_FOREACH_SAFE(var, head, field, tvar)		\
+       for ((var) = STAILQ_FIRST((head));			\
+	    (var) && ((tvar) = STAILQ_NEXT((var), field), 1);	\
+	    (var) = (tvar))
+#endif
+
+#ifndef	STAILQ_INIT
+#define	STAILQ_INIT(head) do {					\
+	(head)->stqh_first = NULL;				\
+	(head)->stqh_last = &(head)->stqh_first;		\
+} while (/*CONSTCOND*/0)
+#endif
+
+#ifndef	STAILQ_INSERT_HEAD
+#define	STAILQ_INSERT_HEAD(head, elm, field) do {			\
+	if (((elm)->field.stqe_next = (head)->stqh_first) == NULL)	\
+		(head)->stqh_last = &(elm)->field.stqe_next;		\
+	(head)->stqh_first = (elm);					\
+} while (/*CONSTCOND*/0)
+#endif
+
+#ifndef	STAILQ_INSERT_TAIL
+#define	STAILQ_INSERT_TAIL(head, elm, field) do {			\
+	(elm)->field.stqe_next = NULL;					\
+	*(head)->stqh_last = (elm);					\
+	(head)->stqh_last = &(elm)->field.stqe_next;			\
+} while (/*CONSTCOND*/0)
+#endif
+
+#ifndef	STAILQ_INSERT_AFTER
+#define	STAILQ_INSERT_AFTER(head, listelm, elm, field) do {		\
+	if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\
+		(head)->stqh_last = &(elm)->field.stqe_next;		\
+	(listelm)->field.stqe_next = (elm);				\
+} while (/*CONSTCOND*/0)
 #endif
 
 #ifndef	STAILQ_LAST
-#define STAILQ_LAST(head, type, field)                                  \
-        (STAILQ_EMPTY((head)) ?                                         \
-                NULL :                                                  \
-                ((struct type *)(void *)                                \
-                ((char *)((head)->stqh_last) - offsetof(struct type, field))))
+#define STAILQ_LAST(head, type, field)					\
+	(STAILQ_EMPTY((head)) ?					\
+	    NULL : ((struct type *)(void *)				\
+	    ((char *)((head)->stqh_last) - offsetof(struct type, field))))
+#endif
+
+#ifndef	STAILQ_NEXT
+#define	STAILQ_NEXT(elm, field)	((elm)->field.stqe_next)
+#endif
+
+#ifndef	STAILQ_REMOVE
+#define	STAILQ_REMOVE(head, elm, type, field) do {			\
+	if ((head)->stqh_first == (elm)) {				\
+		STAILQ_REMOVE_HEAD((head), field);			\
+	} else {							\
+		struct type *curelm = (head)->stqh_first;		\
+		while (curelm->field.stqe_next != (elm))		\
+			curelm = curelm->field.stqe_next;		\
+		if ((curelm->field.stqe_next =				\
+			curelm->field.stqe_next->field.stqe_next) == NULL) \
+			    (head)->stqh_last = &(curelm)->field.stqe_next; \
+	}								\
+} while (/*CONSTCOND*/0)
+#endif
+
+#ifndef	STAILQ_REMOVE_HEAD
+#define	STAILQ_REMOVE_HEAD(head, field) do {				\
+	if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == \
+	    NULL)							\
+		(head)->stqh_last = &(head)->stqh_first;		\
+} while (/*CONSTCOND*/0)
+#endif
+
+/*
+ * The STAILQ_SORT macro is adapted from Simon Tatham's O(n*log(n))
+ * mergesort algorithm.
+ */
+#ifndef	STAILQ_SORT
+#define	STAILQ_SORT(head, type, field, cmp) do {			\
+	STAILQ_HEAD(, type) _la, _lb;					\
+	struct type *_p, *_q, *_e;					\
+	int _i, _sz, _nmerges, _psz, _qsz;				\
+									\
+	_sz = 1;							\
+	do {								\
+		_nmerges = 0;						\
+		STAILQ_INIT(&_lb);					\
+		while (!STAILQ_EMPTY((head))) {				\
+			_nmerges++;					\
+			STAILQ_INIT(&_la);				\
+			_psz = 0;					\
+			for (_i = 0; _i < _sz && !STAILQ_EMPTY((head));	\
+			     _i++) {					\
+				_e = STAILQ_FIRST((head));		\
+				if (_e == NULL)				\
+					break;				\
+				_psz++;					\
+				STAILQ_REMOVE_HEAD((head), field);	\
+				STAILQ_INSERT_TAIL(&_la, _e, field);	\
+			}						\
+			_p = STAILQ_FIRST(&_la);			\
+			_qsz = _sz;					\
+			_q = STAILQ_FIRST((head));			\
+			while (_psz > 0 || (_qsz > 0 && _q != NULL)) {	\
+				if (_psz == 0) {			\
+					_e = _q;			\
+					_q = STAILQ_NEXT(_q, field);	\
+					STAILQ_REMOVE_HEAD((head),	\
+					    field);			\
+					_qsz--;				\
+				} else if (_qsz == 0 || _q == NULL) {	\
+					_e = _p;			\
+					_p = STAILQ_NEXT(_p, field);	\
+					STAILQ_REMOVE_HEAD(&_la, field);\
+					_psz--;				\
+				} else if (cmp(_p, _q) <= 0) {		\
+					_e = _p;			\
+					_p = STAILQ_NEXT(_p, field);	\
+					STAILQ_REMOVE_HEAD(&_la, field);\
+					_psz--;				\
+				} else {				\
+					_e = _q;			\
+					_q = STAILQ_NEXT(_q, field);	\
+					STAILQ_REMOVE_HEAD((head),	\
+					    field);			\
+					_qsz--;				\
+				}					\
+				STAILQ_INSERT_TAIL(&_lb, _e, field);	\
+			}						\
+		}							\
+		(head)->stqh_first = _lb.stqh_first;			\
+		(head)->stqh_last = _lb.stqh_last;			\
+		_sz *= 2;						\
+	} while (_nmerges > 1);						\
+} while (/*CONSTCOND*/0)
 #endif
 
 #ifndef	TAILQ_FOREACH_SAFE
@@ -67,17 +278,24 @@
 	    (var) = (tvar))
 #endif
 
+/* ]] --QUEUE-MACROS-- */
+
 /*
  * VCS Ids.
  */
 
 #ifndef	ELFTC_VCSID
 
+#if defined(__DragonFly__)
+#define	ELFTC_VCSID(ID)		__RCSID(ID)
+#endif
+
 #if defined(__FreeBSD__)
 #define	ELFTC_VCSID(ID)		__FBSDID(ID)
 #endif
 
-#if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)
+#if defined(__APPLE__) || defined(__GLIBC__) || defined(__GNU__) || \
+    defined(__linux__)
 #if defined(__GNUC__)
 #define	ELFTC_VCSID(ID)		__asm__(".ident\t\"" ID "\"")
 #else
@@ -85,10 +303,30 @@
 #endif
 #endif
 
+#if defined(__minix)
+#if defined(__GNUC__)
+#define	ELFTC_VCSID(ID)		__asm__(".ident\t\"" ID "\"")
+#else
+#define	ELFTC_VCSID(ID)		/**/
+#endif	/* __GNU__ */
+#endif
+
 #if defined(__NetBSD__)
 #define	ELFTC_VCSID(ID)		__RCSID(ID)
 #endif
 
+#if defined(__OpenBSD__)
+#if defined(__GNUC__)
+#define	ELFTC_VCSID(ID)		__asm__(".ident\t\"" ID "\"")
+#else
+#define	ELFTC_VCSID(ID)		/**/
+#endif	/* __GNUC__ */
+#endif
+
+#ifndef	ELFTC_VCSID
+#define	ELFTC_VCSID(ID)		/**/
+#endif
+
 #endif	/* ELFTC_VCSID */
 
 /*
@@ -97,34 +335,80 @@
 
 #ifndef	ELFTC_GETPROGNAME
 
-#if defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || \
+    defined(__minix) || defined(__NetBSD__)
 
 #include <stdlib.h>
 
 #define	ELFTC_GETPROGNAME()	getprogname()
 
-#endif	/* defined(__FreeBSD__) || defined(__NetBSD__) */
-
+#endif	/* __DragonFly__ || __FreeBSD__ || __minix || __NetBSD__ */
 
-#if defined(__linux__)
 
+#if defined(__GLIBC__) || defined(__linux__)
+#ifndef _GNU_SOURCE
 /*
  * GLIBC based systems have a global 'char *' pointer referencing
  * the executable's name.
  */
 extern const char *program_invocation_short_name;
+#endif	/* !_GNU_SOURCE */
 
 #define	ELFTC_GETPROGNAME()	program_invocation_short_name
 
-#endif	/* __linux__ */
+#endif	/* __GLIBC__ || __linux__ */
+
+
+#if defined(__OpenBSD__)
+
+extern const char *__progname;
+
+#define	ELFTC_GETPROGNAME()	__progname
+
+#endif	/* __OpenBSD__ */
+
+#ifndef	ELFTC_GETPROGNAME
+#define ELFTC_GETPROGNAME() "no_progname"
+#endif
 
 #endif	/* ELFTC_GETPROGNAME */
 
+
 /**
  ** Per-OS configuration.
  **/
 
-#if defined(__linux__)
+#if defined(__APPLE__)
+
+#include <libkern/OSByteOrder.h>
+#define	htobe32(x)	OSSwapHostToBigInt32(x)
+#define	roundup2	roundup
+
+#define	ELFTC_BYTE_ORDER			_BYTE_ORDER
+#define	ELFTC_BYTE_ORDER_LITTLE_ENDIAN		_LITTLE_ENDIAN
+#define	ELFTC_BYTE_ORDER_BIG_ENDIAN		_BIG_ENDIAN
+
+#define	ELFTC_HAVE_MMAP				1
+#define	ELFTC_HAVE_STRMODE			1
+
+#define ELFTC_NEED_BYTEORDER_EXTENSIONS		1
+#endif /* __APPLE__ */
+
+
+#if defined(__DragonFly__)
+
+#include <osreldate.h>
+#include <sys/endian.h>
+
+#define	ELFTC_BYTE_ORDER			_BYTE_ORDER
+#define	ELFTC_BYTE_ORDER_LITTLE_ENDIAN		_LITTLE_ENDIAN
+#define	ELFTC_BYTE_ORDER_BIG_ENDIAN		_BIG_ENDIAN
+
+#define	ELFTC_HAVE_MMAP				1
+
+#endif
+
+#if defined(__GLIBC__) || defined(__linux__)
 
 #include <endian.h>
 
@@ -132,8 +416,10 @@ extern const char *program_invocation_short_name;
 #define	ELFTC_BYTE_ORDER_LITTLE_ENDIAN		__LITTLE_ENDIAN
 #define	ELFTC_BYTE_ORDER_BIG_ENDIAN		__BIG_ENDIAN
 
+#define	ELFTC_HAVE_MMAP				1
+
 /*
- * Debian GNU/Linux is missing strmode(3).
+ * Debian GNU/Linux and Debian GNU/kFreeBSD do not have strmode(3).
  */
 #define	ELFTC_HAVE_STRMODE			0
 
@@ -142,7 +428,7 @@ extern const char *program_invocation_short_name;
 
 #define	roundup2	roundup
 
-#endif	/* __linux__ */
+#endif	/* __GLIBC__ || __linux__ */
 
 
 #if defined(__FreeBSD__)
@@ -154,6 +440,7 @@ extern const char *program_invocation_short_name;
 #define	ELFTC_BYTE_ORDER_LITTLE_ENDIAN		_LITTLE_ENDIAN
 #define	ELFTC_BYTE_ORDER_BIG_ENDIAN		_BIG_ENDIAN
 
+#define	ELFTC_HAVE_MMAP				1
 #define	ELFTC_HAVE_STRMODE			1
 #if __FreeBSD_version <= 900000
 #define	ELFTC_BROKEN_YY_NO_INPUT		1
@@ -161,16 +448,64 @@ extern const char *program_invocation_short_name;
 #endif	/* __FreeBSD__ */
 
 
+#if defined(__minix)
+#define	ELFTC_HAVE_MMAP				0
+#endif	/* __minix */
+
+
 #if defined(__NetBSD__)
 
+#include <sys/param.h>
 #include <sys/endian.h>
 
 #define	ELFTC_BYTE_ORDER			_BYTE_ORDER
 #define	ELFTC_BYTE_ORDER_LITTLE_ENDIAN		_LITTLE_ENDIAN
 #define	ELFTC_BYTE_ORDER_BIG_ENDIAN		_BIG_ENDIAN
 
+#define	ELFTC_HAVE_MMAP				1
 #define	ELFTC_HAVE_STRMODE			1
-#define	ELFTC_BROKEN_YY_NO_INPUT		1
+#if __NetBSD_Version__ <= 599002100
+/* from src/doc/CHANGES: flex(1): Import flex-2.5.35 [christos 20091025] */
+/* and 5.99.21 was from Wed Oct 21 21:28:36 2009 UTC */
+#  define ELFTC_BROKEN_YY_NO_INPUT		1
+#endif
 #endif	/* __NetBSD __ */
 
+
+#if defined(__OpenBSD__)
+
+#include <sys/param.h>
+#include <sys/endian.h>
+
+#define	ELFTC_BYTE_ORDER			_BYTE_ORDER
+#define	ELFTC_BYTE_ORDER_LITTLE_ENDIAN		_LITTLE_ENDIAN
+#define	ELFTC_BYTE_ORDER_BIG_ENDIAN		_BIG_ENDIAN
+
+#define	ELFTC_HAVE_MMAP				1
+#define	ELFTC_HAVE_STRMODE			1
+
+#define	ELFTC_NEED_BYTEORDER_EXTENSIONS		1
+#define	roundup2	roundup
+
+#endif	/* __OpenBSD__ */
+
+#if defined(__WIN32__) || defined(__CYGWIN__)
+
+#if defined(__CYGWIN__)
+#include <sys/endian.h>
+#else /* __CYGWIN */
+#include <winsock2.h>
+#define htobe32(x)      (x)
+#endif /* __WIN32__ */
+
+#include <sys/param.h>
+
+#define	ELFTC_BYTE_ORDER			_BYTE_ORDER
+#define	ELFTC_BYTE_ORDER_LITTLE_ENDIAN		_LITTLE_ENDIAN
+#define	ELFTC_BYTE_ORDER_BIG_ENDIAN		_BIG_ENDIAN
+
+#define	ELFTC_HAVE_MMAP				1
+
+#endif	/* __WIN32__ || __CYGWIN__ */
+
 #endif	/* _ELFTC_H */
diff --git a/rtemstoolkit/elftoolchain/common/elfdefinitions.h b/rtemstoolkit/elftoolchain/common/elfdefinitions.h
index 79b6e7f..810da8d 100644
--- a/rtemstoolkit/elftoolchain/common/elfdefinitions.h
+++ b/rtemstoolkit/elftoolchain/common/elfdefinitions.h
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: elfdefinitions.h 2132 2011-11-10 08:27:41Z jkoshy $
+ * $Id: elfdefinitions.h 3515 2017-01-24 22:04:22Z emaste $
  */
 
 /*
@@ -153,6 +153,8 @@ _ELF_DEFINE_DT(DT_SUNW_FILTER,      0x6000000FUL,			\
 	"offset of string naming standard filtees")			\
 _ELF_DEFINE_DT(DT_SUNW_CAP,         0x60000010UL,			\
 	"address of hardware capabilities section")			\
+_ELF_DEFINE_DT(DT_SUNW_ASLR,        0x60000023UL,			\
+	"Address Space Layout Randomization flag")			\
 _ELF_DEFINE_DT(DT_HIOS,             0x6FFFF000UL,			\
 	"end of OS-specific types")					\
 _ELF_DEFINE_DT(DT_VALRNGLO,         0x6FFFFD00UL,			\
@@ -171,7 +173,7 @@ _ELF_DEFINE_DT(DT_MOVEENT,          0x6FFFFDFAUL,			\
 	"size of DT_MOVETAB entries")					\
 _ELF_DEFINE_DT(DT_MOVESZ,           0x6FFFFDFBUL,			\
 	"total size of the MOVETAB table")				\
-_ELF_DEFINE_DT(DT_FEATURE_1,        0x6FFFFDFCUL, "feature values")	\
+_ELF_DEFINE_DT(DT_FEATURE,          0x6FFFFDFCUL, "feature values")	\
 _ELF_DEFINE_DT(DT_POSFLAG_1,        0x6FFFFDFDUL,			\
 	"dynamic position flags")					\
 _ELF_DEFINE_DT(DT_SYMINSZ,          0x6FFFFDFEUL,			\
@@ -184,6 +186,10 @@ _ELF_DEFINE_DT(DT_ADDRRNGLO,        0x6FFFFE00UL,			\
 	"start of range using the d_ptr field")				\
 _ELF_DEFINE_DT(DT_GNU_HASH,	    0x6FFFFEF5UL,			\
 	"GNU style hash tables")					\
+_ELF_DEFINE_DT(DT_TLSDESC_PLT,	    0x6FFFFEF6UL,			\
+	"location of PLT entry for TLS descriptor resolver calls")	\
+_ELF_DEFINE_DT(DT_TLSDESC_GOT,	    0x6FFFFEF7UL,			\
+	"location of GOT entry used by TLS descriptor resolver PLT entry") \
 _ELF_DEFINE_DT(DT_GNU_CONFLICT,     0x6FFFFEF8UL,			\
 	"address of conflict section")					\
 _ELF_DEFINE_DT(DT_GNU_LIBLIST,      0x6FFFFEF9UL,			\
@@ -269,7 +275,7 @@ _ELF_DEFINE_DT(DT_MIPS_DELTA_RELOC, 0x7000001BUL,			\
 _ELF_DEFINE_DT(DT_MIPS_DELTA_RELOC_NO, 0x7000001CUL,			\
 	"number of entries in DT_MIPS_DELTA_RELOC")			\
 _ELF_DEFINE_DT(DT_MIPS_DELTA_SYM,   0x7000001DUL,			\
-	"Delta symbols refered by Delta relocations")			\
+	"Delta symbols referred by Delta relocations")			\
 _ELF_DEFINE_DT(DT_MIPS_DELTA_SYM_NO, 0x7000001EUL,			\
 	"number of entries in DT_MIPS_DELTA_SYM")			\
 _ELF_DEFINE_DT(DT_MIPS_DELTA_CLASSSYM, 0x70000020UL,			\
@@ -362,6 +368,18 @@ _ELF_DEFINE_EF(EF_ARM_LE8,          0x00400000UL,			\
 	"file contains LE-8 code")					\
 _ELF_DEFINE_EF(EF_ARM_EABIMASK,     0xFF000000UL,			\
 	"mask for ARM EABI version number (0 denotes GNU or unknown)")	\
+_ELF_DEFINE_EF(EF_ARM_EABI_UNKNOWN, 0x00000000UL,			\
+	"Unknown or GNU ARM EABI version number")			\
+_ELF_DEFINE_EF(EF_ARM_EABI_VER1,    0x01000000UL,			\
+	"ARM EABI version 1")						\
+_ELF_DEFINE_EF(EF_ARM_EABI_VER2,    0x02000000UL,			\
+	"ARM EABI version 2")						\
+_ELF_DEFINE_EF(EF_ARM_EABI_VER3,    0x03000000UL,			\
+	"ARM EABI version 3")						\
+_ELF_DEFINE_EF(EF_ARM_EABI_VER4,    0x04000000UL,			\
+	"ARM EABI version 4")						\
+_ELF_DEFINE_EF(EF_ARM_EABI_VER5,    0x05000000UL,			\
+	"ARM EABI version 5")						\
 _ELF_DEFINE_EF(EF_ARM_INTERWORK,    0x00000004UL,			\
 	"GNU EABI extension")						\
 _ELF_DEFINE_EF(EF_ARM_APCS_26,      0x00000008UL,			\
@@ -528,6 +546,7 @@ _ELF_DEFINE_EABI(ELFOSABI_NSK,        14,				\
 _ELF_DEFINE_EABI(ELFOSABI_AROS,       15, "Amiga Research OS")		\
 _ELF_DEFINE_EABI(ELFOSABI_FENIXOS,    16,				\
 	"The FenixOS highly scalable multi-core OS")			\
+_ELF_DEFINE_EABI(ELFOSABI_CLOUDABI,   17, "Nuxi CloudABI")		\
 _ELF_DEFINE_EABI(ELFOSABI_ARM_AEABI,  64,				\
 	"ARM specific symbol versioning extensions")			\
 _ELF_DEFINE_EABI(ELFOSABI_ARM,        97, "ARM ABI")			\
@@ -553,6 +572,7 @@ _ELF_DEFINE_EM(EM_SPARC,            2, "SPARC")				\
 _ELF_DEFINE_EM(EM_386,              3, "Intel 80386")			\
 _ELF_DEFINE_EM(EM_68K,              4, "Motorola 68000")		\
 _ELF_DEFINE_EM(EM_88K,              5, "Motorola 88000")		\
+_ELF_DEFINE_EM(EM_IAMCU,            6, "Intel MCU")			\
 _ELF_DEFINE_EM(EM_860,              7, "Intel 80860")			\
 _ELF_DEFINE_EM(EM_MIPS,             8, "MIPS I Architecture")		\
 _ELF_DEFINE_EM(EM_S370,             9, "IBM System/370 Processor")	\
@@ -758,6 +778,8 @@ _ELF_DEFINE_EM(EM_ETPU,             178,				\
 	"Freescale Extended Time Processing Unit")			\
 _ELF_DEFINE_EM(EM_SLE9X,            179,				\
 	"Infineon Technologies SLE9X core")				\
+_ELF_DEFINE_EM(EM_AARCH64,          183,				\
+	"AArch64 (64-bit ARM)")						\
 _ELF_DEFINE_EM(EM_AVR32,            185,				\
 	"Atmel Corporation 32-bit microprocessor family")		\
 _ELF_DEFINE_EM(EM_STM8,             186,				\
@@ -782,7 +804,24 @@ _ELF_DEFINE_EM(EM_OPEN8,            196,				\
 	"Open8 8-bit RISC soft processor core")				\
 _ELF_DEFINE_EM(EM_RL78,             197, "Renesas RL78 family")		\
 _ELF_DEFINE_EM(EM_VIDEOCORE5,       198, "Broadcom VideoCore V processor") \
-_ELF_DEFINE_EM(EM_78KOR,            199, "Renesas 78KOR family")
+_ELF_DEFINE_EM(EM_78KOR,            199, "Renesas 78KOR family")	\
+_ELF_DEFINE_EM(EM_56800EX,          200,				\
+	"Freescale 56800EX Digital Signal Controller")			\
+_ELF_DEFINE_EM(EM_BA1,              201, "Beyond BA1 CPU architecture")	\
+_ELF_DEFINE_EM(EM_BA2,              202, "Beyond BA2 CPU architecture")	\
+_ELF_DEFINE_EM(EM_XCORE,            203, "XMOS xCORE processor family") \
+_ELF_DEFINE_EM(EM_MCHP_PIC,         204, "Microchip 8-bit PIC(r) family") \
+_ELF_DEFINE_EM(EM_INTEL205,         205, "Reserved by Intel")           \
+_ELF_DEFINE_EM(EM_INTEL206,         206, "Reserved by Intel")           \
+_ELF_DEFINE_EM(EM_INTEL207,         207, "Reserved by Intel")           \
+_ELF_DEFINE_EM(EM_INTEL208,         208, "Reserved by Intel")           \
+_ELF_DEFINE_EM(EM_INTEL209,         209, "Reserved by Intel")           \
+_ELF_DEFINE_EM(EM_KM32,             210, "KM211 KM32 32-bit processor") \
+_ELF_DEFINE_EM(EM_KMX32,            211, "KM211 KMX32 32-bit processor") \
+_ELF_DEFINE_EM(EM_KMX16,            212, "KM211 KMX16 16-bit processor") \
+_ELF_DEFINE_EM(EM_KMX8,             213, "KM211 KMX8 8-bit processor")  \
+_ELF_DEFINE_EM(EM_KVARC,            214, "KM211 KMX32 KVARC processor") \
+_ELF_DEFINE_EM(EM_RISCV,            243, "RISC-V")
 
 #undef	_ELF_DEFINE_EM
 #define	_ELF_DEFINE_EM(N, V, DESCR)	N = V ,
@@ -791,7 +830,8 @@ enum {
 	EM__LAST__
 };
 
-/* Older synonyms. */
+/* Other synonyms. */
+#define	EM_AMD64		EM_X86_64
 #define	EM_ARC_A5		EM_ARC_COMPACT
 
 /*
@@ -827,6 +867,12 @@ enum {
 #define	GRP_MASKPROC 	0xf0000000	/* processor-specific flags */
 
 /*
+ * Flags / mask for .gnu.versym sections.
+ */
+#define	VERSYM_VERSION	0x7fff
+#define	VERSYM_HIDDEN	0x8000
+
+/*
  * Flags used by program header table entries.
  */
 
@@ -875,6 +921,12 @@ _ELF_DEFINE_PT(PT_GNU_STACK,	    0x6474E551UL,		\
 	"Stack flags")						\
 _ELF_DEFINE_PT(PT_GNU_RELRO,	    0x6474E552UL,		\
 	"Segment becomes read-only after relocation")		\
+_ELF_DEFINE_PT(PT_OPENBSD_RANDOMIZE,0x65A3DBE6UL,		\
+	"Segment filled with random data")			\
+_ELF_DEFINE_PT(PT_OPENBSD_WXNEEDED, 0x65A3DBE7UL,		\
+	"Program violates W^X")					\
+_ELF_DEFINE_PT(PT_OPENBSD_BOOTDATA, 0x65A41BE6UL,		\
+	"Boot data")						\
 _ELF_DEFINE_PT(PT_SUNWBSS,          0x6FFFFFFAUL,		\
 	"A Solaris .SUNW_bss section")				\
 _ELF_DEFINE_PT(PT_SUNWSTACK,        0x6FFFFFFBUL,		\
@@ -936,6 +988,8 @@ _ELF_DEFINE_SHF(SHF_GROUP,           0x200,				\
 	"member of a section group")					\
 _ELF_DEFINE_SHF(SHF_TLS,             0x400,				\
 	"holds thread-local storage")					\
+_ELF_DEFINE_SHF(SHF_COMPRESSED,      0x800,				\
+	"holds compressed data")					\
 _ELF_DEFINE_SHF(SHF_MASKOS,          0x0FF00000UL,			\
 	"bits reserved for OS-specific semantics")			\
 _ELF_DEFINE_SHF(SHF_AMD64_LARGE,     0x10000000UL,			\
@@ -1148,9 +1202,11 @@ _ELF_DEFINE_SHT(SHT_MIPS_XLATE_OLD,  0x70000028UL,			\
 	"obsolete")							\
 _ELF_DEFINE_SHT(SHT_MIPS_PDR_EXCEPTION, 0x70000029UL,			\
 	"runtime procedure descriptor table exception information")	\
+_ELF_DEFINE_SHT(SHT_MIPS_ABIFLAGS,   0x7000002AUL,			\
+	"ABI flags")							\
 _ELF_DEFINE_SHT(SHT_SPARC_GOTDATA,   0x70000000UL,			\
 	"SPARC-specific data")						\
-_ELF_DEFINE_SHT(SHT_AMD64_UNWIND,    0x70000001UL,			\
+_ELF_DEFINE_SHT(SHT_X86_64_UNWIND,   0x70000001UL,			\
 	"unwind tables for the AMD64")					\
 _ELF_DEFINE_SHT(SHT_ORDERED,         0x7FFFFFFFUL,			\
 	"sort entries in the section")					\
@@ -1169,6 +1225,7 @@ enum {
 };
 
 /* Aliases for section types. */
+#define	SHT_AMD64_UNWIND	SHT_X86_64_UNWIND
 #define	SHT_GNU_verdef		SHT_SUNW_verdef
 #define	SHT_GNU_verneed		SHT_SUNW_verneed
 #define	SHT_GNU_versym		SHT_SUNW_versym
@@ -1185,6 +1242,7 @@ _ELF_DEFINE_STB(STB_GLOBAL,          1,					\
 _ELF_DEFINE_STB(STB_WEAK,            2,					\
 	"visible across all object files but with low precedence")	\
 _ELF_DEFINE_STB(STB_LOOS,            10, "start of OS-specific range")	\
+_ELF_DEFINE_STB(STB_GNU_UNIQUE,      10, "unique symbol (GNU)")		\
 _ELF_DEFINE_STB(STB_HIOS,            12, "end of OS-specific range")	\
 _ELF_DEFINE_STB(STB_LOPROC,          13,				\
 	"start of processor-specific range")				\
@@ -1211,11 +1269,13 @@ _ELF_DEFINE_STT(STT_FILE,            4, "source file")			\
 _ELF_DEFINE_STT(STT_COMMON,          5, "uninitialized common block")	\
 _ELF_DEFINE_STT(STT_TLS,             6, "thread local storage")		\
 _ELF_DEFINE_STT(STT_LOOS,            10, "start of OS-specific types")	\
+_ELF_DEFINE_STT(STT_GNU_IFUNC,       10, "indirect function")	\
 _ELF_DEFINE_STT(STT_HIOS,            12, "end of OS-specific types")	\
 _ELF_DEFINE_STT(STT_LOPROC,          13,				\
 	"start of processor-specific types")				\
 _ELF_DEFINE_STT(STT_ARM_TFUNC,       13, "Thumb function (GNU)")	\
 _ELF_DEFINE_STT(STT_ARM_16BIT,       15, "Thumb label (GNU)")		\
+_ELF_DEFINE_STT(STT_SPARC_REGISTER,  13, "SPARC register information")	\
 _ELF_DEFINE_STT(STT_HIPROC,          15,				\
 	"end of processor-specific types")
 
@@ -1352,15 +1412,168 @@ _ELF_DEFINE_RELOC(R_386_GOT32,		3)	\
 _ELF_DEFINE_RELOC(R_386_PLT32,		4)	\
 _ELF_DEFINE_RELOC(R_386_COPY,		5)	\
 _ELF_DEFINE_RELOC(R_386_GLOB_DAT,	6)	\
-_ELF_DEFINE_RELOC(R_386_JMP_SLOT,	7)	\
+_ELF_DEFINE_RELOC(R_386_JUMP_SLOT,	7)	\
 _ELF_DEFINE_RELOC(R_386_RELATIVE,	8)	\
 _ELF_DEFINE_RELOC(R_386_GOTOFF,		9)	\
 _ELF_DEFINE_RELOC(R_386_GOTPC,		10)	\
 _ELF_DEFINE_RELOC(R_386_32PLT,		11)	\
+_ELF_DEFINE_RELOC(R_386_TLS_TPOFF,	14)	\
+_ELF_DEFINE_RELOC(R_386_TLS_IE,		15)	\
+_ELF_DEFINE_RELOC(R_386_TLS_GOTIE,	16)	\
+_ELF_DEFINE_RELOC(R_386_TLS_LE,		17)	\
+_ELF_DEFINE_RELOC(R_386_TLS_GD,		18)	\
+_ELF_DEFINE_RELOC(R_386_TLS_LDM,	19)	\
 _ELF_DEFINE_RELOC(R_386_16,		20)	\
 _ELF_DEFINE_RELOC(R_386_PC16,		21)	\
 _ELF_DEFINE_RELOC(R_386_8,		22)	\
-_ELF_DEFINE_RELOC(R_386_PC8,		23)
+_ELF_DEFINE_RELOC(R_386_PC8,		23)	\
+_ELF_DEFINE_RELOC(R_386_TLS_GD_32,	24)	\
+_ELF_DEFINE_RELOC(R_386_TLS_GD_PUSH,	25)	\
+_ELF_DEFINE_RELOC(R_386_TLS_GD_CALL,	26)	\
+_ELF_DEFINE_RELOC(R_386_TLS_GD_POP,	27)	\
+_ELF_DEFINE_RELOC(R_386_TLS_LDM_32,	28)	\
+_ELF_DEFINE_RELOC(R_386_TLS_LDM_PUSH,	29)	\
+_ELF_DEFINE_RELOC(R_386_TLS_LDM_CALL,	30)	\
+_ELF_DEFINE_RELOC(R_386_TLS_LDM_POP,	31)	\
+_ELF_DEFINE_RELOC(R_386_TLS_LDO_32,	32)	\
+_ELF_DEFINE_RELOC(R_386_TLS_IE_32,	33)	\
+_ELF_DEFINE_RELOC(R_386_TLS_LE_32,	34)	\
+_ELF_DEFINE_RELOC(R_386_TLS_DTPMOD32,	35)	\
+_ELF_DEFINE_RELOC(R_386_TLS_DTPOFF32,	36)	\
+_ELF_DEFINE_RELOC(R_386_TLS_TPOFF32,	37)	\
+_ELF_DEFINE_RELOC(R_386_SIZE32,		38)	\
+_ELF_DEFINE_RELOC(R_386_TLS_GOTDESC,	39)	\
+_ELF_DEFINE_RELOC(R_386_TLS_DESC_CALL,	40)	\
+_ELF_DEFINE_RELOC(R_386_TLS_DESC,	41)	\
+_ELF_DEFINE_RELOC(R_386_IRELATIVE,	42)	\
+_ELF_DEFINE_RELOC(R_386_GOT32X,		43)
+
+
+/*
+ */
+#define	_ELF_DEFINE_AARCH64_RELOCATIONS()				\
+_ELF_DEFINE_RELOC(R_AARCH64_NONE,				0)	\
+_ELF_DEFINE_RELOC(R_AARCH64_ABS64,				257)	\
+_ELF_DEFINE_RELOC(R_AARCH64_ABS32,				258)	\
+_ELF_DEFINE_RELOC(R_AARCH64_ABS16,				259)	\
+_ELF_DEFINE_RELOC(R_AARCH64_PREL64,				260)	\
+_ELF_DEFINE_RELOC(R_AARCH64_PREL32,				261)	\
+_ELF_DEFINE_RELOC(R_AARCH64_PREL16,				262)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_UABS_G0,			263)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_UABS_G0_NC,			264)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_UABS_G1,			265)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_UABS_G1_NC,			266)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_UABS_G2,			267)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_UABS_G2_NC,			268)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_UABS_G3,			269)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_SABS_G0,			270)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_SABS_G1,			271)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_SABS_G2,			272)	\
+_ELF_DEFINE_RELOC(R_AARCH64_LD_PREL_LO19,			273)	\
+_ELF_DEFINE_RELOC(R_AARCH64_ADR_PREL_LO21,			274)	\
+_ELF_DEFINE_RELOC(R_AARCH64_ADR_PREL_PG_HI21,			275)	\
+_ELF_DEFINE_RELOC(R_AARCH64_ADR_PREL_PG_HI21_NC,		276)	\
+_ELF_DEFINE_RELOC(R_AARCH64_ADD_ABS_LO12_NC,			277)	\
+_ELF_DEFINE_RELOC(R_AARCH64_LDST8_ABS_LO12_NC,			278)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TSTBR14,				279)	\
+_ELF_DEFINE_RELOC(R_AARCH64_CONDBR19,				280)	\
+_ELF_DEFINE_RELOC(R_AARCH64_JUMP26,				282)	\
+_ELF_DEFINE_RELOC(R_AARCH64_CALL26,				283)	\
+_ELF_DEFINE_RELOC(R_AARCH64_LDST16_ABS_LO12_NC,			284)	\
+_ELF_DEFINE_RELOC(R_AARCH64_LDST32_ABS_LO12_NC,			285)	\
+_ELF_DEFINE_RELOC(R_AARCH64_LDST64_ABS_LO12_NC,			286)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_PREL_G0,			287)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_PREL_G0_NC,			288)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_PREL_G1,			289)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_PREL_G1_NC,			290)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_PREL_G2,			291)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_PREL_G2_NC,			292)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_PREL_G3,			293)	\
+_ELF_DEFINE_RELOC(R_AARCH64_LDST128_ABS_LO12_NC,		299)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_GOTOFF_G0,			300)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_GOTOFF_G0_NC,			301)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_GOTOFF_G1,			302)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_GOTOFF_G1_NC,			303)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_GOTOFF_G2,			304)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_GOTOFF_G2_NC,			305)	\
+_ELF_DEFINE_RELOC(R_AARCH64_MOVW_GOTOFF_G3,			306)	\
+_ELF_DEFINE_RELOC(R_AARCH64_GOTREL64,				307)	\
+_ELF_DEFINE_RELOC(R_AARCH64_GOTREL32,				308)	\
+_ELF_DEFINE_RELOC(R_AARCH64_GOT_LD_PREL19,			309)	\
+_ELF_DEFINE_RELOC(R_AARCH64_LD64_GOTOFF_LO15,			310)	\
+_ELF_DEFINE_RELOC(R_AARCH64_ADR_GOT_PAGE,			311)	\
+_ELF_DEFINE_RELOC(R_AARCH64_LD64_GOT_LO12_NC,			312)	\
+_ELF_DEFINE_RELOC(R_AARCH64_LD64_GOTPAGE_LO15,			313)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSGD_ADR_PREL21,			512)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSGD_ADR_PAGE21,			513)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSGD_ADD_LO12_NC,			514)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSGD_MOVW_G1,			515)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSGD_MOVW_G0_NC,			516)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_ADR_PREL21,			517)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_ADR_PAGE21,			518)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_ADD_LO12_NC,			519)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_MOVW_G1,			520)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_MOVW_G0_NC,			521)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_LD_PREL19,			522)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_MOVW_DTPREL_G2,		523)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_MOVW_DTPREL_G1,		524)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC,		525)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_MOVW_DTPREL_G0,		526)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC,		527)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_ADD_DTPREL_HI12,		529)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC,		530)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_LDST8_DTPREL_LO12,		531)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC,		532)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_LDST16_DTPREL_LO12,		533)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC,	534)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_LDST32_DTPREL_LO12,		535)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC,	536)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_LDST64_DTPREL_LO12,		537)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC,	538)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSIE_MOVW_GOTTPREL_G1,		539)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC,		540)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21,		541)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC,	542)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSIE_LD_GOTTPREL_PREL19,		543)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_MOVW_TPREL_G2,		544)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_MOVW_TPREL_G1,		545)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_MOVW_TPREL_G1_NC,		546)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_MOVW_TPREL_G0,		547)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_MOVW_TPREL_G0_NC,		548)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_ADD_TPREL_HI12,		549)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_ADD_TPREL_LO12,		550)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_ADD_TPREL_LO12_NC,		551)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_LDST8_TPREL_LO12,		552)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC,		553)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_LDST16_TPREL_LO12,		554)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC,		555)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_LDST32_TPREL_LO12,		556)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC,		557)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_LDST64_TPREL_LO12,		558)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC,		559)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSDESC_LD_PREL19,			560)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSDESC_ADR_PREL21,			561)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSDESC_ADR_PAGE21,			562)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSDESC_LD64_LO12,			563)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSDESC_ADD_LO12,			564)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSDESC_OFF_G1,			565)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSDESC_OFF_G0_NC,			566)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSDESC_LDR,			567)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSDESC_ADD,			568)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSDESC_CALL,			569)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_LDST128_TPREL_LO12,		570)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC,	571)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_LDST128_DTPREL_LO12,		572)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC,	573)	\
+_ELF_DEFINE_RELOC(R_AARCH64_COPY,				1024)	\
+_ELF_DEFINE_RELOC(R_AARCH64_GLOB_DAT,				1025)	\
+_ELF_DEFINE_RELOC(R_AARCH64_JUMP_SLOT,				1026)	\
+_ELF_DEFINE_RELOC(R_AARCH64_RELATIVE,				1027)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLS_DTPREL64,			1028)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLS_DTPMOD64,			1029)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLS_TPREL64,			1030)	\
+_ELF_DEFINE_RELOC(R_AARCH64_TLSDESC,				1031)	\
+_ELF_DEFINE_RELOC(R_AARCH64_IRELATIVE,				1032)
 
 /*
  * These are the symbols used in the Sun ``Linkers and Loaders
@@ -1388,6 +1601,10 @@ _ELF_DEFINE_RELOC(R_AMD64_PC64,		24)	\
 _ELF_DEFINE_RELOC(R_AMD64_GOTOFF64,	25)	\
 _ELF_DEFINE_RELOC(R_AMD64_GOTPC32,	26)
 
+/*
+ * Relocation definitions from the ARM ELF ABI, version "ARM IHI
+ * 0044E" released on 30th November 2012.
+ */
 #define	_ELF_DEFINE_ARM_RELOCATIONS()			\
 _ELF_DEFINE_RELOC(R_ARM_NONE,			0)	\
 _ELF_DEFINE_RELOC(R_ARM_PC24,			1)	\
@@ -1403,6 +1620,7 @@ _ELF_DEFINE_RELOC(R_ARM_THM_CALL,		10)	\
 _ELF_DEFINE_RELOC(R_ARM_THM_PC8,		11)	\
 _ELF_DEFINE_RELOC(R_ARM_BREL_ADJ,		12)	\
 _ELF_DEFINE_RELOC(R_ARM_SWI24,			13)	\
+_ELF_DEFINE_RELOC(R_ARM_TLS_DESC,		13)	\
 _ELF_DEFINE_RELOC(R_ARM_THM_SWI8,		14)	\
 _ELF_DEFINE_RELOC(R_ARM_XPC25,			15)	\
 _ELF_DEFINE_RELOC(R_ARM_THM_XPC22,		16)	\
@@ -1421,12 +1639,12 @@ _ELF_DEFINE_RELOC(R_ARM_CALL,			28)	\
 _ELF_DEFINE_RELOC(R_ARM_JUMP24,			29)	\
 _ELF_DEFINE_RELOC(R_ARM_THM_JUMP24,		30)	\
 _ELF_DEFINE_RELOC(R_ARM_BASE_ABS,		31)	\
-_ELF_DEFINE_RELOC(R_ARM_ALU_PCREL7_0,		32)	\
-_ELF_DEFINE_RELOC(R_ARM_ALU_PCREL15_8,		33)	\
-_ELF_DEFINE_RELOC(R_ARM_ALU_PCREL23_15,		34)	\
-_ELF_DEFINE_RELOC(R_ARM_LDR_SBREL_11_0,		35)	\
-_ELF_DEFINE_RELOC(R_ARM_ALU_SBREL_19_12,	36)	\
-_ELF_DEFINE_RELOC(R_ARM_ALU_SBREL_27_20,	37)	\
+_ELF_DEFINE_RELOC(R_ARM_ALU_PCREL_7_0,		32)	\
+_ELF_DEFINE_RELOC(R_ARM_ALU_PCREL_15_8,		33)	\
+_ELF_DEFINE_RELOC(R_ARM_ALU_PCREL_23_15,	34)	\
+_ELF_DEFINE_RELOC(R_ARM_LDR_SBREL_11_0_NC,	35)	\
+_ELF_DEFINE_RELOC(R_ARM_ALU_SBREL_19_12_NC,	36)	\
+_ELF_DEFINE_RELOC(R_ARM_ALU_SBREL_27_20_CK,	37)	\
 _ELF_DEFINE_RELOC(R_ARM_TARGET1,		38)	\
 _ELF_DEFINE_RELOC(R_ARM_SBREL31,		39)	\
 _ELF_DEFINE_RELOC(R_ARM_V4BX,			40)	\
@@ -1438,7 +1656,7 @@ _ELF_DEFINE_RELOC(R_ARM_MOVW_PREL_NC,		45)	\
 _ELF_DEFINE_RELOC(R_ARM_MOVT_PREL,		46)	\
 _ELF_DEFINE_RELOC(R_ARM_THM_MOVW_ABS_NC,	47)	\
 _ELF_DEFINE_RELOC(R_ARM_THM_MOVT_ABS,		48)	\
-_ELF_DEFINE_RELOC(R_ARM_MOVW_PREL_NC,		49)	\
+_ELF_DEFINE_RELOC(R_ARM_THM_MOVW_PREL_NC,	49)	\
 _ELF_DEFINE_RELOC(R_ARM_THM_MOVT_PREL,		50)	\
 _ELF_DEFINE_RELOC(R_ARM_THM_JUMP19,		51)	\
 _ELF_DEFINE_RELOC(R_ARM_THM_JUMP6,		52)	\
@@ -1501,9 +1719,27 @@ _ELF_DEFINE_RELOC(R_ARM_TLS_LE32,		108)	\
 _ELF_DEFINE_RELOC(R_ARM_TLS_LDO12,		109)	\
 _ELF_DEFINE_RELOC(R_ARM_TLS_LE12,		110)	\
 _ELF_DEFINE_RELOC(R_ARM_TLS_IE12GP,		111)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_0,		112)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_1,		113)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_2,		114)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_3,		115)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_4,		116)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_5,		117)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_6,		118)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_7,		119)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_8,		120)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_9,		121)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_10,		122)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_11,		123)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_12,		124)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_13,		125)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_14,		126)	\
+_ELF_DEFINE_RELOC(R_ARM_PRIVATE_15,		127)	\
 _ELF_DEFINE_RELOC(R_ARM_ME_TOO,			128)	\
 _ELF_DEFINE_RELOC(R_ARM_THM_TLS_DESCSEQ16,	129)	\
-_ELF_DEFINE_RELOC(R_ARM_THM_TLS_DESCSEQ32,	130)
+_ELF_DEFINE_RELOC(R_ARM_THM_TLS_DESCSEQ32,	130)	\
+_ELF_DEFINE_RELOC(R_ARM_THM_GOT_BREL12,		131)	\
+_ELF_DEFINE_RELOC(R_ARM_IRELATIVE,		140)
 
 #define	_ELF_DEFINE_IA64_RELOCATIONS()			\
 _ELF_DEFINE_RELOC(R_IA_64_NONE,			0)	\
@@ -1561,7 +1797,7 @@ _ELF_DEFINE_RELOC(R_IA_64_LTV32MSB,		0x74)	\
 _ELF_DEFINE_RELOC(R_IA_64_LTV32LSB,		0x75)	\
 _ELF_DEFINE_RELOC(R_IA_64_LTV64MSB,		0x76)	\
 _ELF_DEFINE_RELOC(R_IA_64_LTV64LSB,		0x77)	\
-_ELF_DEFINE_RELOC(R_IA_64_PCREL21BIa,		0x79)	\
+_ELF_DEFINE_RELOC(R_IA_64_PCREL21BI,		0x79)	\
 _ELF_DEFINE_RELOC(R_IA_64_PCREL22,		0x7A)	\
 _ELF_DEFINE_RELOC(R_IA_64_PCREL64I,		0x7B)	\
 _ELF_DEFINE_RELOC(R_IA_64_IPLTMSB,		0x80)	\
@@ -1587,25 +1823,45 @@ _ELF_DEFINE_RELOC(R_IA_64_DTPREL64MSB,		0xB6)	\
 _ELF_DEFINE_RELOC(R_IA_64_DTPREL64LSB,		0xB7)	\
 _ELF_DEFINE_RELOC(R_IA_64_LTOFF_DTPREL22,	0xBA)
 
-#define	_ELF_DEFINE_MIPS_RELOCATIONS()		\
-_ELF_DEFINE_RELOC(R_MIPS_NONE,		0)	\
-_ELF_DEFINE_RELOC(R_MIPS_16,		1)	\
-_ELF_DEFINE_RELOC(R_MIPS_32,		2)	\
-_ELF_DEFINE_RELOC(R_MIPS_REL32,		3)	\
-_ELF_DEFINE_RELOC(R_MIPS_26,		4)	\
-_ELF_DEFINE_RELOC(R_MIPS_HI16,		5)	\
-_ELF_DEFINE_RELOC(R_MIPS_LO16,		6)	\
-_ELF_DEFINE_RELOC(R_MIPS_GPREL16,	7)	\
-_ELF_DEFINE_RELOC(R_MIPS_LITERAL, 	8)	\
-_ELF_DEFINE_RELOC(R_MIPS_GOT16,		9)	\
-_ELF_DEFINE_RELOC(R_MIPS_PC16,		10)	\
-_ELF_DEFINE_RELOC(R_MIPS_CALL16,	11)	\
-_ELF_DEFINE_RELOC(R_MIPS_GPREL32,	12)	\
-_ELF_DEFINE_RELOC(R_MIPS_64,		18)	\
-_ELF_DEFINE_RELOC(R_MIPS_GOTHI16,	21)	\
-_ELF_DEFINE_RELOC(R_MIPS_GOTLO16,	22)	\
-_ELF_DEFINE_RELOC(R_MIPS_CALLHI16,	30)	\
-_ELF_DEFINE_RELOC(R_MIPS_CALLLO16,	31)
+#define	_ELF_DEFINE_MIPS_RELOCATIONS()			\
+_ELF_DEFINE_RELOC(R_MIPS_NONE,			0)	\
+_ELF_DEFINE_RELOC(R_MIPS_16,			1)	\
+_ELF_DEFINE_RELOC(R_MIPS_32,			2)	\
+_ELF_DEFINE_RELOC(R_MIPS_REL32,			3)	\
+_ELF_DEFINE_RELOC(R_MIPS_26,			4)	\
+_ELF_DEFINE_RELOC(R_MIPS_HI16,			5)	\
+_ELF_DEFINE_RELOC(R_MIPS_LO16,			6)	\
+_ELF_DEFINE_RELOC(R_MIPS_GPREL16,		7)	\
+_ELF_DEFINE_RELOC(R_MIPS_LITERAL, 		8)	\
+_ELF_DEFINE_RELOC(R_MIPS_GOT16,			9)	\
+_ELF_DEFINE_RELOC(R_MIPS_PC16,			10)	\
+_ELF_DEFINE_RELOC(R_MIPS_CALL16,		11)	\
+_ELF_DEFINE_RELOC(R_MIPS_GPREL32,		12)	\
+_ELF_DEFINE_RELOC(R_MIPS_SHIFT5,		16)	\
+_ELF_DEFINE_RELOC(R_MIPS_SHIFT6,		17)	\
+_ELF_DEFINE_RELOC(R_MIPS_64,			18)	\
+_ELF_DEFINE_RELOC(R_MIPS_GOT_DISP,		19)	\
+_ELF_DEFINE_RELOC(R_MIPS_GOT_PAGE,		20)	\
+_ELF_DEFINE_RELOC(R_MIPS_GOT_OFST,		21)	\
+_ELF_DEFINE_RELOC(R_MIPS_GOT_HI16,		22)	\
+_ELF_DEFINE_RELOC(R_MIPS_GOT_LO16,		23)	\
+_ELF_DEFINE_RELOC(R_MIPS_SUB,			24)	\
+_ELF_DEFINE_RELOC(R_MIPS_CALLHI16,		30)	\
+_ELF_DEFINE_RELOC(R_MIPS_CALLLO16,		31)	\
+_ELF_DEFINE_RELOC(R_MIPS_JALR,			37)	\
+_ELF_DEFINE_RELOC(R_MIPS_TLS_DTPMOD32,		38)	\
+_ELF_DEFINE_RELOC(R_MIPS_TLS_DTPREL32,		39)	\
+_ELF_DEFINE_RELOC(R_MIPS_TLS_DTPMOD64,		40)	\
+_ELF_DEFINE_RELOC(R_MIPS_TLS_DTPREL64,		41)	\
+_ELF_DEFINE_RELOC(R_MIPS_TLS_GD,		42)	\
+_ELF_DEFINE_RELOC(R_MIPS_TLS_LDM,		43)	\
+_ELF_DEFINE_RELOC(R_MIPS_TLS_DTPREL_HI16,	44)	\
+_ELF_DEFINE_RELOC(R_MIPS_TLS_DTPREL_LO16,	45)	\
+_ELF_DEFINE_RELOC(R_MIPS_TLS_GOTTPREL,		46)	\
+_ELF_DEFINE_RELOC(R_MIPS_TLS_TPREL32,		47)	\
+_ELF_DEFINE_RELOC(R_MIPS_TLS_TPREL64,		48)	\
+_ELF_DEFINE_RELOC(R_MIPS_TLS_TPREL_HI16,	49)	\
+_ELF_DEFINE_RELOC(R_MIPS_TLS_TPREL_LO16,	50)
 
 #define	_ELF_DEFINE_PPC32_RELOCATIONS()		\
 _ELF_DEFINE_RELOC(R_PPC_NONE,		0)	\
@@ -1638,7 +1894,7 @@ _ELF_DEFINE_RELOC(R_PPC_REL32,		26)	\
 _ELF_DEFINE_RELOC(R_PPC_PLT32,		27)	\
 _ELF_DEFINE_RELOC(R_PPC_PLTREL32,	28)	\
 _ELF_DEFINE_RELOC(R_PPC_PLT16_LO,	29)	\
-_ELF_DEFINE_RELOC(R_PPL_PLT16_HI,	30)	\
+_ELF_DEFINE_RELOC(R_PPC_PLT16_HI,	30)	\
 _ELF_DEFINE_RELOC(R_PPC_PLT16_HA,	31)	\
 _ELF_DEFINE_RELOC(R_PPC_SDAREL16,	32)	\
 _ELF_DEFINE_RELOC(R_PPC_SECTOFF,	33)	\
@@ -1801,6 +2057,53 @@ _ELF_DEFINE_RELOC(R_PPC64_DTPREL16_HIGHESTA,	106)	\
 _ELF_DEFINE_RELOC(R_PPC64_TLSGD,		107)	\
 _ELF_DEFINE_RELOC(R_PPC64_TLSLD,		108)
 
+#define	_ELF_DEFINE_RISCV_RELOCATIONS()			\
+_ELF_DEFINE_RELOC(R_RISCV_NONE,			0)	\
+_ELF_DEFINE_RELOC(R_RISCV_32,			1)	\
+_ELF_DEFINE_RELOC(R_RISCV_64,			2)	\
+_ELF_DEFINE_RELOC(R_RISCV_RELATIVE,		3)	\
+_ELF_DEFINE_RELOC(R_RISCV_COPY,			4)	\
+_ELF_DEFINE_RELOC(R_RISCV_JUMP_SLOT,		5)	\
+_ELF_DEFINE_RELOC(R_RISCV_TLS_DTPMOD32,		6)	\
+_ELF_DEFINE_RELOC(R_RISCV_TLS_DTPMOD64,		7)	\
+_ELF_DEFINE_RELOC(R_RISCV_TLS_DTPREL32,		8)	\
+_ELF_DEFINE_RELOC(R_RISCV_TLS_DTPREL64,		9)	\
+_ELF_DEFINE_RELOC(R_RISCV_TLS_TPREL32,		10)	\
+_ELF_DEFINE_RELOC(R_RISCV_TLS_TPREL64,		11)	\
+_ELF_DEFINE_RELOC(R_RISCV_BRANCH,		16)	\
+_ELF_DEFINE_RELOC(R_RISCV_JAL,			17)	\
+_ELF_DEFINE_RELOC(R_RISCV_CALL,			18)	\
+_ELF_DEFINE_RELOC(R_RISCV_CALL_PLT,		19)	\
+_ELF_DEFINE_RELOC(R_RISCV_GOT_HI20,		20)	\
+_ELF_DEFINE_RELOC(R_RISCV_TLS_GOT_HI20,		21)	\
+_ELF_DEFINE_RELOC(R_RISCV_TLS_GD_HI20,		22)	\
+_ELF_DEFINE_RELOC(R_RISCV_PCREL_HI20,		23)	\
+_ELF_DEFINE_RELOC(R_RISCV_PCREL_LO12_I,		24)	\
+_ELF_DEFINE_RELOC(R_RISCV_PCREL_LO12_S,		25)	\
+_ELF_DEFINE_RELOC(R_RISCV_HI20,			26)	\
+_ELF_DEFINE_RELOC(R_RISCV_LO12_I,		27)	\
+_ELF_DEFINE_RELOC(R_RISCV_LO12_S,		28)	\
+_ELF_DEFINE_RELOC(R_RISCV_TPREL_HI20,		29)	\
+_ELF_DEFINE_RELOC(R_RISCV_TPREL_LO12_I,		30)	\
+_ELF_DEFINE_RELOC(R_RISCV_TPREL_LO12_S,		31)	\
+_ELF_DEFINE_RELOC(R_RISCV_TPREL_ADD,		32)	\
+_ELF_DEFINE_RELOC(R_RISCV_ADD8,			33)	\
+_ELF_DEFINE_RELOC(R_RISCV_ADD16,		34)	\
+_ELF_DEFINE_RELOC(R_RISCV_ADD32,		35)	\
+_ELF_DEFINE_RELOC(R_RISCV_ADD64,		36)	\
+_ELF_DEFINE_RELOC(R_RISCV_SUB8,			37)	\
+_ELF_DEFINE_RELOC(R_RISCV_SUB16,		38)	\
+_ELF_DEFINE_RELOC(R_RISCV_SUB32,		39)	\
+_ELF_DEFINE_RELOC(R_RISCV_SUB64,		40)	\
+_ELF_DEFINE_RELOC(R_RISCV_GNU_VTINHERIT,	41)	\
+_ELF_DEFINE_RELOC(R_RISCV_GNU_VTENTRY,		42)	\
+_ELF_DEFINE_RELOC(R_RISCV_ALIGN,		43)	\
+_ELF_DEFINE_RELOC(R_RISCV_RVC_BRANCH,		44)	\
+_ELF_DEFINE_RELOC(R_RISCV_RVC_JUMP,		45)	\
+_ELF_DEFINE_RELOC(R_RISCV_RVC_LUI,		46)	\
+_ELF_DEFINE_RELOC(R_RISCV_GPREL_I,		47)	\
+_ELF_DEFINE_RELOC(R_RISCV_GPREL_S,		48)
+
 #define	_ELF_DEFINE_SPARC_RELOCATIONS()		\
 _ELF_DEFINE_RELOC(R_SPARC_NONE,		0)	\
 _ELF_DEFINE_RELOC(R_SPARC_8,		1)	\
@@ -1844,6 +2147,7 @@ _ELF_DEFINE_RELOC(R_SPARC_PC_HM10,	38)	\
 _ELF_DEFINE_RELOC(R_SPARC_PC_LM22,	39)	\
 _ELF_DEFINE_RELOC(R_SPARC_WDISP16,	40)	\
 _ELF_DEFINE_RELOC(R_SPARC_WDISP19,	41)	\
+_ELF_DEFINE_RELOC(R_SPARC_GLOB_JMP,	42)	\
 _ELF_DEFINE_RELOC(R_SPARC_7,		43)	\
 _ELF_DEFINE_RELOC(R_SPARC_5,		44)	\
 _ELF_DEFINE_RELOC(R_SPARC_6,		45)	\
@@ -1857,6 +2161,30 @@ _ELF_DEFINE_RELOC(R_SPARC_L44,		52)	\
 _ELF_DEFINE_RELOC(R_SPARC_REGISTER,	53)	\
 _ELF_DEFINE_RELOC(R_SPARC_UA64,		54)	\
 _ELF_DEFINE_RELOC(R_SPARC_UA16,		55)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_GD_HI22,	56)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_GD_LO10,	57)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_GD_ADD,	58)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_GD_CALL,	59)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_LDM_HI22,	60)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_LDM_LO10,	61)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_LDM_ADD,	62)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_LDM_CALL,	63)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_LDO_HIX22, 64)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_LDO_LOX10, 65)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_LDO_ADD,	66)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_IE_HI22,	67)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_IE_LO10,	68)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_IE_LD,	69)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_IE_LDX,	70)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_IE_ADD,	71)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_LE_HIX22,	72)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_LE_LOX10,	73)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_DTPMOD32,	74)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_DTPMOD64,	75)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_DTPOFF32,	76)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_DTPOFF64,	77)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_TPOFF32,	78)	\
+_ELF_DEFINE_RELOC(R_SPARC_TLS_TPOFF64,	79)	\
 _ELF_DEFINE_RELOC(R_SPARC_GOTDATA_HIX22, 80)	\
 _ELF_DEFINE_RELOC(R_SPARC_GOTDATA_LOX10, 81)	\
 _ELF_DEFINE_RELOC(R_SPARC_GOTDATA_OP_HIX22, 82)	\
@@ -1892,19 +2220,31 @@ _ELF_DEFINE_RELOC(R_X86_64_TPOFF32,	23)	\
 _ELF_DEFINE_RELOC(R_X86_64_PC64,	24)	\
 _ELF_DEFINE_RELOC(R_X86_64_GOTOFF64,	25)	\
 _ELF_DEFINE_RELOC(R_X86_64_GOTPC32,	26)	\
+_ELF_DEFINE_RELOC(R_X86_64_GOT64,	27)	\
+_ELF_DEFINE_RELOC(R_X86_64_GOTPCREL64,	28)	\
+_ELF_DEFINE_RELOC(R_X86_64_GOTPC64,	29)	\
+_ELF_DEFINE_RELOC(R_X86_64_GOTPLT64,	30)	\
+_ELF_DEFINE_RELOC(R_X86_64_PLTOFF64,	31)	\
 _ELF_DEFINE_RELOC(R_X86_64_SIZE32,	32)	\
 _ELF_DEFINE_RELOC(R_X86_64_SIZE64,	33)	\
 _ELF_DEFINE_RELOC(R_X86_64_GOTPC32_TLSDESC, 34)	\
 _ELF_DEFINE_RELOC(R_X86_64_TLSDESC_CALL, 35)	\
-_ELF_DEFINE_RELOC(R_X86_64_TLSDESC,	36)
+_ELF_DEFINE_RELOC(R_X86_64_TLSDESC,	36)	\
+_ELF_DEFINE_RELOC(R_X86_64_IRELATIVE,	37)	\
+_ELF_DEFINE_RELOC(R_X86_64_RELATIVE64,	38)	\
+_ELF_DEFINE_RELOC(R_X86_64_GOTPCRELX,	41)	\
+_ELF_DEFINE_RELOC(R_X86_64_REX_GOTPCRELX, 42)
 
 #define	_ELF_DEFINE_RELOCATIONS()		\
 _ELF_DEFINE_386_RELOCATIONS()			\
+_ELF_DEFINE_AARCH64_RELOCATIONS()		\
 _ELF_DEFINE_AMD64_RELOCATIONS()			\
+_ELF_DEFINE_ARM_RELOCATIONS()			\
 _ELF_DEFINE_IA64_RELOCATIONS()			\
 _ELF_DEFINE_MIPS_RELOCATIONS()			\
 _ELF_DEFINE_PPC32_RELOCATIONS()			\
 _ELF_DEFINE_PPC64_RELOCATIONS()			\
+_ELF_DEFINE_RISCV_RELOCATIONS()			\
 _ELF_DEFINE_SPARC_RELOCATIONS()			\
 _ELF_DEFINE_X86_64_RELOCATIONS()
 
@@ -2058,11 +2398,11 @@ typedef struct {
 
 /* 64-bit entry. */
 typedef struct {
-	Elf64_Word l_name;
-	Elf64_Word l_time_stamp;
-	Elf64_Word l_checksum;
-	Elf64_Word l_version;
-	Elf64_Word l_flags;
+	Elf64_Word l_name;	     /* The name of a shared object. */
+	Elf64_Word l_time_stamp;     /* 32-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;
 
 #define	_ELF_DEFINE_LL_FLAGS()			\
@@ -2164,7 +2504,7 @@ _ELF_DEFINE_ODK(ODK_HWOR,       8,      "hardware OR patch applied")	\
 _ELF_DEFINE_ODK(ODK_GP_GROUP,   9,					\
 	"GP group to use for text/data sections")			\
 _ELF_DEFINE_ODK(ODK_IDENT,      10,     "ID information")		\
-_ELF_DEFINE_ODK(ODK_PAGESIZE,   11,     "page size infomation")
+_ELF_DEFINE_ODK(ODK_PAGESIZE,   11,     "page size information")
 
 #undef	_ELF_DEFINE_ODK
 #define	_ELF_DEFINE_ODK(N, V, DESCR)	N = V ,
@@ -2310,12 +2650,12 @@ typedef struct {
 /* 64 bit PHDR entry. */
 typedef struct {
 	Elf64_Word	p_type;	     /* Type of segment. */
-	Elf64_Word	p_flags;     /* File offset to segment. */
-	Elf64_Off	p_offset;    /* Virtual address in memory. */
-	Elf64_Addr	p_vaddr;     /* Physical address (if relevant). */
-	Elf64_Addr	p_paddr;     /* Size of segment in file. */
-	Elf64_Xword	p_filesz;    /* Size of segment in memory. */
-	Elf64_Xword	p_memsz;     /* Segment flags. */
+	Elf64_Word	p_flags;     /* Segment flags. */
+	Elf64_Off	p_offset;    /* File offset to segment. */
+	Elf64_Addr	p_vaddr;     /* Virtual address in memory. */
+	Elf64_Addr	p_paddr;     /* Physical address (if relevant). */
+	Elf64_Xword	p_filesz;    /* Size of segment in file. */
+	Elf64_Xword	p_memsz;     /* Size of segment in memory. */
 	Elf64_Xword	p_align;     /* Alignment constraints. */
 } Elf64_Phdr;
 
@@ -2399,11 +2739,11 @@ typedef struct {
 
 typedef struct {
 	Elf64_Word	st_name;     /* index of symbol's name */
-	unsigned char	st_info;     /* value for the symbol */
-	unsigned char	st_other;    /* size of associated data */
-	Elf64_Half	st_shndx;    /* type and binding attributes */
-	Elf64_Addr	st_value;    /* visibility */
-	Elf64_Xword	st_size;     /* index of related section */
+	unsigned char	st_info;     /* type and binding attributes */
+	unsigned char	st_other;    /* visibility */
+	Elf64_Half	st_shndx;    /* index of related section */
+	Elf64_Addr	st_value;    /* value for the symbol */
+	Elf64_Xword	st_size;     /* size of associated data */
 } Elf64_Sym;
 
 #define ELF32_ST_BIND(I)	((I) >> 4)
diff --git a/rtemstoolkit/elftoolchain/common/native-elf-format b/rtemstoolkit/elftoolchain/common/native-elf-format
index 4b06672..2bdd914 100755
--- a/rtemstoolkit/elftoolchain/common/native-elf-format
+++ b/rtemstoolkit/elftoolchain/common/native-elf-format
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $Id: native-elf-format 2064 2011-10-26 15:12:32Z jkoshy $
+# $Id: native-elf-format 3293 2016-01-07 19:26:27Z emaste $
 #
 # Find the native ELF format for a host platform by compiling a
 # test object and examining the resulting object.
@@ -19,7 +19,7 @@ touch ${tmp_c}
 echo "/* Generated by ${program} on `date` */"
 
 cc -c ${tmp_c} -o ${tmp_o}
-LANG="C" readelf -h ${tmp_o} | awk '
+LC_ALL=C readelf -h ${tmp_o} | awk '
 $1 ~ "Class:" {
         sub("ELF","",$2); elfclass = $2;
     }
@@ -33,7 +33,9 @@ $1 ~ "Data:"  {
 $1 ~ "Machine:" {
         if (match($0, "Intel.*386")) {
             elfarch = "EM_386";
-        } else if (match($0, ".*X86-64")) {
+        } else if (match($0, "MIPS")) {
+            elfarch = "EM_MIPS";
+        } else if (match($0, ".*[xX]86-64")) {
             elfarch = "EM_X86_64";
         } else {
             elfarch = "unknown";
@@ -44,3 +46,4 @@ END {
     printf("#define	ELFTC_ARCH	%s\n", elfarch);
     printf("#define	ELFTC_BYTEORDER	ELFDATA2%s\n", elfdata);
 }'
+
diff --git a/rtemstoolkit/elftoolchain/common/os.Linux.mk b/rtemstoolkit/elftoolchain/common/os.Linux.mk
index 2339e2a..386f99b 100644
--- a/rtemstoolkit/elftoolchain/common/os.Linux.mk
+++ b/rtemstoolkit/elftoolchain/common/os.Linux.mk
@@ -1,13 +1,15 @@
 #
 # Build recipes for Linux based operating systems.
 #
-# $Id: os.Linux.mk 2064 2011-10-26 15:12:32Z jkoshy $
+# $Id: os.Linux.mk 3594 2018-04-11 18:26:50Z jkoshy $
 
 _NATIVE_ELF_FORMAT = native-elf-format
 
-.BEGIN:	${_NATIVE_ELF_FORMAT}.h
+.if !make(obj)
+.BEGIN:	${.OBJDIR}/${_NATIVE_ELF_FORMAT}.h
 
-${_NATIVE_ELF_FORMAT}.h:
+${.OBJDIR}/${_NATIVE_ELF_FORMAT}.h:
 	${.CURDIR}/${_NATIVE_ELF_FORMAT} > ${.TARGET} || rm ${.TARGET}
+.endif
 
-CLEANFILES += ${_NATIVE_ELF_FORMAT}.h
+CLEANFILES += ${.OBJDIR}/${_NATIVE_ELF_FORMAT}.h
diff --git a/rtemstoolkit/elftoolchain/common/utarray.h b/rtemstoolkit/elftoolchain/common/utarray.h
new file mode 100644
index 0000000..090e354
--- /dev/null
+++ b/rtemstoolkit/elftoolchain/common/utarray.h
@@ -0,0 +1,237 @@
+/*
+Copyright (c) 2008-2013, Troy D. Hanson   http://uthash.sourceforge.net
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* $Id: utarray.h 2694 2012-11-24 17:11:58Z kaiwang27 $ */
+
+/* a dynamic array implementation using macros 
+ * see http://uthash.sourceforge.net/utarray
+ */
+#ifndef UTARRAY_H
+#define UTARRAY_H
+
+#define UTARRAY_VERSION 1.9.7
+
+#ifdef __GNUC__
+#define _UNUSED_ __attribute__ ((__unused__)) 
+#else
+#define _UNUSED_ 
+#endif
+
+#include <stddef.h>  /* size_t */
+#include <string.h>  /* memset, etc */
+#include <stdlib.h>  /* exit */
+
+#ifndef oom
+#define oom() exit(-1)
+#endif
+
+typedef void (ctor_f)(void *dst, const void *src);
+typedef void (dtor_f)(void *elt);
+typedef void (init_f)(void *elt);
+typedef struct {
+    size_t sz;
+    init_f *init;
+    ctor_f *copy;
+    dtor_f *dtor;
+} UT_icd;
+
+typedef struct {
+    unsigned i,n;/* i: index of next available slot, n: num slots */
+    UT_icd icd;  /* initializer, copy and destructor functions */
+    char *d;     /* n slots of size icd->sz*/
+} UT_array;
+
+#define utarray_init(a,_icd) do {                                             \
+  memset(a,0,sizeof(UT_array));                                               \
+  (a)->icd=*_icd;                                                             \
+} while(0)
+
+#define utarray_done(a) do {                                                  \
+  if ((a)->n) {                                                               \
+    if ((a)->icd.dtor) {                                                      \
+      size_t _ut_i;                                                           \
+      for(_ut_i=0; _ut_i < (a)->i; _ut_i++) {                                 \
+        (a)->icd.dtor(utarray_eltptr(a,_ut_i));                               \
+      }                                                                       \
+    }                                                                         \
+    free((a)->d);                                                             \
+  }                                                                           \
+  (a)->n=0;                                                                   \
+} while(0)
+
+#define utarray_new(a,_icd) do {                                              \
+  a=(UT_array*)malloc(sizeof(UT_array));                                      \
+  utarray_init(a,_icd);                                                       \
+} while(0)
+
+#define utarray_free(a) do {                                                  \
+  utarray_done(a);                                                            \
+  free(a);                                                                    \
+} while(0)
+
+#define utarray_reserve(a,by) do {                                            \
+  if (((a)->i+by) > ((a)->n)) {                                               \
+    while(((a)->i+by) > ((a)->n)) { (a)->n = ((a)->n ? (2*(a)->n) : 8); }     \
+    if ( ((a)->d=(char*)realloc((a)->d, (a)->n*(a)->icd.sz)) == NULL) oom();  \
+  }                                                                           \
+} while(0)
+
+#define utarray_push_back(a,p) do {                                           \
+  utarray_reserve(a,1);                                                       \
+  if ((a)->icd.copy) { (a)->icd.copy( _utarray_eltptr(a,(a)->i++), p); }      \
+  else { memcpy(_utarray_eltptr(a,(a)->i++), p, (a)->icd.sz); };              \
+} while(0)
+
+#define utarray_pop_back(a) do {                                              \
+  if ((a)->icd.dtor) { (a)->icd.dtor( _utarray_eltptr(a,--((a)->i))); }       \
+  else { (a)->i--; }                                                          \
+} while(0)
+
+#define utarray_extend_back(a) do {                                           \
+  utarray_reserve(a,1);                                                       \
+  if ((a)->icd.init) { (a)->icd.init(_utarray_eltptr(a,(a)->i)); }            \
+  else { memset(_utarray_eltptr(a,(a)->i),0,(a)->icd.sz); }                   \
+  (a)->i++;                                                                   \
+} while(0)
+
+#define utarray_len(a) ((a)->i)
+
+#define utarray_eltptr(a,j) (((j) < (a)->i) ? _utarray_eltptr(a,j) : NULL)
+#define _utarray_eltptr(a,j) ((char*)((a)->d + ((a)->icd.sz*(j) )))
+
+#define utarray_insert(a,p,j) do {                                            \
+  utarray_reserve(a,1);                                                       \
+  if (j > (a)->i) break;                                                      \
+  if ((j) < (a)->i) {                                                         \
+    memmove( _utarray_eltptr(a,(j)+1), _utarray_eltptr(a,j),                  \
+             ((a)->i - (j))*((a)->icd.sz));                                   \
+  }                                                                           \
+  if ((a)->icd.copy) { (a)->icd.copy( _utarray_eltptr(a,j), p); }             \
+  else { memcpy(_utarray_eltptr(a,j), p, (a)->icd.sz); };                     \
+  (a)->i++;                                                                   \
+} while(0)
+
+#define utarray_inserta(a,w,j) do {                                           \
+  if (utarray_len(w) == 0) break;                                             \
+  if (j > (a)->i) break;                                                      \
+  utarray_reserve(a,utarray_len(w));                                          \
+  if ((j) < (a)->i) {                                                         \
+    memmove(_utarray_eltptr(a,(j)+utarray_len(w)),                            \
+            _utarray_eltptr(a,j),                                             \
+            ((a)->i - (j))*((a)->icd.sz));                                    \
+  }                                                                           \
+  if ((a)->icd.copy) {                                                        \
+    size_t _ut_i;                                                             \
+    for(_ut_i=0;_ut_i<(w)->i;_ut_i++) {                                       \
+      (a)->icd.copy(_utarray_eltptr(a,j+_ut_i), _utarray_eltptr(w,_ut_i));    \
+    }                                                                         \
+  } else {                                                                    \
+    memcpy(_utarray_eltptr(a,j), _utarray_eltptr(w,0),                        \
+           utarray_len(w)*((a)->icd.sz));                                     \
+  }                                                                           \
+  (a)->i += utarray_len(w);                                                   \
+} while(0)
+
+#define utarray_resize(dst,num) do {                                          \
+  size_t _ut_i;                                                               \
+  if (dst->i > (size_t)(num)) {                                               \
+    if ((dst)->icd.dtor) {                                                    \
+      for(_ut_i=num; _ut_i < dst->i; _ut_i++) {                               \
+        (dst)->icd.dtor(utarray_eltptr(dst,_ut_i));                           \
+      }                                                                       \
+    }                                                                         \
+  } else if (dst->i < (size_t)(num)) {                                        \
+    utarray_reserve(dst,num-dst->i);                                          \
+    if ((dst)->icd.init) {                                                    \
+      for(_ut_i=dst->i; _ut_i < num; _ut_i++) {                               \
+        (dst)->icd.init(utarray_eltptr(dst,_ut_i));                           \
+      }                                                                       \
+    } else {                                                                  \
+      memset(_utarray_eltptr(dst,dst->i),0,(dst)->icd.sz*(num-dst->i));       \
+    }                                                                         \
+  }                                                                           \
+  dst->i = num;                                                               \
+} while(0)
+
+#define utarray_concat(dst,src) do {                                          \
+  utarray_inserta((dst),(src),utarray_len(dst));                              \
+} while(0)
+
+#define utarray_erase(a,pos,len) do {                                         \
+  if ((a)->icd.dtor) {                                                        \
+    size_t _ut_i;                                                             \
+    for(_ut_i=0; _ut_i < len; _ut_i++) {                                      \
+      (a)->icd.dtor(utarray_eltptr((a),pos+_ut_i));                           \
+    }                                                                         \
+  }                                                                           \
+  if ((a)->i > (pos+len)) {                                                   \
+    memmove( _utarray_eltptr((a),pos), _utarray_eltptr((a),pos+len),          \
+            (((a)->i)-(pos+len))*((a)->icd.sz));                              \
+  }                                                                           \
+  (a)->i -= (len);                                                            \
+} while(0)
+
+#define utarray_renew(a,u) do {                                               \
+  if (a) utarray_clear(a); \
+  else utarray_new((a),(u));   \
+} while(0) 
+
+#define utarray_clear(a) do {                                                 \
+  if ((a)->i > 0) {                                                           \
+    if ((a)->icd.dtor) {                                                      \
+      size_t _ut_i;                                                           \
+      for(_ut_i=0; _ut_i < (a)->i; _ut_i++) {                                 \
+        (a)->icd.dtor(utarray_eltptr(a,_ut_i));                               \
+      }                                                                       \
+    }                                                                         \
+    (a)->i = 0;                                                               \
+  }                                                                           \
+} while(0)
+
+#define utarray_sort(a,cmp) do {                                              \
+  qsort((a)->d, (a)->i, (a)->icd.sz, cmp);                                    \
+} while(0)
+
+#define utarray_find(a,v,cmp) bsearch((v),(a)->d,(a)->i,(a)->icd.sz,cmp)
+
+#define utarray_front(a) (((a)->i) ? (_utarray_eltptr(a,0)) : NULL)
+#define utarray_next(a,e) (((e)==NULL) ? utarray_front(a) : (((int)((a)->i) > (utarray_eltidx(a,e)+1)) ? _utarray_eltptr(a,utarray_eltidx(a,e)+1) : NULL))
+#define utarray_prev(a,e) (((e)==NULL) ? utarray_back(a) : ((utarray_eltidx(a,e) > 0) ? _utarray_eltptr(a,utarray_eltidx(a,e)-1) : NULL))
+#define utarray_back(a) (((a)->i) ? (_utarray_eltptr(a,(a)->i-1)) : NULL)
+#define utarray_eltidx(a,e) (((char*)(e) >= (char*)((a)->d)) ? (int)(((char*)(e) - (char*)((a)->d))/(a)->icd.sz) : -1)
+
+/* last we pre-define a few icd for common utarrays of ints and strings */
+static void utarray_str_cpy(void *dst, const void *src) {
+  char *const*_src = (char*const*)src, **_dst = (char**)dst;
+  *_dst = (*_src == NULL) ? NULL : strdup(*_src);
+}
+static void utarray_str_dtor(void *elt) {
+  char **eltc = (char**)elt;
+  if (*eltc) free(*eltc);
+}
+static const UT_icd ut_str_icd _UNUSED_ = {sizeof(char*),NULL,utarray_str_cpy,utarray_str_dtor};
+static const UT_icd ut_int_icd _UNUSED_ = {sizeof(int),NULL,NULL,NULL};
+static const UT_icd ut_ptr_icd _UNUSED_ = {sizeof(void*),NULL,NULL,NULL};
+
+
+#endif /* UTARRAY_H */
diff --git a/rtemstoolkit/elftoolchain/common/uthash.h b/rtemstoolkit/elftoolchain/common/uthash.h
index 8428b9c..79e1e71 100644
--- a/rtemstoolkit/elftoolchain/common/uthash.h
+++ b/rtemstoolkit/elftoolchain/common/uthash.h
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2003-2011, Troy D. Hanson     http://uthash.sourceforge.net
+Copyright (c) 2003-2013, Troy D. Hanson     http://uthash.sourceforge.net
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -21,7 +21,7 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-/* $Id: uthash.h 2064 2011-10-26 15:12:32Z jkoshy $ */
+/* $Id: uthash.h 2682 2012-11-23 22:04:22Z kaiwang27 $ */
 
 #ifndef UTHASH_H
 #define UTHASH_H 
@@ -66,14 +66,24 @@ typedef unsigned char uint8_t;
 #include <inttypes.h>   /* uint32_t */
 #endif
 
-#define UTHASH_VERSION 1.9.4
+#define UTHASH_VERSION 1.9.7
 
+#ifndef uthash_fatal
 #define uthash_fatal(msg) exit(-1)        /* fatal error (out of memory,etc) */
+#endif
+#ifndef uthash_malloc
 #define uthash_malloc(sz) malloc(sz)      /* malloc fcn                      */
+#endif
+#ifndef uthash_free
 #define uthash_free(ptr,sz) free(ptr)     /* free fcn                        */
+#endif
 
+#ifndef uthash_noexpand_fyi
 #define uthash_noexpand_fyi(tbl)          /* can be defined to log noexpand  */
+#endif
+#ifndef uthash_expand_fyi
 #define uthash_expand_fyi(tbl)            /* can be defined to log expands   */
+#endif
 
 /* initial number of buckets */
 #define HASH_INITIAL_NUM_BUCKETS 32      /* initial number of buckets        */
@@ -106,12 +116,12 @@ do {
   if (!((tbl)->bloom_bv))  { uthash_fatal( "out of memory"); }                   \
   memset((tbl)->bloom_bv, 0, HASH_BLOOM_BYTELEN);                                \
   (tbl)->bloom_sig = HASH_BLOOM_SIGNATURE;                                       \
-} while (0);
+} while (0) 
 
 #define HASH_BLOOM_FREE(tbl)                                                     \
 do {                                                                             \
   uthash_free((tbl)->bloom_bv, HASH_BLOOM_BYTELEN);                              \
-} while (0);
+} while (0) 
 
 #define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8] |= (1U << ((idx)%8)))
 #define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8] & (1U << ((idx)%8)))
@@ -149,14 +159,14 @@ do {
 } while(0)
 
 #define HASH_ADD(hh,head,fieldname,keylen_in,add)                                \
-        HASH_ADD_KEYPTR(hh,head,&add->fieldname,keylen_in,add)
+        HASH_ADD_KEYPTR(hh,head,&((add)->fieldname),keylen_in,add)
  
 #define HASH_ADD_KEYPTR(hh,head,keyptr,keylen_in,add)                            \
 do {                                                                             \
  unsigned _ha_bkt;                                                               \
  (add)->hh.next = NULL;                                                          \
  (add)->hh.key = (char*)keyptr;                                                  \
- (add)->hh.keylen = keylen_in;                                                   \
+ (add)->hh.keylen = (unsigned)keylen_in;                                                   \
  if (!(head)) {                                                                  \
     head = (add);                                                                \
     (head)->hh.prev = NULL;                                                      \
@@ -207,17 +217,17 @@ do {
         _hd_hh_del = &((delptr)->hh);                                            \
         if ((delptr) == ELMT_FROM_HH((head)->hh.tbl,(head)->hh.tbl->tail)) {     \
             (head)->hh.tbl->tail =                                               \
-                (UT_hash_handle*)((char*)((delptr)->hh.prev) +                   \
+                (UT_hash_handle*)((ptrdiff_t)((delptr)->hh.prev) +               \
                 (head)->hh.tbl->hho);                                            \
         }                                                                        \
         if ((delptr)->hh.prev) {                                                 \
-            ((UT_hash_handle*)((char*)((delptr)->hh.prev) +                      \
+            ((UT_hash_handle*)((ptrdiff_t)((delptr)->hh.prev) +                  \
                     (head)->hh.tbl->hho))->next = (delptr)->hh.next;             \
         } else {                                                                 \
             DECLTYPE_ASSIGN(head,(delptr)->hh.next);                             \
         }                                                                        \
         if (_hd_hh_del->next) {                                                  \
-            ((UT_hash_handle*)((char*)_hd_hh_del->next +                         \
+            ((UT_hash_handle*)((ptrdiff_t)_hd_hh_del->next +                     \
                     (head)->hh.tbl->hho))->prev =                                \
                     _hd_hh_del->prev;                                            \
         }                                                                        \
@@ -357,7 +367,7 @@ do {
   for(_fn_i=0; _fn_i < keylen; _fn_i++)                                          \
       hashv = (hashv * 16777619) ^ _hf_key[_fn_i];                               \
   bkt = hashv & (num_bkts-1);                                                    \
-} while(0);
+} while(0) 
  
 #define HASH_OAT(key,keylen,num_bkts,hashv,bkt)                                  \
 do {                                                                             \
@@ -394,7 +404,7 @@ do {
   char *_hj_key=(char*)(key);                                                    \
   hashv = 0xfeedbeef;                                                            \
   _hj_i = _hj_j = 0x9e3779b9;                                                    \
-  _hj_k = keylen;                                                                \
+  _hj_k = (unsigned)keylen;                                                                \
   while (_hj_k >= 12) {                                                          \
     _hj_i +=    (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 )                      \
         + ( (unsigned)_hj_key[2] << 16 )                                         \
@@ -482,7 +492,7 @@ do {
     hashv ^= hashv << 25;                                                        \
     hashv += hashv >> 6;                                                         \
     bkt = hashv & (num_bkts-1);                                                  \
-} while(0);
+} while(0) 
 
 #ifdef HASH_USING_NO_STRICT_ALIASING
 /* The MurmurHash exploits some CPU's (x86,x86_64) tolerance for unaligned reads.
@@ -494,7 +504,7 @@ do {
  *   gcc -m64 -dM -E - < /dev/null                  (on gcc)
  *   cc -## a.c (where a.c is a simple test file)   (Sun Studio)
  */
-#if (defined(__i386__) || defined(__x86_64__)) 
+#if (defined(__i386__) || defined(__x86_64__)  || defined(_M_IX86))
 #define MUR_GETBLOCK(p,i) p[i]
 #else /* non intel */
 #define MUR_PLUS0_ALIGNED(p) (((unsigned long)p & 0x3) == 0)
@@ -533,10 +543,12 @@ do {                                                                   \
   uint32_t _mur_h1 = 0xf88D5353;                                       \
   uint32_t _mur_c1 = 0xcc9e2d51;                                       \
   uint32_t _mur_c2 = 0x1b873593;                                       \
+  uint32_t _mur_k1 = 0;                                                \
+  const uint8_t *_mur_tail;                                            \
   const uint32_t *_mur_blocks = (const uint32_t*)(_mur_data+_mur_nblocks*4); \
   int _mur_i;                                                          \
   for(_mur_i = -_mur_nblocks; _mur_i; _mur_i++) {                      \
-    uint32_t _mur_k1 = MUR_GETBLOCK(_mur_blocks,_mur_i);               \
+    _mur_k1 = MUR_GETBLOCK(_mur_blocks,_mur_i);                        \
     _mur_k1 *= _mur_c1;                                                \
     _mur_k1 = MUR_ROTL32(_mur_k1,15);                                  \
     _mur_k1 *= _mur_c2;                                                \
@@ -545,8 +557,8 @@ do {                                                                   \
     _mur_h1 = MUR_ROTL32(_mur_h1,13);                                  \
     _mur_h1 = _mur_h1*5+0xe6546b64;                                    \
   }                                                                    \
-  const uint8_t *_mur_tail = (const uint8_t*)(_mur_data + _mur_nblocks*4); \
-  uint32_t _mur_k1=0;                                                  \
+  _mur_tail = (const uint8_t*)(_mur_data + _mur_nblocks*4);            \
+  _mur_k1=0;                                                           \
   switch((keylen) & 3) {                                               \
     case 3: _mur_k1 ^= _mur_tail[2] << 16;                             \
     case 2: _mur_k1 ^= _mur_tail[1] << 8;                              \
@@ -572,10 +584,10 @@ do {
  if (head.hh_head) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,head.hh_head));          \
  else out=NULL;                                                                  \
  while (out) {                                                                   \
-    if (out->hh.keylen == keylen_in) {                                           \
-        if ((HASH_KEYCMP(out->hh.key,keyptr,keylen_in)) == 0) break;             \
+    if ((out)->hh.keylen == keylen_in) {                                           \
+        if ((HASH_KEYCMP((out)->hh.key,keyptr,keylen_in)) == 0) break;             \
     }                                                                            \
-    if (out->hh.hh_next) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,out->hh.hh_next)); \
+    if ((out)->hh.hh_next) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,(out)->hh.hh_next)); \
     else out = NULL;                                                             \
  }                                                                               \
 } while(0)
@@ -816,6 +828,7 @@ do {
   if (head) {                                                                    \
     uthash_free((head)->hh.tbl->buckets,                                         \
                 (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket));      \
+    HASH_BLOOM_FREE((head)->hh.tbl);                                             \
     uthash_free((head)->hh.tbl, sizeof(UT_hash_table));                          \
     (head)=NULL;                                                                 \
   }                                                                              \
diff --git a/rtemstoolkit/elftoolchain/libelf/Makefile b/rtemstoolkit/elftoolchain/libelf/Makefile
index 41e902a..5d4beaa 100644
--- a/rtemstoolkit/elftoolchain/libelf/Makefile
+++ b/rtemstoolkit/elftoolchain/libelf/Makefile
@@ -1,6 +1,6 @@
-# $Id: Makefile 1345 2011-01-01 11:17:52Z jkoshy $
+# $Id: Makefile 3594 2018-04-11 18:26:50Z jkoshy $
 
-TOP=	${.CURDIR}/..
+TOP=	..
 
 LIB=	elf
 
@@ -19,6 +19,7 @@ SRCS=	elf.c							\
 	elf_kind.c						\
 	elf_memory.c						\
 	elf_next.c						\
+	elf_open.c						\
 	elf_rand.c						\
 	elf_rawfile.c						\
 	elf_phnum.c						\
@@ -51,11 +52,15 @@ SRCS=	elf.c							\
 	libelf_data.c						\
 	libelf_ehdr.c						\
 	libelf_extended.c					\
+	libelf_memory.c						\
+	libelf_open.c						\
 	libelf_phdr.c						\
 	libelf_shdr.c						\
 	libelf_xlate.c						\
 	${GENSRCS}
-INCS=	libelf.h gelf.h
+
+INCS=		libelf.h gelf.h
+INCSDIR=	/usr/include
 
 GENSRCS=	libelf_fsize.c libelf_msize.c libelf_convert.c
 CLEANFILES=	${GENSRCS}
@@ -87,6 +92,7 @@ MAN=	elf.3							\
 	elf_kind.3						\
 	elf_memory.3						\
 	elf_next.3						\
+	elf_open.3						\
 	elf_rawfile.3						\
 	elf_rand.3						\
 	elf_strptr.3						\
@@ -126,6 +132,7 @@ MLINKS+= \
 	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	\
diff --git a/rtemstoolkit/elftoolchain/libelf/Version.map b/rtemstoolkit/elftoolchain/libelf/Version.map
index 2c595ea..e71a591 100644
--- a/rtemstoolkit/elftoolchain/libelf/Version.map
+++ b/rtemstoolkit/elftoolchain/libelf/Version.map
@@ -1,9 +1,6 @@
-/*
- * $Id: Version.map 2033 2011-10-23 09:21:13Z jkoshy $
- * 
- * $FreeBSD: src/lib/libelf/Version.map,v 1.3 2007/04/29 14:05:22 deischen Exp $
- */
-FBSD_1.0 {
+/* $Id: Version.map 2574 2012-09-11 15:11:59Z jkoshy $ */
+
+R1.0 {
 global:
 	elf32_checksum;
 	elf32_fsize;
@@ -41,12 +38,12 @@ global:
 	elf_getbase;
 	elf_getdata;
 	elf_getident;
-	elf_getscn;
 	elf_getphdrnum;
 	elf_getphnum;
+	elf_getscn;
 	elf_getshdrnum;
-	elf_getshnum;
 	elf_getshdrstrndx;
+	elf_getshnum;
 	elf_getshstrndx;
 	elf_hash;
 	elf_kind;
@@ -56,6 +53,8 @@ global:
 	elf_newscn;
 	elf_next;
 	elf_nextscn;
+	elf_open;
+	elf_openmemory;
 	elf_rand;
 	elf_rawdata;
 	elf_rawfile;
diff --git a/rtemstoolkit/elftoolchain/libelf/_libelf.h b/rtemstoolkit/elftoolchain/libelf/_libelf.h
index ef15642..be45335 100644
--- a/rtemstoolkit/elftoolchain/libelf/_libelf.h
+++ b/rtemstoolkit/elftoolchain/libelf/_libelf.h
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: _libelf.h 1921 2011-09-23 08:04:02Z jkoshy $
+ * $Id: _libelf.h 3174 2015-03-27 17:13:41Z emaste $
  */
 
 #ifndef	__LIBELF_H_
@@ -48,7 +48,7 @@ struct _libelf_globals {
 	int		libelf_error;
 	int		libelf_fillchar;
 	unsigned int	libelf_version;
-	char		libelf_msg[LIBELF_MSG_SIZE];
+	unsigned char	libelf_msg[LIBELF_MSG_SIZE];
 };
 
 extern struct _libelf_globals _libelf;
@@ -58,9 +58,11 @@ extern struct _libelf_globals _libelf;
 #define	LIBELF_ELF_ERROR_MASK			0xFF
 #define	LIBELF_OS_ERROR_SHIFT			8
 
+#define	LIBELF_ERROR(E, O) (((E) & LIBELF_ELF_ERROR_MASK) |	\
+	((O) << LIBELF_OS_ERROR_SHIFT))
+
 #define	LIBELF_SET_ERROR(E, O) do {					\
-	LIBELF_PRIVATE(error) = ((ELF_E_##E & LIBELF_ELF_ERROR_MASK)|	\
-	    ((O) << LIBELF_OS_ERROR_SHIFT));				\
+		LIBELF_PRIVATE(error) = LIBELF_ERROR(ELF_E_##E, (O));	\
 	} while (0)
 
 #define	LIBELF_ADJUST_AR_SIZE(S)	(((S) + 1U) & ~1U)
@@ -69,14 +71,14 @@ extern struct _libelf_globals _libelf;
  * Flags for library internal use.  These use the upper 16 bits of the
  * `e_flags' field.
  */
-#define	LIBELF_F_API_MASK	0x00FFFF  /* Flags defined by the API. */
-#define	LIBELF_F_AR_HEADER	0x010000  /* translated header available */
-#define	LIBELF_F_AR_VARIANT_SVR4 0x020000 /* BSD style ar(1) archive */
-#define	LIBELF_F_DATA_MALLOCED	0x040000 /* whether data was malloc'ed */
-#define	LIBELF_F_RAWFILE_MALLOC	0x080000 /* whether e_rawfile was malloc'ed */
-#define	LIBELF_F_RAWFILE_MMAP	0x100000 /* whether e_rawfile was mmap'ed */
-#define	LIBELF_F_SHDRS_LOADED	0x200000 /* whether all shdrs were read in */
-#define	LIBELF_F_SPECIAL_FILE	0x400000 /* non-regular file */
+#define	LIBELF_F_API_MASK	0x00FFFFU  /* Flags defined by the API. */
+#define	LIBELF_F_AR_HEADER	0x010000U  /* translated header available */
+#define	LIBELF_F_AR_VARIANT_SVR4 0x020000U /* BSD style ar(1) archive */
+#define	LIBELF_F_DATA_MALLOCED	0x040000U /* whether data was malloc'ed */
+#define	LIBELF_F_RAWFILE_MALLOC	0x080000U /* whether e_rawfile was malloc'ed */
+#define	LIBELF_F_RAWFILE_MMAP	0x100000U /* whether e_rawfile was mmap'ed */
+#define	LIBELF_F_SHDRS_LOADED	0x200000U /* whether all shdrs were read in */
+#define	LIBELF_F_SPECIAL_FILE	0x400000U /* non-regular file */
 
 struct _Elf {
 	int		e_activations;	/* activation count */
@@ -87,7 +89,7 @@ struct _Elf {
 	unsigned int	e_flags;	/* ELF_F_* & LIBELF_F_* flags */
 	Elf_Kind	e_kind;		/* ELF_K_* */
 	Elf		*e_parent; 	/* non-NULL for archive members */
-	char		*e_rawfile;	/* uninterpreted bytes */
+	unsigned char	*e_rawfile;	/* uninterpreted bytes */
 	size_t		e_rawsize;	/* size of uninterpreted bytes */
 	unsigned int	e_version;	/* file version */
 
@@ -97,16 +99,16 @@ struct _Elf {
 	 */
 	union {
 		Elf_Arhdr	*e_arhdr;	/* translated header */
-		char		*e_rawhdr;	/* untranslated header */
+		unsigned char	*e_rawhdr;	/* untranslated header */
 	} e_hdr;
 
 	union {
 		struct {		/* ar(1) archives */
 			off_t	e_next;	/* set by elf_rand()/elf_next() */
 			int	e_nchildren;
-			char	*e_rawstrtab;	/* file name strings */
+			unsigned char *e_rawstrtab; /* file name strings */
 			size_t	e_rawstrtabsz;
-			char	*e_rawsymtab;	/* symbol table */
+			unsigned char *e_rawsymtab;	/* symbol table */
 			size_t	e_rawsymtabsz;
 			Elf_Arsym *e_symtab;
 			size_t	e_symtabsz;
@@ -128,13 +130,23 @@ struct _Elf {
 	} e_u;
 };
 
+/*
+ * The internal descriptor wrapping the "Elf_Data" type.
+ */
+struct _Libelf_Data {
+	Elf_Data	d_data;		/* The exported descriptor. */
+	Elf_Scn		*d_scn;		/* The containing section */
+	unsigned int	d_flags;
+	STAILQ_ENTRY(_Libelf_Data) d_next;
+};
+
 struct _Elf_Scn {
 	union {
 		Elf32_Shdr	s_shdr32;
 		Elf64_Shdr	s_shdr64;
 	} s_shdr;
-	STAILQ_HEAD(, _Elf_Data) s_data;	/* list of Elf_Data descriptors */
-	STAILQ_HEAD(, _Elf_Data) s_rawdata;	/* raw data for this section */
+	STAILQ_HEAD(, _Libelf_Data) s_data;	/* translated data */
+	STAILQ_HEAD(, _Libelf_Data) s_rawdata;	/* raw data */
 	STAILQ_ENTRY(_Elf_Scn) s_next;
 	struct _Elf	*s_elf;		/* parent ELF descriptor */
 	unsigned int	s_flags;	/* flags for the section as a whole */
@@ -150,21 +162,31 @@ enum {
 	ELF_TOMEMORY
 };
 
-#define	LIBELF_COPY_U32(DST,SRC,NAME)	do {		\
-		if ((SRC)->NAME > UINT_MAX) {		\
-			LIBELF_SET_ERROR(RANGE, 0);	\
-			return (0);			\
-		}					\
-		(DST)->NAME = (SRC)->NAME;		\
+
+/*
+ * The LIBELF_COPY macros are used to copy fields from a GElf_*
+ * structure to their 32-bit counterparts, while checking for out of
+ * range values.
+ *
+ * - LIBELF_COPY_U32 :: copy an unsigned 32 bit field.
+ * - LIBELF_COPY_S32 :: copy a signed 32 bit field.
+ */
+
+#define	LIBELF_COPY_U32(DST, SRC, NAME)	do {			\
+		if ((SRC)->NAME > UINT32_MAX) {			\
+			LIBELF_SET_ERROR(RANGE, 0);		\
+			return (0);				\
+		}						\
+		(DST)->NAME = (SRC)->NAME & 0xFFFFFFFFU;	\
 	} while (0)
 
-#define	LIBELF_COPY_S32(DST,SRC,NAME)	do {		\
-		if ((SRC)->NAME > INT_MAX ||		\
-		    (SRC)->NAME < INT_MIN) {		\
-			LIBELF_SET_ERROR(RANGE, 0);	\
-			return (0);			\
-		}					\
-		(DST)->NAME = (SRC)->NAME;		\
+#define	LIBELF_COPY_S32(DST, SRC, NAME)	do {			\
+		if ((SRC)->NAME > INT32_MAX ||			\
+		    (SRC)->NAME < INT32_MIN) {			\
+			LIBELF_SET_ERROR(RANGE, 0);		\
+			return (0);				\
+		}						\
+		(DST)->NAME = (int32_t) (SRC)->NAME;		\
 	} while (0)
 
 
@@ -172,31 +194,35 @@ enum {
  * Function Prototypes.
  */
 
-__BEGIN_DECLS
-Elf_Data *_libelf_allocate_data(Elf_Scn *_s);
+#ifdef __cplusplus
+extern "C" {
+#endif
+struct _Libelf_Data *_libelf_allocate_data(Elf_Scn *_s);
 Elf	*_libelf_allocate_elf(void);
 Elf_Scn	*_libelf_allocate_scn(Elf *_e, size_t _ndx);
 Elf_Arhdr *_libelf_ar_gethdr(Elf *_e);
-Elf	*_libelf_ar_open(Elf *_e);
+Elf	*_libelf_ar_open(Elf *_e, int _reporterror);
 Elf	*_libelf_ar_open_member(int _fd, Elf_Cmd _c, Elf *_ar);
-int	_libelf_ar_get_member(char *_s, size_t _sz, int _base, size_t *_ret);
 Elf_Arsym *_libelf_ar_process_bsd_symtab(Elf *_ar, size_t *_dst);
 Elf_Arsym *_libelf_ar_process_svr4_symtab(Elf *_ar, size_t *_dst);
-unsigned long _libelf_checksum(Elf *_e, int _elfclass);
+long	 _libelf_checksum(Elf *_e, int _elfclass);
 void	*_libelf_ehdr(Elf *_e, int _elfclass, int _allocate);
-int	_libelf_falign(Elf_Type _t, int _elfclass);
+unsigned int _libelf_falign(Elf_Type _t, int _elfclass);
 size_t	_libelf_fsize(Elf_Type _t, int _elfclass, unsigned int _version,
     size_t count);
 int	(*_libelf_get_translator(Elf_Type _t, int _direction, int _elfclass))
-	    (char *_dst, size_t dsz, char *_src, size_t _cnt, int _byteswap);
+	    (unsigned char *_dst, size_t dsz, unsigned char *_src,
+	     size_t _cnt, int _byteswap);
 void	*_libelf_getphdr(Elf *_e, int _elfclass);
 void	*_libelf_getshdr(Elf_Scn *_scn, int _elfclass);
 void	_libelf_init_elf(Elf *_e, Elf_Kind _kind);
 int	_libelf_load_section_headers(Elf *e, void *ehdr);
-int	_libelf_malign(Elf_Type _t, int _elfclass);
+unsigned int _libelf_malign(Elf_Type _t, int _elfclass);
+Elf	*_libelf_memory(unsigned char *_image, size_t _sz, int _reporterror);
 size_t	_libelf_msize(Elf_Type _t, int _elfclass, unsigned int _version);
 void	*_libelf_newphdr(Elf *_e, int _elfclass, size_t _count);
-Elf_Data *_libelf_release_data(Elf_Data *_d);
+Elf	*_libelf_open_object(int _fd, Elf_Cmd _c, int _reporterror);
+struct _Libelf_Data *_libelf_release_data(struct _Libelf_Data *_d);
 Elf	*_libelf_release_elf(Elf *_e);
 Elf_Scn	*_libelf_release_scn(Elf_Scn *_s);
 int	_libelf_setphnum(Elf *_e, void *_eh, int _elfclass, size_t _phnum);
@@ -206,6 +232,8 @@ int	_libelf_setshstrndx(Elf *_e, void *_eh, int _elfclass,
 Elf_Data *_libelf_xlate(Elf_Data *_d, const Elf_Data *_s,
     unsigned int _encoding, int _elfclass, int _direction);
 int	_libelf_xlate_shtype(uint32_t _sht);
-__END_DECLS
+#ifdef __cplusplus
+}
+#endif
 
 #endif	/* __LIBELF_H_ */
diff --git a/rtemstoolkit/elftoolchain/libelf/_libelf_ar.h b/rtemstoolkit/elftoolchain/libelf/_libelf_ar.h
index d6b15a7..45a7e16 100644
--- a/rtemstoolkit/elftoolchain/libelf/_libelf_ar.h
+++ b/rtemstoolkit/elftoolchain/libelf/_libelf_ar.h
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: _libelf_ar.h 2032 2011-10-23 09:07:00Z jkoshy $
+ * $Id: _libelf_ar.h 3013 2014-03-23 06:16:59Z jkoshy $
  */
 
 #ifndef	__LIBELF_AR_H_
@@ -42,15 +42,16 @@
 	(sizeof(LIBELF_AR_BSD_EXTENDED_NAME_PREFIX) - 1)
 
 #define	IS_EXTENDED_BSD_NAME(NAME)				\
-	(strncmp((NAME), LIBELF_AR_BSD_EXTENDED_NAME_PREFIX,	\
+	(strncmp((const char *) (NAME),				\
+	 LIBELF_AR_BSD_EXTENDED_NAME_PREFIX,			\
 	 LIBELF_AR_BSD_EXTENDED_NAME_PREFIX_SIZE) == 0)
 
 
-char	*_libelf_ar_get_string(const char *_buf, size_t _sz, int _rawname,
-    int _svr4names);
+unsigned char *_libelf_ar_get_string(const char *_buf, size_t _sz,
+    unsigned int _rawname, int _svr4names);
 char	*_libelf_ar_get_raw_name(const struct ar_hdr *_arh);
 char	*_libelf_ar_get_translated_name(const struct ar_hdr *_arh, Elf *_ar);
-int	_libelf_ar_get_number(const char *_buf, size_t _sz, int _base,
-    size_t *_ret);
+int	_libelf_ar_get_number(const char *_buf, size_t _sz,
+    unsigned int _base, size_t *_ret);
 
 #endif	/* __LIBELF_AR_H_ */
diff --git a/rtemstoolkit/elftoolchain/libelf/_libelf_config.h b/rtemstoolkit/elftoolchain/libelf/_libelf_config.h
index 120f090..102aa01 100644
--- a/rtemstoolkit/elftoolchain/libelf/_libelf_config.h
+++ b/rtemstoolkit/elftoolchain/libelf/_libelf_config.h
@@ -23,12 +23,24 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: _libelf_config.h 2032 2011-10-23 09:07:00Z jkoshy $
+ * $Id: _libelf_config.h 3566 2017-08-31 02:28:40Z emaste $
  */
 
-#ifdef __FreeBSD__
+#if defined(__APPLE__) || defined(__DragonFly__)
+
+#if	defined(__amd64__)
+#define	LIBELF_ARCH		EM_X86_64
+#define	LIBELF_BYTEORDER	ELFDATA2LSB
+#define	LIBELF_CLASS		ELFCLASS64
+#elif	defined(__i386__)
+#define	LIBELF_ARCH		EM_386
+#define	LIBELF_BYTEORDER	ELFDATA2LSB
+#define	LIBELF_CLASS		ELFCLASS32
+#endif
 
-#define	LIBELF_VCSID(ID)	__FBSDID(ID)
+#endif	/* __DragonFly__ */
+
+#ifdef __FreeBSD__
 
 /*
  * Define LIBELF_{ARCH,BYTEORDER,CLASS} based on the machine architecture.
@@ -41,6 +53,12 @@
 #define	LIBELF_BYTEORDER	ELFDATA2LSB
 #define	LIBELF_CLASS		ELFCLASS64
 
+#elif	defined(__aarch64__)
+
+#define	LIBELF_ARCH		EM_AARCH64
+#define	LIBELF_BYTEORDER	ELFDATA2LSB
+#define	LIBELF_CLASS		ELFCLASS64
+
 #elif	defined(__arm__)
 
 #define	LIBELF_ARCH		EM_ARM
@@ -79,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
@@ -90,13 +114,21 @@
 #endif
 #endif  /* __FreeBSD__ */
 
+/*
+ * Definitions for Minix3.
+ */
+#ifdef __minix
+
+#define	LIBELF_ARCH		EM_386
+#define	LIBELF_BYTEORDER	ELFDATA2LSB
+#define	LIBELF_CLASS		ELFCLASS32
+
+#endif	/* __minix */
 
 #ifdef __NetBSD__
 
 #include <machine/elf_machdep.h>
 
-#define	LIBELF_VCSID(ID)	__RCSID(ID)
-
 #if	!defined(ARCH_ELFSIZE)
 #error	ARCH_ELFSIZE is not defined.
 #endif
@@ -115,30 +147,16 @@
 
 #endif	/* __NetBSD__ */
 
-#ifdef __APPLE__
+#if defined(__OpenBSD__)
 
-#define	LIBELF_VCSID(ID)
-
-#if	defined(__amd64__)
+#include <machine/exec.h>
 
-#define	LIBELF_ARCH		EM_X86_64
-#define	LIBELF_BYTEORDER	ELFDATA2LSB
-#define	LIBELF_CLASS		ELFCLASS64
-
-#elif	defined(__i386__)
-
-#define	LIBELF_ARCH		EM_386
-#define	LIBELF_BYTEORDER	ELFDATA2LSB
-#define	LIBELF_CLASS		ELFCLASS32
+#define	LIBELF_ARCH		ELF_TARG_MACH
+#define	LIBELF_BYTEORDER	ELF_TARG_DATA
+#define	LIBELF_CLASS		ELF_TARG_CLASS
 
-#else
-#error	Unknown Apple architecture.
 #endif
 
-#define	roundup2	roundup
-
-#endif  /* __APPLE__ */
-
 /*
  * GNU & Linux compatibility.
  *
@@ -160,8 +178,6 @@
 
 #endif	/* defined(__linux__) */
 
-#define	LIBELF_VCSID(ID)
-
 #if	LIBELF_CLASS == ELFCLASS32
 #define	Elf_Note		Elf32_Nhdr
 #elif   LIBELF_CLASS == ELFCLASS64
@@ -170,28 +186,26 @@
 #error  LIBELF_CLASS needs to be one of ELFCLASS32 or ELFCLASS64
 #endif
 
-#define	roundup2	roundup
-
 #endif /* defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) */
 
 #if defined(__WIN32__) || defined(__CYGWIN__)
 
-#define	LIBELF_VCSID(ID)
+#define LIBELF_VCSID(ID)
 
-#if	defined(__amd64__)
+#if     defined(__amd64__)
 
-#define	LIBELF_ARCH		EM_X86_64
-#define	LIBELF_BYTEORDER	ELFDATA2LSB
-#define	LIBELF_CLASS		ELFCLASS64
+#define LIBELF_ARCH             EM_X86_64
+#define LIBELF_BYTEORDER        ELFDATA2LSB
+#define LIBELF_CLASS            ELFCLASS64
 
-#elif	defined(__i386__)
+#elif   defined(__i386__)
 
-#define	LIBELF_ARCH		EM_386
-#define	LIBELF_BYTEORDER	ELFDATA2LSB
-#define	LIBELF_CLASS		ELFCLASS32
+#define LIBELF_ARCH             EM_386
+#define LIBELF_BYTEORDER        ELFDATA2LSB
+#define LIBELF_CLASS            ELFCLASS32
 
 #else
-#error	Unknown Apple architecture.
+#error  Unknown Windows architecture.
 #endif
 
-#endif  /* __APPLE__ */
+#endif  /* __WIN32__ || __CYGWIN__ */
diff --git a/rtemstoolkit/elftoolchain/libelf/elf.3 b/rtemstoolkit/elftoolchain/libelf/elf.3
index 5d86f60..20cb944 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf.3
+++ b/rtemstoolkit/elftoolchain/libelf/elf.3
@@ -21,9 +21,9 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $Id: elf.3 1730 2011-08-14 10:03:34Z jkoshy $
+.\" $Id: elf.3 3195 2015-05-12 17:22:19Z emaste $
 .\"
-.Dd August 14, 2011
+.Dd July 28, 2014
 .Os
 .Dt ELF 3
 .Sh NAME
@@ -251,7 +251,7 @@ This value must be non-zero and a power of two.
 .It Vt "void *d_buf"
 A pointer to data in memory.
 .It Vt "uint64_t d_off"
-The offset with the containing section where this descriptors data
+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.
@@ -367,6 +367,11 @@ 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.
@@ -383,13 +388,31 @@ See
 .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_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_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
-.TE
+.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.
@@ -429,7 +452,7 @@ 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 sectino.
+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
@@ -532,7 +555,7 @@ flag on an ELF descriptor using
 .Xr elf_flagelf 3 ,
 following which the library will use the data offsets and alignments
 specified by the application when laying out the file.
-Application control of file layout is described further in the 
+Application control of file layout is described further in the
 .Xr elf_update 3
 manual page.
 .Pp
@@ -585,5 +608,4 @@ 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 jkoshy at FreeBSD.org .
+.An Joseph Koshy Aq Mt jkoshy at FreeBSD.org .
diff --git a/rtemstoolkit/elftoolchain/libelf/elf.c b/rtemstoolkit/elftoolchain/libelf/elf.c
index e3ef7f3..8f1925e 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf.c
@@ -28,7 +28,7 @@
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf.c 1345 2011-01-01 11:17:52Z jkoshy $");
+ELFTC_VCSID("$Id: elf.c 2225 2011-11-26 18:55:54Z jkoshy $");
 
 struct _libelf_globals _libelf = {
 	.libelf_arch		= LIBELF_ARCH,
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_begin.3 b/rtemstoolkit/elftoolchain/libelf/elf_begin.3
index 5a013a4..e6c11b6 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_begin.3
+++ b/rtemstoolkit/elftoolchain/libelf/elf_begin.3
@@ -21,9 +21,9 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $Id: elf_begin.3 1925 2011-09-23 09:34:05Z jkoshy $ 
+.\" $Id: elf_begin.3 3182 2015-04-10 16:08:10Z emaste $
 .\"
-.Dd September 23, 2011
+.Dd December 11, 2011
 .Os
 .Dt ELF_BEGIN 3
 .Sh NAME
@@ -272,7 +272,7 @@ was created.
 .It Bq Er ELF_E_ARGUMENT
 An
 .Xr ar 1
-archive was opened with with
+archive was opened with
 .Ar cmd
 set to
 .Dv ELF_C_RDWR .
@@ -299,6 +299,10 @@ Function
 .Fn elf_begin
 was called before a working version was established with
 .Xr elf_version 3 .
+.It Bq Er ELF_E_VERSION
+The ELF object referenced by argument
+.Ar fd
+was of an unsupported ELF version.
 .El
 .Sh SEE ALSO
 .Xr elf 3 ,
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_begin.c b/rtemstoolkit/elftoolchain/libelf/elf_begin.c
index a6c9e4a..9f4f237 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_begin.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_begin.c
@@ -24,196 +24,11 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
-#include <sys/types.h>
-#include <sys/errno.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-
-#include <ar.h>
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
 #include <libelf.h>
-#include <stdlib.h>
-#include <unistd.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_begin.c 1923 2011-09-23 09:01:13Z jkoshy $");
-
-#define	_LIBELF_INITSIZE	(64*1024)
-
-/*
- * Read from a device file, pipe or socket.
- */
-static void *
-_libelf_read_special_file(int fd, size_t *fsz)
-{
-	ssize_t readsz;
-	size_t bufsz, datasz;
-	unsigned char *buf, *t;
-
-	datasz = 0;
-	readsz = 0;
-	bufsz = _LIBELF_INITSIZE;
-	if ((buf = malloc(bufsz)) == NULL)
-		goto resourceerror;
-
-	/*
-	 * Read data from the file descriptor till we reach EOF, or
-	 * till an error is encountered.
-	 */
-	do {
-		/* Check if we need to expand the data buffer. */
-		if (datasz == bufsz) {
-			bufsz *= 2;
-			if ((t = realloc(buf, bufsz)) == NULL)
-				goto resourceerror;
-			buf = t;
-		}
-
-		do {
-			readsz = bufsz - datasz;
-			t = buf + datasz;
-			if ((readsz = read(fd, t, readsz)) <= 0)
-				break;
-			datasz += readsz;
-		} while (datasz < bufsz);
-
-	} while (readsz > 0);
-
-	if (readsz < 0) {
-		LIBELF_SET_ERROR(IO, errno);
-		goto error;
-	}
-
-	assert(readsz == 0);
-
-	/*
-	 * Free up extra buffer space.
-	 */
-	if (bufsz > datasz) {
-		if (datasz > 0) {
-			if ((t = realloc(buf, datasz)) == NULL)
-				goto resourceerror;
-			buf = t;
-		} else {	/* Zero bytes read. */
-			LIBELF_SET_ERROR(ARGUMENT, 0);
-			free(buf);
-			buf = NULL;
-		}
-	}
-
-	*fsz = datasz;
-	return (buf);
-
-resourceerror:
-	LIBELF_SET_ERROR(RESOURCE, 0);
-error:
-	if (buf != NULL)
-		free(buf);
-	return (NULL);
-}
-
-
-static Elf *
-_libelf_open_object(int fd, Elf_Cmd c)
-{
-	Elf *e;
-	void *m;
-	mode_t mode;
-	size_t fsize;
-	struct stat sb;
-	unsigned int flags;
-
-	assert(c == ELF_C_READ || c == ELF_C_RDWR || c == ELF_C_WRITE);
-
-	if (fstat(fd, &sb) < 0) {
-		LIBELF_SET_ERROR(IO, errno);
-		return (NULL);
-	}
-
-	mode = sb.st_mode;
-	fsize = (size_t) sb.st_size;
-
-	/*
-	 * Reject unsupported file types.
-	 */
-	if (!S_ISREG(mode) && !S_ISCHR(mode) && !S_ISFIFO(mode) &&
-	    !S_ISSOCK(mode)) {
-		LIBELF_SET_ERROR(ARGUMENT, 0);
-		return (NULL);
-	}
-
-	/*
-	 * For ELF_C_WRITE mode, allocate and return a descriptor.
-	 */
-	if (c == ELF_C_WRITE) {
-		if ((e = _libelf_allocate_elf()) != NULL) {
-			_libelf_init_elf(e, ELF_K_ELF);
-			e->e_byteorder = LIBELF_PRIVATE(byteorder);
-			e->e_fd = fd;
-			e->e_cmd = c;
-			if (!S_ISREG(mode))
-				e->e_flags |= LIBELF_F_SPECIAL_FILE;
-		}
-
-		return (e);
-	}
-
-
-	/*
-	 * ELF_C_READ and ELF_C_RDWR mode.
-	 */
-	m = NULL;
-	flags = 0;
-	if (S_ISREG(mode)) {
-		/*
-		 * Always map regular files in with 'PROT_READ'
-		 * permissions.
-		 *
-		 * For objects opened in ELF_C_RDWR mode, when
-		 * elf_update(3) is called, we remove this mapping,
-		 * write file data out using write(2), and map the new
-		 * contents back.
-		 */
-		if ((m = mmap(NULL, fsize, PROT_READ, MAP_PRIVATE, fd,
-		    (off_t) 0)) == MAP_FAILED) {
-			LIBELF_SET_ERROR(IO, errno);
-			return (NULL);
-		}
-
-		flags = LIBELF_F_RAWFILE_MMAP;
-	} else if ((m = _libelf_read_special_file(fd, &fsize)) != NULL)
-		flags = LIBELF_F_RAWFILE_MALLOC | LIBELF_F_SPECIAL_FILE;
-	else
-		return (NULL);
-
-	if ((e = elf_memory(m, fsize)) == NULL) {
-		assert((flags & LIBELF_F_RAWFILE_MALLOC) ||
-		    (flags & LIBELF_F_RAWFILE_MMAP));
-		if (flags & LIBELF_F_RAWFILE_MMAP)
-			(void) munmap(m, fsize);
-		else
-			free(m);
-		return (NULL);
-	}
-
-	/* ar(1) archives aren't supported in RDWR mode. */
-	if (c == ELF_C_RDWR && e->e_kind == ELF_K_AR) {
-		(void) elf_end(e);
-		LIBELF_SET_ERROR(ARGUMENT, 0);
-		return (NULL);
-	}
-
-	e->e_flags |= flags;
-	e->e_fd = fd;
-	e->e_cmd = c;
-
-	return (e);
-}
+ELFTC_VCSID("$Id: elf_begin.c 2364 2011-12-28 17:55:25Z jkoshy $");
 
 Elf *
 elf_begin(int fd, Elf_Cmd c, Elf *a)
@@ -266,7 +81,7 @@ elf_begin(int fd, Elf_Cmd c, Elf *a)
 	}
 
 	if (a == NULL)
-		e = _libelf_open_object(fd, c);
+		e = _libelf_open_object(fd, c, 1);
 	else if (a->e_kind == ELF_K_AR)
 		e = _libelf_ar_open_member(a->e_fd, c, a);
 	else
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_cntl.3 b/rtemstoolkit/elftoolchain/libelf/elf_cntl.3
index 32649d1..2578975 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_cntl.3
+++ b/rtemstoolkit/elftoolchain/libelf/elf_cntl.3
@@ -21,7 +21,7 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $Id: elf_cntl.3 289 2009-01-08 08:26:08Z jkoshy $ 
+.\" $Id: elf_cntl.3 3181 2015-04-10 13:22:51Z emaste $
 .\"
 .Dd August 9, 2006
 .Os
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_cntl.c b/rtemstoolkit/elftoolchain/libelf/elf_cntl.c
index 2021917..0607885 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_cntl.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_cntl.c
@@ -28,7 +28,7 @@
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_cntl.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: elf_cntl.c 2225 2011-11-26 18:55:54Z jkoshy $");
 
 int
 elf_cntl(Elf *e, Elf_Cmd c)
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_data.c b/rtemstoolkit/elftoolchain/libelf/elf_data.c
index 5ac6453..d494eda 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_data.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_data.c
@@ -27,21 +27,26 @@
 #include <assert.h>
 #include <errno.h>
 #include <libelf.h>
+#include <stdint.h>
 #include <stdlib.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_data.c 1765 2011-08-22 05:59:05Z jkoshy $");
+ELFTC_VCSID("$Id: elf_data.c 3466 2016-05-11 18:35:44Z emaste $");
 
 Elf_Data *
-elf_getdata(Elf_Scn *s, Elf_Data *d)
+elf_getdata(Elf_Scn *s, Elf_Data *ed)
 {
 	Elf *e;
-	size_t fsz, msz, count;
-	int elfclass, elftype;
 	unsigned int sh_type;
+	int elfclass, elftype;
+	size_t count, fsz, msz;
+	struct _Libelf_Data *d;
 	uint64_t sh_align, sh_offset, sh_size;
-	int (*xlate)(char *_d, size_t _dsz, char *_s, size_t _c, int _swap);
+	int (*xlate)(unsigned char *_d, size_t _dsz, unsigned char *_s,
+	    size_t _c, int _swap);
+
+	d = (struct _Libelf_Data *) ed;
 
 	if (s == NULL || (e = s->s_elf) == NULL ||
 	    (d != NULL && s != d->d_scn)) {
@@ -52,10 +57,10 @@ elf_getdata(Elf_Scn *s, Elf_Data *d)
 	assert(e->e_kind == ELF_K_ELF);
 
 	if (d == NULL && (d = STAILQ_FIRST(&s->s_data)) != NULL)
-		return (d);
+		return (&d->d_data);
 
 	if (d != NULL)
-		return (STAILQ_NEXT(d, d_next));
+		return (&STAILQ_NEXT(d, d_next)->d_data);
 
 	if (e->e_rawfile == NULL) {
 		/*
@@ -89,7 +94,7 @@ elf_getdata(Elf_Scn *s, Elf_Data *d)
 
 	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);
 	}
@@ -105,28 +110,40 @@ elf_getdata(Elf_Scn *s, Elf_Data *d)
 		return (NULL);
 	}
 
-	count = sh_size / fsz;
+	if (sh_size / fsz > SIZE_MAX) {
+		LIBELF_SET_ERROR(RANGE, 0);
+		return (NULL);
+	}
+
+	count = (size_t) (sh_size / fsz);
 
 	msz = _libelf_msize(elftype, elfclass, e->e_version);
 
+	if (count > 0 && msz > SIZE_MAX / count) {
+		LIBELF_SET_ERROR(RANGE, 0);
+		return (NULL);
+	}
+
 	assert(msz > 0);
+	assert(count <= SIZE_MAX);
+	assert(msz * count <= SIZE_MAX);
 
 	if ((d = _libelf_allocate_data(s)) == NULL)
 		return (NULL);
 
-	d->d_buf     = NULL;
-	d->d_off     = 0;
-	d->d_align   = sh_align;
-	d->d_size    = msz * count;
-	d->d_type    = elftype;
-	d->d_version = e->e_version;
+	d->d_data.d_buf     = NULL;
+	d->d_data.d_off     = 0;
+	d->d_data.d_align   = sh_align;
+	d->d_data.d_size    = msz * count;
+	d->d_data.d_type    = elftype;
+	d->d_data.d_version = e->e_version;
 
 	if (sh_type == SHT_NOBITS || sh_size == 0) {
 	        STAILQ_INSERT_TAIL(&s->s_data, d, d_next);
-		return (d);
+		return (&d->d_data);
         }
 
-	if ((d->d_buf = malloc(msz*count)) == NULL) {
+	if ((d->d_data.d_buf = malloc(msz * count)) == NULL) {
 		(void) _libelf_release_data(d);
 		LIBELF_SET_ERROR(RESOURCE, 0);
 		return (NULL);
@@ -135,7 +152,8 @@ elf_getdata(Elf_Scn *s, Elf_Data *d)
 	d->d_flags  |= LIBELF_F_DATA_MALLOCED;
 
 	xlate = _libelf_get_translator(elftype, ELF_TOMEMORY, elfclass);
-	if (!(*xlate)(d->d_buf, d->d_size, e->e_rawfile + sh_offset, count,
+	if (!(*xlate)(d->d_data.d_buf, (size_t) d->d_data.d_size,
+	    e->e_rawfile + sh_offset, count,
 	    e->e_byteorder != LIBELF_PRIVATE(byteorder))) {
 		_libelf_release_data(d);
 		LIBELF_SET_ERROR(DATA, 0);
@@ -144,14 +162,14 @@ elf_getdata(Elf_Scn *s, Elf_Data *d)
 
 	STAILQ_INSERT_TAIL(&s->s_data, d, d_next);
 
-	return (d);
+	return (&d->d_data);
 }
 
 Elf_Data *
 elf_newdata(Elf_Scn *s)
 {
 	Elf *e;
-	Elf_Data *d;
+	struct _Libelf_Data *d;
 
 	if (s == NULL || (e = s->s_elf) == NULL) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
@@ -173,16 +191,16 @@ elf_newdata(Elf_Scn *s)
 
 	STAILQ_INSERT_TAIL(&s->s_data, d, d_next);
 
-	d->d_align = 1;
-	d->d_buf = NULL;
-	d->d_off = (uint64_t) ~0;
-	d->d_size = 0;
-	d->d_type = ELF_T_BYTE;
-	d->d_version = LIBELF_PRIVATE(version);
+	d->d_data.d_align = 1;
+	d->d_data.d_buf = NULL;
+	d->d_data.d_off = (uint64_t) ~0;
+	d->d_data.d_size = 0;
+	d->d_data.d_type = ELF_T_BYTE;
+	d->d_data.d_version = LIBELF_PRIVATE(version);
 
 	(void) elf_flagscn(s, ELF_C_SET, ELF_F_DIRTY);
 
-	return (d);
+	return (&d->d_data);
 }
 
 /*
@@ -191,11 +209,12 @@ elf_newdata(Elf_Scn *s)
  */
 
 Elf_Data *
-elf_rawdata(Elf_Scn *s, Elf_Data *d)
+elf_rawdata(Elf_Scn *s, Elf_Data *ed)
 {
 	Elf *e;
 	int elf_class;
 	uint32_t sh_type;
+	struct _Libelf_Data *d;
 	uint64_t sh_align, sh_offset, sh_size;
 
 	if (s == NULL || (e = s->s_elf) == NULL || e->e_rawfile == NULL) {
@@ -205,11 +224,13 @@ elf_rawdata(Elf_Scn *s, Elf_Data *d)
 
 	assert(e->e_kind == ELF_K_ELF);
 
+	d = (struct _Libelf_Data *) ed;
+
 	if (d == NULL && (d = STAILQ_FIRST(&s->s_rawdata)) != NULL)
-		return (d);
+		return (&d->d_data);
 
 	if (d != NULL)
-		return (STAILQ_NEXT(d, d_next));
+		return (&STAILQ_NEXT(d, d_next)->d_data);
 
 	elf_class = e->e_class;
 
@@ -227,21 +248,29 @@ elf_rawdata(Elf_Scn *s, Elf_Data *d)
 		sh_align  = s->s_shdr.s_shdr64.sh_addralign;
 	}
 
-	if (sh_type == SHT_NULL)
+	if (sh_type == SHT_NULL) {
+		LIBELF_SET_ERROR(SECTION, 0);
+		return (NULL);
+	}
+
+	if (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);
 
-	d->d_buf     = (sh_type == SHT_NOBITS || sh_size == 0) ? NULL :
+	d->d_data.d_buf = (sh_type == SHT_NOBITS || sh_size == 0) ? NULL :
 	    e->e_rawfile + sh_offset;
-	d->d_off     = 0;
-	d->d_align   = sh_align;
-	d->d_size    = sh_size;
-	d->d_type    = ELF_T_BYTE;
-	d->d_version = e->e_version;
+	d->d_data.d_off     = 0;
+	d->d_data.d_align   = sh_align;
+	d->d_data.d_size    = sh_size;
+	d->d_data.d_type    = ELF_T_BYTE;
+	d->d_data.d_version = e->e_version;
 
 	STAILQ_INSERT_TAIL(&s->s_rawdata, d, d_next);
 
-	return (d);
+	return (&d->d_data);
 }
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_end.c b/rtemstoolkit/elftoolchain/libelf/elf_end.c
index 136ed9a..3f32ebb 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_end.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_end.c
@@ -24,17 +24,17 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
-#include <sys/mman.h>
-
 #include <assert.h>
 #include <libelf.h>
 #include <stdlib.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_end.c 1922 2011-09-23 08:04:33Z jkoshy $");
+#if	ELFTC_HAVE_MMAP
+#include <sys/mman.h>
+#endif
+
+ELFTC_VCSID("$Id: elf_end.c 3174 2015-03-27 17:13:41Z emaste $");
 
 int
 elf_end(Elf *e)
@@ -77,10 +77,12 @@ elf_end(Elf *e)
 		}
 
 		if (e->e_rawfile) {
-			if (e->e_flags & LIBELF_F_RAWFILE_MMAP)
-				(void) munmap(e->e_rawfile, e->e_rawsize);
-			else if (e->e_flags & LIBELF_F_RAWFILE_MALLOC)
+			if (e->e_flags & LIBELF_F_RAWFILE_MALLOC)
 				free(e->e_rawfile);
+#if	ELFTC_HAVE_MMAP
+			else if (e->e_flags & LIBELF_F_RAWFILE_MMAP)
+				(void) munmap(e->e_rawfile, e->e_rawsize);
+#endif
 		}
 
 		sv = e;
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_errmsg.c b/rtemstoolkit/elftoolchain/libelf/elf_errmsg.c
index 7a6e552..9e5b2e9 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_errmsg.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_errmsg.c
@@ -24,21 +24,19 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <libelf.h>
 #include <stdio.h>
 #include <string.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_errmsg.c 1345 2011-01-01 11:17:52Z jkoshy $");
+ELFTC_VCSID("$Id: elf_errmsg.c 3174 2015-03-27 17:13:41Z emaste $");
 
 /*
  * Retrieve a human readable translation for an error message.
  */
 
-const char *_libelf_errors[] = {
+static const char *_libelf_errors[] = {
 #define	DEFINE_ERROR(N,S)	[ELF_E_##N] = S
 	DEFINE_ERROR(NONE,	"No Error"),
 	DEFINE_ERROR(ARCHIVE,	"Malformed ar(1) archive"),
@@ -76,7 +74,7 @@ elf_errmsg(int error)
 	if (error < ELF_E_NONE || error >= ELF_E_NUM)
 		return _libelf_errors[ELF_E_NUM];
 	if (oserr) {
-		(void) snprintf(LIBELF_PRIVATE(msg),
+		(void) snprintf((char *) LIBELF_PRIVATE(msg),
 		    sizeof(LIBELF_PRIVATE(msg)), "%s: %s",
 		    _libelf_errors[error], strerror(oserr));
 		return (const char *)&LIBELF_PRIVATE(msg);
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_errno.c b/rtemstoolkit/elftoolchain/libelf/elf_errno.c
index 95e91b9..10ae69a 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_errno.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_errno.c
@@ -24,13 +24,11 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_errno.c 1345 2011-01-01 11:17:52Z jkoshy $");
+ELFTC_VCSID("$Id: elf_errno.c 3174 2015-03-27 17:13:41Z emaste $");
 
 int
 elf_errno(void)
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_fill.c b/rtemstoolkit/elftoolchain/libelf/elf_fill.c
index ac9e02e..427d78d 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_fill.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_fill.c
@@ -24,13 +24,11 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_fill.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: elf_fill.c 3174 2015-03-27 17:13:41Z emaste $");
 
 void
 elf_fill(int fill)
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_flag.c b/rtemstoolkit/elftoolchain/libelf/elf_flag.c
index 9d31719..7350321 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_flag.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_flag.c
@@ -24,13 +24,11 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_flag.c 1918 2011-09-22 10:42:06Z jkoshy $");
+ELFTC_VCSID("$Id: elf_flag.c 3174 2015-03-27 17:13:41Z emaste $");
 
 unsigned int
 elf_flagarhdr(Elf_Arhdr *a, Elf_Cmd c, unsigned int flags)
@@ -58,6 +56,7 @@ unsigned int
 elf_flagdata(Elf_Data *d, Elf_Cmd c, unsigned int flags)
 {
 	unsigned int r;
+	struct _Libelf_Data *ld;
 
 	if (d == NULL)
 		return (0);
@@ -68,10 +67,12 @@ elf_flagdata(Elf_Data *d, Elf_Cmd c, unsigned int flags)
 		return (0);
 	}
 
+	ld = (struct _Libelf_Data *) d;
+
 	if (c == ELF_C_SET)
-		r = d->d_flags |= flags;
+		r = ld->d_flags |= flags;
 	else
-		r = d->d_flags &= ~flags;
+		r = ld->d_flags &= ~flags;
 
 	return (r & LIBELF_F_API_MASK);
 }
@@ -108,7 +109,7 @@ elf_flagehdr(Elf *e, Elf_Cmd c, unsigned int flags)
 unsigned int
 elf_flagelf(Elf *e, Elf_Cmd c, unsigned int flags)
 {
-	int r;
+	unsigned int r;
 
 	if (e == NULL)
 		return (0);
@@ -170,7 +171,7 @@ elf_flagphdr(Elf *e, Elf_Cmd c, unsigned int flags)
 unsigned int
 elf_flagscn(Elf_Scn *s, Elf_Cmd c, unsigned int flags)
 {
-	int r;
+	unsigned int r;
 
 	if (s == NULL)
 		return (0);
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_flagdata.3 b/rtemstoolkit/elftoolchain/libelf/elf_flagdata.3
index d4fd420..de3cfd9 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_flagdata.3
+++ b/rtemstoolkit/elftoolchain/libelf/elf_flagdata.3
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2006-2008 Joseph Koshy.  All rights reserved.
+.\" Copyright (c) 2006-2008,2011 Joseph Koshy.  All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
 .\" modification, are permitted provided that the following conditions
@@ -21,9 +21,9 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $Id: elf_flagdata.3 221 2008-08-10 04:56:27Z jkoshy $
+.\" $Id: elf_flagdata.3 3479 2016-06-25 20:44:33Z jkoshy $
 .\"
-.Dd October 22, 2007
+.Dd December 3, 2011
 .Os
 .Dt ELF_FLAGDATA 3
 .Sh NAME
@@ -64,6 +64,38 @@ Arguments
 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
@@ -134,7 +166,7 @@ Using a value of zero for argument
 will return the current set of flags for the data structure being
 queried.
 .Sh RETURN VALUES
-These functions return the updated flags is successful, and zero if
+These functions return the updated flags if successful, or zero if
 an error is detected.
 .Sh COMPATIBILITY
 The
@@ -176,16 +208,13 @@ was called without a program header being allocated.
 .Xr elf 3 ,
 .Xr elf32_newehdr 3 ,
 .Xr elf32_newphdr 3 ,
-.Xr elf32_newshdr 3 ,
 .Xr elf64_newehdr 3 ,
 .Xr elf64_newphdr 3 ,
-.Xr elf64_newshdr 3 ,
 .Xr elf_newdata 3 ,
 .Xr elf_update 3 ,
 .Xr gelf 3 ,
 .Xr gelf_newehdr 3 ,
 .Xr gelf_newphdr 3 ,
-.Xr gelf_newshdr 3 ,
 .Xr gelf_update_dyn 3 ,
 .Xr gelf_update_move 3 ,
 .Xr gelf_update_rel 3 ,
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_getarhdr.c b/rtemstoolkit/elftoolchain/libelf/elf_getarhdr.c
index 43ceafd..75e2e86 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_getarhdr.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_getarhdr.c
@@ -24,13 +24,11 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_getarhdr.c 1341 2011-01-01 04:28:29Z jkoshy $");
+ELFTC_VCSID("$Id: elf_getarhdr.c 3174 2015-03-27 17:13:41Z emaste $");
 
 Elf_Arhdr *
 elf_getarhdr(Elf *e)
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_getarsym.c b/rtemstoolkit/elftoolchain/libelf/elf_getarsym.c
index 1852262..3679b81 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_getarsym.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_getarsym.c
@@ -24,13 +24,11 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_getarsym.c 1360 2011-01-08 08:27:41Z jkoshy $");
+ELFTC_VCSID("$Id: elf_getarsym.c 3174 2015-03-27 17:13:41Z emaste $");
 
 Elf_Arsym *
 elf_getarsym(Elf *ar, size_t *ptr)
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_getbase.c b/rtemstoolkit/elftoolchain/libelf/elf_getbase.c
index 30058ca..b038c3d 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_getbase.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_getbase.c
@@ -24,13 +24,11 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_getbase.c 977 2010-06-06 11:50:31Z jkoshy $");
+ELFTC_VCSID("$Id: elf_getbase.c 3174 2015-03-27 17:13:41Z emaste $");
 
 off_t
 elf_getbase(Elf *e)
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_getdata.3 b/rtemstoolkit/elftoolchain/libelf/elf_getdata.3
index 8816a5a..68b2889 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_getdata.3
+++ b/rtemstoolkit/elftoolchain/libelf/elf_getdata.3
@@ -21,7 +21,7 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $Id: elf_getdata.3 1766 2011-08-22 06:01:03Z jkoshy $
+.\" $Id: elf_getdata.3 3181 2015-04-10 13:22:51Z emaste $
 .\"
 .Dd January 26, 2011
 .Os
@@ -174,7 +174,7 @@ These functions return a valid pointer to a data descriptor if successful, or
 NULL if an error occurs.
 .Sh ERRORS
 These functions may fail with the following errors:
-.Bl -tag -width "[ELF_E_RESOURCE]" 
+.Bl -tag -width "[ELF_E_RESOURCE]"
 .It Bq Er ELF_E_ARGUMENT
 Either of the arguments
 .Ar scn
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_getident.c b/rtemstoolkit/elftoolchain/libelf/elf_getident.c
index c17f3a5..a69139c 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_getident.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_getident.c
@@ -24,15 +24,13 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <ar.h>
 #include <assert.h>
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_getident.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: elf_getident.c 3174 2015-03-27 17:13:41Z emaste $");
 
 char *
 elf_getident(Elf *e, size_t *sz)
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_hash.c b/rtemstoolkit/elftoolchain/libelf/elf_hash.c
index 12c764d..ef7e44d 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_hash.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_hash.c
@@ -24,13 +24,11 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <libelf.h>
 
-#include "_libelf_config.h"
+#include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_hash.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: elf_hash.c 3174 2015-03-27 17:13:41Z emaste $");
 
 /*
  * This elf_hash function is defined by the System V ABI.
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_kind.c b/rtemstoolkit/elftoolchain/libelf/elf_kind.c
index 0b4251a..f497bd3 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_kind.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_kind.c
@@ -24,13 +24,11 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_kind.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: elf_kind.c 3174 2015-03-27 17:13:41Z emaste $");
 
 Elf_Kind
 elf_kind(Elf *e)
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_memory.3 b/rtemstoolkit/elftoolchain/libelf/elf_memory.3
index 2f9da44..bcb888f 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_memory.3
+++ b/rtemstoolkit/elftoolchain/libelf/elf_memory.3
@@ -21,7 +21,7 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $Id: elf_memory.3 189 2008-07-20 10:38:08Z jkoshy $
+.\" $Id: elf_memory.3 2314 2011-12-11 06:19:51Z jkoshy $
 .\"
 .Dd June 28, 2006
 .Os
@@ -109,9 +109,9 @@ Function
 was called before a working version was set using
 .Xr elf_version 3 .
 .It Bq Er ELF_E_VERSION
-The argument
+The ELF object referenced by argument
 .Ar image
-corresponds to an ELF file with an unsupported version.
+was of an unsupported ELF version.
 .El
 .Sh SEE ALSO
 .Xr elf 3 ,
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_memory.c b/rtemstoolkit/elftoolchain/libelf/elf_memory.c
index 691beaf..d70f6e0 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_memory.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_memory.c
@@ -24,21 +24,15 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
-#include <ar.h>
 #include <libelf.h>
-#include <string.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_memory.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: elf_memory.c 3013 2014-03-23 06:16:59Z jkoshy $");
 
 Elf *
 elf_memory(char *image, size_t sz)
 {
-	Elf *e;
-
 	if (LIBELF_PRIVATE(version) == EV_NONE) {
 		LIBELF_SET_ERROR(SEQUENCE, 0);
 		return (NULL);
@@ -49,44 +43,5 @@ elf_memory(char *image, size_t sz)
 		return (NULL);
 	}
 
-	if ((e = _libelf_allocate_elf()) == NULL)
-		return (NULL);
-
-	e->e_cmd = ELF_C_READ;
-	e->e_rawfile = image;
-	e->e_rawsize = sz;
-
-#undef	LIBELF_IS_ELF
-#define	LIBELF_IS_ELF(P) ((P)[EI_MAG0] == ELFMAG0 && 		\
-	(P)[EI_MAG1] == ELFMAG1 && (P)[EI_MAG2] == ELFMAG2 &&	\
-	(P)[EI_MAG3] == ELFMAG3)
-
-	if (sz > EI_NIDENT && LIBELF_IS_ELF(image)) {
-		_libelf_init_elf(e, ELF_K_ELF);
-		e->e_class = image[EI_CLASS];
-		e->e_byteorder = image[EI_DATA];
-		e->e_version = image[EI_VERSION];
-
-		if (e->e_version > EV_CURRENT) {
-			e = _libelf_release_elf(e);
-			LIBELF_SET_ERROR(VERSION, 0);
-			return (NULL);
-		}
-
-		if ((e->e_byteorder != ELFDATA2LSB && e->e_byteorder !=
- 		    ELFDATA2MSB) || (e->e_class != ELFCLASS32 && e->e_class !=
-		    ELFCLASS64)) {
-			e = _libelf_release_elf(e);
-			LIBELF_SET_ERROR(HEADER, 0);
-			return (NULL);
-		}
-
-	} else if (sz >= SARMAG &&
-	    strncmp(image, ARMAG, (size_t) SARMAG) == 0) {
-		_libelf_init_elf(e, ELF_K_AR);
-		e = _libelf_ar_open(e);
-	} else
-		_libelf_init_elf(e, ELF_K_NONE);
-
-	return (e);
+	return (_libelf_memory((unsigned char *) image, sz, 1));
 }
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_next.c b/rtemstoolkit/elftoolchain/libelf/elf_next.c
index d6ca552..4c33714 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_next.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_next.c
@@ -24,15 +24,13 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <ar.h>
 #include <assert.h>
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_next.c 1678 2011-07-28 04:36:34Z jkoshy $");
+ELFTC_VCSID("$Id: elf_next.c 3174 2015-03-27 17:13:41Z emaste $");
 
 Elf_Cmd
 elf_next(Elf *e)
@@ -48,13 +46,17 @@ elf_next(Elf *e)
 		 return (ELF_C_NULL);
 	 }
 
-	assert (parent->e_kind == ELF_K_AR);
-	assert (parent->e_cmd == ELF_C_READ);
+	assert(parent->e_kind == ELF_K_AR);
+	assert(parent->e_cmd == ELF_C_READ);
 	assert(e->e_rawfile > parent->e_rawfile);
 
-	next = e->e_rawfile - parent->e_rawfile + e->e_rawsize;
+	next = e->e_rawfile - parent->e_rawfile + (off_t) e->e_rawsize;
 	next = (next + 1) & ~1;	/* round up to an even boundary */
 
+	/*
+	 * Setup the 'e_next' field of the archive descriptor for the
+	 * next call to 'elf_begin()'.
+	 */
 	parent->e_u.e_ar.e_next = (next >= (off_t) parent->e_rawsize) ?
 	    (off_t) 0 : next;
 
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_open.3 b/rtemstoolkit/elftoolchain/libelf/elf_open.3
new file mode 100644
index 0000000..3dd1e36
--- /dev/null
+++ b/rtemstoolkit/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/rtemstoolkit/elftoolchain/libelf/elf_open.c b/rtemstoolkit/elftoolchain/libelf/elf_open.c
new file mode 100644
index 0000000..5aad459
--- /dev/null
+++ b/rtemstoolkit/elftoolchain/libelf/elf_open.c
@@ -0,0 +1,67 @@
+/*-
+ * Copyright (c) 2011 Joseph Koshy
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <libelf.h>
+
+#include "_libelf.h"
+
+ELFTC_VCSID("$Id$");
+
+/*
+ * Extension API: open a file for reading, ignoring parse errors.
+ */
+
+Elf *
+elf_open(int fd)
+{
+	if (LIBELF_PRIVATE(version) == EV_NONE) {
+		LIBELF_SET_ERROR(SEQUENCE, 0);
+		return (NULL);
+	}
+
+	return (_libelf_open_object(fd, ELF_C_READ, 0));
+}
+
+/*
+ * Extension API: create an ELF descriptor for an in-memory object,
+ * ignoring parse errors.
+ */
+
+Elf *
+elf_openmemory(char *image, size_t sz)
+{
+	if (LIBELF_PRIVATE(version) == EV_NONE) {
+		LIBELF_SET_ERROR(SEQUENCE, 0);
+		return (NULL);
+	}
+
+	if (image == NULL || sz == 0) {
+		LIBELF_SET_ERROR(ARGUMENT, 0);
+		return (NULL);
+	}
+
+	return (_libelf_memory((unsigned char *) image, sz, 0));
+}
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_phnum.c b/rtemstoolkit/elftoolchain/libelf/elf_phnum.c
index d63c490..4ac665d 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_phnum.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_phnum.c
@@ -24,14 +24,12 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <ar.h>
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_phnum.c 466 2009-08-04 17:17:42Z jkoshy $");
+ELFTC_VCSID("$Id: elf_phnum.c 3174 2015-03-27 17:13:41Z emaste $");
 
 static int
 _libelf_getphdrnum(Elf *e, size_t *phnum)
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_rand.c b/rtemstoolkit/elftoolchain/libelf/elf_rand.c
index 2e7328a..eb2c9ea 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_rand.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_rand.c
@@ -24,14 +24,12 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <ar.h>
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_rand.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: elf_rand.c 3174 2015-03-27 17:13:41Z emaste $");
 
 off_t
 elf_rand(Elf *ar, off_t offset)
@@ -40,7 +38,7 @@ elf_rand(Elf *ar, off_t offset)
 
 	if (ar == NULL || ar->e_kind != ELF_K_AR ||
 	    (offset & 1) || offset < SARMAG ||
-	    offset + sizeof(struct ar_hdr) >= ar->e_rawsize) {
+	    (size_t) offset + sizeof(struct ar_hdr) >= ar->e_rawsize) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return 0;
 	}
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_rawfile.c b/rtemstoolkit/elftoolchain/libelf/elf_rawfile.c
index 22a9f95..f63982f 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_rawfile.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_rawfile.c
@@ -24,19 +24,17 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_rawfile.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: elf_rawfile.c 3174 2015-03-27 17:13:41Z emaste $");
 
 char *
 elf_rawfile(Elf *e, size_t *sz)
 {
-	char *ptr;
 	size_t size;
+	unsigned char *ptr;
 
 	size = e ? e->e_rawsize : 0;
 	ptr = NULL;
@@ -49,5 +47,5 @@ elf_rawfile(Elf *e, size_t *sz)
 	if (sz)
 		*sz = size;
 
-	return (ptr);
+	return ((char *) ptr);
 }
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_scn.c b/rtemstoolkit/elftoolchain/libelf/elf_scn.c
index 80444fd..d3e2747 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_scn.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_scn.c
@@ -24,7 +24,6 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
 #include <sys/queue.h>
 
 #include <assert.h>
@@ -32,11 +31,12 @@
 #include <gelf.h>
 #include <libelf.h>
 #include <stddef.h>
+#include <stdint.h>
 #include <stdlib.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_scn.c 1077 2010-08-09 15:37:40Z jkoshy $");
+ELFTC_VCSID("$Id: elf_scn.c 3177 2015-03-30 18:19:41Z emaste $");
 
 /*
  * Load an ELF section table and create a list of Elf_Scn structures.
@@ -44,22 +44,25 @@ LIBELF_VCSID("$Id: elf_scn.c 1077 2010-08-09 15:37:40Z jkoshy $");
 int
 _libelf_load_section_headers(Elf *e, void *ehdr)
 {
-	int ec, swapbytes;
-	size_t fsz, i, shnum;
+	Elf_Scn *scn;
 	uint64_t shoff;
-	char *src;
 	Elf32_Ehdr *eh32;
 	Elf64_Ehdr *eh64;
-	Elf_Scn *scn;
-	int (*xlator)(char *_d, size_t _dsz, char *_s, size_t _c, int _swap);
+	int ec, swapbytes;
+	unsigned char *src;
+	size_t fsz, i, shnum;
+	int (*xlator)(unsigned char *_d, size_t _dsz, unsigned char *_s,
+	    size_t _c, int _swap);
 
 	assert(e != NULL);
 	assert(ehdr != NULL);
 	assert((e->e_flags & LIBELF_F_SHDRS_LOADED) == 0);
 
 #define	CHECK_EHDR(E,EH)	do {				\
-		if (fsz != (EH)->e_shentsize ||			\
-		    shoff + fsz * shnum > e->e_rawsize) {	\
+		if (shoff > e->e_rawsize ||			\
+		    fsz != (EH)->e_shentsize ||			\
+		    shnum > SIZE_MAX / fsz ||			\
+		    fsz * shnum > e->e_rawsize - shoff) {	\
 			LIBELF_SET_ERROR(HEADER, 0);		\
 			return (0);				\
 		}						\
@@ -95,7 +98,7 @@ _libelf_load_section_headers(Elf *e, void *ehdr)
 	if (!STAILQ_EMPTY(&e->e_u.e_elf.e_scn)) {
 		assert(STAILQ_FIRST(&e->e_u.e_elf.e_scn) ==
 		    STAILQ_LAST(&e->e_u.e_elf.e_scn, _Elf_Scn, s_next));
-    
+
 		i = 1;
 		src += fsz;
 	}
@@ -104,8 +107,8 @@ _libelf_load_section_headers(Elf *e, void *ehdr)
 		if ((scn = _libelf_allocate_scn(e, i)) == NULL)
 			return (0);
 
-		(*xlator)((char *) &scn->s_shdr, sizeof(scn->s_shdr), src,
-		    (size_t) 1, swapbytes);
+		(*xlator)((unsigned char *) &scn->s_shdr, sizeof(scn->s_shdr),
+		    src, (size_t) 1, swapbytes);
 
 		if (ec == ELFCLASS32) {
 			scn->s_offset = scn->s_rawoff =
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_shnum.c b/rtemstoolkit/elftoolchain/libelf/elf_shnum.c
index 515027a..5c0560f 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_shnum.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_shnum.c
@@ -24,14 +24,12 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <ar.h>
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_shnum.c 466 2009-08-04 17:17:42Z jkoshy $");
+ELFTC_VCSID("$Id: elf_shnum.c 3174 2015-03-27 17:13:41Z emaste $");
 
 static int
 _libelf_getshdrnum(Elf *e, size_t *shnum)
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_shstrndx.c b/rtemstoolkit/elftoolchain/libelf/elf_shstrndx.c
index bac14b4..dac40c9 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_shstrndx.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_shstrndx.c
@@ -24,14 +24,12 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <ar.h>
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_shstrndx.c 466 2009-08-04 17:17:42Z jkoshy $");
+ELFTC_VCSID("$Id: elf_shstrndx.c 3174 2015-03-27 17:13:41Z emaste $");
 
 static int
 _libelf_getshdrstrndx(Elf *e, size_t *strndx)
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_strptr.c b/rtemstoolkit/elftoolchain/libelf/elf_strptr.c
index bfa39de..e2a6b28 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_strptr.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_strptr.c
@@ -24,12 +24,14 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/param.h>
+
 #include <assert.h>
 #include <gelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_strptr.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: elf_strptr.c 2990 2014-03-17 09:56:58Z jkoshy $");
 
 /*
  * Convert an ELF section#,offset pair to a string pointer.
@@ -40,8 +42,8 @@ elf_strptr(Elf *e, size_t scndx, size_t offset)
 {
 	Elf_Scn *s;
 	Elf_Data *d;
-	size_t alignment, count;
 	GElf_Shdr shdr;
+	uint64_t alignment, count;
 
 	if (e == NULL || e->e_kind != ELF_K_ELF) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
@@ -88,7 +90,7 @@ elf_strptr(Elf *e, size_t scndx, size_t offset)
 		 * account 'holes' in coverage of the section introduced
 		 * by alignment requirements.
 		 */
-		count = (size_t) 0;	/* cumulative count of bytes seen */
+		count = (uint64_t) 0;	/* cumulative count of bytes seen */
 		while ((d = elf_getdata(s, d)) != NULL && count <= offset) {
 
 			if (d->d_buf == NULL || d->d_size == 0)
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_update.c b/rtemstoolkit/elftoolchain/libelf/elf_update.c
index 9806131..6cc109d 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_update.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_update.c
@@ -24,7 +24,7 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/mman.h>
+#include <sys/param.h>
 #include <sys/stat.h>
 
 #include <assert.h>
@@ -37,7 +37,11 @@
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_update.c 1922 2011-09-23 08:04:33Z jkoshy $");
+#if	ELFTC_HAVE_MMAP
+#include <sys/mman.h>
+#endif
+
+ELFTC_VCSID("$Id: elf_update.c 3190 2015-05-04 15:23:08Z jkoshy $");
 
 /*
  * Layout strategy:
@@ -106,14 +110,14 @@ SLIST_HEAD(_Elf_Extent_List, _Elf_Extent);
 static int
 _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t rc)
 {
-	int ec;
-	size_t fsz, msz;
 	Elf_Data *d;
-	Elf32_Shdr *shdr32;
-	Elf64_Shdr *shdr64;
+	size_t fsz, msz;
+	int ec, elftype;
 	uint32_t sh_type;
 	uint64_t d_align;
-	unsigned int elftype;
+	Elf32_Shdr *shdr32;
+	Elf64_Shdr *shdr64;
+	struct _Libelf_Data *ld;
 	uint64_t scn_size, scn_alignment;
 	uint64_t sh_align, sh_entsize, sh_offset, sh_size;
 
@@ -187,7 +191,9 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t rc)
 	 */
 	scn_size = 0L;
 	scn_alignment = 0;
-	STAILQ_FOREACH(d, &s->s_data, d_next)  {
+	STAILQ_FOREACH(ld, &s->s_data, d_next)  {
+
+		d = &ld->d_data;
 
 		/*
 		 * The data buffer's type is known.
@@ -246,7 +252,7 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t rc)
 			scn_size = roundup2(scn_size, d->d_align);
 			d->d_off = scn_size;
 			fsz = _libelf_fsize(d->d_type, ec, d->d_version,
-			    d->d_size / msz);
+			    (size_t) d->d_size / msz);
 			scn_size += fsz;
 		}
 
@@ -265,8 +271,10 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t rc)
 	 * offsets and alignment for sanity.
 	 */
 	if (e->e_flags & ELF_F_LAYOUT) {
-		if (scn_alignment > sh_align || sh_offset % sh_align ||
-		    sh_size < scn_size) {
+		if (scn_alignment > sh_align ||
+		    sh_offset % sh_align ||
+		    sh_size < scn_size ||
+		    sh_offset % _libelf_falign(elftype, ec)) {
 			LIBELF_SET_ERROR(LAYOUT, 0);
 			return (0);
 		}
@@ -300,7 +308,7 @@ computeoffset:
 	 * Compute the new offset for the section based on
 	 * the section's alignment needs.
 	 */
-	sh_offset = roundup(rc, sh_align);
+	sh_offset = roundup((uint64_t) rc, sh_align);
 
 	/*
 	 * Update the section header.
@@ -464,7 +472,7 @@ _libelf_resync_sections(Elf *e, off_t rc, struct _Elf_Extent_List *extents)
 			return ((off_t) -1);
 
 		if ((size_t) rc < s->s_offset + s->s_size)
-			rc = s->s_offset + s->s_size;
+			rc = (off_t) (s->s_offset + s->s_size);
 	}
 
 	return (rc);
@@ -495,7 +503,7 @@ _libelf_resync_sections(Elf *e, off_t rc, struct _Elf_Extent_List *extents)
 static off_t
 _libelf_resync_elf(Elf *e, struct _Elf_Extent_List *extents)
 {
-	int ec, eh_class, eh_type;
+	int ec, eh_class;
 	unsigned int eh_byteorder, eh_version;
 	size_t align, fsz;
 	size_t phnum, shnum;
@@ -522,19 +530,22 @@ _libelf_resync_elf(Elf *e, struct _Elf_Extent_List *extents)
 	if (ec == ELFCLASS32) {
 		eh_byteorder = eh32->e_ident[EI_DATA];
 		eh_class     = eh32->e_ident[EI_CLASS];
-		phoff        = (uint64_t) eh32->e_phoff;
-		shoff        = (uint64_t) eh32->e_shoff;
-		eh_type      = eh32->e_type;
+		phoff        = (off_t) eh32->e_phoff;
+		shoff        = (off_t) eh32->e_shoff;
 		eh_version   = eh32->e_version;
 	} else {
 		eh_byteorder = eh64->e_ident[EI_DATA];
 		eh_class     = eh64->e_ident[EI_CLASS];
-		phoff        = eh64->e_phoff;
-		shoff        = eh64->e_shoff;
-		eh_type      = eh64->e_type;
+		phoff        = (off_t) eh64->e_phoff;
+		shoff        = (off_t) eh64->e_shoff;
 		eh_version   = eh64->e_version;
 	}
 
+	if (phoff < 0 || shoff < 0) {
+		LIBELF_SET_ERROR(HEADER, 0);
+		return ((off_t) -1);
+	}
+
 	if (eh_version == EV_NONE)
 		eh_version = EV_CURRENT;
 
@@ -559,18 +570,20 @@ _libelf_resync_elf(Elf *e, struct _Elf_Extent_List *extents)
 	e->e_byteorder = eh_byteorder;
 
 #define	INITIALIZE_EHDR(E,EC,V)	do {					\
+		unsigned int _version = (unsigned int) (V);		\
 		(E)->e_ident[EI_MAG0] = ELFMAG0;			\
 		(E)->e_ident[EI_MAG1] = ELFMAG1;			\
 		(E)->e_ident[EI_MAG2] = ELFMAG2;			\
 		(E)->e_ident[EI_MAG3] = ELFMAG3;			\
-		(E)->e_ident[EI_CLASS] = (EC);				\
-		(E)->e_ident[EI_VERSION] = (V);				\
-		(E)->e_ehsize = _libelf_fsize(ELF_T_EHDR, (EC), (V),	\
-		    (size_t) 1);					\
-		(E)->e_phentsize = (phnum == 0) ? 0 : _libelf_fsize(	\
-		    ELF_T_PHDR, (EC), (V), (size_t) 1);			\
-		(E)->e_shentsize = _libelf_fsize(ELF_T_SHDR, (EC), (V),	\
-		    (size_t) 1);					\
+		(E)->e_ident[EI_CLASS] = (unsigned char) (EC);		\
+		(E)->e_ident[EI_VERSION] = (_version & 0xFFU);		\
+		(E)->e_ehsize = (uint16_t) _libelf_fsize(ELF_T_EHDR,	\
+		    (EC), _version, (size_t) 1);			\
+		(E)->e_phentsize = (uint16_t) ((phnum == 0) ? 0 :	\
+		    _libelf_fsize(ELF_T_PHDR, (EC), _version,		\
+			(size_t) 1));					\
+		(E)->e_shentsize = (uint16_t) _libelf_fsize(ELF_T_SHDR,	\
+		    (EC), _version, (size_t) 1);			\
 	} while (0)
 
 	if (ec == ELFCLASS32)
@@ -580,9 +593,10 @@ _libelf_resync_elf(Elf *e, struct _Elf_Extent_List *extents)
 
 	(void) elf_flagehdr(e, ELF_C_SET, ELF_F_DIRTY);
 
-	rc += _libelf_fsize(ELF_T_EHDR, ec, eh_version, (size_t) 1);
+	rc += (off_t) _libelf_fsize(ELF_T_EHDR, ec, eh_version, (size_t) 1);
 
-	if (!_libelf_insert_extent(extents, ELF_EXTENT_EHDR, 0, rc, ehdr))
+	if (!_libelf_insert_extent(extents, ELF_EXTENT_EHDR, 0, (uint64_t) rc,
+		ehdr))
 		return ((off_t) -1);
 
 	/*
@@ -603,20 +617,20 @@ _libelf_resync_elf(Elf *e, struct _Elf_Extent_List *extents)
 				return ((off_t) -1);
 			}
 
-			if (phoff % align) {
+			if (phoff % (off_t) align) {
 				LIBELF_SET_ERROR(LAYOUT, 0);
 				return ((off_t) -1);
 			}
 
 		} else
-			phoff = roundup(rc, align);
+			phoff = roundup(rc, (off_t) align);
 
-		rc = phoff + fsz;
+		rc = phoff + (off_t) fsz;
 
 		phdr = _libelf_getphdr(e, ec);
 
-		if (!_libelf_insert_extent(extents, ELF_EXTENT_PHDR, phoff,
-			fsz, phdr))
+		if (!_libelf_insert_extent(extents, ELF_EXTENT_PHDR,
+			(uint64_t) phoff, fsz, phdr))
 			return ((off_t) -1);
 	} else
 		phoff = 0;
@@ -651,18 +665,18 @@ _libelf_resync_elf(Elf *e, struct _Elf_Extent_List *extents)
 		align = _libelf_falign(ELF_T_SHDR, ec);
 
 		if (e->e_flags & ELF_F_LAYOUT) {
-			if (shoff % align) {
+			if (shoff % (off_t) align) {
 				LIBELF_SET_ERROR(LAYOUT, 0);
 				return ((off_t) -1);
 			}
 		} else
-			shoff = roundup(rc, align);
+			shoff = roundup(rc, (off_t) align);
 
-		if (shoff + fsz > (size_t) rc)
-			rc = shoff + fsz;
+		if (shoff + (off_t) fsz > rc)
+			rc = shoff + (off_t) fsz;
 
-		if (!_libelf_insert_extent(extents, ELF_EXTENT_SHDR, shoff,
-		    fsz, NULL))
+		if (!_libelf_insert_extent(extents, ELF_EXTENT_SHDR,
+			(uint64_t) shoff, fsz, NULL))
 			return ((off_t) -1);
 	} else
 		shoff = 0;
@@ -695,21 +709,23 @@ _libelf_resync_elf(Elf *e, struct _Elf_Extent_List *extents)
  * Write out the contents of an ELF section.
  */
 
-static size_t
-_libelf_write_scn(Elf *e, char *nf, struct _Elf_Extent *ex)
+static off_t
+_libelf_write_scn(Elf *e, unsigned char *nf, struct _Elf_Extent *ex)
 {
 	int ec;
-	size_t fsz, msz, nobjects, rc;
-	uint32_t sh_type;
-	uint64_t sh_off, sh_size;
-	int elftype;
+	off_t rc;
 	Elf_Scn *s;
+	int elftype;
 	Elf_Data *d, dst;
+	uint32_t sh_type;
+	struct _Libelf_Data *ld;
+	uint64_t sh_off, sh_size;
+	size_t fsz, msz, nobjects;
 
 	assert(ex->ex_type == ELF_EXTENT_SECTION);
 
 	s = ex->ex_desc;
-	rc = ex->ex_start;
+	rc = (off_t) ex->ex_start;
 
 	if ((ec = e->e_class) == ELFCLASS32) {
 		sh_type = s->s_shdr.s_shdr32.sh_type;
@@ -744,21 +760,26 @@ _libelf_write_scn(Elf *e, char *nf, struct _Elf_Extent *ex)
 		if ((d = elf_rawdata(s, NULL)) == NULL)
 			return ((off_t) -1);
 
-		STAILQ_FOREACH(d, &s->s_rawdata, d_next) {
+		STAILQ_FOREACH(ld, &s->s_rawdata, d_next) {
+
+			d = &ld->d_data;
+
 			if ((uint64_t) rc < sh_off + d->d_off)
 				(void) memset(nf + rc,
-				    LIBELF_PRIVATE(fillchar), sh_off +
-				    d->d_off - rc);
-			rc = sh_off + d->d_off;
+				    LIBELF_PRIVATE(fillchar),
+				    (size_t) (sh_off + d->d_off -
+					(uint64_t) rc));
+			rc = (off_t) (sh_off + d->d_off);
 
 			assert(d->d_buf != NULL);
 			assert(d->d_type == ELF_T_BYTE);
 			assert(d->d_version == e->e_version);
 
 			(void) memcpy(nf + rc,
-			    e->e_rawfile + s->s_rawoff + d->d_off, d->d_size);
+			    e->e_rawfile + s->s_rawoff + d->d_off,
+			    (size_t) d->d_size);
 
-			rc += d->d_size;
+			rc += (off_t) d->d_size;
 		}
 
 		return (rc);
@@ -772,21 +793,24 @@ _libelf_write_scn(Elf *e, char *nf, struct _Elf_Extent *ex)
 
 	dst.d_version = e->e_version;
 
-	STAILQ_FOREACH(d, &s->s_data, d_next) {
+	STAILQ_FOREACH(ld, &s->s_data, d_next) {
+
+		d = &ld->d_data;
 
 		msz = _libelf_msize(d->d_type, ec, e->e_version);
 
 		if ((uint64_t) rc < sh_off + d->d_off)
 			(void) memset(nf + rc,
-			    LIBELF_PRIVATE(fillchar), sh_off + d->d_off - rc);
+			    LIBELF_PRIVATE(fillchar),
+			    (size_t) (sh_off + d->d_off - (uint64_t) rc));
 
-		rc = sh_off + d->d_off;
+		rc = (off_t) (sh_off + d->d_off);
 
 		assert(d->d_buf != NULL);
 		assert(d->d_version == e->e_version);
 		assert(d->d_size % msz == 0);
 
-		nobjects = d->d_size / msz;
+		nobjects = (size_t) (d->d_size / msz);
 
 		fsz = _libelf_fsize(d->d_type, ec, e->e_version, nobjects);
 
@@ -797,10 +821,10 @@ _libelf_write_scn(Elf *e, char *nf, struct _Elf_Extent *ex)
 		    NULL)
 			return ((off_t) -1);
 
-		rc += fsz;
+		rc += (off_t) fsz;
 	}
 
-	return ((off_t) rc);
+	return (rc);
 }
 
 /*
@@ -808,7 +832,7 @@ _libelf_write_scn(Elf *e, char *nf, struct _Elf_Extent *ex)
  */
 
 static off_t
-_libelf_write_ehdr(Elf *e, char *nf, struct _Elf_Extent *ex)
+_libelf_write_ehdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex)
 {
 	int ec;
 	void *ehdr;
@@ -849,7 +873,7 @@ _libelf_write_ehdr(Elf *e, char *nf, struct _Elf_Extent *ex)
  */
 
 static off_t
-_libelf_write_phdr(Elf *e, char *nf, struct _Elf_Extent *ex)
+_libelf_write_phdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex)
 {
 	int ec;
 	void *ehdr;
@@ -898,7 +922,7 @@ _libelf_write_phdr(Elf *e, char *nf, struct _Elf_Extent *ex)
 	    NULL)
 		return ((off_t) -1);
 
-	return (phoff + fsz);
+	return ((off_t) (phoff + fsz));
 }
 
 /*
@@ -906,7 +930,7 @@ _libelf_write_phdr(Elf *e, char *nf, struct _Elf_Extent *ex)
  */
 
 static off_t
-_libelf_write_shdr(Elf *e, char *nf, struct _Elf_Extent *ex)
+_libelf_write_shdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex)
 {
 	int ec;
 	void *ehdr;
@@ -958,7 +982,7 @@ _libelf_write_shdr(Elf *e, char *nf, struct _Elf_Extent *ex)
 			return ((off_t) -1);
 	}
 
-	return (ex->ex_start + nscn * fsz);
+	return ((off_t) (ex->ex_start + nscn * fsz));
 }
 
 /*
@@ -982,9 +1006,9 @@ static off_t
 _libelf_write_elf(Elf *e, off_t newsize, struct _Elf_Extent_List *extents)
 {
 	off_t nrc, rc;
-	char *newfile;
 	Elf_Scn *scn, *tscn;
 	struct _Elf_Extent *ex;
+	unsigned char *newfile;
 
 	assert(e->e_kind == ELF_K_ELF);
 	assert(e->e_cmd == ELF_C_RDWR || e->e_cmd == ELF_C_WRITE);
@@ -1001,7 +1025,7 @@ _libelf_write_elf(Elf *e, off_t newsize, struct _Elf_Extent_List *extents)
 		/* Fill inter-extent gaps. */
 		if (ex->ex_start > (size_t) rc)
 			(void) memset(newfile + rc, LIBELF_PRIVATE(fillchar),
-			    ex->ex_start - rc);
+			    (size_t) (ex->ex_start - (uint64_t) rc));
 
 		switch (ex->ex_type) {
 		case ELF_EXTENT_EHDR:
@@ -1047,6 +1071,7 @@ _libelf_write_elf(Elf *e, off_t newsize, struct _Elf_Extent_List *extents)
 			LIBELF_SET_ERROR(IO, errno);
 			goto error;
 		}
+#if	ELFTC_HAVE_MMAP
 		if (e->e_flags & LIBELF_F_RAWFILE_MMAP) {
 			assert(e->e_rawfile != NULL);
 			assert(e->e_cmd == ELF_C_RDWR);
@@ -1055,6 +1080,7 @@ _libelf_write_elf(Elf *e, off_t newsize, struct _Elf_Extent_List *extents)
 				goto error;
 			}
 		}
+#endif
 	}
 
 	/*
@@ -1071,21 +1097,26 @@ _libelf_write_elf(Elf *e, off_t newsize, struct _Elf_Extent_List *extents)
 	 */
 	if (e->e_cmd == ELF_C_RDWR) {
 		assert(e->e_rawfile != NULL);
-		if (e->e_flags & LIBELF_F_RAWFILE_MMAP) {
+		assert((e->e_flags & LIBELF_F_RAWFILE_MALLOC) ||
+		    (e->e_flags & LIBELF_F_RAWFILE_MMAP));
+		if (e->e_flags & LIBELF_F_RAWFILE_MALLOC) {
+			free(e->e_rawfile);
+			e->e_rawfile = newfile;
+			newfile = NULL;
+		}
+#if	ELFTC_HAVE_MMAP
+		else if (e->e_flags & LIBELF_F_RAWFILE_MMAP) {
 			if ((e->e_rawfile = mmap(NULL, (size_t) newsize,
 			    PROT_READ, MAP_PRIVATE, e->e_fd, (off_t) 0)) ==
 			    MAP_FAILED) {
 				LIBELF_SET_ERROR(IO, errno);
 				goto error;
 			}
-		} else if (e->e_flags & LIBELF_F_RAWFILE_MALLOC) {
-			free(e->e_rawfile);
-			e->e_rawfile = newfile;
-			newfile = NULL;
 		}
+#endif	/* ELFTC_HAVE_MMAP */
 
 		/* Record the new size of the file. */
-		e->e_rawsize = newsize;
+		e->e_rawsize = (size_t) newsize;
 	} else {
 		/* File opened in ELF_C_WRITE mode. */
 		assert(e->e_rawfile == NULL);
@@ -1176,7 +1207,7 @@ elf_update(Elf *e, Elf_Cmd c)
 		goto done;
 	}
 
-	return (_libelf_write_elf(e, rc, &extents));
+	rc = _libelf_write_elf(e, rc, &extents);
 
 done:
 	_libelf_release_extents(&extents);
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_version.c b/rtemstoolkit/elftoolchain/libelf/elf_version.c
index 48950f4..cd25954 100644
--- a/rtemstoolkit/elftoolchain/libelf/elf_version.c
+++ b/rtemstoolkit/elftoolchain/libelf/elf_version.c
@@ -24,13 +24,11 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: elf_version.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: elf_version.c 3174 2015-03-27 17:13:41Z emaste $");
 
 unsigned int
 elf_version(unsigned int v)
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf.3 b/rtemstoolkit/elftoolchain/libelf/gelf.3
index a5d68ce..d00d5b3 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf.3
+++ b/rtemstoolkit/elftoolchain/libelf/gelf.3
@@ -21,7 +21,7 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $Id: gelf.3 189 2008-07-20 10:38:08Z jkoshy $
+.\" $Id: gelf.3 3195 2015-05-12 17:22:19Z emaste $
 .\"
 .Dd September 1, 2006
 .Os
@@ -197,5 +197,4 @@ This implementation of the API first appeared in
 .Fx 7.0 .
 .Sh AUTHORS
 The GElf API was implemented by
-.An "Joseph Koshy"
-.Aq jkoshy at FreeBSD.org .
+.An Joseph Koshy Aq Mt jkoshy at FreeBSD.org .
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf.h b/rtemstoolkit/elftoolchain/libelf/gelf.h
index 0a7dc24..6eae0a5 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf.h
+++ b/rtemstoolkit/elftoolchain/libelf/gelf.h
@@ -23,14 +23,12 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: gelf.h 1168 2010-09-04 01:03:25Z jkoshy $
+ * $Id: gelf.h 3174 2015-03-27 17:13:41Z emaste $
  */
 
 #ifndef	_GELF_H_
 #define	_GELF_H_
 
-#include <sys/cdefs.h>
-
 #include <libelf.h>
 
 typedef Elf64_Addr	GElf_Addr;	/* Addresses */
@@ -69,7 +67,9 @@ typedef Elf64_Syminfo	GElf_Syminfo;	/* Symbol information */
 #define	GELF_ST_TYPE			ELF64_ST_TYPE
 #define	GELF_ST_VISIBILITY		ELF64_ST_VISIBILITY
 
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
 long		gelf_checksum(Elf *_elf);
 size_t		gelf_fsize(Elf *_elf, Elf_Type _type, size_t _count,
 			unsigned int _version);
@@ -103,6 +103,8 @@ GElf_Syminfo	*gelf_getsyminfo(Elf_Data *_src, int _index, GElf_Syminfo *_dst);
 int		gelf_update_cap(Elf_Data *_dst, int _index, GElf_Cap *_src);
 int		gelf_update_move(Elf_Data *_dst, int _index, GElf_Move *_src);
 int		gelf_update_syminfo(Elf_Data *_dst, int _index, GElf_Syminfo *_src);
-__END_DECLS
+#ifdef __cplusplus
+}
+#endif
 
 #endif	/* _GELF_H_ */
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_cap.c b/rtemstoolkit/elftoolchain/libelf/gelf_cap.c
index af0b388..f509c69 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_cap.c
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_cap.c
@@ -24,25 +24,28 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <gelf.h>
+#include <limits.h>
+#include <stdint.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: gelf_cap.c 1166 2010-09-04 00:54:36Z jkoshy $");
+ELFTC_VCSID("$Id: gelf_cap.c 3177 2015-03-30 18:19:41Z emaste $");
 
 GElf_Cap *
-gelf_getcap(Elf_Data *d, int ndx, GElf_Cap *dst)
+gelf_getcap(Elf_Data *ed, int ndx, GElf_Cap *dst)
 {
 	int ec;
 	Elf *e;
+	size_t msz;
 	Elf_Scn *scn;
 	Elf32_Cap *cap32;
 	Elf64_Cap *cap64;
-	size_t msz;
 	uint32_t sh_type;
+	struct _Libelf_Data *d;
+
+	d = (struct _Libelf_Data *) ed;
 
 	if (d == NULL || ndx < 0 || dst == NULL ||
 	    (scn = d->d_scn) == NULL ||
@@ -68,21 +71,21 @@ gelf_getcap(Elf_Data *d, int ndx, GElf_Cap *dst)
 
 	assert(msz > 0);
 
-	if (msz * ndx >= d->d_size) {
+	if (msz * (size_t) ndx >= d->d_data.d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (NULL);
 	}
 
 	if (ec == ELFCLASS32) {
 
-		cap32 = (Elf32_Cap *) d->d_buf + ndx;
+		cap32 = (Elf32_Cap *) d->d_data.d_buf + ndx;
 
 		dst->c_tag  = cap32->c_tag;
 		dst->c_un.c_val = (Elf64_Xword) cap32->c_un.c_val;
 
 	} else {
 
-		cap64 = (Elf64_Cap *) d->d_buf + ndx;
+		cap64 = (Elf64_Cap *) d->d_data.d_buf + ndx;
 
 		*dst = *cap64;
 	}
@@ -91,15 +94,18 @@ gelf_getcap(Elf_Data *d, int ndx, GElf_Cap *dst)
 }
 
 int
-gelf_update_cap(Elf_Data *d, int ndx, GElf_Cap *gc)
+gelf_update_cap(Elf_Data *ed, int ndx, GElf_Cap *gc)
 {
 	int ec;
 	Elf *e;
+	size_t msz;
 	Elf_Scn *scn;
 	Elf32_Cap *cap32;
 	Elf64_Cap *cap64;
-	size_t msz;
 	uint32_t sh_type;
+	struct _Libelf_Data *d;
+
+	d = (struct _Libelf_Data *) ed;
 
 	if (d == NULL || ndx < 0 || gc == NULL ||
 	    (scn = d->d_scn) == NULL ||
@@ -124,18 +130,18 @@ gelf_update_cap(Elf_Data *d, int ndx, GElf_Cap *gc)
 	msz = _libelf_msize(ELF_T_CAP, ec, e->e_version);
 	assert(msz > 0);
 
-	if (msz * ndx >= d->d_size) {
+	if (msz * (size_t) ndx >= d->d_data.d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (0);
 	}
 
 	if (ec == ELFCLASS32) {
-		cap32 = (Elf32_Cap *) d->d_buf + ndx;
+		cap32 = (Elf32_Cap *) d->d_data.d_buf + ndx;
 
 		LIBELF_COPY_U32(cap32, gc, c_tag);
 		LIBELF_COPY_U32(cap32, gc, c_un.c_val);
 	} else {
-		cap64 = (Elf64_Cap *) d->d_buf + ndx;
+		cap64 = (Elf64_Cap *) d->d_data.d_buf + ndx;
 
 		*cap64 = *gc;
 	}
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_checksum.c b/rtemstoolkit/elftoolchain/libelf/gelf_checksum.c
index 30fbb97..b16272f 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_checksum.c
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_checksum.c
@@ -24,14 +24,12 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <gelf.h>
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: gelf_checksum.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: gelf_checksum.c 3174 2015-03-27 17:13:41Z emaste $");
 
 long
 elf32_checksum(Elf *e)
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_dyn.c b/rtemstoolkit/elftoolchain/libelf/gelf_dyn.c
index 6a2885c..7423309 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_dyn.c
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_dyn.c
@@ -24,25 +24,28 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <gelf.h>
+#include <limits.h>
+#include <stdint.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: gelf_dyn.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: gelf_dyn.c 3177 2015-03-30 18:19:41Z emaste $");
 
 GElf_Dyn *
-gelf_getdyn(Elf_Data *d, int ndx, GElf_Dyn *dst)
+gelf_getdyn(Elf_Data *ed, int ndx, GElf_Dyn *dst)
 {
 	int ec;
 	Elf *e;
+	size_t msz;
 	Elf_Scn *scn;
 	Elf32_Dyn *dyn32;
 	Elf64_Dyn *dyn64;
-	size_t msz;
 	uint32_t sh_type;
+	struct _Libelf_Data *d;
+
+	d = (struct _Libelf_Data *) ed;
 
 	if (d == NULL || ndx < 0 || dst == NULL ||
 	    (scn = d->d_scn) == NULL ||
@@ -67,21 +70,22 @@ gelf_getdyn(Elf_Data *d, int ndx, GElf_Dyn *dst)
 	msz = _libelf_msize(ELF_T_DYN, ec, e->e_version);
 
 	assert(msz > 0);
+	assert(ndx >= 0);
 
-	if (msz * ndx >= d->d_size) {
+	if (msz * (size_t) ndx >= d->d_data.d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (NULL);
 	}
 
 	if (ec == ELFCLASS32) {
-		dyn32 = (Elf32_Dyn *) d->d_buf + ndx;
+		dyn32 = (Elf32_Dyn *) d->d_data.d_buf + ndx;
 
 		dst->d_tag      = dyn32->d_tag;
 		dst->d_un.d_val = (Elf64_Xword) dyn32->d_un.d_val;
 
 	} else {
 
-		dyn64 = (Elf64_Dyn *) d->d_buf + ndx;
+		dyn64 = (Elf64_Dyn *) d->d_data.d_buf + ndx;
 
 		*dst = *dyn64;
 	}
@@ -90,15 +94,18 @@ gelf_getdyn(Elf_Data *d, int ndx, GElf_Dyn *dst)
 }
 
 int
-gelf_update_dyn(Elf_Data *d, int ndx, GElf_Dyn *ds)
+gelf_update_dyn(Elf_Data *ed, int ndx, GElf_Dyn *ds)
 {
 	int ec;
 	Elf *e;
+	size_t msz;
 	Elf_Scn *scn;
 	Elf32_Dyn *dyn32;
 	Elf64_Dyn *dyn64;
-	size_t msz;
 	uint32_t sh_type;
+	struct _Libelf_Data *d;
+
+	d = (struct _Libelf_Data *) ed;
 
 	if (d == NULL || ndx < 0 || ds == NULL ||
 	    (scn = d->d_scn) == NULL ||
@@ -121,20 +128,22 @@ gelf_update_dyn(Elf_Data *d, int ndx, GElf_Dyn *ds)
 	}
 
 	msz = _libelf_msize(ELF_T_DYN, ec, e->e_version);
+
 	assert(msz > 0);
+	assert(ndx >= 0);
 
-	if (msz * ndx >= d->d_size) {
+	if (msz * (size_t) ndx >= d->d_data.d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (0);
 	}
 
 	if (ec == ELFCLASS32) {
-		dyn32 = (Elf32_Dyn *) d->d_buf + ndx;
+		dyn32 = (Elf32_Dyn *) d->d_data.d_buf + ndx;
 
 		LIBELF_COPY_S32(dyn32, ds, d_tag);
 		LIBELF_COPY_U32(dyn32, ds, d_un.d_val);
 	} else {
-		dyn64 = (Elf64_Dyn *) d->d_buf + ndx;
+		dyn64 = (Elf64_Dyn *) d->d_data.d_buf + ndx;
 
 		*dyn64 = *ds;
 	}
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_ehdr.c b/rtemstoolkit/elftoolchain/libelf/gelf_ehdr.c
index 37ccce8..dcd260e 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_ehdr.c
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_ehdr.c
@@ -24,16 +24,16 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <gelf.h>
 #include <libelf.h>
+#include <limits.h>
+#include <stdint.h>
 #include <string.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: gelf_ehdr.c 1678 2011-07-28 04:36:34Z jkoshy $");
+ELFTC_VCSID("$Id: gelf_ehdr.c 3177 2015-03-30 18:19:41Z emaste $");
 
 Elf32_Ehdr *
 elf32_getehdr(Elf *e)
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_fsize.c b/rtemstoolkit/elftoolchain/libelf/gelf_fsize.c
index 0e38d14..afdea73 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_fsize.c
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_fsize.c
@@ -24,14 +24,12 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <gelf.h>
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: gelf_fsize.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: gelf_fsize.c 3174 2015-03-27 17:13:41Z emaste $");
 
 size_t
 elf32_fsize(Elf_Type t, size_t c, unsigned int v)
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_getclass.c b/rtemstoolkit/elftoolchain/libelf/gelf_getclass.c
index 349a9cd..d7f6803 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_getclass.c
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_getclass.c
@@ -24,13 +24,11 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <gelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: gelf_getclass.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: gelf_getclass.c 3174 2015-03-27 17:13:41Z emaste $");
 
 int
 gelf_getclass(Elf *e)
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_move.c b/rtemstoolkit/elftoolchain/libelf/gelf_move.c
index 753aba9..2ec8f25 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_move.c
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_move.c
@@ -24,25 +24,28 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <gelf.h>
+#include <limits.h>
+#include <stdint.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: gelf_move.c 1166 2010-09-04 00:54:36Z jkoshy $");
+ELFTC_VCSID("$Id: gelf_move.c 3177 2015-03-30 18:19:41Z emaste $");
 
 GElf_Move *
-gelf_getmove(Elf_Data *d, int ndx, GElf_Move *dst)
+gelf_getmove(Elf_Data *ed, int ndx, GElf_Move *dst)
 {
 	int ec;
 	Elf *e;
+	size_t msz;
 	Elf_Scn *scn;
+	uint32_t sh_type;
 	Elf32_Move *move32;
 	Elf64_Move *move64;
-	size_t msz;
-	uint32_t sh_type;
+	struct _Libelf_Data *d;
+
+	d = (struct _Libelf_Data *) ed;
 
 	if (d == NULL || ndx < 0 || dst == NULL ||
 	    (scn = d->d_scn) == NULL ||
@@ -67,15 +70,16 @@ gelf_getmove(Elf_Data *d, int ndx, GElf_Move *dst)
 	msz = _libelf_msize(ELF_T_MOVE, ec, e->e_version);
 
 	assert(msz > 0);
+	assert(ndx >= 0);
 
-	if (msz * ndx >= d->d_size) {
+	if (msz * (size_t) ndx >= d->d_data.d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (NULL);
 	}
 
 	if (ec == ELFCLASS32) {
 
-		move32 = (Elf32_Move *) d->d_buf + ndx;
+		move32 = (Elf32_Move *) d->d_data.d_buf + ndx;
 
 		dst->m_value   = move32->m_value;
 		dst->m_info    = (Elf64_Xword) move32->m_info;
@@ -84,7 +88,7 @@ gelf_getmove(Elf_Data *d, int ndx, GElf_Move *dst)
 		dst->m_stride = move32->m_stride;
 	} else {
 
-		move64 = (Elf64_Move *) d->d_buf + ndx;
+		move64 = (Elf64_Move *) d->d_data.d_buf + ndx;
 
 		*dst = *move64;
 	}
@@ -93,15 +97,18 @@ gelf_getmove(Elf_Data *d, int ndx, GElf_Move *dst)
 }
 
 int
-gelf_update_move(Elf_Data *d, int ndx, GElf_Move *gm)
+gelf_update_move(Elf_Data *ed, int ndx, GElf_Move *gm)
 {
 	int ec;
 	Elf *e;
+	size_t msz;
 	Elf_Scn *scn;
+	uint32_t sh_type;
 	Elf32_Move *move32;
 	Elf64_Move *move64;
-	size_t msz;
-	uint32_t sh_type;
+	struct _Libelf_Data *d;
+
+	d = (struct _Libelf_Data *) ed;
 
 	if (d == NULL || ndx < 0 || gm == NULL ||
 	    (scn = d->d_scn) == NULL ||
@@ -124,15 +131,17 @@ gelf_update_move(Elf_Data *d, int ndx, GElf_Move *gm)
 	}
 
 	msz = _libelf_msize(ELF_T_MOVE, ec, e->e_version);
+
 	assert(msz > 0);
+	assert(ndx >= 0);
 
-	if (msz * ndx >= d->d_size) {
+	if (msz * (size_t) ndx >= d->d_data.d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (0);
 	}
 
 	if (ec == ELFCLASS32) {
-		move32 = (Elf32_Move *) d->d_buf + ndx;
+		move32 = (Elf32_Move *) d->d_data.d_buf + ndx;
 
 		move32->m_value  = gm->m_value;
 		LIBELF_COPY_U32(move32, gm, m_info);
@@ -141,7 +150,7 @@ gelf_update_move(Elf_Data *d, int ndx, GElf_Move *gm)
 		move32->m_stride = gm->m_stride;
 
 	} else {
-		move64 = (Elf64_Move *) d->d_buf + ndx;
+		move64 = (Elf64_Move *) d->d_data.d_buf + ndx;
 
 		*move64 = *gm;
 	}
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_newehdr.3 b/rtemstoolkit/elftoolchain/libelf/gelf_newehdr.3
index 180fea9..cba9de0 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_newehdr.3
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_newehdr.3
@@ -21,7 +21,7 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $Id: gelf_newehdr.3 189 2008-07-20 10:38:08Z jkoshy $
+.\" $Id: gelf_newehdr.3 3500 2016-12-04 11:08:44Z jkoshy $
 .\"
 .Dd October 22, 2007
 .Os
@@ -127,6 +127,15 @@ flag on ELF descriptor
 .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]"
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_newphdr.3 b/rtemstoolkit/elftoolchain/libelf/gelf_newphdr.3
index 931385e..27e561d 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_newphdr.3
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_newphdr.3
@@ -21,7 +21,7 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $Id: gelf_newphdr.3 189 2008-07-20 10:38:08Z jkoshy $
+.\" $Id: gelf_newphdr.3 3500 2016-12-04 11:08:44Z jkoshy $
 .\"
 .Dd October 22, 2007
 .Os
@@ -97,6 +97,15 @@ 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]"
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_phdr.c b/rtemstoolkit/elftoolchain/libelf/gelf_phdr.c
index 47000d8..0916ccf 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_phdr.c
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_phdr.c
@@ -24,14 +24,14 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <gelf.h>
 #include <libelf.h>
+#include <limits.h>
+#include <stdint.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: gelf_phdr.c 189 2008-07-20 10:38:08Z jkoshy $");
+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/rtemstoolkit/elftoolchain/libelf/gelf_rel.c b/rtemstoolkit/elftoolchain/libelf/gelf_rel.c
index 7d0b6af..02a6133 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_rel.c
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_rel.c
@@ -24,25 +24,28 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <gelf.h>
+#include <limits.h>
+#include <stdint.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: gelf_rel.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: gelf_rel.c 3177 2015-03-30 18:19:41Z emaste $");
 
 GElf_Rel *
-gelf_getrel(Elf_Data *d, int ndx, GElf_Rel *dst)
+gelf_getrel(Elf_Data *ed, int ndx, GElf_Rel *dst)
 {
 	int ec;
 	Elf *e;
+	size_t msz;
 	Elf_Scn *scn;
+	uint32_t sh_type;
 	Elf32_Rel *rel32;
 	Elf64_Rel *rel64;
-	size_t msz;
-	uint32_t sh_type;
+	struct _Libelf_Data *d;
+
+	d = (struct _Libelf_Data *) ed;
 
 	if (d == NULL || ndx < 0 || dst == NULL ||
 	    (scn = d->d_scn) == NULL ||
@@ -67,14 +70,15 @@ gelf_getrel(Elf_Data *d, int ndx, GElf_Rel *dst)
 	msz = _libelf_msize(ELF_T_REL, ec, e->e_version);
 
 	assert(msz > 0);
+	assert(ndx >= 0);
 
-	if (msz * ndx >= d->d_size) {
+	if (msz * (size_t) ndx >= d->d_data.d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (NULL);
 	}
 
 	if (ec == ELFCLASS32) {
-		rel32 = (Elf32_Rel *) d->d_buf + ndx;
+		rel32 = (Elf32_Rel *) d->d_data.d_buf + ndx;
 
 		dst->r_offset = (Elf64_Addr) rel32->r_offset;
 		dst->r_info   = ELF64_R_INFO(
@@ -83,7 +87,7 @@ gelf_getrel(Elf_Data *d, int ndx, GElf_Rel *dst)
 
 	} else {
 
-		rel64 = (Elf64_Rel *) d->d_buf + ndx;
+		rel64 = (Elf64_Rel *) d->d_data.d_buf + ndx;
 
 		*dst = *rel64;
 	}
@@ -92,15 +96,18 @@ gelf_getrel(Elf_Data *d, int ndx, GElf_Rel *dst)
 }
 
 int
-gelf_update_rel(Elf_Data *d, int ndx, GElf_Rel *dr)
+gelf_update_rel(Elf_Data *ed, int ndx, GElf_Rel *dr)
 {
 	int ec;
 	Elf *e;
+	size_t msz;
 	Elf_Scn *scn;
+	uint32_t sh_type;
 	Elf32_Rel *rel32;
 	Elf64_Rel *rel64;
-	size_t msz;
-	uint32_t sh_type;
+	struct _Libelf_Data *d;
+
+	d = (struct _Libelf_Data *) ed;
 
 	if (d == NULL || ndx < 0 || dr == NULL ||
 	    (scn = d->d_scn) == NULL ||
@@ -123,15 +130,17 @@ gelf_update_rel(Elf_Data *d, int ndx, GElf_Rel *dr)
 	}
 
 	msz = _libelf_msize(ELF_T_REL, ec, e->e_version);
+
 	assert(msz > 0);
+	assert(ndx >= 0);
 
-	if (msz * ndx >= d->d_size) {
+	if (msz * (size_t) ndx >= d->d_data.d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (0);
 	}
 
 	if (ec == ELFCLASS32) {
-		rel32 = (Elf32_Rel *) d->d_buf + ndx;
+		rel32 = (Elf32_Rel *) d->d_data.d_buf + ndx;
 
 		LIBELF_COPY_U32(rel32, dr, r_offset);
 
@@ -140,10 +149,11 @@ gelf_update_rel(Elf_Data *d, int ndx, GElf_Rel *dr)
 			LIBELF_SET_ERROR(RANGE, 0);
 			return (0);
 		}
-		rel32->r_info = ELF32_R_INFO(ELF64_R_SYM(dr->r_info),
-		    ELF64_R_TYPE(dr->r_info));
+		rel32->r_info = ELF32_R_INFO(
+			(Elf32_Word) ELF64_R_SYM(dr->r_info),
+			(Elf32_Word) ELF64_R_TYPE(dr->r_info));
 	} else {
-		rel64 = (Elf64_Rel *) d->d_buf + ndx;
+		rel64 = (Elf64_Rel *) d->d_data.d_buf + ndx;
 
 		*rel64 = *dr;
 	}
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_rela.c b/rtemstoolkit/elftoolchain/libelf/gelf_rela.c
index 722c1ad..d485ab9 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_rela.c
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_rela.c
@@ -24,25 +24,28 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <gelf.h>
+#include <limits.h>
+#include <stdint.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: gelf_rela.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: gelf_rela.c 3177 2015-03-30 18:19:41Z emaste $");
 
 GElf_Rela *
-gelf_getrela(Elf_Data *d, int ndx, GElf_Rela *dst)
+gelf_getrela(Elf_Data *ed, int ndx, GElf_Rela *dst)
 {
 	int ec;
 	Elf *e;
+	size_t msz;
 	Elf_Scn *scn;
+	uint32_t sh_type;
 	Elf32_Rela *rela32;
 	Elf64_Rela *rela64;
-	size_t msz;
-	uint32_t sh_type;
+	struct _Libelf_Data *d;
+
+	d = (struct _Libelf_Data *) ed;
 
 	if (d == NULL || ndx < 0 || dst == NULL ||
 	    (scn = d->d_scn) == NULL ||
@@ -67,14 +70,15 @@ gelf_getrela(Elf_Data *d, int ndx, GElf_Rela *dst)
 	msz = _libelf_msize(ELF_T_RELA, ec, e->e_version);
 
 	assert(msz > 0);
+	assert(ndx >= 0);
 
-	if (msz * ndx >= d->d_size) {
+	if (msz * (size_t) ndx >= d->d_data.d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (NULL);
 	}
 
 	if (ec == ELFCLASS32) {
-		rela32 = (Elf32_Rela *) d->d_buf + ndx;
+		rela32 = (Elf32_Rela *) d->d_data.d_buf + ndx;
 
 		dst->r_offset = (Elf64_Addr) rela32->r_offset;
 		dst->r_info   = ELF64_R_INFO(
@@ -84,7 +88,7 @@ gelf_getrela(Elf_Data *d, int ndx, GElf_Rela *dst)
 
 	} else {
 
-		rela64 = (Elf64_Rela *) d->d_buf + ndx;
+		rela64 = (Elf64_Rela *) d->d_data.d_buf + ndx;
 
 		*dst = *rela64;
 	}
@@ -93,15 +97,18 @@ gelf_getrela(Elf_Data *d, int ndx, GElf_Rela *dst)
 }
 
 int
-gelf_update_rela(Elf_Data *d, int ndx, GElf_Rela *dr)
+gelf_update_rela(Elf_Data *ed, int ndx, GElf_Rela *dr)
 {
 	int ec;
 	Elf *e;
+	size_t msz;
 	Elf_Scn *scn;
+	uint32_t sh_type;
 	Elf32_Rela *rela32;
 	Elf64_Rela *rela64;
-	size_t msz;
-	uint32_t sh_type;
+	struct _Libelf_Data *d;
+
+	d = (struct _Libelf_Data *) ed;
 
 	if (d == NULL || ndx < 0 || dr == NULL ||
 	    (scn = d->d_scn) == NULL ||
@@ -124,15 +131,17 @@ gelf_update_rela(Elf_Data *d, int ndx, GElf_Rela *dr)
 	}
 
 	msz = _libelf_msize(ELF_T_RELA, ec, e->e_version);
+
 	assert(msz > 0);
+	assert(ndx >= 0);
 
-	if (msz * ndx >= d->d_size) {
+	if (msz * (size_t) ndx >= d->d_data.d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (0);
 	}
 
 	if (ec == ELFCLASS32) {
-		rela32 = (Elf32_Rela *) d->d_buf + ndx;
+		rela32 = (Elf32_Rela *) d->d_data.d_buf + ndx;
 
 		LIBELF_COPY_U32(rela32, dr, r_offset);
 
@@ -141,12 +150,13 @@ gelf_update_rela(Elf_Data *d, int ndx, GElf_Rela *dr)
 			LIBELF_SET_ERROR(RANGE, 0);
 			return (0);
 		}
-		rela32->r_info = ELF32_R_INFO(ELF64_R_SYM(dr->r_info),
-		    ELF64_R_TYPE(dr->r_info));
+		rela32->r_info = ELF32_R_INFO(
+			(Elf32_Word) ELF64_R_SYM(dr->r_info),
+			(Elf32_Word) ELF64_R_TYPE(dr->r_info));
 
 		LIBELF_COPY_S32(rela32, dr, r_addend);
 	} else {
-		rela64 = (Elf64_Rela *) d->d_buf + ndx;
+		rela64 = (Elf64_Rela *) d->d_data.d_buf + ndx;
 
 		*rela64 = *dr;
 	}
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_shdr.c b/rtemstoolkit/elftoolchain/libelf/gelf_shdr.c
index 47e56e9..1a9d949 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_shdr.c
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_shdr.c
@@ -24,15 +24,15 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <gelf.h>
 #include <libelf.h>
+#include <limits.h>
+#include <stdint.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: gelf_shdr.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: gelf_shdr.c 3177 2015-03-30 18:19:41Z emaste $");
 
 Elf32_Shdr *
 elf32_getshdr(Elf_Scn *s)
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_sym.c b/rtemstoolkit/elftoolchain/libelf/gelf_sym.c
index 3f84a17..ecd85fc 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_sym.c
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_sym.c
@@ -24,25 +24,28 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <gelf.h>
+#include <limits.h>
+#include <stdint.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: gelf_sym.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: gelf_sym.c 3177 2015-03-30 18:19:41Z emaste $");
 
 GElf_Sym *
-gelf_getsym(Elf_Data *d, int ndx, GElf_Sym *dst)
+gelf_getsym(Elf_Data *ed, int ndx, GElf_Sym *dst)
 {
 	int ec;
 	Elf *e;
+	size_t msz;
 	Elf_Scn *scn;
+	uint32_t sh_type;
 	Elf32_Sym *sym32;
 	Elf64_Sym *sym64;
-	size_t msz;
-	uint32_t sh_type;
+	struct _Libelf_Data *d;
+
+	d = (struct _Libelf_Data *) ed;
 
 	if (d == NULL || ndx < 0 || dst == NULL ||
 	    (scn = d->d_scn) == NULL ||
@@ -67,26 +70,24 @@ gelf_getsym(Elf_Data *d, int ndx, GElf_Sym *dst)
 	msz = _libelf_msize(ELF_T_SYM, ec, e->e_version);
 
 	assert(msz > 0);
+	assert(ndx >= 0);
 
-	if (msz * ndx >= d->d_size) {
+	if (msz * (size_t) ndx >= d->d_data.d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (NULL);
 	}
 
 	if (ec == ELFCLASS32) {
-
-		sym32 = (Elf32_Sym *) d->d_buf + ndx;
+		sym32 = (Elf32_Sym *) d->d_data.d_buf + ndx;
 
 		dst->st_name  = sym32->st_name;
 		dst->st_value = (Elf64_Addr) sym32->st_value;
 		dst->st_size  = (Elf64_Xword) sym32->st_size;
-		dst->st_info  = ELF64_ST_INFO(ELF32_ST_BIND(sym32->st_info),
-		    ELF32_ST_TYPE(sym32->st_info));
+		dst->st_info  = sym32->st_info;
 		dst->st_other = sym32->st_other;
 		dst->st_shndx = sym32->st_shndx;
 	} else {
-
-		sym64 = (Elf64_Sym *) d->d_buf + ndx;
+		sym64 = (Elf64_Sym *) d->d_data.d_buf + ndx;
 
 		*dst = *sym64;
 	}
@@ -95,15 +96,18 @@ gelf_getsym(Elf_Data *d, int ndx, GElf_Sym *dst)
 }
 
 int
-gelf_update_sym(Elf_Data *d, int ndx, GElf_Sym *gs)
+gelf_update_sym(Elf_Data *ed, int ndx, GElf_Sym *gs)
 {
 	int ec;
 	Elf *e;
+	size_t msz;
 	Elf_Scn *scn;
+	uint32_t sh_type;
 	Elf32_Sym *sym32;
 	Elf64_Sym *sym64;
-	size_t msz;
-	uint32_t sh_type;
+	struct _Libelf_Data *d;
+
+	d = (struct _Libelf_Data *) ed;
 
 	if (d == NULL || ndx < 0 || gs == NULL ||
 	    (scn = d->d_scn) == NULL ||
@@ -126,15 +130,17 @@ gelf_update_sym(Elf_Data *d, int ndx, GElf_Sym *gs)
 	}
 
 	msz = _libelf_msize(ELF_T_SYM, ec, e->e_version);
+
 	assert(msz > 0);
+	assert(ndx >= 0);
 
-	if (msz * ndx >= d->d_size) {
+	if (msz * (size_t) ndx >= d->d_data.d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (0);
 	}
 
 	if (ec == ELFCLASS32) {
-		sym32 = (Elf32_Sym *) d->d_buf + ndx;
+		sym32 = (Elf32_Sym *) d->d_data.d_buf + ndx;
 
 		sym32->st_name  = gs->st_name;
 		sym32->st_info  = gs->st_info;
@@ -144,7 +150,7 @@ gelf_update_sym(Elf_Data *d, int ndx, GElf_Sym *gs)
 		LIBELF_COPY_U32(sym32, gs, st_value);
 		LIBELF_COPY_U32(sym32, gs, st_size);
 	} else {
-		sym64 = (Elf64_Sym *) d->d_buf + ndx;
+		sym64 = (Elf64_Sym *) d->d_data.d_buf + ndx;
 
 		*sym64 = *gs;
 	}
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_syminfo.c b/rtemstoolkit/elftoolchain/libelf/gelf_syminfo.c
index 2e8d9d8..f6d7b6c 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_syminfo.c
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_syminfo.c
@@ -24,25 +24,26 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <gelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: gelf_syminfo.c 1166 2010-09-04 00:54:36Z jkoshy $");
+ELFTC_VCSID("$Id: gelf_syminfo.c 3174 2015-03-27 17:13:41Z emaste $");
 
 GElf_Syminfo *
-gelf_getsyminfo(Elf_Data *d, int ndx, GElf_Syminfo *dst)
+gelf_getsyminfo(Elf_Data *ed, int ndx, GElf_Syminfo *dst)
 {
 	int ec;
 	Elf *e;
+	size_t msz;
 	Elf_Scn *scn;
+	uint32_t sh_type;
+	struct _Libelf_Data *d;
 	Elf32_Syminfo *syminfo32;
 	Elf64_Syminfo *syminfo64;
-	size_t msz;
-	uint32_t sh_type;
+
+	d = (struct _Libelf_Data *) ed;
 
 	if (d == NULL || ndx < 0 || dst == NULL ||
 	    (scn = d->d_scn) == NULL ||
@@ -67,22 +68,23 @@ gelf_getsyminfo(Elf_Data *d, int ndx, GElf_Syminfo *dst)
 	msz = _libelf_msize(ELF_T_SYMINFO, ec, e->e_version);
 
 	assert(msz > 0);
+	assert(ndx >= 0);
 
-	if (msz * ndx >= d->d_size) {
+	if (msz * (size_t) ndx >= d->d_data.d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (NULL);
 	}
 
 	if (ec == ELFCLASS32) {
 
-		syminfo32 = (Elf32_Syminfo *) d->d_buf + ndx;
+		syminfo32 = (Elf32_Syminfo *) d->d_data.d_buf + ndx;
 
 		dst->si_boundto = syminfo32->si_boundto;
 		dst->si_flags   = syminfo32->si_flags;
 
 	} else {
 
-		syminfo64 = (Elf64_Syminfo *) d->d_buf + ndx;
+		syminfo64 = (Elf64_Syminfo *) d->d_data.d_buf + ndx;
 
 		*dst = *syminfo64;
 	}
@@ -91,15 +93,18 @@ gelf_getsyminfo(Elf_Data *d, int ndx, GElf_Syminfo *dst)
 }
 
 int
-gelf_update_syminfo(Elf_Data *d, int ndx, GElf_Syminfo *gs)
+gelf_update_syminfo(Elf_Data *ed, int ndx, GElf_Syminfo *gs)
 {
 	int ec;
 	Elf *e;
+	size_t msz;
 	Elf_Scn *scn;
+	uint32_t sh_type;
+	struct _Libelf_Data *d;
 	Elf32_Syminfo *syminfo32;
 	Elf64_Syminfo *syminfo64;
-	size_t msz;
-	uint32_t sh_type;
+
+	d = (struct _Libelf_Data *) ed;
 
 	if (d == NULL || ndx < 0 || gs == NULL ||
 	    (scn = d->d_scn) == NULL ||
@@ -122,21 +127,23 @@ gelf_update_syminfo(Elf_Data *d, int ndx, GElf_Syminfo *gs)
 	}
 
 	msz = _libelf_msize(ELF_T_SYMINFO, ec, e->e_version);
+
 	assert(msz > 0);
+	assert(ndx >= 0);
 
-	if (msz * ndx >= d->d_size) {
+	if (msz * (size_t) ndx >= d->d_data.d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (0);
 	}
 
 	if (ec == ELFCLASS32) {
-		syminfo32 = (Elf32_Syminfo *) d->d_buf + ndx;
+		syminfo32 = (Elf32_Syminfo *) d->d_data.d_buf + ndx;
 
 		syminfo32->si_boundto  = gs->si_boundto;
 		syminfo32->si_flags  = gs->si_flags;
 
 	} else {
-		syminfo64 = (Elf64_Syminfo *) d->d_buf + ndx;
+		syminfo64 = (Elf64_Syminfo *) d->d_data.d_buf + ndx;
 
 		*syminfo64 = *gs;
 	}
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_symshndx.c b/rtemstoolkit/elftoolchain/libelf/gelf_symshndx.c
index ab3549c..b490aa2 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_symshndx.c
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_symshndx.c
@@ -24,14 +24,12 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <gelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: gelf_symshndx.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: gelf_symshndx.c 3174 2015-03-27 17:13:41Z emaste $");
 
 GElf_Sym *
 gelf_getsymshndx(Elf_Data *d, Elf_Data *id, int ndx, GElf_Sym *dst,
@@ -39,15 +37,19 @@ gelf_getsymshndx(Elf_Data *d, Elf_Data *id, int ndx, GElf_Sym *dst,
 {
 	int ec;
 	Elf *e;
-	Elf_Scn *scn;
 	size_t msz;
+	Elf_Scn *scn;
 	uint32_t sh_type;
+	struct _Libelf_Data *ld, *lid;
+
+	ld = (struct _Libelf_Data *) d;
+	lid = (struct _Libelf_Data *) id;
 
 	if (gelf_getsym(d, ndx, dst) == 0)
 		return (NULL);
 
-	if (id == NULL || (scn = id->d_scn) == NULL ||
-	    (e = scn->s_elf) == NULL || (e != d->d_scn->s_elf) ||
+	if (lid == NULL || (scn = lid->d_scn) == NULL ||
+	    (e = scn->s_elf) == NULL || (e != ld->d_scn->s_elf) ||
 	    shindex == NULL) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (NULL);
@@ -70,8 +72,9 @@ gelf_getsymshndx(Elf_Data *d, Elf_Data *id, int ndx, GElf_Sym *dst,
 	msz = _libelf_msize(ELF_T_WORD, ec, e->e_version);
 
 	assert(msz > 0);
+	assert(ndx >= 0);
 
-	if (msz * ndx >= id->d_size) {
+	if (msz * (size_t) ndx >= id->d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (NULL);
 	}
@@ -87,15 +90,19 @@ gelf_update_symshndx(Elf_Data *d, Elf_Data *id, int ndx, GElf_Sym *gs,
 {
 	int ec;
 	Elf *e;
-	Elf_Scn *scn;
 	size_t msz;
+	Elf_Scn *scn;
 	uint32_t sh_type;
+	struct _Libelf_Data *ld, *lid;
+
+	ld = (struct _Libelf_Data *) d;
+	lid = (struct _Libelf_Data *) id;
 
 	if (gelf_update_sym(d, ndx, gs) == 0)
 		return (0);
 
-	if (id == NULL || (scn = id->d_scn) == NULL ||
-	    (e = scn->s_elf) == NULL || (e != d->d_scn->s_elf)) {
+	if (lid == NULL || (scn = lid->d_scn) == NULL ||
+	    (e = scn->s_elf) == NULL || (e != ld->d_scn->s_elf)) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (0);
 	}
@@ -115,9 +122,11 @@ gelf_update_symshndx(Elf_Data *d, Elf_Data *id, int ndx, GElf_Sym *gs,
 	}
 
 	msz = _libelf_msize(ELF_T_WORD, ec, e->e_version);
+
 	assert(msz > 0);
+	assert(ndx >= 0);
 
-	if (msz * ndx >= id->d_size) {
+	if (msz * (size_t) ndx >= id->d_size) {
 		LIBELF_SET_ERROR(ARGUMENT, 0);
 		return (0);
 	}
diff --git a/rtemstoolkit/elftoolchain/libelf/gelf_xlate.c b/rtemstoolkit/elftoolchain/libelf/gelf_xlate.c
index 6cdf705..f501819 100644
--- a/rtemstoolkit/elftoolchain/libelf/gelf_xlate.c
+++ b/rtemstoolkit/elftoolchain/libelf/gelf_xlate.c
@@ -24,15 +24,13 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <gelf.h>
 #include <libelf.h>
 #include <string.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: gelf_xlate.c 1678 2011-07-28 04:36:34Z jkoshy $");
+ELFTC_VCSID("$Id: gelf_xlate.c 3174 2015-03-27 17:13:41Z emaste $");
 
 Elf_Data *
 elf32_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned int encoding)
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf.h b/rtemstoolkit/elftoolchain/libelf/libelf.h
index 60b0f1c..3fce280 100644
--- a/rtemstoolkit/elftoolchain/libelf/libelf.h
+++ b/rtemstoolkit/elftoolchain/libelf/libelf.h
@@ -23,17 +23,22 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: libelf.h 1345 2011-01-01 11:17:52Z jkoshy $
+ * $Id: libelf.h 3174 2015-03-27 17:13:41Z emaste $
  */
 
 #ifndef	_LIBELF_H_
 #define	_LIBELF_H_
 
-#include <sys/param.h>
-#include <sys/queue.h>
+#include <sys/types.h>
 
 #include <elfdefinitions.h>
 
+/* Not defined anywhere on Windows */
+#if defined(__WIN32__)
+typedef int gid_t;
+typedef int uid_t;
+#endif
+
 /* Library private data structures */
 typedef struct _Elf Elf;
 typedef struct _Elf_Scn Elf_Scn;
@@ -112,13 +117,6 @@ typedef struct _Elf_Data {
 	uint64_t	d_size;
 	Elf_Type	d_type;
 	unsigned int	d_version;
-
-	/*
-	 * Members that are not part of the public API.
-	 */
-	Elf_Scn		*d_scn;		/* containing section */
-	unsigned int	d_flags;
-	STAILQ_ENTRY(_Elf_Data)	d_next;
 } Elf_Data;
 
 /*
@@ -137,7 +135,7 @@ typedef struct {
 	/*
 	 * Members that are not part of the public API.
 	 */
-	int		ar_flags;
+	unsigned int	ar_flags;
 } Elf_Arhdr;
 
 /*
@@ -184,7 +182,9 @@ enum Elf_Error {
 #define	ELF_F_ARCHIVE	   0x100U /* archive creation */
 #define	ELF_F_ARCHIVE_SYSV 0x200U /* SYSV style archive */
 
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
 Elf		*elf_begin(int _fd, Elf_Cmd _cmd, Elf *_elf);
 int		elf_cntl(Elf *_elf, Elf_Cmd _cmd);
 int		elf_end(Elf *_elf);
@@ -220,6 +220,8 @@ Elf_Data	*elf_newdata(Elf_Scn *_scn);
 Elf_Scn		*elf_newscn(Elf *_elf);
 Elf_Scn		*elf_nextscn(Elf *_elf, Elf_Scn *_scn);
 Elf_Cmd		elf_next(Elf *_elf);
+Elf		*elf_open(int _fd);
+Elf		*elf_openmemory(char *_image, size_t _size);
 off_t		elf_rand(Elf *_elf, off_t _off);
 Elf_Data	*elf_rawdata(Elf_Scn *_scn, Elf_Data *_data);
 char		*elf_rawfile(Elf *_elf, size_t *_size);
@@ -253,6 +255,8 @@ Elf_Data	*elf64_xlatetof(Elf_Data *_dst, const Elf_Data *_src,
 			unsigned int _enc);
 Elf_Data	*elf64_xlatetom(Elf_Data *_dst, const Elf_Data *_src,
 			unsigned int _enc);
-__END_DECLS
+#ifdef __cplusplus
+}
+#endif
 
 #endif	/* _LIBELF_H_ */
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_align.c b/rtemstoolkit/elftoolchain/libelf/libelf_align.c
index 55a65f9..5afb98b 100644
--- a/rtemstoolkit/elftoolchain/libelf/libelf_align.c
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_align.c
@@ -24,19 +24,17 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <sys/types.h>
 
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: libelf_align.c 1169 2010-09-04 01:06:31Z jkoshy $");
+ELFTC_VCSID("$Id: libelf_align.c 3174 2015-03-27 17:13:41Z emaste $");
 
 struct align {
-	int a32;
-	int a64;
+	unsigned int a32;
+	unsigned int a64;
 };
 
 #ifdef	__GNUC__
@@ -87,7 +85,7 @@ static struct align malign[ELF_T_NUM] = {
 	[ELF_T_GNUHASH] = MALIGN_WORD()
 };
 
-int
+unsigned int
 _libelf_malign(Elf_Type t, int elfclass)
 {
 	if (t >= ELF_T_NUM || (int) t < 0)
@@ -126,7 +124,7 @@ static struct align falign[ELF_T_NUM] = {
 	[ELF_T_GNUHASH] = FALIGN(4,8)
 };
 
-int
+unsigned int
 _libelf_falign(Elf_Type t, int elfclass)
 {
 	if (t >= ELF_T_NUM || (int) t < 0)
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_allocate.c b/rtemstoolkit/elftoolchain/libelf/libelf_allocate.c
index a753e8e..0a74fac 100644
--- a/rtemstoolkit/elftoolchain/libelf/libelf_allocate.c
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_allocate.c
@@ -28,10 +28,6 @@
  * Internal APIs
  */
 
-#include <sys/cdefs.h>
-
-#include <sys/errno.h>
-
 #include <assert.h>
 #include <errno.h>
 #include <libelf.h>
@@ -40,7 +36,7 @@
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: libelf_allocate.c 1341 2011-01-01 04:28:29Z jkoshy $");
+ELFTC_VCSID("$Id: libelf_allocate.c 3174 2015-03-27 17:13:41Z emaste $");
 
 Elf *
 _libelf_allocate_elf(void)
@@ -135,12 +131,12 @@ _libelf_release_elf(Elf *e)
 	return (NULL);
 }
 
-Elf_Data *
+struct _Libelf_Data *
 _libelf_allocate_data(Elf_Scn *s)
 {
-	Elf_Data *d;
+	struct _Libelf_Data *d;
 
-	if ((d = calloc((size_t) 1, sizeof(Elf_Data))) == NULL) {
+	if ((d = calloc((size_t) 1, sizeof(*d))) == NULL) {
 		LIBELF_SET_ERROR(RESOURCE, 0);
 		return (NULL);
 	}
@@ -150,12 +146,12 @@ _libelf_allocate_data(Elf_Scn *s)
 	return (d);
 }
 
-Elf_Data *
-_libelf_release_data(Elf_Data *d)
+struct _Libelf_Data *
+_libelf_release_data(struct _Libelf_Data *d)
 {
 
 	if (d->d_flags & LIBELF_F_DATA_MALLOCED)
-		free(d->d_buf);
+		free(d->d_data.d_buf);
 
 	free(d);
 
@@ -187,18 +183,18 @@ Elf_Scn *
 _libelf_release_scn(Elf_Scn *s)
 {
 	Elf *e;
-	Elf_Data *d, *td;
+	struct _Libelf_Data *d, *td;
 
 	assert(s != NULL);
 
 	STAILQ_FOREACH_SAFE(d, &s->s_data, d_next, td) {
-		STAILQ_REMOVE(&s->s_data, d, _Elf_Data, d_next);
+		STAILQ_REMOVE(&s->s_data, d, _Libelf_Data, d_next);
 		d = _libelf_release_data(d);
 	}
 
 	STAILQ_FOREACH_SAFE(d, &s->s_rawdata, d_next, td) {
 		assert((d->d_flags & LIBELF_F_DATA_MALLOCED) == 0);
-		STAILQ_REMOVE(&s->s_rawdata, d, _Elf_Data, d_next);
+		STAILQ_REMOVE(&s->s_rawdata, d, _Libelf_Data, d_next);
 		d = _libelf_release_data(d);
 	}
 
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_ar.c b/rtemstoolkit/elftoolchain/libelf/libelf_ar.c
index 14b383d..8fce741 100644
--- a/rtemstoolkit/elftoolchain/libelf/libelf_ar.c
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_ar.c
@@ -24,8 +24,6 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <ctype.h>
 #include <libelf.h>
@@ -35,7 +33,7 @@
 #include "_libelf.h"
 #include "_libelf_ar.h"
 
-LIBELF_VCSID("$Id: libelf_ar.c 1341 2011-01-01 04:28:29Z jkoshy $");
+ELFTC_VCSID("$Id: libelf_ar.c 3446 2016-05-03 01:31:17Z emaste $");
 
 #define	LIBELF_NALLOC_SIZE	16
 
@@ -66,7 +64,7 @@ LIBELF_VCSID("$Id: libelf_ar.c 1341 2011-01-01 04:28:29Z jkoshy $");
  * 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
@@ -110,8 +108,8 @@ Elf_Arhdr *
 _libelf_ar_gethdr(Elf *e)
 {
 	Elf *parent;
-	char *namelen;
 	Elf_Arhdr *eh;
+	char *namelen;
 	size_t n, nlen;
 	struct ar_hdr *arh;
 
@@ -192,7 +190,7 @@ _libelf_ar_gethdr(Elf *e)
 	}
 
 	e->e_flags &= ~LIBELF_F_AR_HEADER;
-	e->e_hdr.e_rawhdr = (char *) arh;
+	e->e_hdr.e_rawhdr = (unsigned char *) arh;
 
 	return (NULL);
 }
@@ -201,10 +199,10 @@ Elf *
 _libelf_ar_open_member(int fd, Elf_Cmd c, Elf *elf)
 {
 	Elf *e;
-	char *member, *namelen;
-	size_t nsz, sz;
 	off_t next;
+	size_t nsz, sz;
 	struct ar_hdr *arh;
+	char *member, *namelen;
 
 	assert(elf->e_kind == ELF_K_AR);
 
@@ -249,12 +247,12 @@ _libelf_ar_open_member(int fd, Elf_Cmd c, Elf *elf)
 		member = (char *) (arh + 1);
 
 
-	if ((e = elf_memory((char *) member, sz)) == NULL)
+	if ((e = elf_memory(member, sz)) == NULL)
 		return (NULL);
 
 	e->e_fd = fd;
 	e->e_cmd = c;
-	e->e_hdr.e_rawhdr = (char *) arh;
+	e->e_hdr.e_rawhdr = (unsigned char *) arh;
 
 	elf->e_u.e_ar.e_nchildren++;
 	e->e_parent = elf;
@@ -274,9 +272,10 @@ _libelf_ar_open_member(int fd, Elf_Cmd c, Elf *elf)
  */
 
 /*
- * A helper macro to read in a 'long' value from the archive.  We use
- * memcpy() since the source pointer may be misaligned with respect to
- * the natural alignment for a C 'long'.
+ * A helper macro to read in a 'long' value from the archive.
+ *
+ * We use memcpy() since the source pointer may be misaligned with
+ * respect to the natural alignment for a C 'long'.
  */
 #define	GET_LONG(P, V)do {				\
 		memcpy(&(V), (P), sizeof(long));	\
@@ -287,9 +286,10 @@ Elf_Arsym *
 _libelf_ar_process_bsd_symtab(Elf *e, size_t *count)
 {
 	Elf_Arsym *symtab, *sym;
+	unsigned int n, nentries;
 	unsigned char *end, *p, *p0, *s, *s0;
-	const unsigned int entrysize = 2 * sizeof(long);
-	long arraysize, fileoffset, n, nentries, stroffset, strtabsize;
+	const size_t entrysize = 2 * sizeof(long);
+	long arraysize, fileoffset, stroffset, strtabsize;
 
 	assert(e != NULL);
 	assert(count != NULL);
@@ -313,7 +313,8 @@ _libelf_ar_process_bsd_symtab(Elf *e, size_t *count)
 	 */
 	GET_LONG(p, arraysize);
 
-	if (p0 + arraysize >= end || (arraysize % entrysize != 0))
+	if (arraysize < 0 || p0 + arraysize >= end ||
+	    ((size_t) arraysize % entrysize != 0))
 		goto symtaberror;
 
 	/*
@@ -323,10 +324,10 @@ _libelf_ar_process_bsd_symtab(Elf *e, size_t *count)
 	GET_LONG(s, strtabsize);
 
 	s0 = s;			/* Start of string table. */
-	if (s0 + strtabsize > end)
+	if (strtabsize < 0 || s0 + strtabsize > end)
 		goto symtaberror;
 
-	nentries = arraysize / entrysize;
+	nentries = (size_t) arraysize / entrysize;
 
 	/*
 	 * Allocate space for the returned Elf_Arsym array.
@@ -341,12 +342,16 @@ _libelf_ar_process_bsd_symtab(Elf *e, size_t *count)
 		GET_LONG(p, stroffset);
 		GET_LONG(p, fileoffset);
 
+		if (stroffset < 0 || fileoffset <  0 ||
+		    (size_t) fileoffset >= e->e_rawsize)
+			goto symtaberror;
+
 		s = s0 + stroffset;
 
 		if (s >= end)
 			goto symtaberror;
 
-		sym->as_off = fileoffset;
+		sym->as_off = (off_t) fileoffset;
 		sym->as_hash = elf_hash((char *) s);
 		sym->as_name = (char *) s;
 	}
@@ -393,7 +398,8 @@ symtaberror:
 Elf_Arsym *
 _libelf_ar_process_svr4_symtab(Elf *e, size_t *count)
 {
-	size_t n, nentries, off;
+	uint32_t off;
+	size_t n, nentries;
 	Elf_Arsym *symtab, *sym;
 	unsigned char *p, *s, *end;
 
@@ -424,15 +430,14 @@ _libelf_ar_process_svr4_symtab(Elf *e, size_t *count)
 	s = p + (nentries * INTSZ); /* start of the string table. */
 
 	for (n = nentries, sym = symtab; n > 0; n--) {
-
 		if (s >= end)
 			goto symtaberror;
 
-		off = 0;
-
 		GET_WORD(p, off);
+		if (off >= e->e_rawsize)
+			goto symtaberror;
 
-		sym->as_off = off;
+		sym->as_off = (off_t) off;
 		sym->as_hash = elf_hash((char *) s);
 		sym->as_name = (char *) s;
 
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_ar_util.c b/rtemstoolkit/elftoolchain/libelf/libelf_ar_util.c
index 7051fe8..239612e 100644
--- a/rtemstoolkit/elftoolchain/libelf/libelf_ar_util.c
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_ar_util.c
@@ -24,8 +24,6 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <libelf.h>
 #include <stdlib.h>
@@ -34,21 +32,23 @@
 #include "_libelf.h"
 #include "_libelf_ar.h"
 
-LIBELF_VCSID("$Id: libelf_ar_util.c 2066 2011-10-26 15:40:28Z jkoshy $");
+ELFTC_VCSID("$Id: libelf_ar_util.c 3174 2015-03-27 17:13:41Z emaste $");
 
 /*
  * Convert a string bounded by `start' and `start+sz' (exclusive) to a
  * number in the specified base.
  */
 int
-_libelf_ar_get_number(const char *s, size_t sz, int base, size_t *ret)
+_libelf_ar_get_number(const char *src, size_t sz, unsigned int base,
+    size_t *ret)
 {
-	int c, v;
 	size_t r;
-	const char *e;
+	unsigned int c, v;
+	const unsigned char *e, *s;
 
 	assert(base <= 10);
 
+	s = (const unsigned char *) src;
 	e = s + sz;
 
 	/* skip leading blanks */
@@ -79,17 +79,18 @@ _libelf_ar_get_number(const char *s, size_t sz, int base, size_t *ret)
 char *
 _libelf_ar_get_translated_name(const struct ar_hdr *arh, Elf *ar)
 {
-	char c, *s;
+	char *s;
+	unsigned char c;
 	size_t len, offset;
-	const char *buf, *p, *q, *r;
+	const unsigned char *buf, *p, *q, *r;
 	const size_t bufsize = sizeof(arh->ar_name);
 
 	assert(arh != NULL);
 	assert(ar->e_kind == ELF_K_AR);
-	assert((const char *) arh >= ar->e_rawfile &&
-	    (const char *) arh < ar->e_rawfile + ar->e_rawsize);
+	assert((const unsigned char *) arh >= ar->e_rawfile &&
+	    (const unsigned char *) arh < ar->e_rawfile + ar->e_rawsize);
 
-	buf = arh->ar_name;
+	buf = (const unsigned char *) arh->ar_name;
 
 	/*
 	 * Check for extended naming.
@@ -104,8 +105,8 @@ _libelf_ar_get_translated_name(const struct ar_hdr *arh, Elf *ar)
 		 * the archive string table where the actual name
 		 * resides.
 		 */
-		if (_libelf_ar_get_number(buf + 1, bufsize - 1, 10,
-			&offset) == 0) {
+		if (_libelf_ar_get_number((const char *) (buf + 1),
+			bufsize - 1, 10, &offset) == 0) {
 			LIBELF_SET_ERROR(ARCHIVE, 0);
 			return (NULL);
 		}
@@ -120,21 +121,21 @@ _libelf_ar_get_translated_name(const struct ar_hdr *arh, Elf *ar)
 
 		for (; p < r && *p != '/'; p++)
 			;
-		len = p - q + 1; /* space for the trailing NUL */
+		len = (size_t) (p - q + 1); /* space for the trailing NUL */
 
 		if ((s = malloc(len)) == NULL) {
 			LIBELF_SET_ERROR(RESOURCE, 0);
 			return (NULL);
 		}
 
-		(void) strncpy(s, q, len - 1);
+		(void) strncpy(s, (const char *) q, len - 1);
 		s[len - 1] = '\0';
 
 		return (s);
 	} else if (IS_EXTENDED_BSD_NAME(buf)) {
 		r = buf + LIBELF_AR_BSD_EXTENDED_NAME_PREFIX_SIZE;
 
-		if (_libelf_ar_get_number(r, bufsize -
+		if (_libelf_ar_get_number((const char *) r, bufsize -
 			LIBELF_AR_BSD_EXTENDED_NAME_PREFIX_SIZE, 10,
 			&len) == 0) {
 			LIBELF_SET_ERROR(ARCHIVE, 0);
@@ -153,9 +154,9 @@ _libelf_ar_get_translated_name(const struct ar_hdr *arh, Elf *ar)
 		/*
 		 * The file name follows the archive header.
 		 */
-		q = (const char *) (arh + 1);
+		q = (const unsigned char *) (arh + 1);
 
-		(void) strncpy(s, q, len);
+		(void) strncpy(s, (const char *) q, len);
 		s[len] = '\0';
 
 		return (s);
@@ -183,10 +184,10 @@ _libelf_ar_get_translated_name(const struct ar_hdr *arh, Elf *ar)
 				q--;
 		}
 
-		len = q - buf + 2; /* Add space for a trailing NUL. */
+		len = (size_t) (q - buf + 2); /* Space for a trailing NUL. */
 	} else {
 		/* The buffer only had blanks. */
-		buf = "";
+		buf = (const unsigned char *) "";
 		len = 1;
 	}
 
@@ -195,7 +196,7 @@ _libelf_ar_get_translated_name(const struct ar_hdr *arh, Elf *ar)
 		return (NULL);
 	}
 
-	(void) strncpy(s, buf, len - 1);
+	(void) strncpy(s, (const char *) buf, len - 1);
 	s[len - 1] = '\0';
 
 	return (s);
@@ -225,14 +226,15 @@ _libelf_ar_get_raw_name(const struct ar_hdr *arh)
  * Open an 'ar' archive.
  */
 Elf *
-_libelf_ar_open(Elf *e)
+_libelf_ar_open(Elf *e, int reporterror)
 {
-	int scanahead;
-	char *s, *end;
 	size_t sz;
+	int scanahead;
 	struct ar_hdr arh;
+	unsigned char *s, *end;
+
+	_libelf_init_elf(e, ELF_K_AR);
 
-	e->e_kind = ELF_K_AR;
 	e->e_u.e_ar.e_nchildren = 0;
 	e->e_u.e_ar.e_next = (off_t) -1;
 
@@ -263,7 +265,7 @@ _libelf_ar_open(Elf *e)
 		(void) memcpy(&(ARH), (S), sizeof((ARH)));		\
 		if ((ARH).ar_fmag[0] != '`' || (ARH).ar_fmag[1] != '\n') \
 			goto error;					\
-		if (_libelf_ar_get_number((ARH).ar_size,		\
+		if (_libelf_ar_get_number((char *) (ARH).ar_size,	\
 		    sizeof((ARH).ar_size), 10, &(SZ)) == 0)		\
 			goto error;					\
 	} while (0)
@@ -274,8 +276,8 @@ _libelf_ar_open(Elf *e)
 	 * Handle special archive members for the SVR4 format.
 	 */
 	if (arh.ar_name[0] == '/') {
-
-		assert(sz > 0);
+		if (sz == 0)
+			goto error;
 
 		e->e_flags |= LIBELF_F_AR_VARIANT_SVR4;
 
@@ -348,7 +350,11 @@ _libelf_ar_open(Elf *e)
 	return (e);
 
 error:
+	if (!reporterror) {
+		e->e_kind = ELF_K_NONE;
+		return (e);
+	}
+
 	LIBELF_SET_ERROR(ARCHIVE, 0);
 	return (NULL);
-
 }
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_checksum.c b/rtemstoolkit/elftoolchain/libelf/libelf_checksum.c
index 0bece9a..ef86877 100644
--- a/rtemstoolkit/elftoolchain/libelf/libelf_checksum.c
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_checksum.c
@@ -24,13 +24,11 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <gelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: libelf_checksum.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: libelf_checksum.c 3174 2015-03-27 17:13:41Z emaste $");
 
 static unsigned long
 _libelf_sum(unsigned long c, const unsigned char *s, size_t size)
@@ -44,7 +42,7 @@ _libelf_sum(unsigned long c, const unsigned char *s, size_t size)
 	return (c);
 }
 
-unsigned long
+long
 _libelf_checksum(Elf *e, int elfclass)
 {
 	size_t shn;
@@ -90,11 +88,11 @@ _libelf_checksum(Elf *e, int elfclass)
 		d = NULL;
 		while ((d = elf_rawdata(scn, d)) != NULL)
 			checksum = _libelf_sum(checksum,
-			    (unsigned char *) d->d_buf, d->d_size);
+			    (unsigned char *) d->d_buf, (size_t) d->d_size);
 	}
 
 	/*
 	 * Return a 16-bit checksum compatible with Solaris.
 	 */
-	return (((checksum >> 16) & 0xFFFFUL) + (checksum & 0xFFFFUL));
+	return (long) (((checksum >> 16) & 0xFFFFUL) + (checksum & 0xFFFFUL));
 }
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_convert.m4 b/rtemstoolkit/elftoolchain/libelf/libelf_convert.m4
index 9b1679a..ec39590 100644
--- a/rtemstoolkit/elftoolchain/libelf/libelf_convert.m4
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_convert.m4
@@ -24,15 +24,13 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <libelf.h>
 #include <string.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: libelf_convert.m4 1734 2011-08-16 09:55:07Z jkoshy $");
+ELFTC_VCSID("$Id: libelf_convert.m4 3429 2016-03-12 04:12:39Z emaste $");
 
 /* WARNING: GENERATED FROM __file__. */
 
@@ -143,8 +141,8 @@ define(`SIZEDEP_OFF',	1)
 # Generates a pair of conversion functions.
 define(`MAKEPRIMFUNCS',`
 static int
-libelf_cvt_$1$4_tof(char *dst, size_t dsz, char *src, size_t count,
-    int byteswap)
+_libelf_cvt_$1$4_tof(unsigned char *dst, size_t dsz, unsigned char *src,
+    size_t count, int byteswap)
 {
 	Elf$3_$2 t, *s = (Elf$3_$2 *) (uintptr_t) src;
 	size_t c;
@@ -166,8 +164,8 @@ libelf_cvt_$1$4_tof(char *dst, size_t dsz, char *src, size_t count,
 }
 
 static int
-libelf_cvt_$1$4_tom(char *dst, size_t dsz, char *src, size_t count,
-    int byteswap)
+_libelf_cvt_$1$4_tom(unsigned char *dst, size_t dsz, unsigned char *src,
+    size_t count, int byteswap)
 {
 	Elf$3_$2 t, *d = (Elf$3_$2 *) (uintptr_t) dst;
 	size_t c;
@@ -267,8 +265,8 @@ define(`READ_STRUCT',
 # `$3': ELF class specifier, one of [`', `32', `64']
 define(`MAKECOMPFUNCS', `ifdef(`NOFUNC_'$1$3,`',`
 static int
-libelf_cvt_$1$3_tof(char *dst, size_t dsz, char *src, size_t count,
-    int byteswap)
+_libelf_cvt_$1$3_tof(unsigned char *dst, size_t dsz, unsigned char *src,
+    size_t count, int byteswap)
 {
 	Elf$3_$2	t, *s;
 	size_t c;
@@ -288,16 +286,16 @@ libelf_cvt_$1$3_tof(char *dst, size_t dsz, char *src, size_t count,
 }
 
 static int
-libelf_cvt_$1$3_tom(char *dst, size_t dsz, char *src, size_t count,
-    int byteswap)
+_libelf_cvt_$1$3_tom(unsigned char *dst, size_t dsz, unsigned char *src,
+    size_t count, int byteswap)
 {
-	Elf$3_$2	 t, *d;
-	char		*s,*s0;
+	Elf$3_$2	t, *d;
+	unsigned char	*s,*s0;
 	size_t		fsz;
 
 	fsz = elf$3_fsize(ELF_T_$1, (size_t) 1, EV_CURRENT);
 	d   = ((Elf$3_$2 *) (uintptr_t) dst) + (count - 1);
-	s0  = (char *) src + (count - 1) * fsz;
+	s0  = src + (count - 1) * fsz;
 
 	if (dsz < count * sizeof(Elf$3_$2))
 		return (0);
@@ -349,9 +347,9 @@ define(`CONV',
     `.$3$2 = NULL',
     `ifdef(`PRIM_'$1,
       `ifdef(`SIZEDEP_'$1,
-	`.$3$2 = libelf_cvt_$1$2_$3',
-	`.$3$2 = libelf_cvt_$1_$3')',
-      `.$3$2 = libelf_cvt_$1$2_$3')')')
+	`.$3$2 = _libelf_cvt_$1$2_$3',
+	`.$3$2 = _libelf_cvt_$1_$3')',
+      `.$3$2 = _libelf_cvt_$1$2_$3')')')
 
 # CONVERTER_NAME(ELFTYPE)
 #
@@ -398,8 +396,8 @@ define(`MAKE_VERSION_CONVERTERS',
 # conversion function.
 define(`MAKE_VERSION_CONVERTER',`
 static int
-libelf_cvt_$1$5_tof(char *dst, size_t dsz, char *src, size_t count,
-    int byteswap)
+_libelf_cvt_$1$5_tof(unsigned char *dst, size_t dsz, unsigned char *src,
+    size_t count, int byteswap)
 {
 	Elf$5_$2	t;
 	Elf$5_$3	a;
@@ -407,12 +405,12 @@ libelf_cvt_$1$5_tof(char *dst, size_t dsz, char *src, size_t count,
 	const size_t	auxfsz = FSZ(Elf$5_$3_DEF);
 	const size_t	vermsz = sizeof(Elf$5_$2);
 	const size_t	auxmsz = sizeof(Elf$5_$3);
-	char * const	dstend = dst + dsz;
-	char * const	srcend = src + count;
-	char		*dtmp, *dstaux, *srcaux;
+	unsigned char * const dstend = dst + dsz;
+	unsigned char * const srcend = src + count;
+	unsigned char	*dtmp, *dstaux, *srcaux;
 	Elf$5_Word	aux, anext, cnt, vnext;
 
-	for (dtmp = dst, vnext = ~0;
+	for (dtmp = dst, vnext = ~0U;
 	     vnext != 0 && dtmp + verfsz <= dstend && src + vermsz <= srcend;
 	     dtmp += vnext, src += vnext) {
 
@@ -434,7 +432,7 @@ libelf_cvt_$1$5_tof(char *dst, size_t dsz, char *src, size_t count,
 			return (0);
 
 		/* Process AUX entries. */
-		for (anext = ~0, dstaux = dtmp + aux, srcaux = src + aux;
+		for (anext = ~0U, dstaux = dtmp + aux, srcaux = src + aux;
 		     cnt != 0 && anext != 0 && dstaux + auxfsz <= dstend &&
 			srcaux + auxmsz <= srcend;
 		     dstaux += anext, srcaux += anext, cnt--) {
@@ -462,8 +460,8 @@ libelf_cvt_$1$5_tof(char *dst, size_t dsz, char *src, size_t count,
 }
 
 static int
-libelf_cvt_$1$5_tom(char *dst, size_t dsz, char *src, size_t count,
-    int byteswap)
+_libelf_cvt_$1$5_tom(unsigned char *dst, size_t dsz, unsigned char *src,
+    size_t count, int byteswap)
 {
 	Elf$5_$2	t, *dp;
 	Elf$5_$3	a, *ap;
@@ -471,12 +469,12 @@ libelf_cvt_$1$5_tom(char *dst, size_t dsz, char *src, size_t count,
 	const size_t	auxfsz = FSZ(Elf$5_$3_DEF);
 	const size_t	vermsz = sizeof(Elf$5_$2);
 	const size_t	auxmsz = sizeof(Elf$5_$3);
-	char * const	dstend = dst + dsz;
-	char * const	srcend = src + count;
-	char		*dstaux, *s, *srcaux, *stmp;
+	unsigned char * const dstend = dst + dsz;
+	unsigned char * const srcend = src + count;
+	unsigned char	*dstaux, *s, *srcaux, *stmp;
 	Elf$5_Word	aux, anext, cnt, vnext;
 
-	for (stmp = src, vnext = ~0;
+	for (stmp = src, vnext = ~0U;
 	     vnext != 0 && stmp + verfsz <= srcend && dst + vermsz <= dstend;
 	     stmp += vnext, dst += vnext) {
 
@@ -498,7 +496,7 @@ libelf_cvt_$1$5_tom(char *dst, size_t dsz, char *src, size_t count,
 			return (0);
 
 		/* Process AUX entries. */
-		for (anext = ~0, dstaux = dst + aux, srcaux = stmp + aux;
+		for (anext = ~0U, dstaux = dst + aux, srcaux = stmp + aux;
 		     cnt != 0 && anext != 0 && dstaux + auxmsz <= dstend &&
 			srcaux + auxfsz <= srcend;
 		     dstaux += anext, srcaux += anext, cnt--) {
@@ -536,22 +534,23 @@ divert(0)
 #define	SWAP_IDENT(X)	do { (void) (X); } while (0)
 #define	SWAP_HALF(X)	do {						\
 		uint16_t _x = (uint16_t) (X);				\
-		uint16_t _t = _x & 0xFF;				\
-		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
-		(X) = _t;						\
+		uint32_t _t = _x & 0xFFU;				\
+		_t <<= 8U; _x >>= 8U; _t |= _x & 0xFFU;			\
+		(X) = (uint16_t) _t;					\
 	} while (0)
-#define	SWAP_WORD(X)	do {						\
+#define	_SWAP_WORD(X, T) do {						\
 		uint32_t _x = (uint32_t) (X);				\
 		uint32_t _t = _x & 0xFF;				\
 		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
 		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
 		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
-		(X) = _t;						\
+		(X) = (T) _t;						\
 	} while (0)
-#define	SWAP_ADDR32(X)	SWAP_WORD(X)
-#define	SWAP_OFF32(X)	SWAP_WORD(X)
-#define	SWAP_SWORD(X)	SWAP_WORD(X)
-#define	SWAP_WORD64(X)	do {						\
+#define	SWAP_ADDR32(X)	_SWAP_WORD(X, Elf32_Addr)
+#define	SWAP_OFF32(X)	_SWAP_WORD(X, Elf32_Off)
+#define	SWAP_SWORD(X)	_SWAP_WORD(X, Elf32_Sword)
+#define	SWAP_WORD(X)	_SWAP_WORD(X, Elf32_Word)
+#define	_SWAP_WORD64(X, T) do {						\
 		uint64_t _x = (uint64_t) (X);				\
 		uint64_t _t = _x & 0xFF;				\
 		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
@@ -561,13 +560,13 @@ divert(0)
 		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
 		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
 		_t <<= 8; _x >>= 8; _t |= _x & 0xFF;			\
-		(X) = _t;						\
+		(X) = (T) _t;						\
 	} while (0)
-#define	SWAP_ADDR64(X)	SWAP_WORD64(X)
-#define	SWAP_LWORD(X)	SWAP_WORD64(X)
-#define	SWAP_OFF64(X)	SWAP_WORD64(X)
-#define	SWAP_SXWORD(X)	SWAP_WORD64(X)
-#define	SWAP_XWORD(X)	SWAP_WORD64(X)
+#define	SWAP_ADDR64(X)	_SWAP_WORD64(X, Elf64_Addr)
+#define	SWAP_LWORD(X)	_SWAP_WORD64(X, Elf64_Lword)
+#define	SWAP_OFF64(X)	_SWAP_WORD64(X, Elf64_Off)
+#define	SWAP_SXWORD(X)	_SWAP_WORD64(X, Elf64_Sxword)
+#define	SWAP_XWORD(X)	_SWAP_WORD64(X, Elf64_Xword)
 
 /*
  * C macros to write out various integral values.
@@ -578,22 +577,22 @@ divert(0)
  * - The destination pointer is incremented after the write.
  */
 #define	WRITE_BYTE(P,X) do {						\
-		char *const _p = (char *) (P);	\
-		_p[0]		= (char) (X);			\
+		unsigned char *const _p = (unsigned char *) (P);	\
+		_p[0]		= (unsigned char) (X);			\
 		(P)		= _p + 1;				\
 	} while (0)
 #define	WRITE_HALF(P,X)	do {						\
 		uint16_t _t	= (X);					\
-		char *const _p	= (char *) (P);	\
-		const char *const _q = (char *) &_t;	\
+		unsigned char *const _p	= (unsigned char *) (P);	\
+		const unsigned char *const _q = (unsigned char *) &_t;	\
 		_p[0]		= _q[0];				\
 		_p[1]		= _q[1];				\
 		(P)		= _p + 2;				\
 	} while (0)
-#define	WRITE_WORD(P,X)	do {						\
-		uint32_t _t	= (X);					\
-		char *const _p	= (char *) (P);	\
-		const char *const _q = (char *) &_t;	\
+#define	WRITE_WORD(P,X) do {						\
+		uint32_t _t	= (uint32_t) (X);			\
+		unsigned char *const _p	= (unsigned char *) (P);	\
+		const unsigned char *const _q = (unsigned char *) &_t;	\
 		_p[0]		= _q[0];				\
 		_p[1]		= _q[1];				\
 		_p[2]		= _q[2];				\
@@ -604,9 +603,9 @@ divert(0)
 #define	WRITE_OFF32(P,X)	WRITE_WORD(P,X)
 #define	WRITE_SWORD(P,X)	WRITE_WORD(P,X)
 #define	WRITE_WORD64(P,X)	do {					\
-		uint64_t _t	= (X);					\
-		char *const _p	= (char *) (P);	\
-		const char *const _q = (char *) &_t;	\
+		uint64_t _t	= (uint64_t) (X);			\
+		unsigned char *const _p	= (unsigned char *) (P);	\
+		const unsigned char *const _q = (unsigned char *) &_t;	\
 		_p[0]		= _q[0];				\
 		_p[1]		= _q[1];				\
 		_p[2]		= _q[2];				\
@@ -637,41 +636,42 @@ divert(0)
  */
 
 #define	READ_BYTE(P,X)	do {						\
-		const char *const _p =				\
-			(const char *) (P);			\
+		const unsigned char *const _p =				\
+			(const unsigned char *) (P);			\
 		(X)		= _p[0];				\
 		(P)		= (P) + 1;				\
 	} while (0)
 #define	READ_HALF(P,X)	do {						\
 		uint16_t _t;						\
-		char *const _q = (char *) &_t;	\
-		const char *const _p =				\
-			(const char *) (P);			\
+		unsigned char *const _q = (unsigned char *) &_t;	\
+		const unsigned char *const _p =				\
+			(const unsigned char *) (P);			\
 		_q[0]		= _p[0];				\
 		_q[1]		= _p[1];				\
 		(P)		= (P) + 2;				\
 		(X)		= _t;					\
 	} while (0)
-#define	READ_WORD(P,X)	do {						\
+#define	_READ_WORD(P,X,T) do {						\
 		uint32_t _t;						\
-		char *const _q = (char *) &_t;	\
-		const char *const _p =				\
-			(const char *) (P);			\
+		unsigned char *const _q = (unsigned char *) &_t;	\
+		const unsigned char *const _p =				\
+			(const unsigned char *) (P);			\
 		_q[0]		= _p[0];				\
 		_q[1]		= _p[1];				\
 		_q[2]		= _p[2];				\
 		_q[3]		= _p[3];				\
 		(P)		= (P) + 4;				\
-		(X)		= _t;					\
+		(X)		= (T) _t;				\
 	} while (0)
-#define	READ_ADDR32(P,X)	READ_WORD(P,X)
-#define	READ_OFF32(P,X)		READ_WORD(P,X)
-#define	READ_SWORD(P,X)		READ_WORD(P,X)
-#define	READ_WORD64(P,X)	do {					\
+#define	READ_ADDR32(P,X)	_READ_WORD(P, X, Elf32_Addr)
+#define	READ_OFF32(P,X)		_READ_WORD(P, X, Elf32_Off)
+#define	READ_SWORD(P,X)		_READ_WORD(P, X, Elf32_Sword)
+#define	READ_WORD(P,X)		_READ_WORD(P, X, Elf32_Word)
+#define	_READ_WORD64(P,X,T)	do {					\
 		uint64_t _t;						\
-		char *const _q = (char *) &_t;	\
-		const char *const _p =				\
-			(const char *) (P);			\
+		unsigned char *const _q = (unsigned char *) &_t;	\
+		const unsigned char *const _p =				\
+			(const unsigned char *) (P);			\
 		_q[0]		= _p[0];				\
 		_q[1]		= _p[1];				\
 		_q[2]		= _p[2];				\
@@ -681,13 +681,13 @@ divert(0)
 		_q[6]		= _p[6];				\
 		_q[7]		= _p[7];				\
 		(P)		= (P) + 8;				\
-		(X)		= _t;					\
+		(X)		= (T) _t;				\
 	} while (0)
-#define	READ_ADDR64(P,X)	READ_WORD64(P,X)
-#define	READ_LWORD(P,X)		READ_WORD64(P,X)
-#define	READ_OFF64(P,X)		READ_WORD64(P,X)
-#define	READ_SXWORD(P,X)	READ_WORD64(P,X)
-#define	READ_XWORD(P,X)		READ_WORD64(P,X)
+#define	READ_ADDR64(P,X)	_READ_WORD64(P, X, Elf64_Addr)
+#define	READ_LWORD(P,X)		_READ_WORD64(P, X, Elf64_Lword)
+#define	READ_OFF64(P,X)		_READ_WORD64(P, X, Elf64_Off)
+#define	READ_SXWORD(P,X)	_READ_WORD64(P, X, Elf64_Sxword)
+#define	READ_XWORD(P,X)		_READ_WORD64(P, X, Elf64_Xword)
 #define	READ_IDENT(P,X)		do {					\
 		(void) memcpy((X), (P), sizeof((X)));			\
 		(P)		= (P) + EI_NIDENT;			\
@@ -707,8 +707,8 @@ MAKE_VERSION_CONVERTERS(VNEED,Verneed,Vernaux,vn)
  */
 
 static int
-libelf_cvt_BYTE_tox(char *dst, size_t dsz, char *src, size_t count,
-    int byteswap)
+_libelf_cvt_BYTE_tox(unsigned char *dst, size_t dsz, unsigned char *src,
+    size_t count, int byteswap)
 {
 	(void) byteswap;
 	if (dsz < count)
@@ -732,24 +732,24 @@ libelf_cvt_BYTE_tox(char *dst, size_t dsz, char *src, size_t count,
  */
 
 static int
-libelf_cvt_GNUHASH32_tom(char *dst, size_t dsz, char *src, size_t srcsz,
-    int byteswap)
+_libelf_cvt_GNUHASH32_tom(unsigned char *dst, size_t dsz, unsigned char *src,
+    size_t srcsz, int byteswap)
 {
-	return (libelf_cvt_WORD_tom(dst, dsz, src, srcsz / sizeof(uint32_t),
+	return (_libelf_cvt_WORD_tom(dst, dsz, src, srcsz / sizeof(uint32_t),
 		byteswap));
 }
 
 static int
-libelf_cvt_GNUHASH32_tof(char *dst, size_t dsz, char *src, size_t srcsz,
-    int byteswap)
+_libelf_cvt_GNUHASH32_tof(unsigned char *dst, size_t dsz, unsigned char *src,
+    size_t srcsz, int byteswap)
 {
-	return (libelf_cvt_WORD_tof(dst, dsz, src, srcsz / sizeof(uint32_t),
+	return (_libelf_cvt_WORD_tof(dst, dsz, src, srcsz / sizeof(uint32_t),
 		byteswap));
 }
 
 static int
-libelf_cvt_GNUHASH64_tom(char *dst, size_t dsz, char *src, size_t srcsz,
-    int byteswap)
+_libelf_cvt_GNUHASH64_tom(unsigned char *dst, size_t dsz, unsigned char *src,
+    size_t srcsz, int byteswap)
 {
 	size_t sz;
 	uint64_t t64, *bloom64;
@@ -834,8 +834,8 @@ libelf_cvt_GNUHASH64_tom(char *dst, size_t dsz, char *src, size_t srcsz,
 }
 
 static int
-libelf_cvt_GNUHASH64_tof(char *dst, size_t dsz, char *src, size_t srcsz,
-    int byteswap)
+_libelf_cvt_GNUHASH64_tof(unsigned char *dst, size_t dsz, unsigned char *src,
+    size_t srcsz, int byteswap)
 {
 	uint32_t *s32;
 	size_t sz, hdrsz;
@@ -921,8 +921,8 @@ libelf_cvt_GNUHASH64_tof(char *dst, size_t dsz, char *src, size_t srcsz,
  * The destination buffer needs to be at least `count' bytes in size.
  */
 static int
-libelf_cvt_NOTE_tom(char *dst, size_t dsz, char *src, size_t count,
-    int byteswap)
+_libelf_cvt_NOTE_tom(unsigned char *dst, size_t dsz, unsigned char *src,
+    size_t count, int byteswap)
 {
 	uint32_t namesz, descsz, type;
 	Elf_Note *en;
@@ -962,8 +962,8 @@ libelf_cvt_NOTE_tom(char *dst, size_t dsz, char *src, size_t count,
 		dst += sizeof(Elf_Note);
 		count -= hdrsz;
 
-		ROUNDUP2(namesz, 4);
-		ROUNDUP2(descsz, 4);
+		ROUNDUP2(namesz, 4U);
+		ROUNDUP2(descsz, 4U);
 
 		sz = namesz + descsz;
 
@@ -983,8 +983,8 @@ libelf_cvt_NOTE_tom(char *dst, size_t dsz, char *src, size_t count,
 }
 
 static int
-libelf_cvt_NOTE_tof(char *dst, size_t dsz, char *src, size_t count,
-    int byteswap)
+_libelf_cvt_NOTE_tof(unsigned char *dst, size_t dsz, unsigned char *src,
+    size_t count, int byteswap)
 {
 	uint32_t namesz, descsz, type;
 	Elf_Note *en;
@@ -1005,6 +1005,11 @@ libelf_cvt_NOTE_tof(char *dst, size_t dsz, char *src, size_t count,
 		descsz = en->n_descsz;
 		type = en->n_type;
 
+		sz = namesz;
+		ROUNDUP2(sz, 4U);
+		sz += descsz;
+		ROUNDUP2(sz, 4U);
+
 		SWAP_WORD(namesz);
 		SWAP_WORD(descsz);
 		SWAP_WORD(type);
@@ -1014,11 +1019,7 @@ libelf_cvt_NOTE_tof(char *dst, size_t dsz, char *src, size_t count,
 		WRITE_WORD(dst, type);
 
 		src += sizeof(Elf_Note);
-
-		ROUNDUP2(namesz, 4);
-		ROUNDUP2(descsz, 4);
-
-		sz = namesz + descsz;
+		count -= sizeof(Elf_Note);
 
 		if (count < sz)
 			sz = count;
@@ -1034,14 +1035,14 @@ libelf_cvt_NOTE_tof(char *dst, size_t dsz, char *src, size_t count,
 }
 
 struct converters {
-	int	(*tof32)(char *dst, size_t dsz, char *src, size_t cnt,
-		    int byteswap);
-	int	(*tom32)(char *dst, size_t dsz, char *src, size_t cnt,
-		    int byteswap);
-	int	(*tof64)(char *dst, size_t dsz, char *src, size_t cnt,
-		    int byteswap);
-	int	(*tom64)(char *dst, size_t dsz, char *src, size_t cnt,
-		    int byteswap);
+	int	(*tof32)(unsigned char *dst, size_t dsz, unsigned char *src,
+		    size_t cnt, int byteswap);
+	int	(*tom32)(unsigned char *dst, size_t dsz, unsigned char *src,
+		    size_t cnt, int byteswap);
+	int	(*tof64)(unsigned char *dst, size_t dsz, unsigned char *src,
+		    size_t cnt, int byteswap);
+	int	(*tom64)(unsigned char *dst, size_t dsz, unsigned char *src,
+		    size_t cnt, int byteswap);
 };
 
 
@@ -1055,22 +1056,23 @@ CONVERTER_NAMES(ELF_TYPE_LIST)
 	 */
 
 	[ELF_T_BYTE] = {
-		.tof32 = libelf_cvt_BYTE_tox,
-		.tom32 = libelf_cvt_BYTE_tox,
-		.tof64 = libelf_cvt_BYTE_tox,
-		.tom64 = libelf_cvt_BYTE_tox
+		.tof32 = _libelf_cvt_BYTE_tox,
+		.tom32 = _libelf_cvt_BYTE_tox,
+		.tof64 = _libelf_cvt_BYTE_tox,
+		.tom64 = _libelf_cvt_BYTE_tox
 	},
 
 	[ELF_T_NOTE] = {
-		.tof32 = libelf_cvt_NOTE_tof,
-		.tom32 = libelf_cvt_NOTE_tom,
-		.tof64 = libelf_cvt_NOTE_tof,
-		.tom64 = libelf_cvt_NOTE_tom
+		.tof32 = _libelf_cvt_NOTE_tof,
+		.tom32 = _libelf_cvt_NOTE_tom,
+		.tof64 = _libelf_cvt_NOTE_tof,
+		.tom64 = _libelf_cvt_NOTE_tom
 	}
 };
 
 int (*_libelf_get_translator(Elf_Type t, int direction, int elfclass))
- (char *_dst, size_t dsz, char *_src, size_t _cnt, int _byteswap)
+ (unsigned char *_dst, size_t dsz, unsigned char *_src, size_t _cnt,
+  int _byteswap)
 {
 	assert(elfclass == ELFCLASS32 || elfclass == ELFCLASS64);
 	assert(direction == ELF_TOFILE || direction == ELF_TOMEMORY);
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_data.c b/rtemstoolkit/elftoolchain/libelf/libelf_data.c
index 8044c74..fcffd8b 100644
--- a/rtemstoolkit/elftoolchain/libelf/libelf_data.c
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_data.c
@@ -24,17 +24,18 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: libelf_data.c 1264 2010-11-12 14:53:23Z jkoshy $");
+ELFTC_VCSID("$Id: libelf_data.c 3174 2015-03-27 17:13:41Z emaste $");
 
 int
 _libelf_xlate_shtype(uint32_t sht)
 {
+	/*
+	 * Look for known section types.
+	 */
 	switch (sht) {
 	case SHT_DYNAMIC:
 		return (ELF_T_DYN);
@@ -83,6 +84,18 @@ _libelf_xlate_shtype(uint32_t sht)
 	case SHT_SUNW_versym:	/* == SHT_GNU_versym */
 		return (ELF_T_HALF);
 	default:
+		/*
+		 * Values in the range [SHT_LOOS..SHT_HIUSER] (i.e.,
+		 * OS, processor and user-defined section types) are
+		 * legal, but since we do not know anything more about
+		 * their semantics, we return a type of ELF_T_BYTE.
+		 */
+		if (sht >= SHT_LOOS && sht <= SHT_HIUSER)
+			return (ELF_T_BYTE);
+
+		/*
+		 * Other values are unsupported.
+		 */
 		return (-1);
 	}
 }
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_ehdr.c b/rtemstoolkit/elftoolchain/libelf/libelf_ehdr.c
index affe541..6630e6e 100644
--- a/rtemstoolkit/elftoolchain/libelf/libelf_ehdr.c
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_ehdr.c
@@ -24,8 +24,6 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <gelf.h>
 #include <libelf.h>
@@ -33,7 +31,7 @@
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: libelf_ehdr.c 1677 2011-07-28 04:35:53Z jkoshy $");
+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
@@ -45,7 +43,8 @@ _libelf_load_extended(Elf *e, int ec, uint64_t shoff, uint16_t phnum,
 {
 	Elf_Scn *scn;
 	size_t fsz;
-	int (*xlator)(char *_d, size_t _dsz, char *_s, size_t _c, int _swap);
+	int (*xlator)(unsigned char *_d, size_t _dsz, unsigned char *_s,
+	    size_t _c, int _swap);
 	uint32_t shtype;
 
 	assert(STAILQ_EMPTY(&e->e_u.e_elf.e_scn));
@@ -62,8 +61,8 @@ _libelf_load_extended(Elf *e, int ec, uint64_t shoff, uint16_t phnum,
 		return (0);
 
 	xlator = _libelf_get_translator(ELF_T_SHDR, ELF_TOMEMORY, ec);
-	(*xlator)((char *) &scn->s_shdr, sizeof(scn->s_shdr),
-	    e->e_rawfile + shoff, (size_t) 1,
+	(*xlator)((unsigned char *) &scn->s_shdr, sizeof(scn->s_shdr),
+	    (unsigned char *) e->e_rawfile + shoff, (size_t) 1,
 	    e->e_byteorder != LIBELF_PRIVATE(byteorder));
 
 #define	GET_SHDR_MEMBER(M) ((ec == ELFCLASS32) ? scn->s_shdr.s_shdr32.M : \
@@ -74,7 +73,7 @@ _libelf_load_extended(Elf *e, int ec, uint64_t shoff, uint16_t phnum,
 		return (0);
 	}
 
-	e->e_u.e_elf.e_nscn = GET_SHDR_MEMBER(sh_size);
+	e->e_u.e_elf.e_nscn = (size_t) GET_SHDR_MEMBER(sh_size);
 	e->e_u.e_elf.e_nphdr = (phnum != PN_XNUM) ? phnum :
 	    GET_SHDR_MEMBER(sh_info);
 	e->e_u.e_elf.e_strndx = (strndx != SHN_XINDEX) ? strndx :
@@ -92,7 +91,7 @@ _libelf_load_extended(Elf *e, int ec, uint64_t shoff, uint16_t phnum,
 		eh->e_ident[EI_MAG3] = ELFMAG3;				\
 		eh->e_ident[EI_CLASS] = ELFCLASS##SZ;			\
 		eh->e_ident[EI_DATA]  = ELFDATANONE;			\
-		eh->e_ident[EI_VERSION] = LIBELF_PRIVATE(version);	\
+		eh->e_ident[EI_VERSION] = LIBELF_PRIVATE(version) & 0xFFU; \
 		eh->e_machine = EM_NONE;				\
 		eh->e_type    = ELF_K_NONE;				\
 		eh->e_version = LIBELF_PRIVATE(version);		\
@@ -105,7 +104,8 @@ _libelf_ehdr(Elf *e, int ec, int allocate)
 	size_t fsz, msz;
 	uint16_t phnum, shnum, strndx;
 	uint64_t shoff;
-	int (*xlator)(char *_d, size_t _dsz, char *_s, size_t _c, int _swap);
+	int (*xlator)(unsigned char *_d, size_t _dsz, unsigned char *_s,
+	    size_t _c, int _swap);
 
 	assert(ec == ELFCLASS32 || ec == ELFCLASS64);
 
@@ -167,13 +167,9 @@ _libelf_ehdr(Elf *e, int ec, int allocate)
 		return (ehdr);
 
 	xlator = _libelf_get_translator(ELF_T_EHDR, ELF_TOMEMORY, ec);
-	(*xlator)(ehdr, msz, e->e_rawfile, (size_t) 1,
+	(*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/rtemstoolkit/elftoolchain/libelf/libelf_extended.c b/rtemstoolkit/elftoolchain/libelf/libelf_extended.c
index 10590bb..96765a8 100644
--- a/rtemstoolkit/elftoolchain/libelf/libelf_extended.c
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_extended.c
@@ -24,14 +24,12 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: libelf_extended.c 1360 2011-01-08 08:27:41Z jkoshy $");
+ELFTC_VCSID("$Id: libelf_extended.c 3174 2015-03-27 17:13:41Z emaste $");
 
 /*
  * Retrieve section #0, allocating a new section if needed.
@@ -69,9 +67,9 @@ _libelf_setshnum(Elf *e, void *eh, int ec, size_t shnum)
 	}
 
 	if (ec == ELFCLASS32)
-		((Elf32_Ehdr *) eh)->e_shnum = shnum;
+		((Elf32_Ehdr *) eh)->e_shnum = shnum & 0xFFFFU;
 	else
-		((Elf64_Ehdr *) eh)->e_shnum = shnum;
+		((Elf64_Ehdr *) eh)->e_shnum = shnum & 0xFFFFU;
 
 
 	return (1);
@@ -99,9 +97,9 @@ _libelf_setshstrndx(Elf *e, void *eh, int ec, size_t shstrndx)
 	}
 
 	if (ec == ELFCLASS32)
-		((Elf32_Ehdr *) eh)->e_shstrndx = shstrndx;
+		((Elf32_Ehdr *) eh)->e_shstrndx = shstrndx & 0xFFFFU;
 	else
-		((Elf64_Ehdr *) eh)->e_shstrndx = shstrndx;
+		((Elf64_Ehdr *) eh)->e_shstrndx = shstrndx & 0xFFFFU;
 
 	return (1);
 }
@@ -128,9 +126,9 @@ _libelf_setphnum(Elf *e, void *eh, int ec, size_t phnum)
 	}
 
 	if (ec == ELFCLASS32)
-		((Elf32_Ehdr *) eh)->e_phnum = phnum;
+		((Elf32_Ehdr *) eh)->e_phnum = phnum & 0xFFFFU;
 	else
-		((Elf64_Ehdr *) eh)->e_phnum = phnum;
+		((Elf64_Ehdr *) eh)->e_phnum = phnum & 0xFFFFU;
 
 	return (1);
 }
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_fsize.m4 b/rtemstoolkit/elftoolchain/libelf/libelf_fsize.m4
index 4829789..9942d27 100644
--- a/rtemstoolkit/elftoolchain/libelf/libelf_fsize.m4
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_fsize.m4
@@ -28,7 +28,7 @@
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: libelf_fsize.m4 1724 2011-08-13 05:35:42Z jkoshy $");
+ELFTC_VCSID("$Id: libelf_fsize.m4 2225 2011-11-26 18:55:54Z jkoshy $");
 
 /* WARNING: GENERATED FROM __file__. */
 
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_memory.c b/rtemstoolkit/elftoolchain/libelf/libelf_memory.c
new file mode 100644
index 0000000..cb8e8f2
--- /dev/null
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_memory.c
@@ -0,0 +1,96 @@
+/*-
+ * Copyright (c) 2011 Joseph Koshy
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ar.h>
+#include <assert.h>
+#include <string.h>
+#include <libelf.h>
+
+#include "_libelf.h"
+
+ELFTC_VCSID("$Id: libelf_memory.c 3013 2014-03-23 06:16:59Z jkoshy $");
+
+/*
+ * Create an ELF descriptor for a memory image, optionally reporting
+ * parse errors.
+ */
+
+Elf *
+_libelf_memory(unsigned char *image, size_t sz, int reporterror)
+{
+	Elf *e;
+	int e_class;
+	enum Elf_Error error;
+	unsigned int e_byteorder, e_version;
+
+	assert(image != NULL);
+	assert(sz > 0);
+
+	if ((e = _libelf_allocate_elf()) == NULL)
+		return (NULL);
+
+	e->e_cmd = ELF_C_READ;
+	e->e_rawfile = image;
+	e->e_rawsize = sz;
+
+#undef	LIBELF_IS_ELF
+#define	LIBELF_IS_ELF(P) ((P)[EI_MAG0] == ELFMAG0 && 		\
+	(P)[EI_MAG1] == ELFMAG1 && (P)[EI_MAG2] == ELFMAG2 &&	\
+	(P)[EI_MAG3] == ELFMAG3)
+
+	if (sz > EI_NIDENT && LIBELF_IS_ELF(image)) {
+		e_byteorder = image[EI_DATA];
+		e_class     = image[EI_CLASS];
+		e_version   = image[EI_VERSION];
+
+		error = ELF_E_NONE;
+
+		if (e_version > EV_CURRENT)
+			error = ELF_E_VERSION;
+		else if ((e_byteorder != ELFDATA2LSB && e_byteorder !=
+ 		    ELFDATA2MSB) || (e_class != ELFCLASS32 && e_class !=
+		    ELFCLASS64))
+			error = ELF_E_HEADER;
+
+		if (error != ELF_E_NONE) {
+			if (reporterror) {
+				LIBELF_PRIVATE(error) = LIBELF_ERROR(error, 0);
+				(void) _libelf_release_elf(e);
+				return (NULL);
+			}
+		} else {
+			_libelf_init_elf(e, ELF_K_ELF);
+
+			e->e_byteorder = e_byteorder;
+			e->e_class = e_class;
+			e->e_version = e_version;
+		}
+	} else if (sz >= SARMAG &&
+	    strncmp((const char *) image, ARMAG, (size_t) SARMAG) == 0)
+		return (_libelf_ar_open(e, reporterror));
+
+	return (e);
+}
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_msize.m4 b/rtemstoolkit/elftoolchain/libelf/libelf_msize.m4
index 95621fb..179880c 100644
--- a/rtemstoolkit/elftoolchain/libelf/libelf_msize.m4
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_msize.m4
@@ -24,15 +24,13 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <libelf.h>
 #include <string.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: libelf_msize.m4 1724 2011-08-13 05:35:42Z jkoshy $");
+ELFTC_VCSID("$Id: libelf_msize.m4 3174 2015-03-27 17:13:41Z emaste $");
 
 /* WARNING: GENERATED FROM __file__. */
 
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_open.c b/rtemstoolkit/elftoolchain/libelf/libelf_open.c
new file mode 100644
index 0000000..7ec3395
--- /dev/null
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_open.c
@@ -0,0 +1,249 @@
+/*-
+ * Copyright (c) 2006,2008-2011 Joseph Koshy
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <libelf.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "_libelf.h"
+
+#if	ELFTC_HAVE_MMAP
+#include <sys/mman.h>
+#endif
+
+ELFTC_VCSID("$Id: libelf_open.c 3007 2014-03-22 08:10:14Z jkoshy $");
+
+#define	_LIBELF_INITSIZE	(64*1024)
+
+/*
+ * Read from a device file, pipe or socket.
+ */
+static void *
+_libelf_read_special_file(int fd, size_t *fsz)
+{
+	ssize_t readsz;
+	size_t bufsz, datasz;
+	unsigned char *buf, *t;
+
+	datasz = 0;
+	readsz = 0;
+	bufsz = _LIBELF_INITSIZE;
+	if ((buf = malloc(bufsz)) == NULL)
+		goto resourceerror;
+
+	/*
+	 * Read data from the file descriptor till we reach EOF, or
+	 * till an error is encountered.
+	 */
+	do {
+		/* Check if we need to expand the data buffer. */
+		if (datasz == bufsz) {
+			bufsz *= 2;
+			if ((t = realloc(buf, bufsz)) == NULL)
+				goto resourceerror;
+			buf = t;
+		}
+
+		do {
+			assert(bufsz - datasz > 0);
+			t = buf + datasz;
+			if ((readsz = read(fd, t, bufsz - datasz)) <= 0)
+				break;
+			datasz += (size_t) readsz;
+		} while (datasz < bufsz);
+
+	} while (readsz > 0);
+
+	if (readsz < 0) {
+		LIBELF_SET_ERROR(IO, errno);
+		goto error;
+	}
+
+	assert(readsz == 0);
+
+	/*
+	 * Free up extra buffer space.
+	 */
+	if (bufsz > datasz) {
+		if (datasz > 0) {
+			if ((t = realloc(buf, datasz)) == NULL)
+				goto resourceerror;
+			buf = t;
+		} else {	/* Zero bytes read. */
+			LIBELF_SET_ERROR(ARGUMENT, 0);
+			free(buf);
+			buf = NULL;
+		}
+	}
+
+	*fsz = datasz;
+	return (buf);
+
+resourceerror:
+	LIBELF_SET_ERROR(RESOURCE, 0);
+error:
+	if (buf != NULL)
+		free(buf);
+	return (NULL);
+}
+
+/*
+ * Read the contents of the file referenced by the file descriptor
+ * 'fd'.
+ */
+
+Elf *
+_libelf_open_object(int fd, Elf_Cmd c, int reporterror)
+{
+	Elf *e;
+	void *m;
+	mode_t mode;
+	size_t fsize;
+	struct stat sb;
+	unsigned int flags;
+
+	assert(c == ELF_C_READ || c == ELF_C_RDWR || c == ELF_C_WRITE);
+
+	if (fstat(fd, &sb) < 0) {
+		LIBELF_SET_ERROR(IO, errno);
+		return (NULL);
+	}
+
+	mode = sb.st_mode;
+	fsize = (size_t) sb.st_size;
+
+	/*
+	 * Reject unsupported file types.
+	 */
+	if (!S_ISREG(mode) && !S_ISCHR(mode) && !S_ISFIFO(mode) &&
+	    !S_ISSOCK(mode)) {
+		LIBELF_SET_ERROR(ARGUMENT, 0);
+		return (NULL);
+	}
+
+	/*
+	 * For ELF_C_WRITE mode, allocate and return a descriptor.
+	 */
+	if (c == ELF_C_WRITE) {
+		if ((e = _libelf_allocate_elf()) != NULL) {
+			_libelf_init_elf(e, ELF_K_ELF);
+			e->e_byteorder = LIBELF_PRIVATE(byteorder);
+			e->e_fd = fd;
+			e->e_cmd = c;
+			if (!S_ISREG(mode))
+				e->e_flags |= LIBELF_F_SPECIAL_FILE;
+		}
+
+		return (e);
+	}
+
+
+	/*
+	 * ELF_C_READ and ELF_C_RDWR mode.
+	 */
+	m = NULL;
+	flags = 0;
+	if (S_ISREG(mode)) {
+
+		/*
+		 * Reject zero length files.
+		 */
+		if (fsize == 0) {
+			LIBELF_SET_ERROR(ARGUMENT, 0);
+			return (NULL);
+		}
+
+#if	ELFTC_HAVE_MMAP
+		/*
+		 * Always map regular files in with 'PROT_READ'
+		 * permissions.
+		 *
+		 * For objects opened in ELF_C_RDWR mode, when
+		 * elf_update(3) is called, we remove this mapping,
+		 * write file data out using write(2), and map the new
+		 * contents back.
+		 */
+		m = mmap(NULL, fsize, PROT_READ, MAP_PRIVATE, fd, (off_t) 0);
+
+		if (m == MAP_FAILED)
+			m = NULL;
+		else
+			flags = LIBELF_F_RAWFILE_MMAP;
+#endif
+
+		/*
+		 * Fallback to a read() if the call to mmap() failed,
+		 * or if mmap() is not available.
+		 */
+		if (m == NULL) {
+			if ((m = malloc(fsize)) == NULL) {
+				LIBELF_SET_ERROR(RESOURCE, 0);
+				return (NULL);
+			}
+
+			if (read(fd, m, fsize) != (ssize_t) fsize) {
+				LIBELF_SET_ERROR(IO, errno);
+				free(m);
+				return (NULL);
+			}
+
+			flags = LIBELF_F_RAWFILE_MALLOC;
+		}
+	} else if ((m = _libelf_read_special_file(fd, &fsize)) != NULL)
+		flags = LIBELF_F_RAWFILE_MALLOC | LIBELF_F_SPECIAL_FILE;
+	else
+		return (NULL);
+
+	if ((e = _libelf_memory(m, fsize, reporterror)) == NULL) {
+		assert((flags & LIBELF_F_RAWFILE_MALLOC) ||
+		    (flags & LIBELF_F_RAWFILE_MMAP));
+		if (flags & LIBELF_F_RAWFILE_MALLOC)
+			free(m);
+#if	ELFTC_HAVE_MMAP
+		else
+			(void) munmap(m, fsize);
+#endif
+		return (NULL);
+	}
+
+	/* ar(1) archives aren't supported in RDWR mode. */
+	if (c == ELF_C_RDWR && e->e_kind == ELF_K_AR) {
+		(void) elf_end(e);
+		LIBELF_SET_ERROR(ARGUMENT, 0);
+		return (NULL);
+	}
+
+	e->e_flags |= flags;
+	e->e_fd = fd;
+	e->e_cmd = c;
+
+	return (e);
+}
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_phdr.c b/rtemstoolkit/elftoolchain/libelf/libelf_phdr.c
index 5a5bb5f..ba872bb 100644
--- a/rtemstoolkit/elftoolchain/libelf/libelf_phdr.c
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_phdr.c
@@ -24,8 +24,6 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <gelf.h>
 #include <libelf.h>
@@ -33,18 +31,19 @@
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: libelf_phdr.c 1677 2011-07-28 04:35:53Z jkoshy $");
+ELFTC_VCSID("$Id: libelf_phdr.c 3174 2015-03-27 17:13:41Z emaste $");
 
 void *
 _libelf_getphdr(Elf *e, int ec)
 {
-	size_t phnum, phentsize;
+	size_t phnum;
 	size_t fsz, msz;
 	uint64_t phoff;
 	Elf32_Ehdr *eh32;
 	Elf64_Ehdr *eh64;
 	void *ehdr, *phdr;
-	int (*xlator)(char *_d, size_t _dsz, char *_s, size_t _c, int _swap);
+	int (*xlator)(unsigned char *_d, size_t _dsz, unsigned char *_s,
+	    size_t _c, int _swap);
 
 	assert(ec == ELFCLASS32 || ec == ELFCLASS64);
 
@@ -69,11 +68,9 @@ _libelf_getphdr(Elf *e, int ec)
 
 	if (ec == ELFCLASS32) {
 		eh32      = (Elf32_Ehdr *) ehdr;
-		phentsize = eh32->e_phentsize;
 		phoff     = (uint64_t) eh32->e_phoff;
 	} else {
 		eh64      = (Elf64_Ehdr *) ehdr;
-		phentsize = eh64->e_phentsize;
 		phoff     = (uint64_t) eh64->e_phoff;
 	}
 
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_shdr.c b/rtemstoolkit/elftoolchain/libelf/libelf_shdr.c
index a696cef..862264b 100644
--- a/rtemstoolkit/elftoolchain/libelf/libelf_shdr.c
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_shdr.c
@@ -24,14 +24,12 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <gelf.h>
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: libelf_shdr.c 189 2008-07-20 10:38:08Z jkoshy $");
+ELFTC_VCSID("$Id: libelf_shdr.c 3174 2015-03-27 17:13:41Z emaste $");
 
 void *
 _libelf_getshdr(Elf_Scn *s, int ec)
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_xlate.c b/rtemstoolkit/elftoolchain/libelf/libelf_xlate.c
index ace4e09..6ee7624 100644
--- a/rtemstoolkit/elftoolchain/libelf/libelf_xlate.c
+++ b/rtemstoolkit/elftoolchain/libelf/libelf_xlate.c
@@ -24,14 +24,12 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <assert.h>
 #include <libelf.h>
 
 #include "_libelf.h"
 
-LIBELF_VCSID("$Id: libelf_xlate.c 316 2009-02-28 16:08:44Z jkoshy $");
+ELFTC_VCSID("$Id: libelf_xlate.c 3174 2015-03-27 17:13:41Z emaste $");
 
 /*
  * Translate to/from the file representation of ELF objects.
@@ -99,10 +97,10 @@ _libelf_xlate(Elf_Data *dst, const Elf_Data *src, unsigned int encoding,
 	 * buffer.
 	 */
 	if (direction == ELF_TOMEMORY) {
-		cnt = src->d_size / fsz;
+		cnt = (size_t) src->d_size / fsz;
 		dsz = cnt * msz;
 	} else {
-		cnt = src->d_size / msz;
+		cnt = (size_t) src->d_size / msz;
 		dsz = cnt * fsz;
 	}
 
@@ -112,9 +110,9 @@ _libelf_xlate(Elf_Data *dst, const Elf_Data *src, unsigned int encoding,
 	}
 
 	sb = (uintptr_t) src->d_buf;
-	se = sb + src->d_size;
+	se = sb + (size_t) src->d_size;
 	db = (uintptr_t) dst->d_buf;
-	de = db + dst->d_size;
+	de = db + (size_t) dst->d_size;
 
 	/*
 	 * Check for overlapping buffers.  Note that db == sb is
diff --git a/rtemstoolkit/win32/sys/cdefs.h b/rtemstoolkit/win32/sys/cdefs.h
index c96b517..441b45b 100644
--- a/rtemstoolkit/win32/sys/cdefs.h
+++ b/rtemstoolkit/win32/sys/cdefs.h
@@ -44,12 +44,6 @@
 #define __rangeof(type, start, end) \
   (__offsetof(type, end) - __offsetof(type, start))
 
-/*
- * Hack. Have to put this somewhere.
- */
-typedef int gid_t;
-typedef int uid_t;
-
 /* Macros for counting and rounding. */
 #ifndef howmany
 #define howmany(x, y)   (((x)+((y)-1))/(y))
diff --git a/rtemstoolkit/wscript b/rtemstoolkit/wscript
index 0500075..f4e46b4 100644
--- a/rtemstoolkit/wscript
+++ b/rtemstoolkit/wscript
@@ -1,6 +1,6 @@
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2014-2016 Chris Johns (chrisj at rtems.org)
+# Copyright 2014-2018 Chris Johns (chrisj at rtems.org)
 # All rights reserved.
 #
 # This file is part of the RTEMS Tools package in 'rtems-tools'.
@@ -40,7 +40,7 @@ def configure(conf):
     conf.load('compiler_c')
     conf.load('compiler_cxx')
     conf_libiberty(conf)
-    conf_libelf(conf)
+    conf_elftoolchain(conf)
 
     conf.find_program('m4')
 
@@ -58,7 +58,9 @@ def build(bld):
     #
     # The include paths.
     #
-    conf['includes'] = ['elftoolchain/libelf', 'elftoolchain/common', 'libiberty']
+    conf['includes'] = ['elftoolchain/libelf',
+                        'elftoolchain/common',
+                        'libiberty']
     if bld.env.DEST_OS == 'win32':
         conf['includes'] += ['win32']
 
@@ -75,7 +77,7 @@ def build(bld):
     # Create each of the modules as object files each with their own
     # configurations.
     #
-    bld_libelf(bld, conf)
+    bld_elftoolchain(bld, conf)
     bld_libiberty(bld, conf)
 
     #
@@ -161,20 +163,22 @@ def tags(ctx):
 #
 # Libelf module.
 #
-def conf_libelf(conf):
+def conf_elftoolchain(conf):
     pass
 
-def bld_libelf(bld, conf):
+def bld_elftoolchain(bld, conf):
     libelf = 'elftoolchain/libelf/'
-    m4_rule = '${M4} -D SRCDIR=../rtemstoolkit/' + libelf[:-1] + ' ${SRC} > ${TGT}'
+    libelf_m4_rule = '${M4} -D SRCDIR=../rtemstoolkit/' + libelf[:-1] + ' ${SRC} > ${TGT}'
     if bld.env.DEST_OS == 'win32':
         includes = ['win32']
     else:
         includes = []
 
-    bld(target = 'libelf_convert.c', source = libelf + 'libelf_convert.m4', rule = m4_rule)
-    bld(target = 'libelf_fsize.c',   source = libelf + 'libelf_fsize.m4',   rule = m4_rule)
-    bld(target = 'libelf_msize.c',   source = libelf + 'libelf_msize.m4',   rule = m4_rule)
+    libelf_m4_source = ['libelf_convert.c',
+                        'libelf_fsize.c',
+                        'libelf_msize.c']
+    for s in libelf_m4_source:
+        bld(target = s, source = libelf + s[:-2] + '.m4', rule = libelf_m4_rule)
 
     host_source = []
 
@@ -212,6 +216,7 @@ def bld_libelf(bld, conf):
                        libelf + 'elf_kind.c',
                        libelf + 'elf_memory.c',
                        libelf + 'elf_next.c',
+                       libelf + 'elf_open.c',
                        libelf + 'elf_rand.c',
                        libelf + 'elf_rawfile.c',
                        libelf + 'elf_phnum.c',
@@ -244,12 +249,11 @@ def bld_libelf(bld, conf):
                        libelf + 'libelf_data.c',
                        libelf + 'libelf_ehdr.c',
                        libelf + 'libelf_extended.c',
+                       libelf + 'libelf_memory.c',
+                       libelf + 'libelf_open.c',
                        libelf + 'libelf_phdr.c',
                        libelf + 'libelf_shdr.c',
-                       libelf + 'libelf_xlate.c',
-                       'libelf_convert.c',
-                       'libelf_fsize.c',
-                       'libelf_msize.c'] + host_source)
+                       libelf + 'libelf_xlate.c'] + libelf_m4_source + host_source)
 
 #
 # Libiberty module.



More information about the vc mailing list