From aaebecf0fb6f2696254d42c2b6f86823a7f8ff7e Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Sun, 19 Jun 2011 18:52:00 +0200
Subject: [PATCH 02/18] hwpmc: Some DragonFly specific adjustments to libelf.

* STAILQ_FOREACH_SAFE -> STAILQ_FOREACH_MUTABLE

* Get rid of __FreeBSD_version checks

* Put the CVS id into the comments
---
 lib/libelf/Makefile          |    2 --
 lib/libelf/elf_begin.c       |    5 ++---
 lib/libelf/elf_cntl.c        |    5 ++---
 lib/libelf/elf_data.c        |    5 ++---
 lib/libelf/elf_end.c         |    7 +++----
 lib/libelf/elf_errmsg.c      |    5 ++---
 lib/libelf/elf_errno.c       |    5 ++---
 lib/libelf/elf_fill.c        |    5 ++---
 lib/libelf/elf_flag.c        |    5 ++---
 lib/libelf/elf_getarhdr.c    |    5 ++---
 lib/libelf/elf_getarsym.c    |    5 ++---
 lib/libelf/elf_getbase.c     |    5 ++---
 lib/libelf/elf_getident.c    |    5 ++---
 lib/libelf/elf_hash.c        |    5 ++---
 lib/libelf/elf_kind.c        |    5 ++---
 lib/libelf/elf_memory.c      |    5 ++---
 lib/libelf/elf_next.c        |    5 ++---
 lib/libelf/elf_phnum.c       |    5 ++---
 lib/libelf/elf_rand.c        |    5 ++---
 lib/libelf/elf_rawfile.c     |    5 ++---
 lib/libelf/elf_scn.c         |    5 ++---
 lib/libelf/elf_shnum.c       |    5 ++---
 lib/libelf/elf_shstrndx.c    |    5 ++---
 lib/libelf/elf_strptr.c      |    5 ++---
 lib/libelf/elf_update.c      |   11 +++++------
 lib/libelf/elf_version.c     |    5 ++---
 lib/libelf/gelf.h            |    4 ----
 lib/libelf/gelf_cap.c        |    9 ++-------
 lib/libelf/gelf_checksum.c   |    5 ++---
 lib/libelf/gelf_dyn.c        |    5 ++---
 lib/libelf/gelf_ehdr.c       |    5 ++---
 lib/libelf/gelf_fsize.c      |    5 ++---
 lib/libelf/gelf_getclass.c   |    5 ++---
 lib/libelf/gelf_move.c       |    9 ++-------
 lib/libelf/gelf_phdr.c       |    5 ++---
 lib/libelf/gelf_rel.c        |    5 ++---
 lib/libelf/gelf_rela.c       |    5 ++---
 lib/libelf/gelf_shdr.c       |    5 ++---
 lib/libelf/gelf_sym.c        |    5 ++---
 lib/libelf/gelf_syminfo.c    |    9 ++-------
 lib/libelf/gelf_symshndx.c   |    5 ++---
 lib/libelf/gelf_xlate.c      |    5 ++---
 lib/libelf/libelf.c          |    5 ++---
 lib/libelf/libelf_align.c    |   29 ++---------------------------
 lib/libelf/libelf_allocate.c |    9 ++++-----
 lib/libelf/libelf_ar.c       |    5 ++---
 lib/libelf/libelf_ar_util.c  |    5 ++---
 lib/libelf/libelf_checksum.c |    5 ++---
 lib/libelf/libelf_convert.m4 |   20 +++++---------------
 lib/libelf/libelf_data.c     |    9 ++-------
 lib/libelf/libelf_ehdr.c     |    3 ---
 lib/libelf/libelf_extended.c |    5 ++---
 lib/libelf/libelf_fsize.m4   |    5 ++---
 lib/libelf/libelf_msize.m4   |   10 ++++------
 lib/libelf/libelf_phdr.c     |    3 ---
 lib/libelf/libelf_shdr.c     |    5 ++---
 lib/libelf/libelf_xlate.c    |    5 ++---
 57 files changed, 117 insertions(+), 232 deletions(-)

diff --git a/lib/libelf/Makefile b/lib/libelf/Makefile
index 8f732c2..adfe9fe 100644
--- a/lib/libelf/Makefile
+++ b/lib/libelf/Makefile
@@ -147,8 +147,6 @@ MLINKS+= \
 	gelf_xlatetof.3	elf${E}_xlatetom.3
 .endfor
 
-VERSION_MAP=		${.CURDIR}/Version.map
-
 LIBELF_TEST_HOOKS?=	1
 .if defined(LIBELF_TEST_HOOKS) && (${LIBELF_TEST_HOOKS} > 0)
 CFLAGS+= -DLIBELF_TEST_HOOKS
diff --git a/lib/libelf/elf_begin.c b/lib/libelf/elf_begin.c
index 4161ab1..0fb3d18 100644
--- a/lib/libelf/elf_begin.c
+++ b/lib/libelf/elf_begin.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_begin.c,v 1.3 2010/07/21 13:18:57 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_begin.c,v 1.3 2010/07/21 13:18:57 kaiw Exp $");
-
 #include <sys/types.h>
 #include <sys/errno.h>
 #include <sys/mman.h>
diff --git a/lib/libelf/elf_cntl.c b/lib/libelf/elf_cntl.c
index 4d9372c..8338197 100644
--- a/lib/libelf/elf_cntl.c
+++ b/lib/libelf/elf_cntl.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_cntl.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_cntl.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <libelf.h>
 
 #include "_libelf.h"
