Module Name:    src
Committed By:   thorpej
Date:           Sun Dec 20 23:23:46 UTC 2009

Modified Files:
        src/external/bsd/libelf/dist: _libelf.h elf_begin.c elf_data.c
            elf_scn.c libelf.c libelf_ehdr.c libelf_phdr.c libelf_xlate.c

Log Message:
- _libelf_globals::libelf_arch and _libelf_globals::libelf_class are
  completely unused.  Remove them.
- _libelf_globals::libelf_byteorder is really all about the byte order of
  the host running libelf, so replace it with a _libelf_host_byteorder()
  internal function that computes the host byte order in a very portable
  way (doesn't rely on BSD-specific header files).


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/bsd/libelf/dist/_libelf.h \
    src/external/bsd/libelf/dist/elf_scn.c \
    src/external/bsd/libelf/dist/libelf_ehdr.c
cvs rdiff -u -r1.2 -r1.3 src/external/bsd/libelf/dist/elf_begin.c
cvs rdiff -u -r1.1.1.1 -r1.2 src/external/bsd/libelf/dist/elf_data.c \
    src/external/bsd/libelf/dist/libelf_phdr.c \
    src/external/bsd/libelf/dist/libelf_xlate.c
cvs rdiff -u -r1.4 -r1.5 src/external/bsd/libelf/dist/libelf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/libelf/dist/_libelf.h
diff -u src/external/bsd/libelf/dist/_libelf.h:1.3 src/external/bsd/libelf/dist/_libelf.h:1.4
--- src/external/bsd/libelf/dist/_libelf.h:1.3	Sat Dec 19 07:47:22 2009
+++ src/external/bsd/libelf/dist/_libelf.h	Sun Dec 20 23:23:46 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: _libelf.h,v 1.3 2009/12/19 07:47:22 thorpej Exp $	*/
+/*	$NetBSD: _libelf.h,v 1.4 2009/12/20 23:23:46 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2006 Joseph Koshy
@@ -44,9 +44,6 @@
 #define LIBELF_MSG_SIZE	256
 
 struct _libelf_globals {
-	int		libelf_arch;
-	unsigned int	libelf_byteorder;
-	int		libelf_class;
 	int		libelf_error;
 	int		libelf_fillchar;
 	unsigned int	libelf_version;
@@ -161,6 +158,8 @@
  * Prototypes
  */
 
+unsigned int _libelf_host_byteorder(void);
+
 Elf_Data *_libelf_allocate_data(Elf_Scn *_s);
 Elf	*_libelf_allocate_elf(void);
 Elf_Scn	*_libelf_allocate_scn(Elf *_e, size_t _ndx);
Index: src/external/bsd/libelf/dist/elf_scn.c
diff -u src/external/bsd/libelf/dist/elf_scn.c:1.3 src/external/bsd/libelf/dist/elf_scn.c:1.4
--- src/external/bsd/libelf/dist/elf_scn.c:1.3	Sat Dec 19 07:44:27 2009
+++ src/external/bsd/libelf/dist/elf_scn.c	Sun Dec 20 23:23:46 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: elf_scn.c,v 1.3 2009/12/19 07:44:27 thorpej Exp $	*/
+/*	$NetBSD: elf_scn.c,v 1.4 2009/12/20 23:23:46 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2006 Joseph Koshy
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 /* __FBSDID("$FreeBSD: src/lib/libelf/elf_scn.c,v 1.2.10.1.2.1 2009/10/25 01:10:29 kensmith Exp $"); */
-__RCSID("$NetBSD: elf_scn.c,v 1.3 2009/12/19 07:44:27 thorpej Exp $");
+__RCSID("$NetBSD: elf_scn.c,v 1.4 2009/12/20 23:23:46 thorpej Exp $");
 
 #include <assert.h>
 #include <errno.h>
@@ -85,7 +85,7 @@
 
 	xlator = _libelf_get_translator(ELF_T_SHDR, ELF_TOMEMORY, ec);
 
-	swapbytes = e->e_byteorder != LIBELF_PRIVATE(byteorder);
+	swapbytes = e->e_byteorder != _libelf_host_byteorder();
 	if (shoff > SSIZE_MAX) {
 		LIBELF_SET_ERROR(HEADER, 0);
 		return (0);
Index: src/external/bsd/libelf/dist/libelf_ehdr.c
diff -u src/external/bsd/libelf/dist/libelf_ehdr.c:1.3 src/external/bsd/libelf/dist/libelf_ehdr.c:1.4
--- src/external/bsd/libelf/dist/libelf_ehdr.c:1.3	Sat Dec 19 09:00:56 2009
+++ src/external/bsd/libelf/dist/libelf_ehdr.c	Sun Dec 20 23:23:46 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: libelf_ehdr.c,v 1.3 2009/12/19 09:00:56 thorpej Exp $	*/
+/*	$NetBSD: libelf_ehdr.c,v 1.4 2009/12/20 23:23:46 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2006 Joseph Koshy
@@ -30,7 +30,7 @@
 
 #include <sys/cdefs.h>
 /* __FBSDID("$FreeBSD: src/lib/libelf/libelf_ehdr.c,v 1.2.10.1.2.1 2009/10/25 01:10:29 kensmith Exp $"); */
-__RCSID("$NetBSD: libelf_ehdr.c,v 1.3 2009/12/19 09:00:56 thorpej Exp $");
+__RCSID("$NetBSD: libelf_ehdr.c,v 1.4 2009/12/20 23:23:46 thorpej Exp $");
 
 #include <assert.h>
 #include <gelf.h>
@@ -73,7 +73,7 @@
 
 	xlator = _libelf_get_translator(ELF_T_SHDR, ELF_TOMEMORY, ec);
 	(*xlator)((void *) &scn->s_shdr, e->e_rawfile + (ssize_t)shoff,
-	    (size_t) 1, e->e_byteorder != LIBELF_PRIVATE(byteorder));
+	    (size_t) 1, e->e_byteorder != _libelf_host_byteorder());
 
 #define	GET_SHDR_MEMBER(M) ((ec == ELFCLASS32) ? scn->s_shdr.s_shdr32.M : \
 		scn->s_shdr.s_shdr64.M)
