summaryrefslogtreecommitdiffstats
path: root/libelf
diff options
context:
space:
mode:
authorRoland McGrath <[email protected]>2007-08-23 08:10:54 +0000
committerRoland McGrath <[email protected]>2007-08-23 08:10:54 +0000
commitcb6d865011ad98a8ac2018f072f396a2268739ca (patch)
treec497c4dacb592f9da5f5740a8b9fa8d362468079 /libelf
parent50c6a2f8b9621ae01c8943e80c39bc859c9d5c22 (diff)
readelf register printing sort order tweak
Diffstat (limited to 'libelf')
-rw-r--r--libelf/ChangeLog16
-rw-r--r--libelf/Makefile.am1
-rw-r--r--libelf/abstract.h19
-rw-r--r--libelf/exttypes.h4
-rw-r--r--libelf/gelf.h10
-rw-r--r--libelf/gelf_fsize.c5
-rw-r--r--libelf/gelf_getauxv.c130
-rw-r--r--libelf/gelf_update_auxv.c135
-rw-r--r--libelf/gelf_xlate.c5
-rw-r--r--libelf/gelf_xlate.h3
-rw-r--r--libelf/libelf.h3
-rw-r--r--libelf/libelf.map6
12 files changed, 328 insertions, 9 deletions
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index a26728cd..4962c30a 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,19 @@
+2007-08-19 Roland McGrath <[email protected]>
+
+ * gelf_update_auxv.c: New file.
+ * gelf_getauxv.c: New file.
+ * Makefile.am (libelf_a_SOURCES): Add them.
+ * gelf.h: Declare gelf_getauxv, gelf_update_auxv.
+ * libelf.map (ELFUTILS_1.3): New set, inherits fom ELFUTILS_1.2.
+ Export gelf_getauxv, gelf_update_auxv.
+
+ * libelf.h (Elf_Type): Add ELF_T_AUXV.
+ * abstract.h: Add auxv_t entries.
+ * exttypes.h: Likewise.
+ * gelf_xlate.h: Likewise.
+ * gelf_xlate.c (__elf_xfctstom): Add ELF_T_AUXV entries.
+ * gelf_fsize.c (__libelf_type_sizes): Likewise.
+
2007-08-12 Roland McGrath <[email protected]>
* elf32_updatefile.c (compare_sections): Sort secondarily on sh_size,
diff --git a/libelf/Makefile.am b/libelf/Makefile.am
index b93f49c6..3e8322e9 100644
--- a/libelf/Makefile.am
+++ b/libelf/Makefile.am
@@ -83,6 +83,7 @@ libelf_a_SOURCES = elf_version.c elf_hash.c elf_error.c elf_fill.c \
gelf_getdyn.c gelf_update_dyn.c \
gelf_getmove.c gelf_update_move.c \
gelf_getsyminfo.c gelf_update_syminfo.c \
+ gelf_getauxv.c gelf_update_auxv.c \
gelf_xlatetof.c gelf_xlatetom.c \
nlist.c \
gelf_getsymshndx.c gelf_update_symshndx.c \
diff --git a/libelf/abstract.h b/libelf/abstract.h
index 3c6250d0..e359f96b 100644
--- a/libelf/abstract.h
+++ b/libelf/abstract.h
@@ -1,5 +1,5 @@
/* Abstract description of component ELF types.
- Copyright (C) 1998, 1999, 2000, 2002, 2004 Red Hat, Inc.
+ Copyright (C) 1998, 1999, 2000, 2002, 2004, 2007 Red Hat, Inc.
This file is part of Red Hat elfutils.
Written by Ulrich Drepper <[email protected]>, 1998.
@@ -314,3 +314,20 @@ END (Bits, Ext##Lib)
Lib (32, Ext)
#define Lib64(Ext) \
Lib (64, Ext)
+
+#define auxv_t32(Ext) \
+START (32, auxv_t, Ext##auxv_t) \
+ TYPE_NAME (ElfW2(32, Ext##Word), a_type) \
+ TYPE_EXTRA (union {) \
+ TYPE_EXTRA (ElfW2(32, Ext##Word) a_val;) \
+ TYPE_XLATE (Elf32_cvt_Addr1 (&tdest->a_un.a_val, &tsrc->a_un.a_val);) \
+ TYPE_EXTRA (} a_un;) \
+END (32, Ext##auxv_t)
+#define auxv_t64(Ext) \
+START (64, auxv_t, Ext##auxv_t) \
+ TYPE_NAME (ElfW2(64, Ext##Xword), a_type) \
+ TYPE_EXTRA (union {) \
+ TYPE_EXTRA (ElfW2(64, Ext##Xword) a_val;) \
+ TYPE_XLATE (Elf64_cvt_Addr1 (&tdest->a_un.a_val, &tsrc->a_un.a_val);) \
+ TYPE_EXTRA (} a_un;) \
+END (64, Ext##auxv_t)
diff --git a/libelf/exttypes.h b/libelf/exttypes.h
index 1dff8ce3..3bb90c3a 100644
--- a/libelf/exttypes.h
+++ b/libelf/exttypes.h
@@ -1,5 +1,5 @@
/* External ELF types.
- Copyright (C) 1998, 1999, 2000, 2002 Red Hat, Inc.
+ Copyright (C) 1998, 1999, 2000, 2002, 2007 Red Hat, Inc.
This file is part of Red Hat elfutils.
Contributed by Ulrich Drepper <[email protected]>, 1998.
@@ -94,6 +94,7 @@ Verneed32 (Ext_);
Vernaux32 (Ext_);
Syminfo32 (Ext_);
Move32 (Ext_);
+auxv_t32 (Ext_);
Ehdr64 (Ext_);
Phdr64 (Ext_);
@@ -109,6 +110,7 @@ Verneed64 (Ext_);
Vernaux64 (Ext_);
Syminfo64 (Ext_);
Move64 (Ext_);
+auxv_t64 (Ext_);
#undef START
#undef END
diff --git a/libelf/gelf.h b/libelf/gelf.h
index 2ef256cc..b985c1c0 100644
--- a/libelf/gelf.h
+++ b/libelf/gelf.h
@@ -1,5 +1,5 @@
/* This file defines generic ELF types, structures, and macros.
- Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005 Red Hat, Inc.
+ Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2007 Red Hat, Inc.
This file is part of Red Hat elfutils.
Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -327,6 +327,14 @@ extern int gelf_update_verdaux (Elf_Data *__data, int __offset,
GElf_Verdaux *__src);
+/* Get auxv entry at the given index. */
+extern GElf_auxv_t *gelf_getauxv (Elf_Data *__data, int __ndx,
+ GElf_auxv_t *__dst);
+
+/* Update auxv entry at the given index. */
+extern int gelf_update_auxv (Elf_Data *__data, int __ndx, GElf_auxv_t *__src);
+
+
/* Retrieve uninterpreted chunk of the file contents. */
extern char *gelf_rawchunk (Elf *__elf, GElf_Off __offset, GElf_Word __size);
diff --git a/libelf/gelf_fsize.c b/libelf/gelf_fsize.c
index a8c368c3..98197e0f 100644
--- a/libelf/gelf_fsize.c
+++ b/libelf/gelf_fsize.c
@@ -1,5 +1,5 @@
/* Return the size of an object file type.
- Copyright (C) 1998, 1999, 2000, 2002 Red Hat, Inc.
+ Copyright (C) 1998, 1999, 2000, 2002, 2007 Red Hat, Inc.
This file is part of Red Hat elfutils.
Written by Ulrich Drepper <[email protected]>, 1998.
@@ -86,7 +86,8 @@ const size_t __libelf_type_sizes[EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM] =
[ELF_T_VNAUX] = sizeof (ElfW2(LIBELFBITS, Ext_Vernaux)), \
[ELF_T_NHDR] = sizeof (ElfW2(LIBELFBITS, Ext_Nhdr)), \
[ELF_T_SYMINFO] = sizeof (ElfW2(LIBELFBITS, Ext_Syminfo)), \
- [ELF_T_MOVE] = sizeof (ElfW2(LIBELFBITS, Ext_Move))
+ [ELF_T_MOVE] = sizeof (ElfW2(LIBELFBITS, Ext_Move)), \
+ [ELF_T_AUXV] = sizeof (ElfW2(LIBELFBITS, Ext_auxv_t))
TYPE_SIZES (32)
},
[ELFCLASS64 - 1] = {
diff --git a/libelf/gelf_getauxv.c b/libelf/gelf_getauxv.c
new file mode 100644
index 00000000..036bdccf
--- /dev/null
+++ b/libelf/gelf_getauxv.c
@@ -0,0 +1,130 @@
+/* Get information from auxiliary vector at the given index.
+ Copyright (C) 2007 Red Hat, Inc.
+ This file is part of Red Hat elfutils.
+
+ Red Hat elfutils is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by the
+ Free Software Foundation; version 2 of the License.
+
+ Red Hat elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Red Hat elfutils; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+ In addition, as a special exception, Red Hat, Inc. gives You the
+ additional right to link the code of Red Hat elfutils with code licensed
+ under any Open Source Initiative certified open source license
+ (http://www.opensource.org/licenses/index.php) which requires the
+ distribution of source code with any binary distribution and to
+ distribute linked combinations of the two. Non-GPL Code permitted under
+ this exception must only link to the code of Red Hat elfutils through
+ those well defined interfaces identified in the file named EXCEPTION
+ found in the source code files (the "Approved Interfaces"). The files
+ of Non-GPL Code may instantiate templates or use macros or inline
+ functions from the Approved Interfaces without causing the resulting
+ work to be covered by the GNU General Public License. Only Red Hat,
+ Inc. may make changes or additions to the list of Approved Interfaces.
+ Red Hat's grant of this exception is conditioned upon your not adding
+ any new exceptions. If you wish to add a new Approved Interface or
+ exception, please contact Red Hat. You must obey the GNU General Public
+ License in all respects for all of the Red Hat elfutils code and other
+ code used in conjunction with Red Hat elfutils except the Non-GPL Code
+ covered by this exception. If you modify this file, you may extend this
+ exception to your version of the file, but you are not obligated to do
+ so. If you do not wish to provide this exception without modification,
+ you must delete this exception statement from your version and license
+ this file solely under the GPL without exception.
+
+ Red Hat elfutils is an included package of the Open Invention Network.
+ An included package of the Open Invention Network is a package for which
+ Open Invention Network licensees cross-license their patents. No patent
+ license is granted, either expressly or impliedly, by designation as an
+ included package. Should you wish to participate in the Open Invention
+ Network licensing program, please visit www.openinventionnetwork.com
+ <http://www.openinventionnetwork.com>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <assert.h>
+#include <gelf.h>
+#include <string.h>
+
+#include "libelfP.h"
+
+
+GElf_auxv_t *
+gelf_getauxv (data, ndx, dst)
+ Elf_Data *data;
+ int ndx;
+ GElf_auxv_t *dst;
+{
+ Elf_Data_Scn *data_scn = (Elf_Data_Scn *) data;
+ GElf_auxv_t *result = NULL;
+ Elf *elf;
+
+ if (data_scn == NULL)
+ return NULL;
+
+ if (unlikely (data_scn->d.d_type != ELF_T_AUXV))
+ {
+ __libelf_seterrno (ELF_E_INVALID_HANDLE);
+ return NULL;
+ }
+
+ elf = data_scn->s->elf;
+
+ rwlock_rdlock (elf->lock);
+
+ /* This is the one place where we have to take advantage of the fact
+ that an `Elf_Data' pointer is also a pointer to `Elf_Data_Scn'.
+ The interface is broken so that it requires this hack. */
+ if (elf->class == ELFCLASS32)
+ {
+ Elf32_auxv_t *src;
+
+ /* Here it gets a bit more complicated. The format of the vector
+ entries has to be converted. The user better have provided a
+ buffer where we can store the information. While copying the data
+ we convert the format. */
+ if (unlikely ((ndx + 1) * sizeof (Elf32_auxv_t) > data_scn->d.d_size))
+ {
+ __libelf_seterrno (ELF_E_INVALID_INDEX);
+ goto out;
+ }
+
+ src = &((Elf32_auxv_t *) data_scn->d.d_buf)[ndx];
+
+ /* This might look like a simple copy operation but it's
+ not. There are zero- and sign-extensions going on. */
+ dst->a_type = src->a_type;
+ dst->a_un.a_val = src->a_un.a_val;
+ }
+ else
+ {
+ /* If this is a 64 bit object it's easy. */
+ assert (sizeof (GElf_auxv_t) == sizeof (Elf64_auxv_t));
+
+ /* The data is already in the correct form. Just make sure the
+ index is OK. */
+ if (unlikely ((ndx + 1) * sizeof (GElf_auxv_t) > data_scn->d.d_size))
+ {
+ __libelf_seterrno (ELF_E_INVALID_INDEX);
+ goto out;
+ }
+
+ *dst = ((GElf_auxv_t *) data_scn->d.d_buf)[ndx];
+ }
+
+ result = dst;
+
+ out:
+ rwlock_unlock (elf->lock);
+
+ return result;
+}
diff --git a/libelf/gelf_update_auxv.c b/libelf/gelf_update_auxv.c
new file mode 100644
index 00000000..b294ead7
--- /dev/null
+++ b/libelf/gelf_update_auxv.c
@@ -0,0 +1,135 @@
+/* Update information in dynamic table at the given index.
+ Copyright (C) 2007 Red Hat, Inc.
+ This file is part of Red Hat elfutils.
+
+ Red Hat elfutils is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by the
+ Free Software Foundation; version 2 of the License.
+
+ Red Hat elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Red Hat elfutils; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+ In addition, as a special exception, Red Hat, Inc. gives You the
+ additional right to link the code of Red Hat elfutils with code licensed
+ under any Open Source Initiative certified open source license
+ (http://www.opensource.org/licenses/index.php) which requires the
+ distribution of source code with any binary distribution and to
+ distribute linked combinations of the two. Non-GPL Code permitted under
+ this exception must only link to the code of Red Hat elfutils through
+ those well defined interfaces identified in the file named EXCEPTION
+ found in the source code files (the "Approved Interfaces"). The files
+ of Non-GPL Code may instantiate templates or use macros or inline
+ functions from the Approved Interfaces without causing the resulting
+ work to be covered by the GNU General Public License. Only Red Hat,
+ Inc. may make changes or additions to the list of Approved Interfaces.
+ Red Hat's grant of this exception is conditioned upon your not adding
+ any new exceptions. If you wish to add a new Approved Interface or
+ exception, please contact Red Hat. You must obey the GNU General Public
+ License in all respects for all of the Red Hat elfutils code and other
+ code used in conjunction with Red Hat elfutils except the Non-GPL Code
+ covered by this exception. If you modify this file, you may extend this
+ exception to your version of the file, but you are not obligated to do
+ so. If you do not wish to provide this exception without modification,
+ you must delete this exception statement from your version and license
+ this file solely under the GPL without exception.
+
+ Red Hat elfutils is an included package of the Open Invention Network.
+ An included package of the Open Invention Network is a package for which
+ Open Invention Network licensees cross-license their patents. No patent
+ license is granted, either expressly or impliedly, by designation as an
+ included package. Should you wish to participate in the Open Invention
+ Network licensing program, please visit www.openinventionnetwork.com
+ <http://www.openinventionnetwork.com>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <gelf.h>
+#include <string.h>
+
+#include "libelfP.h"
+
+
+int
+gelf_update_auxv (data, ndx, src)
+ Elf_Data *data;
+ int ndx;
+ GElf_auxv_t *src;
+{
+ Elf_Data_Scn *data_scn = (Elf_Data_Scn *) data;
+ Elf_Scn *scn;
+ int result = 0;
+
+ if (data == NULL)
+ return 0;
+
+ if (unlikely (ndx < 0))
+ {
+ __libelf_seterrno (ELF_E_INVALID_INDEX);
+ return 0;
+ }
+
+ if (unlikely (data_scn->d.d_type != ELF_T_AUXV))
+ {
+ /* The type of the data better should match. */
+ __libelf_seterrno (ELF_E_DATA_MISMATCH);
+ return 0;
+ }
+
+ scn = data_scn->s;
+ rwlock_wrlock (scn->elf->lock);
+
+ if (scn->elf->class == ELFCLASS32)
+ {
+ Elf32_auxv_t *auxv;
+
+ /* There is the possibility that the values in the input are
+ too large. */
+ if (unlikely (src->a_type > 0xffffffffll)
+ || unlikely (src->a_un.a_val > 0xffffffffull))
+ {
+ __libelf_seterrno (ELF_E_INVALID_DATA);
+ goto out;
+ }
+
+ /* Check whether we have to resize the data buffer. */
+ if (unlikely ((ndx + 1) * sizeof (Elf32_auxv_t) > data_scn->d.d_size))
+ {
+ __libelf_seterrno (ELF_E_INVALID_INDEX);
+ goto out;
+ }
+
+ auxv = &((Elf32_auxv_t *) data_scn->d.d_buf)[ndx];
+
+ auxv->a_type = src->a_type;
+ auxv->a_un.a_val = src->a_un.a_val;
+ }
+ else
+ {
+ /* Check whether we have to resize the data buffer. */
+ if (unlikely ((ndx + 1) * sizeof (Elf64_auxv_t) > data_scn->d.d_size))
+ {
+ __libelf_seterrno (ELF_E_INVALID_INDEX);
+ goto out;
+ }
+
+ ((Elf64_auxv_t *) data_scn->d.d_buf)[ndx] = *src;
+ }
+
+ result = 1;
+
+ /* Mark the section as modified. */
+ scn->flags |= ELF_F_DIRTY;
+
+ out:
+ rwlock_unlock (scn->elf->lock);
+
+ return result;
+}
diff --git a/libelf/gelf_xlate.c b/libelf/gelf_xlate.c
index f1bbdf3a..080474fd 100644
--- a/libelf/gelf_xlate.c
+++ b/libelf/gelf_xlate.c
@@ -1,5 +1,5 @@
/* Transformation functions for ELF data types.
- Copyright (C) 1998, 1999, 2000, 2002, 2004, 2005, 2006 Red Hat, Inc.
+ Copyright (C) 1998,1999,2000,2002,2004,2005,2006,2007 Red Hat, Inc.
This file is part of Red Hat elfutils.
Written by Ulrich Drepper <[email protected]>, 1998.
@@ -216,7 +216,8 @@ const xfct_t __elf_xfctstom[EV_NUM - 1][EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM]
[ELF_T_NHDR] = ElfW2(Bits, cvt_Nhdr), \
[ELF_T_SYMINFO] = ElfW2(Bits, cvt_Syminfo), \
[ELF_T_MOVE] = ElfW2(Bits, cvt_Move), \
- [ELF_T_LIB] = ElfW2(Bits, cvt_Lib)
+ [ELF_T_LIB] = ElfW2(Bits, cvt_Lib), \
+ [ELF_T_AUXV] = ElfW2(Bits, cvt_auxv_t)
define_xfcts (32),
[ELF_T_GNUHASH] = Elf32_cvt_Word
},
diff --git a/libelf/gelf_xlate.h b/libelf/gelf_xlate.h
index eec47ee6..e7659f12 100644
--- a/libelf/gelf_xlate.h
+++ b/libelf/gelf_xlate.h
@@ -1,5 +1,5 @@
/* Helper file for type conversion function generation.
- Copyright (C) 1998, 1999, 2000, 2002, 2004 Red Hat, Inc.
+ Copyright (C) 1998, 1999, 2000, 2002, 2004, 2007 Red Hat, Inc.
This file is part of Red Hat elfutils.
Contributed by Ulrich Drepper <[email protected]>, 1998.
@@ -70,6 +70,7 @@ TYPE (Dyn, LIBELFBITS)
TYPE (Syminfo, LIBELFBITS)
TYPE (Move, LIBELFBITS)
TYPE (Lib, LIBELFBITS)
+TYPE (auxv_t, LIBELFBITS)
/* Prepare for the next round. */
diff --git a/libelf/libelf.h b/libelf/libelf.h
index 2f58e4c4..a5d744cf 100644
--- a/libelf/libelf.h
+++ b/libelf/libelf.h
@@ -1,5 +1,5 @@
/* Interface for libelf.
- Copyright (C) 1998, 1999, 2000, 2002, 2004, 2005, 2006 Red Hat, Inc.
+ Copyright (C) 1998, 1999, 2000, 2002, 2004, 2005, 2006, 2007 Red Hat, Inc.
This file is part of Red Hat elfutils.
Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -83,6 +83,7 @@ typedef enum
ELF_T_MOVE, /* Elf32_Move, Elf64_Move, ... */
ELF_T_LIB, /* Elf32_Lib, Elf64_Lib, ... */
ELF_T_GNUHASH, /* GNU-style hash section. */
+ ELF_T_AUXV, /* Elf32_auxv_t, Elf64_auxv_t, ... */
/* Keep this the last entry. */
ELF_T_NUM
} Elf_Type;
diff --git a/libelf/libelf.map b/libelf/libelf.map
index 9549c317..bc597c6f 100644
--- a/libelf/libelf.map
+++ b/libelf/libelf.map
@@ -117,3 +117,9 @@ ELFUTILS_1.2 {
global:
elf_gnu_hash;
} ELFUTILS_1.1.1;
+
+ELFUTILS_1.3 {
+ global:
+ gelf_getauxv;
+ gelf_update_auxv;
+};