Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/libelf/dist - _libelf_globals::libelf_arch and ...



details:   https://anonhg.NetBSD.org/src/rev/0b8bef42a24f
branches:  trunk
changeset: 750224:0b8bef42a24f
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Dec 20 23:23:46 2009 +0000

description:
- _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).

diffstat:

 external/bsd/libelf/dist/_libelf.h      |   7 ++---
 external/bsd/libelf/dist/elf_begin.c    |   6 ++--
 external/bsd/libelf/dist/elf_data.c     |   6 ++--
 external/bsd/libelf/dist/elf_scn.c      |   6 ++--
 external/bsd/libelf/dist/libelf.c       |  34 +++++++++++++-------------------
 external/bsd/libelf/dist/libelf_ehdr.c  |   8 +++---
 external/bsd/libelf/dist/libelf_phdr.c  |   6 ++--
 external/bsd/libelf/dist/libelf_xlate.c |  10 ++++----
 8 files changed, 38 insertions(+), 45 deletions(-)

diffs (274 lines):

diff -r ff6b54c944d7 -r 0b8bef42a24f external/bsd/libelf/dist/_libelf.h
--- a/external/bsd/libelf/dist/_libelf.h        Sun Dec 20 23:00:59 2009 +0000
+++ b/external/bsd/libelf/dist/_libelf.h        Sun Dec 20 23:23:46 2009 +0000
@@ -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);
diff -r ff6b54c944d7 -r 0b8bef42a24f external/bsd/libelf/dist/elf_begin.c
--- a/external/bsd/libelf/dist/elf_begin.c      Sun Dec 20 23:00:59 2009 +0000
+++ b/external/bsd/libelf/dist/elf_begin.c      Sun Dec 20 23:23:46 2009 +0000
@@ -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;
                }
diff -r ff6b54c944d7 -r 0b8bef42a24f external/bsd/libelf/dist/elf_data.c
--- a/external/bsd/libelf/dist/elf_data.c       Sun Dec 20 23:00:59 2009 +0000
+++ b/external/bsd/libelf/dist/elf_data.c       Sun Dec 20 23:23:46 2009 +0000
@@ -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);
 }
diff -r ff6b54c944d7 -r 0b8bef42a24f external/bsd/libelf/dist/elf_scn.c
--- a/external/bsd/libelf/dist/elf_scn.c        Sun Dec 20 23:00:59 2009 +0000
+++ b/external/bsd/libelf/dist/elf_scn.c        Sun Dec 20 23:23:46 2009 +0000
@@ -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);
diff -r ff6b54c944d7 -r 0b8bef42a24f external/bsd/libelf/dist/libelf.c
--- a/external/bsd/libelf/dist/libelf.c Sun Dec 20 23:00:59 2009 +0000
+++ b/external/bsd/libelf/dist/libelf.c Sun Dec 20 23:23:46 2009 +0000
@@ -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
diff -r ff6b54c944d7 -r 0b8bef42a24f external/bsd/libelf/dist/libelf_ehdr.c
--- a/external/bsd/libelf/dist/libelf_ehdr.c    Sun Dec 20 23:00:59 2009 +0000
+++ b/external/bsd/libelf/dist/libelf_ehdr.c    Sun Dec 20 23:23:46 2009 +0000
@@ -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
diff -r ff6b54c944d7 -r 0b8bef42a24f external/bsd/libelf/dist/libelf_phdr.c
--- a/external/bsd/libelf/dist/libelf_phdr.c    Sun Dec 20 23:00:59 2009 +0000
+++ b/external/bsd/libelf/dist/libelf_phdr.c    Sun Dec 20 23:23:46 2009 +0000
@@ -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);
 }
diff -r ff6b54c944d7 -r 0b8bef42a24f external/bsd/libelf/dist/libelf_xlate.c
--- a/external/bsd/libelf/dist/libelf_xlate.c   Sun Dec 20 23:00:59 2009 +0000
+++ b/external/bsd/libelf/dist/libelf_xlate.c   Sun Dec 20 23:23:46 2009 +0000
@@ -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);
 }



Home | Main Index | Thread Index | Old Index