@@ -182,7 +182,7 @@
 
 	xlator = _libelf_get_translator(ELF_T_EHDR, ELF_TOMEMORY, ec);
 	(*xlator)(ehdr, e->e_rawfile, (size_t) 1,
-	    e->e_byteorder != LIBELF_PRIVATE(byteorder));
+	    e->e_byteorder != _libelf_host_byteorder());
 
 	/*
 	 * If extended numbering is being used, read the correct

Index: src/external/bsd/libelf/dist/elf_begin.c
diff -u src/external/bsd/libelf/dist/elf_begin.c:1.2 src/external/bsd/libelf/dist/elf_begin.c:1.3
--- src/external/bsd/libelf/dist/elf_begin.c:1.2	Sat Dec 19 06:22:25 2009
+++ src/external/bsd/libelf/dist/elf_begin.c	Sun Dec 20 23:23:46 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: elf_begin.c,v 1.2 2009/12/19 06:22:25 thorpej Exp $	*/
+/*	$NetBSD: elf_begin.c,v 1.3 2009/12/20 23:23:46 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2006 Joseph Koshy
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 /* __FBSDID("$FreeBSD: src/lib/libelf/elf_begin.c,v 1.1.10.1.2.1 2009/10/25 01:10:29 kensmith Exp $"); */
-__RCSID("$NetBSD: elf_begin.c,v 1.2 2009/12/19 06:22:25 thorpej Exp $");
+__RCSID("$NetBSD: elf_begin.c,v 1.3 2009/12/20 23:23:46 thorpej Exp $");
 
 #include <sys/types.h>
 #include <sys/mman.h>
@@ -118,7 +118,7 @@
 
 		if ((e = _libelf_allocate_elf()) != NULL) {
 			_libelf_init_elf(e, ELF_K_ELF);
-			e->e_byteorder = LIBELF_PRIVATE(byteorder);
+			e->e_byteorder = _libelf_host_byteorder();
 			e->e_fd = fd;
 			e->e_cmd = c;
 		}