diff --git a/lib/libelf/elf_data.c b/lib/libelf/elf_data.c
index e6f02bf..a167361 100644
--- a/lib/libelf/elf_data.c
+++ b/lib/libelf/elf_data.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_data.c,v 1.6 2011/05/07 11:04:36 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_data.c,v 1.6 2011/05/07 11:04:36 kaiw Exp $");
-
 #include <assert.h>
 #include <errno.h>
 #include <libelf.h>
diff --git a/lib/libelf/elf_end.c b/lib/libelf/elf_end.c
index b11bd4a..cddbbd5 100644
--- a/lib/libelf/elf_end.c
+++ b/lib/libelf/elf_end.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_end.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_end.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <sys/mman.h>
 
 #include <assert.h>
@@ -65,7 +64,7 @@ elf_end(Elf *e)
 			/*
 			 * Reclaim all section descriptors.
 			 */
-			STAILQ_FOREACH_SAFE(scn, &e->e_u.e_elf.e_scn, s_next, tscn)
+			STAILQ_FOREACH_MUTABLE(scn, &e->e_u.e_elf.e_scn, s_next, tscn)
 				scn = _libelf_release_scn(scn);
 			break;
 		case ELF_K_NUM:
diff --git a/lib/libelf/elf_errmsg.c b/lib/libelf/elf_errmsg.c
index 52693fb..c1cfd1f 100644
--- a/lib/libelf/elf_errmsg.c
+++ b/lib/libelf/elf_errmsg.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_errmsg.c,v 1.2 2006/12/09 16:27:15 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_errmsg.c,v 1.2 2006/12/09 16:27:15 jkoshy Exp $");
-
 #include <libelf.h>
 #include <string.h>
 
diff --git a/lib/libelf/elf_errno.c b/lib/libelf/elf_errno.c
index 225e43f..ac5d977 100644
--- a/lib/libelf/elf_errno.c
+++ b/lib/libelf/elf_errno.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_errno.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_errno.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <libelf.h>
 
 #include "_libelf.h"
diff --git a/lib/libelf/elf_fill.c b/lib/libelf/elf_fill.c
index 15957d0..ab57625 100644
--- a/lib/libelf/elf_fill.c
+++ b/lib/libelf/elf_fill.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_fill.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_fill.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <libelf.h>
 
 #include "_libelf.h"
diff --git a/lib/libelf/elf_flag.c b/lib/libelf/elf_flag.c
index 92d6a16..84f0048 100644
--- a/lib/libelf/elf_flag.c
+++ b/lib/libelf/elf_flag.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_flag.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_flag.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <libelf.h>
 
 #include "_libelf.h"
diff --git a/lib/libelf/elf_getarhdr.c b/lib/libelf/elf_getarhdr.c
index 30b6e51..674e86f 100644
--- a/lib/libelf/elf_getarhdr.c
+++ b/lib/libelf/elf_getarhdr.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_getarhdr.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_getarhdr.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <libelf.h>
 
 #include "_libelf.h"
diff --git a/lib/libelf/elf_getarsym.c b/lib/libelf/elf_getarsym.c
index 7cf493b..615020c 100644
--- a/lib/libelf/elf_getarsym.c
+++ b/lib/libelf/elf_getarsym.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_getarsym.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_getarsym.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <libelf.h>
 
 #include "_libelf.h"
diff --git a/lib/libelf/elf_getbase.c b/lib/libelf/elf_getbase.c
index 4b9f4e1..dd4da09 100644
--- a/lib/libelf/elf_getbase.c
+++ b/lib/libelf/elf_getbase.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_getbase.c,v 1.2 2010/06/13 10:58:50 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_getbase.c,v 1.2 2010/06/13 10:58:50 kaiw Exp $");
-
 #include <libelf.h>
 
 #include "_libelf.h"
diff --git a/lib/libelf/elf_getident.c b/lib/libelf/elf_getident.c
index d8a7436..de230bf 100644
--- a/lib/libelf/elf_getident.c
+++ b/lib/libelf/elf_getident.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_getident.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_getident.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <ar.h>
 #include <assert.h>
 #include <libelf.h>
