From owner-svn-src-stable-7@FreeBSD.ORG Sat Sep 4 12:52:53 2010 Return-Path: Delivered-To: svn-src-stable-7@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C24B510656FB; Sat, 4 Sep 2010 12:52:51 +0000 (UTC) (envelope-from kaiw@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B68238FC18; Sat, 4 Sep 2010 12:52:51 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o84CqpUc008824; Sat, 4 Sep 2010 12:52:51 GMT (envelope-from kaiw@svn.freebsd.org) Received: (from kaiw@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o84Cqp9m008807; Sat, 4 Sep 2010 12:52:51 GMT (envelope-from kaiw@svn.freebsd.org) Message-Id: <201009041252.o84Cqp9m008807@svn.freebsd.org> From: Kai Wang Date: Sat, 4 Sep 2010 12:52:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212205 - stable/7/lib/libelf X-BeenThere: svn-src-stable-7@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 7-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Sep 2010 12:52:53 -0000 Author: kaiw Date: Sat Sep 4 12:52:51 2010 New Revision: 212205 URL: http://svn.freebsd.org/changeset/base/212205 Log: MFC r210344,r210345,r210348. r210344: Avoid switching between "unsigned char" and "char" in the C code generated from "libelf_convert.m4". r210345: * Deprecate `elf_getshnum()`, `elf_getphnum()` and `elf_getshstrndx()` in favour of `elf_getshdrnum()`, `elf_getphdrnum()` and `elf_getshdrstrndx()` respectively. * Add new manual pages for `elf_getshdrstrndx()`, `elf_getphdrnum()` and `elf_getshdrnum()`. * Add a deprecation warning for `elf_getshstrndx()`, `elf_getphnum()` and `elf_getshnum()`. r210348: Move helper functions `_libelf_ar_get_{name,number,string}()` and `_libelf_ar_open()` to a new compilation unit "libelf_ar_util.c" to break the circular dependency between "elf_memory.o" and "libelf_ar.o". Added: stable/7/lib/libelf/elf_getphdrnum.3 - copied unchanged from r210345, head/lib/libelf/elf_getphdrnum.3 stable/7/lib/libelf/elf_getshdrnum.3 - copied unchanged from r210345, head/lib/libelf/elf_getshdrnum.3 stable/7/lib/libelf/elf_getshdrstrndx.3 - copied unchanged from r210345, head/lib/libelf/elf_getshdrstrndx.3 stable/7/lib/libelf/libelf_ar_util.c - copied unchanged from r210348, head/lib/libelf/libelf_ar_util.c Modified: stable/7/lib/libelf/Makefile stable/7/lib/libelf/Version.map stable/7/lib/libelf/_libelf.h stable/7/lib/libelf/elf_getphnum.3 stable/7/lib/libelf/elf_getshnum.3 stable/7/lib/libelf/elf_getshstrndx.3 stable/7/lib/libelf/elf_phnum.c stable/7/lib/libelf/elf_shnum.c stable/7/lib/libelf/elf_shstrndx.c stable/7/lib/libelf/libelf.h stable/7/lib/libelf/libelf_ar.c stable/7/lib/libelf/libelf_convert.m4 Directory Properties: stable/7/lib/libelf/ (props changed) Modified: stable/7/lib/libelf/Makefile ============================================================================== --- stable/7/lib/libelf/Makefile Sat Sep 4 12:52:44 2010 (r212204) +++ stable/7/lib/libelf/Makefile Sat Sep 4 12:52:51 2010 (r212205) @@ -44,6 +44,7 @@ SRCS= elf_begin.c \ libelf_align.c \ libelf_allocate.c \ libelf_ar.c \ + libelf_ar_util.c \ libelf_checksum.c \ libelf_data.c \ libelf_ehdr.c \ @@ -65,7 +66,8 @@ WARNS?= 6 MAN= elf.3 \ elf_begin.3 \ elf_cntl.3 \ - elf_end.3 elf_errmsg.3 \ + elf_end.3 \ + elf_errmsg.3 \ elf_fill.3 \ elf_flagdata.3 \ elf_getarhdr.3 \ @@ -74,8 +76,11 @@ MAN= elf.3 \ elf_getdata.3 \ elf_getident.3 \ elf_getscn.3 \ + elf_getphdrnum.3 \ elf_getphnum.3 \ + elf_getshdrnum.3 \ elf_getshnum.3 \ + elf_getshdrstrndx.3 \ elf_getshstrndx.3 \ elf_hash.3 \ elf_kind.3 \ Modified: stable/7/lib/libelf/Version.map ============================================================================== --- stable/7/lib/libelf/Version.map Sat Sep 4 12:52:44 2010 (r212204) +++ stable/7/lib/libelf/Version.map Sat Sep 4 12:52:51 2010 (r212205) @@ -39,8 +39,11 @@ global: elf_getdata; elf_getident; elf_getscn; + elf_getphdrnum; elf_getphnum; + elf_getshdrnum; elf_getshnum; + elf_getshdrstrndx; elf_getshstrndx; elf_hash; elf_kind; Modified: stable/7/lib/libelf/_libelf.h ============================================================================== --- stable/7/lib/libelf/_libelf.h Sat Sep 4 12:52:44 2010 (r212204) +++ stable/7/lib/libelf/_libelf.h Sat Sep 4 12:52:51 2010 (r212205) @@ -165,6 +165,10 @@ Elf_Scn *_libelf_allocate_scn(Elf *_e, s Elf_Arhdr *_libelf_ar_gethdr(Elf *_e); Elf *_libelf_ar_open(Elf *_e); 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); +char *_libelf_ar_get_string(const char *_buf, size_t _sz, int _rawname); +char *_libelf_ar_get_name(char *_buf, size_t _sz, Elf *_e); +int _libelf_ar_get_number(char *_buf, size_t _sz, int _base, size_t *_ret); Elf_Arsym *_libelf_ar_process_symtab(Elf *_ar, size_t *_dst); unsigned long _libelf_checksum(Elf *_e, int _elfclass); void *_libelf_ehdr(Elf *_e, int _elfclass, int _allocate); Copied: stable/7/lib/libelf/elf_getphdrnum.3 (from r210345, head/lib/libelf/elf_getphdrnum.3) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/7/lib/libelf/elf_getphdrnum.3 Sat Sep 4 12:52:51 2010 (r212205, copy of r210345, head/lib/libelf/elf_getphdrnum.3) @@ -0,0 +1,86 @@ +.\" Copyright (c) 2006,2008 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. +.\" +.\" $FreeBSD$ +.\" +.Dd August 5, 2009 +.Os +.Dt ELF_GETPHDRNUM 3 +.Sh NAME +.Nm elf_getphdrnum +.Nd return the number of program headers in an ELF file +.Sh LIBRARY +.Lb libelf +.Sh SYNOPSIS +.In libelf.h +.Ft int +.Fn elf_getphdrnum "Elf *elf" "size_t *phnum" +.Sh DESCRIPTION +Function +.Fn elf_getphdrnum +retrieves the number of ELF program headers associated with descriptor +.Ar elf +and stores it into the location pointed to by argument +.Ar phnum . +.Pp +This routine allows applications to uniformly process both normal ELF +objects and ELF objects that use extended numbering. +.Pp +.Sh RETURN VALUES +Function +.Fn elf_getphdrnum +returns a zero value if successful, or -1 in case of an error. +.Sh ERRORS +Function +.Fn elf_getphnum +can fail with the following errors: +.Bl -tag -width "[ELF_E_RESOURCE]" +.It Bq Er ELF_E_ARGUMENT +A NULL value was passed in for argument +.Ar elf . +.It Bq Er ELF_E_ARGUMENT +Argument +.Ar elf +was not for an ELF file. +.It Bq Er ELF_E_ARGUMENT +Argument +.Ar elf +lacks an ELF Executable Header. +.It Bq Er ELF_E_HEADER +The ELF Executable Header associated with argument +.Ar elf +was corrupt. +.It Bq Er ELF_E_SECTION +The section header at index +.Dv SHN_UNDEF +was corrupt. +.El +.Sh SEE ALSO +.Xr elf 3 , +.Xr elf32_getehdr 3 , +.Xr elf64_getehdr 3 , +.Xr elf_getident 3 , +.Xr elf_getshdrnum 3 , +.Xr elf_getshdrstrndx 3 , +.Xr gelf 3 , +.Xr gelf_getehdr 3 Modified: stable/7/lib/libelf/elf_getphnum.3 ============================================================================== --- stable/7/lib/libelf/elf_getphnum.3 Sat Sep 4 12:52:44 2010 (r212204) +++ stable/7/lib/libelf/elf_getphnum.3 Sat Sep 4 12:52:51 2010 (r212205) @@ -23,7 +23,7 @@ .\" .\" $FreeBSD$ .\" -.Dd December 16, 2006 +.Dd August 5, 2009 .Os .Dt ELF_GETPHNUM 3 .Sh NAME @@ -36,6 +36,11 @@ .Ft int .Fn elf_getphnum "Elf *elf" "size_t *phnum" .Sh DESCRIPTION +This function is deprecated. +Please use function +.Xr elf_getphdrnum 3 +instead. +.Pp Function .Fn elf_getphnum retrieves the number of ELF program headers associated with descriptor @@ -81,7 +86,8 @@ was corrupt. .Xr elf32_getehdr 3 , .Xr elf64_getehdr 3 , .Xr elf_getident 3 , -.Xr elf_getshnum 3 , -.Xr elf_getshstrndx 3 , +.Xr elf_getphdrnum 3 , +.Xr elf_getshdrnum 3 , +.Xr elf_getshdrstrndx 3 , .Xr gelf 3 , .Xr gelf_getehdr 3 Copied: stable/7/lib/libelf/elf_getshdrnum.3 (from r210345, head/lib/libelf/elf_getshdrnum.3) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/7/lib/libelf/elf_getshdrnum.3 Sat Sep 4 12:52:51 2010 (r212205, copy of r210345, head/lib/libelf/elf_getshdrnum.3) @@ -0,0 +1,78 @@ +.\" Copyright (c) 2006,2008 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. +.\" +.\" $FreeBSD$ +.\" +.Dd August 4, 2009 +.Os +.Dt ELF_GETSHDRNUM 3 +.Sh NAME +.Nm elf_getshdrnum +.Nd return the number of sections in an ELF file +.Sh LIBRARY +.Lb libelf +.Sh SYNOPSIS +.In libelf.h +.Ft int +.Fn elf_getshdrnum "Elf *elf" "size_t *shnum" +.Sh DESCRIPTION +Function +.Fn elf_getshdrnum +retrieves the number of ELF sections associated with descriptor +.Ar elf +and stores it into the location pointed to by argument +.Ar shnum . +.Pp +This routine allows applications to uniformly process both normal ELF +objects, and ELF objects that use extended section numbering. +.Pp +.Sh RETURN VALUES +Function +.Fn elf_getshdrnum +returns zero value if successful, or -1 in case of an error. +.Sh ERRORS +Function +.Fn elf_getshdrnum +can fail with the following errors: +.Bl -tag -width "[ELF_E_RESOURCE]" +.It Bq Er ELF_E_ARGUMENT +A NULL value was passed in for argument +.Ar elf . +.It Bq Er ELF_E_ARGUMENT +Argument +.Ar elf +was not for an ELF file. +.It Bq Er ELF_E_ARGUMENT +Argument +.Ar elf +lacks an ELF Executable header. +.El +.Sh SEE ALSO +.Xr elf 3 , +.Xr elf32_getehdr 3 , +.Xr elf64_getehdr 3 , +.Xr elf_getident 3 , +.Xr elf_getphdrnum 3 , +.Xr elf_getshdrstrndx 3 , +.Xr gelf 3 , +.Xr gelf_getehdr 3 Copied: stable/7/lib/libelf/elf_getshdrstrndx.3 (from r210345, head/lib/libelf/elf_getshdrstrndx.3) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/7/lib/libelf/elf_getshdrstrndx.3 Sat Sep 4 12:52:51 2010 (r212205, copy of r210345, head/lib/libelf/elf_getshdrstrndx.3) @@ -0,0 +1,79 @@ +.\" Copyright (c) 2006,2008 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. +.\" +.\" $FreeBSD$ +.\" +.Dd August 5, 2009 +.Os +.Dt ELF_GETSHDRSTRNDX 3 +.Sh NAME +.Nm elf_getshdrstrndx +.Nd retrieve the index of the section name string table +.Sh LIBRARY +.Lb libelf +.Sh SYNOPSIS +.In libelf.h +.Ft int +.Fn elf_getshdrstrndx "Elf *elf" "size_t *ndxptr" +.Sh DESCRIPTION +Function +.Fn elf_getshdrstrndx +retrieves the section index of the string table containing section +names from descriptor +.Ar elf +and stores it into the location pointed to by argument +.Ar ndxptr . +.Pp +This function allow applications to process both normal ELF +objects and ELF objects that use extended section numbering uniformly. +.Pp +.Sh RETURN VALUES +These functions return zero if successful, or -1 in case of an error. +.Sh ERRORS +These functions can fail with the following errors: +.Bl -tag -width "[ELF_E_RESOURCE]" +.It Bq Er ELF_E_ARGUMENT +A NULL value was passed in for argument +.Ar elf . +.It Bq Er ELF_E_ARGUMENT +Argument +.Ar elf +was not for an ELF file. +.It Bq Er ELF_E_ARGUMENT +Argument +.Ar elf +lacks an ELF Executable header. +.It Bq Er ELF_E_ARGUMENT +Argument +.Ar ndx +contained a value in the reserved range of section indices. +.El +.Sh SEE ALSO +.Xr elf 3 , +.Xr elf32_getehdr 3 , +.Xr elf64_getehdr 3 , +.Xr elf_getident 3 , +.Xr elf_getphdrnum 3 , +.Xr elf_getshdrnum 3 , +.Xr gelf 3 , +.Xr gelf_getehdr 3 Modified: stable/7/lib/libelf/elf_getshnum.3 ============================================================================== --- stable/7/lib/libelf/elf_getshnum.3 Sat Sep 4 12:52:44 2010 (r212204) +++ stable/7/lib/libelf/elf_getshnum.3 Sat Sep 4 12:52:51 2010 (r212205) @@ -23,7 +23,7 @@ .\" .\" $FreeBSD$ .\" -.Dd October 31, 2006 +.Dd August 5, 2009 .Os .Dt ELF_GETSHNUM 3 .Sh NAME @@ -36,6 +36,11 @@ .Ft int .Fn elf_getshnum "Elf *elf" "size_t *shnum" .Sh DESCRIPTION +This function is deprecated. +Please use +.Xr elf_getshdrnum 3 +instead. +.Pp Function .Fn elf_getshnum retrieves the number of ELF sections associated with descriptor @@ -73,6 +78,7 @@ lacks an ELF Executable header. .Xr elf32_getehdr 3 , .Xr elf64_getehdr 3 , .Xr elf_getident 3 , -.Xr elf_getshstrndx 3 , +.Xr elf_getphdrnum 3 , +.Xr elf_getshdrstrndx 3 , .Xr gelf 3 , .Xr gelf_getehdr 3 Modified: stable/7/lib/libelf/elf_getshstrndx.3 ============================================================================== --- stable/7/lib/libelf/elf_getshstrndx.3 Sat Sep 4 12:52:44 2010 (r212204) +++ stable/7/lib/libelf/elf_getshstrndx.3 Sat Sep 4 12:52:51 2010 (r212205) @@ -23,7 +23,7 @@ .\" .\" $FreeBSD$ .\" -.Dd October 31, 2006 +.Dd August 5, 2009 .Os .Dt ELF_GETSHSTRNDX 3 .Sh NAME @@ -46,6 +46,12 @@ names from descriptor .Ar elf and stores it into the location pointed to by argument .Ar ndxptr . +Function +.Fn elf_getshstrndx +is deprecated. +Please use +.Xr elf_getshdrstrndx 3 +instead. .Pp Function .Fn elf_setshstrndx @@ -82,6 +88,7 @@ contained a value in the reserved range .Xr elf32_getehdr 3 , .Xr elf64_getehdr 3 , .Xr elf_getident 3 , -.Xr elf_getshnum 3 , +.Xr elf_getphdrnum 3 , +.Xr elf_getshdrnum 3 , .Xr gelf 3 , .Xr gelf_getehdr 3 Modified: stable/7/lib/libelf/elf_phnum.c ============================================================================== --- stable/7/lib/libelf/elf_phnum.c Sat Sep 4 12:52:44 2010 (r212204) +++ stable/7/lib/libelf/elf_phnum.c Sat Sep 4 12:52:51 2010 (r212205) @@ -32,8 +32,8 @@ __FBSDID("$FreeBSD$"); #include "_libelf.h" -int -elf_getphnum(Elf *e, size_t *phnum) +static int +_libelf_getphdrnum(Elf *e, size_t *phnum) { void *eh; int ec; @@ -41,13 +41,26 @@ elf_getphnum(Elf *e, size_t *phnum) if (e == NULL || e->e_kind != ELF_K_ELF || ((ec = e->e_class) != ELFCLASS32 && ec != ELFCLASS64)) { LIBELF_SET_ERROR(ARGUMENT, 0); - return (0); + return (-1); } if ((eh = _libelf_ehdr(e, ec, 0)) == NULL) - return (0); + return (-1); *phnum = e->e_u.e_elf.e_nphdr; - return (1); + return (0); +} + +int +elf_getphdrnum(Elf *e, size_t *phnum) +{ + return (_libelf_getphdrnum(e, phnum)); +} + +/* Deprecated API */ +int +elf_getphnum(Elf *e, size_t *phnum) +{ + return (_libelf_getphdrnum(e, phnum) >= 0); } Modified: stable/7/lib/libelf/elf_shnum.c ============================================================================== --- stable/7/lib/libelf/elf_shnum.c Sat Sep 4 12:52:44 2010 (r212204) +++ stable/7/lib/libelf/elf_shnum.c Sat Sep 4 12:52:51 2010 (r212205) @@ -32,8 +32,8 @@ __FBSDID("$FreeBSD$"); #include "_libelf.h" -int -elf_getshnum(Elf *e, size_t *shnum) +static int +_libelf_getshdrnum(Elf *e, size_t *shnum) { void *eh; int ec; @@ -41,13 +41,26 @@ elf_getshnum(Elf *e, size_t *shnum) if (e == NULL || e->e_kind != ELF_K_ELF || ((ec = e->e_class) != ELFCLASS32 && ec != ELFCLASS64)) { LIBELF_SET_ERROR(ARGUMENT, 0); - return (0); + return (-1); } if ((eh = _libelf_ehdr(e, ec, 0)) == NULL) - return (0); + return (-1); *shnum = e->e_u.e_elf.e_nscn; - return (1); + return (0); +} + +int +elf_getshdrnum(Elf *e, size_t *shnum) +{ + return (_libelf_getshdrnum(e, shnum)); +} + +/* Deprecated API. */ +int +elf_getshnum(Elf *e, size_t *shnum) +{ + return (_libelf_getshdrnum(e, shnum) >= 0); } Modified: stable/7/lib/libelf/elf_shstrndx.c ============================================================================== --- stable/7/lib/libelf/elf_shstrndx.c Sat Sep 4 12:52:44 2010 (r212204) +++ stable/7/lib/libelf/elf_shstrndx.c Sat Sep 4 12:52:51 2010 (r212205) @@ -32,8 +32,8 @@ __FBSDID("$FreeBSD$"); #include "_libelf.h" -int -elf_getshstrndx(Elf *e, size_t *strndx) +static int +_libelf_getshdrstrndx(Elf *e, size_t *strndx) { void *eh; int ec; @@ -41,15 +41,27 @@ elf_getshstrndx(Elf *e, size_t *strndx) if (e == NULL || e->e_kind != ELF_K_ELF || ((ec = e->e_class) != ELFCLASS32 && ec != ELFCLASS64)) { LIBELF_SET_ERROR(ARGUMENT, 0); - return (0); + return (-1); } if ((eh = _libelf_ehdr(e, ec, 0)) == NULL) - return (0); + return (-1); *strndx = e->e_u.e_elf.e_strndx; - return (1); + return (0); +} + +int +elf_getshdrstrndx(Elf *e, size_t *strndx) +{ + return (_libelf_getshdrstrndx(e, strndx)); +} + +int +elf_getshstrndx(Elf *e, size_t *strndx) /* Deprecated API. */ +{ + return (_libelf_getshdrstrndx(e, strndx) >= 0); } int Modified: stable/7/lib/libelf/libelf.h ============================================================================== --- stable/7/lib/libelf/libelf.h Sat Sep 4 12:52:44 2010 (r212204) +++ stable/7/lib/libelf/libelf.h Sat Sep 4 12:52:51 2010 (r212205) @@ -192,10 +192,13 @@ Elf_Arsym *elf_getarsym(Elf *_elf, size_ off_t elf_getbase(Elf *_elf); Elf_Data *elf_getdata(Elf_Scn *, Elf_Data *); char *elf_getident(Elf *_elf, size_t *_ptr); -int elf_getphnum(Elf *_elf, size_t *_dst); +int elf_getphdrnum(Elf *_elf, size_t *_dst); +int elf_getphnum(Elf *_elf, size_t *_dst); /* Deprecated */ Elf_Scn *elf_getscn(Elf *_elf, size_t _index); -int elf_getshnum(Elf *_elf, size_t *_dst); -int elf_getshstrndx(Elf *_elf, size_t *_dst); +int elf_getshdrnum(Elf *_elf, size_t *_dst); +int elf_getshnum(Elf *_elf, size_t *_dst); /* Deprecated */ +int elf_getshdrstrndx(Elf *_elf, size_t *_dst); +int elf_getshstrndx(Elf *_elf, size_t *_dst); /* Deprecated */ unsigned long elf_hash(const char *_name); Elf_Kind elf_kind(Elf *_elf); Elf *elf_memory(char *_image, size_t _size); Modified: stable/7/lib/libelf/libelf_ar.c ============================================================================== --- stable/7/lib/libelf/libelf_ar.c Sat Sep 4 12:52:44 2010 (r212204) +++ stable/7/lib/libelf/libelf_ar.c Sat Sep 4 12:52:51 2010 (r212205) @@ -72,145 +72,6 @@ __FBSDID("$FreeBSD$"); * they must be the very first objects and in that order. */ -/* - * Convert a string bounded by `start' and `start+sz' (exclusive) to a - * number in the specified base. - */ -static int -_libelf_ar_get_number(char *s, size_t sz, int base, size_t *ret) -{ - int c, v; - size_t r; - char *e; - - assert(base <= 10); - - e = s + sz; - - /* skip leading blanks */ - for (;s < e && (c = *s) == ' '; s++) - ; - - r = 0L; - for (;s < e; s++) { - if ((c = *s) == ' ') - break; - if (c < '0' || c > '9') - return (0); - v = c - '0'; - if (v >= base) /* Illegal digit. */ - break; - r *= base; - r += v; - } - - *ret = r; - - return (1); -} - -/* - * Retrieve a string from a name field. If `rawname' is set, leave - * ar(1) control characters in. - */ -static char * -_libelf_ar_get_string(const char *buf, size_t bufsize, int rawname) -{ - const char *q; - char *r; - size_t sz; - - if (rawname) - sz = bufsize + 1; - else { - /* Skip back over trailing blanks. */ - for (q = buf + bufsize - 1; q >= buf && *q == ' '; --q) - ; - - if (q < buf) { - /* - * If the input buffer only had blanks in it, - * return a zero-length string. - */ - buf = ""; - sz = 1; - } else { - /* - * Remove the trailing '/' character, but only - * if the name isn't one of the special names - * "/" and "//". - */ - if (q > buf + 1 || - (q == (buf + 1) && *buf != '/')) - q--; - - sz = q - buf + 2; /* Space for a trailing NUL. */ - } - } - - if ((r = malloc(sz)) == NULL) { - LIBELF_SET_ERROR(RESOURCE, 0); - return (NULL); - } - - (void) strncpy(r, buf, sz); - r[sz - 1] = '\0'; - - return (r); -} - -/* - * Retrieve the full name of the archive member. - */ -static char * -_libelf_ar_get_name(char *buf, size_t bufsize, Elf *e) -{ - char c, *q, *r, *s; - size_t len; - size_t offset; - - assert(e->e_kind == ELF_K_AR); - - if (buf[0] == '/' && (c = buf[1]) >= '0' && c <= '9') { - /* - * The value in field ar_name is a decimal offset into - * the archive string table where the actual name - * resides. - */ - if (_libelf_ar_get_number(buf + 1, bufsize - 1, 10, - &offset) == 0) { - LIBELF_SET_ERROR(ARCHIVE, 0); - return (NULL); - } - - if (offset > e->e_u.e_ar.e_rawstrtabsz) { - LIBELF_SET_ERROR(ARCHIVE, 0); - return (NULL); - } - - s = q = e->e_u.e_ar.e_rawstrtab + offset; - r = e->e_u.e_ar.e_rawstrtab + e->e_u.e_ar.e_rawstrtabsz; - - for (s = q; s < r && *s != '/'; s++) - ; - len = s - q + 1; /* space for the trailing NUL */ - - if ((s = malloc(len)) == NULL) { - LIBELF_SET_ERROR(RESOURCE, 0); - return (NULL); - } - - (void) strncpy(s, q, len); - s[len - 1] = '\0'; - - return (s); - } - - /* - * Normal 'name' - */ - return (_libelf_ar_get_string(buf, bufsize, 0)); -} Elf_Arhdr * @@ -323,79 +184,6 @@ _libelf_ar_open_member(int fd, Elf_Cmd c return (e); } -Elf * -_libelf_ar_open(Elf *e) -{ - int i; - char *s, *end; - size_t sz; - struct ar_hdr arh; - - e->e_kind = ELF_K_AR; - e->e_u.e_ar.e_nchildren = 0; - e->e_u.e_ar.e_next = (off_t) -1; - - /* - * Look for special members. - */ - - s = e->e_rawfile + SARMAG; - end = e->e_rawfile + e->e_rawsize; - - assert(e->e_rawsize > 0); - - /* - * Look for magic names "/ " and "// " in the first two entries - * of the archive. - */ - for (i = 0; i < 2; i++) { - - if (s + sizeof(arh) > end) { - LIBELF_SET_ERROR(ARCHIVE, 0); - return (NULL); - } - - (void) memcpy(&arh, s, sizeof(arh)); - - if (arh.ar_fmag[0] != '`' || arh.ar_fmag[1] != '\n') { - LIBELF_SET_ERROR(ARCHIVE, 0); - return (NULL); - } - - if (arh.ar_name[0] != '/') /* not a special symbol */ - break; - - if (_libelf_ar_get_number(arh.ar_size, sizeof(arh.ar_size), 10, &sz) == 0) { - LIBELF_SET_ERROR(ARCHIVE, 0); - return (NULL); - } - - assert(sz > 0); - - s += sizeof(arh); - - if (arh.ar_name[1] == ' ') { /* "/ " => symbol table */ - - e->e_u.e_ar.e_rawsymtab = s; - e->e_u.e_ar.e_rawsymtabsz = sz; - - } else if (arh.ar_name[1] == '/' && arh.ar_name[2] == ' ') { - - /* "// " => string table for long file names */ - e->e_u.e_ar.e_rawstrtab = s; - e->e_u.e_ar.e_rawstrtabsz = sz; - } - - sz = LIBELF_ADJUST_AR_SIZE(sz); - - s += sz; - } - - e->e_u.e_ar.e_next = (off_t) (s - e->e_rawfile); - - return (e); -} - /* * An ar(1) symbol table has the following layout: * Copied: stable/7/lib/libelf/libelf_ar_util.c (from r210348, head/lib/libelf/libelf_ar_util.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/7/lib/libelf/libelf_ar_util.c Sat Sep 4 12:52:51 2010 (r212205, copy of r210348, head/lib/libelf/libelf_ar_util.c) @@ -0,0 +1,253 @@ +/*- + * Copyright (c) 2006,2009 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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include + +#include "_libelf.h" + +/* + * Convert a string bounded by `start' and `start+sz' (exclusive) to a + * number in the specified base. + */ +int +_libelf_ar_get_number(char *s, size_t sz, int base, size_t *ret) +{ + int c, v; + size_t r; + char *e; + + assert(base <= 10); + + e = s + sz; + + /* skip leading blanks */ + for (;s < e && (c = *s) == ' '; s++) + ; + + r = 0L; + for (;s < e; s++) { + if ((c = *s) == ' ') + break; + if (c < '0' || c > '9') + return (0); + v = c - '0'; + if (v >= base) /* Illegal digit. */ + break; + r *= base; + r += v; + } + + *ret = r; + + return (1); +} + +/* + * Retrieve a string from a name field. If `rawname' is set, leave + * ar(1) control characters in. + */ +char * +_libelf_ar_get_string(const char *buf, size_t bufsize, int rawname) +{ + const char *q; + char *r; + size_t sz; + + if (rawname) + sz = bufsize + 1; + else { + /* Skip back over trailing blanks. */ + for (q = buf + bufsize - 1; q >= buf && *q == ' '; --q) + ; + + if (q < buf) { + /* + * If the input buffer only had blanks in it, + * return a zero-length string. + */ + buf = ""; + sz = 1; + } else { + /* + * Remove the trailing '/' character, but only + * if the name isn't one of the special names + * "/" and "//". + */ + if (q > buf + 1 || + (q == (buf + 1) && *buf != '/')) + q--; + + sz = q - buf + 2; /* Space for a trailing NUL. */ + } + } + + if ((r = malloc(sz)) == NULL) { + LIBELF_SET_ERROR(RESOURCE, 0); + return (NULL); + } + + (void) strncpy(r, buf, sz); + r[sz - 1] = '\0'; + + return (r); +} + +/* + * Retrieve the full name of the archive member. + */ +char * +_libelf_ar_get_name(char *buf, size_t bufsize, Elf *e) +{ + char c, *q, *r, *s; + size_t len; + size_t offset; + + assert(e->e_kind == ELF_K_AR); + + if (buf[0] == '/' && (c = buf[1]) >= '0' && c <= '9') { + /* + * The value in field ar_name is a decimal offset into + * the archive string table where the actual name + * resides. + */ + if (_libelf_ar_get_number(buf + 1, bufsize - 1, 10, + &offset) == 0) { + LIBELF_SET_ERROR(ARCHIVE, 0); + return (NULL); + } + + if (offset > e->e_u.e_ar.e_rawstrtabsz) { + LIBELF_SET_ERROR(ARCHIVE, 0); + return (NULL); + } + + s = q = e->e_u.e_ar.e_rawstrtab + offset; + r = e->e_u.e_ar.e_rawstrtab + e->e_u.e_ar.e_rawstrtabsz; + + for (s = q; s < r && *s != '/'; s++) + ; + len = s - q + 1; /* space for the trailing NUL */ + + if ((s = malloc(len)) == NULL) { + LIBELF_SET_ERROR(RESOURCE, 0); + return (NULL); + } + + (void) strncpy(s, q, len); + s[len - 1] = '\0'; + + return (s); + } + + /* + * Normal 'name' + */ + return (_libelf_ar_get_string(buf, bufsize, 0)); +} + +/* + * Open an 'ar' archive. + */ +Elf * +_libelf_ar_open(Elf *e) +{ + int i; + char *s, *end; + size_t sz; + struct ar_hdr arh; + + e->e_kind = ELF_K_AR; + e->e_u.e_ar.e_nchildren = 0; + e->e_u.e_ar.e_next = (off_t) -1; + + /* + * Look for special members. + */ + + s = e->e_rawfile + SARMAG; + end = e->e_rawfile + e->e_rawsize; + + assert(e->e_rawsize > 0); + + /* + * Look for magic names "/ " and "// " in the first two entries + * of the archive. + */ + for (i = 0; i < 2; i++) { + + if (s + sizeof(arh) > end) { + LIBELF_SET_ERROR(ARCHIVE, 0); + return (NULL); *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***