Index: src/external/bsd/libelf/dist/elf_data.c
diff -u src/external/bsd/libelf/dist/elf_data.c:1.1.1.1 src/external/bsd/libelf/dist/elf_data.c:1.2
--- src/external/bsd/libelf/dist/elf_data.c:1.1.1.1	Sat Dec 19 05:43:39 2009
+++ src/external/bsd/libelf/dist/elf_data.c	Sun Dec 20 23:23:46 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: elf_data.c,v 1.1.1.1 2009/12/19 05:43:39 thorpej Exp $	*/
+/*	$NetBSD: elf_data.c,v 1.2 2009/12/20 23:23:46 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2006 Joseph Koshy
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 /* __FBSDID("$FreeBSD: src/lib/libelf/elf_data.c,v 1.2.10.1.2.1 2009/10/25 01:10:29 kensmith Exp $"); */
-__RCSID("$NetBSD: elf_data.c,v 1.1.1.1 2009/12/19 05:43:39 thorpej Exp $");
+__RCSID("$NetBSD: elf_data.c,v 1.2 2009/12/20 23:23:46 thorpej Exp $");
 
 #include <assert.h>
 #include <errno.h>
@@ -127,7 +127,7 @@
 
 	xlate = _libelf_get_translator(elftype, ELF_TOMEMORY, elfclass);
 	(*xlate)(d->d_buf, e->e_rawfile + sh_offset, count, e->e_byteorder !=
-	    LIBELF_PRIVATE(byteorder));
+	    _libelf_host_byteorder());
 
 	return (d);
 }
Index: src/external/bsd/libelf/dist/libelf_phdr.c
diff -u src/external/bsd/libelf/dist/libelf_phdr.c:1.1.1.1 src/external/bsd/libelf/dist/libelf_phdr.c:1.2
--- src/external/bsd/libelf/dist/libelf_phdr.c:1.1.1.1	Sat Dec 19 05:43:41 2009
+++ src/external/bsd/libelf/dist/libelf_phdr.c	Sun Dec 20 23:23:46 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: libelf_phdr.c,v 1.1.1.1 2009/12/19 05:43:41 thorpej Exp $	*/
+/*	$NetBSD: libelf_phdr.c,v 1.2 2009/12/20 23:23:46 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2006 Joseph Koshy
@@ -30,7 +30,7 @@
 
 #include <sys/cdefs.h>
 /* __FBSDID("$FreeBSD: src/lib/libelf/libelf_phdr.c,v 1.2.10.1.2.1 2009/10/25 01:10:29 kensmith Exp $"); */
-__RCSID("$NetBSD: libelf_phdr.c,v 1.1.1.1 2009/12/19 05:43:41 thorpej Exp $");
+__RCSID("$NetBSD: libelf_phdr.c,v 1.2 2009/12/20 23:23:46 thorpej Exp $");
 
 #include <assert.h>
 #include <gelf.h>
@@ -107,7 +107,7 @@
 
 	xlator = _libelf_get_translator(ELF_T_PHDR, ELF_TOMEMORY, ec);
 	(*xlator)(phdr, e->e_rawfile + phoff, phnum,
-	    e->e_byteorder != LIBELF_PRIVATE(byteorder));
+	    e->e_byteorder != _libelf_host_byteorder());
 
 	return (phdr);
 }
Index: src/external/bsd/libelf/dist/libelf_xlate.c
diff -u src/external/bsd/libelf/dist/libelf_xlate.c:1.1.1.1 src/external/bsd/libelf/dist/libelf_xlate.c:1.2
--- src/external/bsd/libelf/dist/libelf_xlate.c:1.1.1.1	Sat Dec 19 05:43:41 2009
+++ src/external/bsd/libelf/dist/libelf_xlate.c	Sun Dec 20 23:23:46 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: libelf_xlate.c,v 1.1.1.1 2009/12/19 05:43:41 thorpej Exp $	*/
+/*	$NetBSD: libelf_xlate.c,v 1.2 2009/12/20 23:23:46 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2006 Joseph Koshy
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 /* __FBSDID("$FreeBSD: src/lib/libelf/libelf_xlate.c,v 1.3.2.1.2.1 2009/10/25 01:10:29 kensmith Exp $"); */
-__RCSID("$NetBSD: libelf_xlate.c,v 1.1.1.1 2009/12/19 05:43:41 thorpej Exp $");
+__RCSID("$NetBSD: libelf_xlate.c,v 1.2 2009/12/20 23:23:46 thorpej Exp $");
 
 #include <assert.h>
 #include <libelf.h>