diff --git a/lib/libelf/elf_hash.c b/lib/libelf/elf_hash.c
index 9918fdc..19d126d 100644
--- a/lib/libelf/elf_hash.c
+++ b/lib/libelf/elf_hash.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_hash.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_hash.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <libelf.h>
 
 /*
diff --git a/lib/libelf/elf_kind.c b/lib/libelf/elf_kind.c
index f2be2c8..d2a988a 100644
--- a/lib/libelf/elf_kind.c
+++ b/lib/libelf/elf_kind.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_kind.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_kind.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <libelf.h>
 
 #include "_libelf.h"
diff --git a/lib/libelf/elf_memory.c b/lib/libelf/elf_memory.c
index e1b45eb..825c556 100644
--- a/lib/libelf/elf_memory.c
+++ b/lib/libelf/elf_memory.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_memory.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_memory.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <ar.h>
 #include <libelf.h>
 #include <string.h>
diff --git a/lib/libelf/elf_next.c b/lib/libelf/elf_next.c
index 1670b5c..b335bd9 100644
--- a/lib/libelf/elf_next.c
+++ b/lib/libelf/elf_next.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_next.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_next.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <ar.h>
 #include <assert.h>
 #include <libelf.h>
diff --git a/lib/libelf/elf_phnum.c b/lib/libelf/elf_phnum.c
index 8ccedfc..e06631b 100644
--- a/lib/libelf/elf_phnum.c
+++ b/lib/libelf/elf_phnum.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_phnum.c,v 1.2 2010/07/21 12:14:50 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_phnum.c,v 1.2 2010/07/21 12:14:50 kaiw Exp $");
-
 #include <ar.h>
 #include <libelf.h>
 
diff --git a/lib/libelf/elf_rand.c b/lib/libelf/elf_rand.c
index 3df5ade..111e28d 100644
--- a/lib/libelf/elf_rand.c
+++ b/lib/libelf/elf_rand.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_rand.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_rand.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <ar.h>
 #include <libelf.h>
 
diff --git a/lib/libelf/elf_rawfile.c b/lib/libelf/elf_rawfile.c
index 4141536..adb0f19 100644
--- a/lib/libelf/elf_rawfile.c
+++ b/lib/libelf/elf_rawfile.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_rawfile.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_rawfile.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <libelf.h>
 
 #include "_libelf.h"
diff --git a/lib/libelf/elf_scn.c b/lib/libelf/elf_scn.c
index d6a5286..a54e7c4 100644
--- a/lib/libelf/elf_scn.c
+++ b/lib/libelf/elf_scn.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_scn.c,v 1.4 2010/07/21 10:25:02 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_scn.c,v 1.4 2010/07/21 10:25:02 kaiw Exp $");
-
 #include <assert.h>
 #include <errno.h>
 #include <gelf.h>
diff --git a/lib/libelf/elf_shnum.c b/lib/libelf/elf_shnum.c
index 39773aa..d4732f0 100644
--- a/lib/libelf/elf_shnum.c
+++ b/lib/libelf/elf_shnum.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_shnum.c,v 1.3 2010/07/21 12:14:50 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_shnum.c,v 1.3 2010/07/21 12:14:50 kaiw Exp $");
-
 #include <ar.h>
 #include <libelf.h>
 
diff --git a/lib/libelf/elf_shstrndx.c b/lib/libelf/elf_shstrndx.c
index 69d7c03..feefeba 100644
--- a/lib/libelf/elf_shstrndx.c
+++ b/lib/libelf/elf_shstrndx.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_shstrndx.c,v 1.3 2010/07/21 12:14:50 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_shstrndx.c,v 1.3 2010/07/21 12:14:50 kaiw Exp $");
-
 #include <ar.h>
 #include <libelf.h>
 
diff --git a/lib/libelf/elf_strptr.c b/lib/libelf/elf_strptr.c
index 6132e4c..13574e0 100644
--- a/lib/libelf/elf_strptr.c
+++ b/lib/libelf/elf_strptr.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_strptr.c,v 1.2 2008/05/23 07:35:36 jb Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_strptr.c,v 1.2 2008/05/23 07:35:36 jb Exp $");
-
 #include <sys/param.h>
 
 #include <assert.h>
diff --git a/lib/libelf/elf_update.c b/lib/libelf/elf_update.c
index a3f39cc..3a122f5 100644
--- a/lib/libelf/elf_update.c
+++ b/lib/libelf/elf_update.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_update.c,v 1.11 2010/09/09 18:51:50 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_update.c,v 1.11 2010/09/09 18:51:50 kaiw Exp $");
-
 #include <sys/mman.h>
 #include <sys/param.h>
 
@@ -159,7 +158,7 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t *rc)
 
 	scn_size = 0L;
 
-	STAILQ_FOREACH_SAFE(d, &s->s_data, d_next, td) {
+	STAILQ_FOREACH_MUTABLE(d, &s->s_data, d_next, td) {
 		if (e->e_flags & ELF_F_LAYOUT) {
 			if ((uint64_t) d->d_off + d->d_size > scn_size)
 				scn_size = d->d_off + d->d_size;
@@ -287,7 +286,7 @@ _libelf_resync_sections(Elf *e, off_t rc)
 		if (_libelf_compute_section_extents(e, s, &nrc) == 0)
 			return ((off_t) -1);
 
-	STAILQ_FOREACH_SAFE(s, &e->e_u.e_elf.e_scn, s_next, ts) {
+	STAILQ_FOREACH_MUTABLE(s, &e->e_u.e_elf.e_scn, s_next, ts) {
 		if (ec == ELFCLASS32)
 			sh_type = s->s_shdr.s_shdr32.sh_type;
 		else
@@ -831,7 +830,7 @@ _libelf_write_elf(Elf *e, off_t newsize)
 
 	e->e_flags &= ~ELF_F_DIRTY;
 
-	STAILQ_FOREACH_SAFE(scn, &e->e_u.e_elf.e_scn, s_next, tscn)
+	STAILQ_FOREACH_MUTABLE(scn, &e->e_u.e_elf.e_scn, s_next, tscn)
 		_libelf_release_scn(scn);
 
 	if (ec == ELFCLASS32) {
diff --git a/lib/libelf/elf_version.c b/lib/libelf/elf_version.c
index 2166fc3..2cdd5a2 100644
--- a/lib/libelf/elf_version.c
+++ b/lib/libelf/elf_version.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/elf_version.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/elf_version.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <libelf.h>
 
 #include "_libelf.h"
diff --git a/lib/libelf/gelf.h b/lib/libelf/gelf.h
index 3dd844c..31920d2 100644
--- a/lib/libelf/gelf.h
+++ b/lib/libelf/gelf.h
@@ -50,11 +50,9 @@ typedef Elf64_Sym	GElf_Sym;	/* Symbol table entries */
 typedef Elf64_Rel	GElf_Rel;	/* Relocation entries */
 typedef Elf64_Rela	GElf_Rela;	/* Relocation entries with addend */
 