@@ -55,7 +55,7 @@
 	uintptr_t sb, se, db, de;
 
 	if (encoding == ELFDATANONE)
-		encoding = LIBELF_PRIVATE(byteorder);
+		encoding = _libelf_host_byteorder();
 
 	if ((encoding != ELFDATA2LSB && encoding != ELFDATA2MSB) ||
 	    dst == NULL || src == NULL || dst == src)	{
@@ -136,11 +136,11 @@
 	dst->d_size = dsz;
 
 	if (src->d_size == 0 ||
-	    (db == sb && encoding == LIBELF_PRIVATE(byteorder) && fsz == msz))
+	    (db == sb && encoding == _libelf_host_byteorder() && fsz == msz))
 		return (dst);	/* nothing more to do */
 
 	(_libelf_get_translator(src->d_type, direction, elfclass))(dst->d_buf,
-	    src->d_buf, cnt, encoding != LIBELF_PRIVATE(byteorder));
+	    src->d_buf, cnt, encoding != _libelf_host_byteorder());
 
 	return (dst);
 }

Index: src/external/bsd/libelf/dist/libelf.c
diff -u src/external/bsd/libelf/dist/libelf.c:1.4 src/external/bsd/libelf/dist/libelf.c:1.5
--- src/external/bsd/libelf/dist/libelf.c:1.4	Sun Dec 20 19:38:13 2009
+++ src/external/bsd/libelf/dist/libelf.c	Sun Dec 20 23:23:46 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: libelf.c,v 1.4 2009/12/20 19:38:13 mrg Exp $	*/
+/*	$NetBSD: libelf.c,v 1.5 2009/12/20 23:23:46 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2006 Joseph Koshy
@@ -28,38 +28,32 @@
 
 #include <sys/cdefs.h>
 /* __FBSDID("$FreeBSD: src/lib/libelf/libelf.c,v 1.1.10.1.2.1 2009/10/25 01:10:29 kensmith Exp $"); */
-__RCSID("$NetBSD: libelf.c,v 1.4 2009/12/20 19:38:13 mrg Exp $");
+__RCSID("$NetBSD: libelf.c,v 1.5 2009/12/20 23:23:46 thorpej Exp $");
 
 #include <sys/param.h>
 
-#if defined(__FreeBSD__)
-#include <machine/elf.h>
-#endif /* __FreeBSD__ */
-#include <machine/endian.h>
-
 #include <libelf.h>
 
 #include "_libelf.h"
 
-#if defined(__NetBSD__)
-# if ARCH_ELFSIZE == 64
-#  define ELF_TARG_DATA		ELF64_MACHDEP_ENDIANNESS
-#  define ELF_TARG_CLASS	ELFCLASS64
-# else
-#  define ELF_TARG_DATA		ELF32_MACHDEP_ENDIANNESS
-#  define ELF_TARG_CLASS	ELFCLASS32
-# endif /* ARCH_ELFSIZE */
-#endif /* __NetBSD__ */
-
 struct _libelf_globals _libelf = {
-	.libelf_arch		= 0 /* unused - ELF_ARCH */,
-	.libelf_byteorder	= ELF_TARG_DATA,
-	.libelf_class		= ELF_TARG_CLASS,
 	.libelf_error		= 0,
 	.libelf_fillchar	= 0,
 	.libelf_version		= EV_NONE
 };
 
+unsigned int
+_libelf_host_byteorder(void)
+{
+	static union {
+		uint32_t	val;
+		uint8_t		bytes[4];
+	} byte_order_check = {
+		.val	=	0xdeadbeef,
+	};
+
+	return (byte_order_check.bytes[0] == 0xef ? ELFDATA2LSB : ELFDATA2MSB);
+}
 
 #if defined(LIBELF_TEST_HOOKS)
 int

Reply via email to