-#if	__FreeBSD_version >= 700025
 typedef	Elf64_Cap	GElf_Cap;	/* SW/HW capabilities */
 typedef Elf64_Move	GElf_Move;	/* Move entries */
 typedef Elf64_Syminfo	GElf_Syminfo;	/* Symbol information */
-#endif
 
 #define	GELF_M_INFO			ELF64_M_INFO
 #define	GELF_M_SIZE			ELF64_M_SIZE
@@ -100,14 +98,12 @@ int		gelf_update_symshndx(Elf_Data *_symdst, Elf_Data *_shindexdst,
 Elf_Data 	*gelf_xlatetof(Elf *_elf, Elf_Data *_dst, const Elf_Data *_src, unsigned int _encode);
 Elf_Data 	*gelf_xlatetom(Elf *_elf, Elf_Data *_dst, const Elf_Data *_src, unsigned int _encode);
 
-#if	__FreeBSD_version >= 700025
 GElf_Cap	*gelf_getcap(Elf_Data *_data, int _index, GElf_Cap *_cap);
 GElf_Move	*gelf_getmove(Elf_Data *_src, int _index, GElf_Move *_dst);
 GElf_Syminfo	*gelf_getsyminfo(Elf_Data *_src, int _index, GElf_Syminfo *_dst);
 int		gelf_update_cap(Elf_Data *_dst, int _index, GElf_Cap *_src);
 int		gelf_update_move(Elf_Data *_dst, int _index, GElf_Move *_src);
 int		gelf_update_syminfo(Elf_Data *_dst, int _index, GElf_Syminfo *_src);
-#endif
 __END_DECLS
 
 #endif	/* _GELF_H_ */
diff --git a/lib/libelf/gelf_cap.c b/lib/libelf/gelf_cap.c
index 2c6fd0f..c678cc7 100644
--- a/lib/libelf/gelf_cap.c
+++ b/lib/libelf/gelf_cap.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/gelf_cap.c,v 1.2 2006/12/18 05:40:01 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/gelf_cap.c,v 1.2 2006/12/18 05:40:01 jkoshy Exp $");
-
 #include <sys/limits.h>
 
 #include <assert.h>
@@ -35,8 +34,6 @@ __FBSDID("$FreeBSD: src/lib/libelf/gelf_cap.c,v 1.2 2006/12/18 05:40:01 jkoshy E
 
 #include "_libelf.h"
 
-#if	__FreeBSD_version >= 700025
-
 GElf_Cap *
 gelf_getcap(Elf_Data *d, int ndx, GElf_Cap *dst)
 {
@@ -146,5 +143,3 @@ gelf_update_cap(Elf_Data *d, int ndx, GElf_Cap *gc)
 
 	return (1);
 }
-
-#endif	/* __FreeBSD_version >= 700025 */
diff --git a/lib/libelf/gelf_checksum.c b/lib/libelf/gelf_checksum.c
index 8e4c868..47196f2 100644
--- a/lib/libelf/gelf_checksum.c
+++ b/lib/libelf/gelf_checksum.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/gelf_checksum.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/gelf_checksum.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <gelf.h>
 #include <libelf.h>
 
diff --git a/lib/libelf/gelf_dyn.c b/lib/libelf/gelf_dyn.c
index 6170c78..d3fdfbd 100644
--- a/lib/libelf/gelf_dyn.c
+++ b/lib/libelf/gelf_dyn.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/gelf_dyn.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/gelf_dyn.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <sys/limits.h>
 
 #include <assert.h>
diff --git a/lib/libelf/gelf_ehdr.c b/lib/libelf/gelf_ehdr.c
index 83947e4..0577cff 100644
--- a/lib/libelf/gelf_ehdr.c
+++ b/lib/libelf/gelf_ehdr.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/gelf_ehdr.c,v 1.2 2010/07/21 08:58:52 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/gelf_ehdr.c,v 1.2 2010/07/21 08:58:52 kaiw Exp $");
-
 #include <sys/limits.h>
 
 #include <assert.h>
diff --git a/lib/libelf/gelf_fsize.c b/lib/libelf/gelf_fsize.c
index e593ae4..94d6b6c 100644
--- a/lib/libelf/gelf_fsize.c
+++ b/lib/libelf/gelf_fsize.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/gelf_fsize.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/gelf_fsize.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <gelf.h>
 #include <libelf.h>
 
diff --git a/lib/libelf/gelf_getclass.c b/lib/libelf/gelf_getclass.c
index 290af7a..cdb74bd 100644
--- a/lib/libelf/gelf_getclass.c
+++ b/lib/libelf/gelf_getclass.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/gelf_getclass.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/gelf_getclass.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <gelf.h>
 
 #include "_libelf.h"
diff --git a/lib/libelf/gelf_move.c b/lib/libelf/gelf_move.c
index c07d8d8..cbc2d07 100644
--- a/lib/libelf/gelf_move.c
+++ b/lib/libelf/gelf_move.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/gelf_move.c,v 1.2 2006/12/18 05:40:01 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/gelf_move.c,v 1.2 2006/12/18 05:40:01 jkoshy Exp $");
-
 #include <sys/limits.h>
 
 #include <assert.h>
@@ -35,8 +34,6 @@ __FBSDID("$FreeBSD: src/lib/libelf/gelf_move.c,v 1.2 2006/12/18 05:40:01 jkoshy
 
 #include "_libelf.h"
 
-#if	__FreeBSD_version >= 700025
-
 GElf_Move *
 gelf_getmove(Elf_Data *d, int ndx, GElf_Move *dst)
 {
@@ -152,5 +149,3 @@ gelf_update_move(Elf_Data *d, int ndx, GElf_Move *gm)
 
 	return (1);
 }
-
-#endif	/* __FreeBSD_version >= 700025 */
diff --git a/lib/libelf/gelf_phdr.c b/lib/libelf/gelf_phdr.c
index 963a8f4..28e329f 100644
--- a/lib/libelf/gelf_phdr.c
+++ b/lib/libelf/gelf_phdr.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/gelf_phdr.c,v 1.2 2010/07/21 08:58:52 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/gelf_phdr.c,v 1.2 2010/07/21 08:58:52 kaiw Exp $");
-
 #include <sys/limits.h>
 
 #include <gelf.h>
diff --git a/lib/libelf/gelf_rel.c b/lib/libelf/gelf_rel.c
index 38a9f73..f87835e 100644
--- a/lib/libelf/gelf_rel.c
+++ b/lib/libelf/gelf_rel.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/gelf_rel.c,v 1.2 2008/03/02 06:33:10 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/gelf_rel.c,v 1.2 2008/03/02 06:33:10 jkoshy Exp $");
-
 #include <sys/limits.h>
 
 #include <assert.h>
diff --git a/lib/libelf/gelf_rela.c b/lib/libelf/gelf_rela.c
index f3b05c0..36b0bb6 100644
--- a/lib/libelf/gelf_rela.c
+++ b/lib/libelf/gelf_rela.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/gelf_rela.c,v 1.2 2008/03/02 06:33:10 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/gelf_rela.c,v 1.2 2008/03/02 06:33:10 jkoshy Exp $");
-
 #include <sys/limits.h>
 
 #include <assert.h>
diff --git a/lib/libelf/gelf_shdr.c b/lib/libelf/gelf_shdr.c
index 83d76a7..36e96eb 100644
--- a/lib/libelf/gelf_shdr.c
+++ b/lib/libelf/gelf_shdr.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/gelf_shdr.c,v 1.2 2010/07/21 08:58:52 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/gelf_shdr.c,v 1.2 2010/07/21 08:58:52 kaiw Exp $");
-
 #include <sys/limits.h>
 
 #include <assert.h>
diff --git a/lib/libelf/gelf_sym.c b/lib/libelf/gelf_sym.c
index 3f07517..c35cecd 100644
--- a/lib/libelf/gelf_sym.c
+++ b/lib/libelf/gelf_sym.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/gelf_sym.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/gelf_sym.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <sys/limits.h>
 
 #include <assert.h>
diff --git a/lib/libelf/gelf_syminfo.c b/lib/libelf/gelf_syminfo.c
index 66807ce..7d759f8 100644
--- a/lib/libelf/gelf_syminfo.c
+++ b/lib/libelf/gelf_syminfo.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/gelf_syminfo.c,v 1.2 2006/12/18 05:40:01 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/gelf_syminfo.c,v 1.2 2006/12/18 05:40:01 jkoshy Exp $");
-
 #include <sys/limits.h>
 
 #include <assert.h>
@@ -35,8 +34,6 @@ __FBSDID("$FreeBSD: src/lib/libelf/gelf_syminfo.c,v 1.2 2006/12/18 05:40:01 jkos
 
 #include "_libelf.h"
 
-#if	__FreeBSD_version >= 700025
-
 GElf_Syminfo *
 gelf_getsyminfo(Elf_Data *d, int ndx, GElf_Syminfo *dst)
 {
@@ -147,5 +144,3 @@ gelf_update_syminfo(Elf_Data *d, int ndx, GElf_Syminfo *gs)
 
 	return (1);
 }
-
-#endif	/* __FreeBSD_version >= 700025 */
diff --git a/lib/libelf/gelf_symshndx.c b/lib/libelf/gelf_symshndx.c
index 3afba97..77b179a 100644
--- a/lib/libelf/gelf_symshndx.c
+++ b/lib/libelf/gelf_symshndx.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/gelf_symshndx.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/gelf_symshndx.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <sys/limits.h>
 
 #include <assert.h>
diff --git a/lib/libelf/gelf_xlate.c b/lib/libelf/gelf_xlate.c
index 68e99a3..ec7f0c0 100644
--- a/lib/libelf/gelf_xlate.c
+++ b/lib/libelf/gelf_xlate.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/gelf_xlate.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/gelf_xlate.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <gelf.h>
 #include <libelf.h>
 #include <string.h>
diff --git a/lib/libelf/libelf.c b/lib/libelf/libelf.c
index dc70731..2a62f3e 100644
--- a/lib/libelf/libelf.c
+++ b/lib/libelf/libelf.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/libelf.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/libelf.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <sys/param.h>
 
 #include <machine/elf.h>
diff --git a/lib/libelf/libelf_align.c b/lib/libelf/libelf_align.c
index f3cef5e..851b215 100644
--- a/lib/libelf/libelf_align.c
+++ b/lib/libelf/libelf_align.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/libelf_align.c,v 1.4 2010/07/21 09:56:42 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/libelf_align.c,v 1.4 2010/07/21 09:56:42 kaiw Exp $");
-
 #include <sys/types.h>
 
 #include <machine/elf.h>
@@ -66,20 +65,14 @@ struct align {
 static struct align malign[ELF_T_NUM] = {
 	[ELF_T_ADDR]	= MALIGN(Addr),
 	[ELF_T_BYTE]	= { .a32 = 1, .a64 = 1 },
-#if	__FreeBSD_version >= 700025
 	[ELF_T_CAP]	= MALIGN(Cap),
-#endif
 	[ELF_T_DYN]	= MALIGN(Dyn),
 	[ELF_T_EHDR]	= MALIGN(Ehdr),
 	[ELF_T_HALF]	= MALIGN(Half),
-#if	__FreeBSD_version >= 700025
 	[ELF_T_LWORD]	= MALIGN(Lword),
 	[ELF_T_MOVE]	= MALIGN(Move),
-#endif
 	[ELF_T_MOVEP] 	= UNSUPPORTED(),
-#if	__FreeBSD_version >= 700025
 	[ELF_T_NOTE]	= MALIGN(Nhdr),
-#endif
 	[ELF_T_OFF]	= MALIGN(Off),
 	[ELF_T_PHDR]	= MALIGN(Phdr),
 	[ELF_T_REL]	= MALIGN(Rel),
@@ -88,18 +81,12 @@ static struct align malign[ELF_T_NUM] = {
 	[ELF_T_SWORD]	= MALIGN(Sword),
 	[ELF_T_SXWORD]	= MALIGN64(Sxword),
 	[ELF_T_SYM]	= MALIGN(Sym),
-#if	__FreeBSD_version >= 700025
 	[ELF_T_SYMINFO]	= MALIGN(Syminfo),
-#endif
-#if	__FreeBSD_version >= 700009
 	[ELF_T_VDEF]	= MALIGN(Verdef),
 	[ELF_T_VNEED]	= MALIGN(Verneed),
-#endif
 	[ELF_T_WORD]	= MALIGN(Word),
 	[ELF_T_XWORD]	= MALIGN64(Xword),
-#if	__FreeBSD_version >= 800062
 	[ELF_T_GNUHASH] = MALIGN_WORD()
-#endif
 };
 
 int
@@ -117,20 +104,14 @@ _libelf_malign(Elf_Type t, int elfclass)
 static struct align falign[ELF_T_NUM] = {
 	[ELF_T_ADDR]	= FALIGN(4,8),
 	[ELF_T_BYTE]	= FALIGN(1,1),
-#if	__FreeBSD_version >= 700025
 	[ELF_T_CAP]	= FALIGN(4,8),
-#endif
 	[ELF_T_DYN]	= FALIGN(4,8),
 	[ELF_T_EHDR]	= FALIGN(4,8),
 	[ELF_T_HALF]	= FALIGN(2,2),
-#if	__FreeBSD_version >= 700025
 	[ELF_T_LWORD]	= FALIGN(8,8),
 	[ELF_T_MOVE]	= FALIGN(8,8),
-#endif
 	[ELF_T_MOVEP] 	= UNSUPPORTED(),
-#if	__FreeBSD_version >= 700025
 	[ELF_T_NOTE]	= FALIGN(1,1),
-#endif
 	[ELF_T_OFF]	= FALIGN(4,8),
 	[ELF_T_PHDR]	= FALIGN(4,8),
 	[ELF_T_REL]	= FALIGN(4,8),
@@ -139,18 +120,12 @@ static struct align falign[ELF_T_NUM] = {
 	[ELF_T_SWORD]	= FALIGN(4,4),
 	[ELF_T_SXWORD]	= FALIGN(0,8),
 	[ELF_T_SYM]	= FALIGN(4,8),
-#if	__FreeBSD_version >= 700025
 	[ELF_T_SYMINFO]	= FALIGN(2,2),
-#endif
-#if	__FreeBSD_version >= 700009
 	[ELF_T_VDEF]	= FALIGN(4,4),
 	[ELF_T_VNEED]	= FALIGN(4,4),
-#endif
 	[ELF_T_WORD]	= FALIGN(4,4),
 	[ELF_T_XWORD]	= FALIGN(0,8),
-#if	__FreeBSD_version >= 800062
 	[ELF_T_GNUHASH] = FALIGN(4,8)
-#endif
 };
 
 int
diff --git a/lib/libelf/libelf_allocate.c b/lib/libelf/libelf_allocate.c
index e7a069e..83e1ab9 100644
--- a/lib/libelf/libelf_allocate.c
+++ b/lib/libelf/libelf_allocate.c
@@ -22,15 +22,14 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/libelf_allocate.c,v 1.2 2007/02/21 08:14:22 dumbbell Exp $
  */
 
 /*
  * Internal APIs
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/libelf_allocate.c,v 1.2 2007/02/21 08:14:22 dumbbell Exp $");
-
 #include <sys/errno.h>
 
 #include <assert.h>
@@ -186,12 +185,12 @@ _libelf_release_scn(Elf_Scn *s)
 
 	assert(s != NULL);
 
-	STAILQ_FOREACH_SAFE(d, &s->s_data, d_next, td) {
+	STAILQ_FOREACH_MUTABLE(d, &s->s_data, d_next, td) {
 		STAILQ_REMOVE(&s->s_data, d, _Elf_Data, d_next);
 		d = _libelf_release_data(d);
 	}
 
-	STAILQ_FOREACH_SAFE(d, &s->s_rawdata, d_next, td) {
+	STAILQ_FOREACH_MUTABLE(d, &s->s_rawdata, d_next, td) {
 		assert((d->d_flags & LIBELF_F_MALLOCED) == 0);
 		STAILQ_REMOVE(&s->s_rawdata, d, _Elf_Data, d_next);
 		d = _libelf_release_data(d);
diff --git a/lib/libelf/libelf_ar.c b/lib/libelf/libelf_ar.c
index 8514ed4..f39ea78 100644
--- a/lib/libelf/libelf_ar.c
+++ b/lib/libelf/libelf_ar.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/libelf_ar.c,v 1.4 2010/07/21 12:54:34 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/libelf_ar.c,v 1.4 2010/07/21 12:54:34 kaiw Exp $");
-
 #include <ar.h>
 #include <assert.h>
 #include <ctype.h>
diff --git a/lib/libelf/libelf_ar_util.c b/lib/libelf/libelf_ar_util.c
index a821870..8c0a2a9 100644
--- a/lib/libelf/libelf_ar_util.c
+++ b/lib/libelf/libelf_ar_util.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/libelf_ar_util.c,v 1.1 2010/07/21 12:54:34 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/libelf_ar_util.c,v 1.1 2010/07/21 12:54:34 kaiw Exp $");
-
 #include <ar.h>
 #include <assert.h>
 #include <libelf.h>
diff --git a/lib/libelf/libelf_checksum.c b/lib/libelf/libelf_checksum.c
index 57bbe04..39f0262 100644
--- a/lib/libelf/libelf_checksum.c
+++ b/lib/libelf/libelf_checksum.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/libelf_checksum.c,v 1.2 2006/12/25 02:22:22 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/libelf_checksum.c,v 1.2 2006/12/25 02:22:22 jkoshy Exp $");
-
 #include <gelf.h>
 
 #include "_libelf.h"
diff --git a/lib/libelf/libelf_convert.m4 b/lib/libelf/libelf_convert.m4
index 2dfc7fa..0515a65 100644
--- a/lib/libelf/libelf_convert.m4
+++ b/lib/libelf/libelf_convert.m4
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/libelf_convert.m4,v 1.10 2011/03/01 11:47:51 brucec Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/libelf_convert.m4,v 1.10 2011/03/01 11:47:51 brucec Exp $");
-
 #include <sys/types.h>
 #include <sys/elf32.h>
 #include <sys/elf64.h>
@@ -465,8 +464,7 @@ libelf_cvt$3_$1_tom(char *dst, size_t dsz, char *src, size_t count,
  */
 
 define(`MAKE_TYPE_CONVERTER',
-  `#if	__FreeBSD_version >= $3 /* $1 */
-ifdef(`BASE'_$1,
+  `ifdef(`BASE'_$1,
     `ifdef(`IGNORE_'$1,`',
       `MAKEPRIM_TO_F($1,$2,`',64)
        MAKEPRIM_TO_M($1,$2,`',64)')',
@@ -478,9 +476,7 @@ ifdef(`BASE'_$1,
       `MAKE_TO_F($1,$2,32)dnl
        MAKE_TO_F($1,$2,64)dnl
        MAKE_TO_M($1,$2,32)dnl
-       MAKE_TO_M($1,$2,64)')')
-#endif /* $1 */
-')
+       MAKE_TO_M($1,$2,64)')')')
 
 define(`MAKE_TYPE_CONVERTERS',
   `ifelse($#,1,`',
@@ -507,7 +503,6 @@ libelf_cvt_BYTE_tox(char *dst, size_t dsz, char *src, size_t count,
 
 MAKE_TYPE_CONVERTERS(ELF_TYPE_LIST)
 
-#if	__FreeBSD_version >= 800062
 /*
  * Sections of type ELF_T_GNUHASH start with a header containing 4 32-bit
  * words.  Bloom filter data comes next, followed by hash buckets and the
@@ -701,7 +696,6 @@ libelf_cvt64_GNUHASH_tof(char *dst, size_t dsz, char *src, size_t srcsz,
 
 	return (1);
 }
-#endif
 
 /*
  * Elf_Note structures comprise a fixed size header followed by variable
@@ -847,11 +841,9 @@ define(`CONV',
 
 define(`CONVERTER_NAME',
   `ifdef(`IGNORE_'$1,`',
-    `#if	__FreeBSD_version >= $3
-    [ELF_T_$1] = {
+    `[ELF_T_$1] = {
         CONV($1,32,tof), CONV($1,32,tom),
         CONV($1,64,tof), CONV($1,64,tom) },
-#endif
 ')')
 
 define(`CONVERTER_NAMES',
@@ -875,14 +867,12 @@ CONVERTER_NAMES(ELF_TYPE_LIST)
 		.tom64 = libelf_cvt_BYTE_tox
 	},
 
-#if	__FreeBSD_version >= 800062
 	[ELF_T_GNUHASH] = {
 		.tof32 = libelf_cvt32_GNUHASH_tof,
 		.tom32 = libelf_cvt32_GNUHASH_tom,
 		.tof64 = libelf_cvt64_GNUHASH_tof,
 		.tom64 = libelf_cvt64_GNUHASH_tom
 	},
-#endif
 
 	[ELF_T_NOTE] = {
 		.tof32 = libelf_cvt_NOTE_tof,
diff --git a/lib/libelf/libelf_data.c b/lib/libelf/libelf_data.c
index d7f5617..23dc3e7 100644
--- a/lib/libelf/libelf_data.c
+++ b/lib/libelf/libelf_data.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/libelf_data.c,v 1.7 2011/05/07 01:05:31 obrien Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/libelf_data.c,v 1.7 2011/05/07 01:05:31 obrien Exp $");
-
 #include <libelf.h>
 #include <osreldate.h>
 
@@ -42,10 +41,8 @@ _libelf_xlate_shtype(uint32_t sht)
 		return (ELF_T_SYM);
 	case SHT_FINI_ARRAY:
 		return (ELF_T_ADDR);
-#if	__FreeBSD_version >= 800062
 	case SHT_GNU_HASH:
 		return (ELF_T_GNUHASH);
-#endif
 	case SHT_GROUP:
 		return (ELF_T_WORD);
 	case SHT_HASH:
@@ -70,7 +67,6 @@ _libelf_xlate_shtype(uint32_t sht)
 		return (ELF_T_SYM);
 	case SHT_SYMTAB_SHNDX:
 		return (ELF_T_WORD);
-#if	__FreeBSD_version >= 700025
 	case SHT_GNU_verdef:	/* == SHT_SUNW_verdef */
 		return (ELF_T_VDEF);
 	case SHT_GNU_verneed:	/* == SHT_SUNW_verneed */
@@ -83,7 +79,6 @@ _libelf_xlate_shtype(uint32_t sht)
 		return (ELF_T_SYMINFO);
 	case SHT_SUNW_dof:
 		return (ELF_T_BYTE);
-#endif
 	case SHT_MIPS_DWARF:
 		/* FALLTHROUGH */
 	case SHT_AMD64_UNWIND:	/* == SHT_IA_64_UNWIND */
diff --git a/lib/libelf/libelf_ehdr.c b/lib/libelf/libelf_ehdr.c
index 80833f0..b79fd1d 100644
--- a/lib/libelf/libelf_ehdr.c
+++ b/lib/libelf/libelf_ehdr.c
@@ -26,9 +26,6 @@
  * $FreeBSD: src/lib/libelf/libelf_ehdr.c,v 1.3 2010/07/21 10:25:02 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/libelf_ehdr.c,v 1.3 2010/07/21 10:25:02 kaiw Exp $");
-
 #include <assert.h>
 #include <gelf.h>
 #include <libelf.h>
diff --git a/lib/libelf/libelf_extended.c b/lib/libelf/libelf_extended.c
index d371bba..3ec0399 100644
--- a/lib/libelf/libelf_extended.c
+++ b/lib/libelf/libelf_extended.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/libelf_extended.c,v 1.1 2006/12/25 02:22:22 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/libelf_extended.c,v 1.1 2006/12/25 02:22:22 jkoshy Exp $");
-
 #include <assert.h>
 #include <libelf.h>
 
diff --git a/lib/libelf/libelf_fsize.m4 b/lib/libelf/libelf_fsize.m4
index 617ba35..be4f5f7 100644
--- a/lib/libelf/libelf_fsize.m4
+++ b/lib/libelf/libelf_fsize.m4
@@ -118,9 +118,8 @@ DEFINE_ELF_FSIZES(ELF_TYPE_LIST)
 DEFINE_ELF_FSIZE(`IDENT',`')	# `IDENT' is a pseudo type
 
 define(`FSIZE',
-  `#if	__FreeBSD_version >= $3
-    [ELF_T_$1] = { .fsz32 = $1_SIZE32, .fsz64 = $1_SIZE64 },
-#endif')
+  `[ELF_T_$1] = { .fsz32 = $1_SIZE32, .fsz64 = $1_SIZE64 },
+')
 define(`FSIZES',
   `ifelse($#,1,`',
     `FSIZE($1)
diff --git a/lib/libelf/libelf_msize.m4 b/lib/libelf/libelf_msize.m4
index 055df87..bc5ac25 100644
--- a/lib/libelf/libelf_msize.m4
+++ b/lib/libelf/libelf_msize.m4
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/libelf_msize.m4,v 1.3 2010/07/21 09:56:42 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/libelf_msize.m4,v 1.3 2010/07/21 09:56:42 kaiw Exp $");
-
 #include <sys/types.h>
 #include <sys/elf32.h>
 #include <sys/elf64.h>
@@ -75,9 +74,8 @@ define(`DEFINE_ELF_MSIZES',
 DEFINE_ELF_MSIZES(ELF_TYPE_LIST)
 
 define(`MSIZE',
-  `#if	__FreeBSD_version >= $3
-    [ELF_T_$1] = { .msz32 = $1_SIZE32, .msz64 = $1_SIZE64 },
-#endif')
+  `[ELF_T_$1] = { .msz32 = $1_SIZE32, .msz64 = $1_SIZE64 },
+')
 define(`MSIZES',
   `ifelse($#,1,`',
     `MSIZE($1)
diff --git a/lib/libelf/libelf_phdr.c b/lib/libelf/libelf_phdr.c
index 0dfc6a9..18afe89 100644
--- a/lib/libelf/libelf_phdr.c
+++ b/lib/libelf/libelf_phdr.c
@@ -26,9 +26,6 @@
  * $FreeBSD: src/lib/libelf/libelf_phdr.c,v 1.3 2010/07/21 10:25:02 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/libelf_phdr.c,v 1.3 2010/07/21 10:25:02 kaiw Exp $");
-
 #include <assert.h>
 #include <gelf.h>
 #include <libelf.h>
diff --git a/lib/libelf/libelf_shdr.c b/lib/libelf/libelf_shdr.c
index 441c4bf..5df8386 100644
--- a/lib/libelf/libelf_shdr.c
+++ b/lib/libelf/libelf_shdr.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/libelf_shdr.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/libelf_shdr.c,v 1.1 2006/11/11 17:16:33 jkoshy Exp $");
-
 #include <gelf.h>
 #include <libelf.h>
 
diff --git a/lib/libelf/libelf_xlate.c b/lib/libelf/libelf_xlate.c
index e9b7309..ce095ff 100644
--- a/lib/libelf/libelf_xlate.c
+++ b/lib/libelf/libelf_xlate.c
@@ -22,11 +22,10 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libelf/libelf_xlate.c,v 1.4 2010/07/21 10:25:02 kaiw Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libelf/libelf_xlate.c,v 1.4 2010/07/21 10:25:02 kaiw Exp $");
-
 #include <assert.h>
 #include <libelf.h>
 
-- 
1.7.0.5

