Update ELF Tool Chain to upstream r3769

This contains many small bugfixes and documentation improvements.

Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Ed Maste 2019-12-05 13:20:15 +00:00
commit d003e0d7fe
71 changed files with 556 additions and 290 deletions

View File

@ -0,0 +1,22 @@
freebsd_11_task:
freebsd_instance:
image: freebsd-11-2-release-amd64
install_script: pkg install -y git py27-yaml
script:
- fetch http://tetworks.opengroup.org/downloads/38/software/Sources/3.8/tet3.8-src.tar.gz
- tar -x -C test/tet -f tet3.8-src.tar.gz
- make
debian_stable_task:
container:
image: debian:stable
setup_script:
- apt-get update
- apt-get install -y
binutils bison bmake curl flex g++ gcc git
libarchive-dev libbsd-dev libc6-dev libexpat1-dev lsb-release
m4 perl python-yaml sharutils zlib1g-dev
script:
- curl -O http://tetworks.opengroup.org/downloads/38/software/Sources/3.8/tet3.8-src.tar.gz
- tar -x -C test/tet -z -f tet3.8-src.tar.gz
- bmake

View File

@ -62,12 +62,12 @@ The project uses subversion_ for its version control system.
The subversion branch for the current set of sources may be accessed
at the following URL::
https://elftoolchain.svn.sourceforge.net/svnroot/elftoolchain/trunk
https://sourceforge.net/p/elftoolchain/code/HEAD/tree/trunk/
The project's source tree may be checked out from its repository by
using the ``svn checkout`` command::
% svn checkout https://elftoolchain.svn.sourceforge.net/svnroot/elftoolchain/trunk
% svn checkout https://svn.code.sf.net/p/elftoolchain/code/trunk
Checked-out sources may be kept upto-date by running ``svn update``
inside the source directory::
@ -105,10 +105,10 @@ The project's developers may be contacted using the mailing list:
Reporting Bugs
--------------
Please use our `Trac instance`_ for viewing existing bug reports and
Please use our `bug tracker`_ for viewing existing bug reports and
for submitting new bug reports.
.. _`Trac instance`: http://sourceforge.net/apps/trac/elftoolchain/report
.. _`bug tracker`: https://sourceforge.net/p/elftoolchain/tickets/
Additional Information
@ -119,7 +119,7 @@ website`_.
.. _project website: http://elftoolchain.sourceforge.net/
.. $Id: README.rst 3656 2018-12-26 09:46:24Z jkoshy $
.. $Id: README.rst 3677 2019-02-11 09:37:09Z jkoshy $
.. Local Variables:
.. mode: rst

View File

@ -42,7 +42,7 @@
#include "uthash.h"
#include "_elftc.h"
ELFTC_VCSID("$Id: addr2line.c 3544 2017-06-05 14:51:44Z emaste $");
ELFTC_VCSID("$Id: addr2line.c 3499 2016-11-25 16:06:29Z emaste $");
struct Func {
char *name;

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: elfdefinitions.h 3515 2017-01-24 22:04:22Z emaste $
* $Id: elfdefinitions.h 3769 2019-06-29 15:15:02Z emaste $
*/
/*
@ -72,7 +72,39 @@ _ELF_DEFINE_DF(DF_TEXTREL, 0x4, \
_ELF_DEFINE_DF(DF_BIND_NOW, 0x8, \
"process relocation entries at load time") \
_ELF_DEFINE_DF(DF_STATIC_TLS, 0x10, \
"uses static thread-local storage")
"uses static thread-local storage") \
_ELF_DEFINE_DF(DF_1_BIND_NOW, 0x1, \
"process relocation entries at load time") \
_ELF_DEFINE_DF(DF_1_GLOBAL, 0x2, \
"unused") \
_ELF_DEFINE_DF(DF_1_GROUP, 0x4, \
"object is a member of a group") \
_ELF_DEFINE_DF(DF_1_NODELETE, 0x8, \
"object cannot be deleted from a process") \
_ELF_DEFINE_DF(DF_1_LOADFLTR, 0x10, \
"immediate load filtees") \
_ELF_DEFINE_DF(DF_1_INITFIRST, 0x20, \
"initialize object first") \
_ELF_DEFINE_DF(DF_1_NOOPEN, 0x40, \
"disallow dlopen()") \
_ELF_DEFINE_DF(DF_1_ORIGIN, 0x80, \
"object being loaded may refer to $ORIGIN") \
_ELF_DEFINE_DF(DF_1_DIRECT, 0x100, \
"direct bindings enabled") \
_ELF_DEFINE_DF(DF_1_INTERPOSE, 0x400, \
"object is interposer") \
_ELF_DEFINE_DF(DF_1_NODEFLIB, 0x800, \
"ignore default library search path") \
_ELF_DEFINE_DF(DF_1_NODUMP, 0x1000, \
"disallow dldump()") \
_ELF_DEFINE_DF(DF_1_CONFALT, 0x2000, \
"object is a configuration alternative") \
_ELF_DEFINE_DF(DF_1_ENDFILTEE, 0x4000, \
"filtee terminates filter search") \
_ELF_DEFINE_DF(DF_1_DISPRELDNE, 0x8000, \
"displacement relocation done") \
_ELF_DEFINE_DF(DF_1_DISPRELPND, 0x10000, \
"displacement relocation pending")
#undef _ELF_DEFINE_DF
#define _ELF_DEFINE_DF(N, V, DESCR) N = V ,
enum {
@ -2464,7 +2496,10 @@ _ELF_DEFINE_NT(NT_PSTATUS, 10, "Linux process status") \
_ELF_DEFINE_NT(NT_FPREGS, 12, "Linux floating point regset") \
_ELF_DEFINE_NT(NT_PSINFO, 13, "Linux process information") \
_ELF_DEFINE_NT(NT_LWPSTATUS, 16, "Linux lwpstatus_t type") \
_ELF_DEFINE_NT(NT_LWPSINFO, 17, "Linux lwpinfo_t type")
_ELF_DEFINE_NT(NT_LWPSINFO, 17, "Linux lwpinfo_t type") \
_ELF_DEFINE_NT(NT_FREEBSD_NOINIT_TAG, 2, "FreeBSD no .init tag") \
_ELF_DEFINE_NT(NT_FREEBSD_ARCH_TAG, 3, "FreeBSD arch tag") \
_ELF_DEFINE_NT(NT_FREEBSD_FEATURE_CTL, 4, "FreeBSD feature control")
#undef _ELF_DEFINE_NT
#define _ELF_DEFINE_NT(N, V, DESCR) N = V ,
@ -2822,7 +2857,8 @@ typedef struct {
#define ELF64_R_SYM(I) ((I) >> 32)
#define ELF64_R_TYPE(I) ((I) & 0xFFFFFFFFUL)
#define ELF64_R_INFO(S,T) (((S) << 32) + ((T) & 0xFFFFFFFFUL))
#define ELF64_R_INFO(S,T) \
(((Elf64_Xword) (S) << 32) + ((T) & 0xFFFFFFFFUL))
/*
* Symbol versioning structures.

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# $Id: native-elf-format 3650 2018-11-25 12:06:28Z jkoshy $
# $Id: native-elf-format 3735 2019-04-25 19:44:47Z jkoshy $
#
# Find the native ELF format for a host platform by compiling a
# test object and examining the resulting object.
@ -37,6 +37,8 @@ $1 ~ "Machine:" {
elfarch = "EM_MIPS";
} else if (match($0, ".*[xX]86[-_]64")) {
elfarch = "EM_X86_64";
} else if (match($0, "PowerPC64")) {
elfarch = "EM_PPC64";
} else {
elfarch = "unknown";
}

View File

@ -36,7 +36,7 @@
#include "elfcopy.h"
ELFTC_VCSID("$Id: ascii.c 3487 2016-08-24 18:12:08Z emaste $");
ELFTC_VCSID("$Id: ascii.c 3757 2019-06-28 01:15:28Z emaste $");
static void append_data(struct section *s, const void *buf, size_t sz);
static char hex_digit(uint8_t n);

View File

@ -36,7 +36,7 @@
#include "elfcopy.h"
ELFTC_VCSID("$Id: binary.c 3611 2018-04-16 21:35:18Z jkoshy $");
ELFTC_VCSID("$Id: binary.c 3757 2019-06-28 01:15:28Z emaste $");
/*
* Convert ELF object to `binary'. Sections with SHF_ALLOC flag set

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: elfcopy.h 3615 2018-05-17 04:12:24Z kaiwang27 $
* $Id: elfcopy.h 3757 2019-06-28 01:15:28Z emaste $
*/
#include <sys/queue.h>

View File

@ -39,7 +39,7 @@
#include "elfcopy.h"
ELFTC_VCSID("$Id: main.c 3577 2017-09-14 02:19:42Z emaste $");
ELFTC_VCSID("$Id: main.c 3757 2019-06-28 01:15:28Z emaste $");
enum options
{

View File

@ -34,7 +34,7 @@
#include "elfcopy.h"
ELFTC_VCSID("$Id: sections.c 3646 2018-10-27 02:25:39Z emaste $");
ELFTC_VCSID("$Id: sections.c 3758 2019-06-28 01:16:50Z emaste $");
static void add_gnu_debuglink(struct elfcopy *ecp);
static uint32_t calc_crc32(const char *p, size_t len, uint32_t crc);

View File

@ -50,7 +50,7 @@
#include "_elftc.h"
ELFTC_VCSID("$Id: elfdump.c 3584 2017-11-05 20:51:43Z jkoshy $");
ELFTC_VCSID("$Id: elfdump.c 3762 2019-06-28 21:06:24Z emaste $");
#if defined(ELFTC_NEED_ELF_NOTE_DEFINITION)
#include "native-elf-format.h"

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: dwarf.h 3494 2016-09-20 17:16:13Z emaste $
* $Id: dwarf.h 3749 2019-06-28 01:10:44Z emaste $
*/
#ifndef _DWARF_H_

View File

@ -27,7 +27,7 @@
#include "_libdwarf.h"
ELFTC_VCSID("$Id: dwarf_dump.c 3494 2016-09-20 17:16:13Z emaste $");
ELFTC_VCSID("$Id: dwarf_dump.c 3749 2019-06-28 01:10:44Z emaste $");
int
dwarf_get_ACCESS_name(unsigned access, const char **s)
@ -605,7 +605,7 @@ dwarf_get_DS_name(unsigned ds, const char **s)
case DW_DS_leading_separate:
*s = "DW_DS_leading_separate"; break;
case DW_DS_trailing_separate:
*s = "DW_DS_trailing_separate";
*s = "DW_DS_trailing_separate"; break;
default:
return (DW_DLV_NO_ENTRY);
}

View File

@ -27,7 +27,7 @@
#include "_libdwarf.h"
ELFTC_VCSID("$Id: libdwarf_attr.c 3064 2014-06-06 19:35:55Z kaiwang27 $");
ELFTC_VCSID("$Id: libdwarf_attr.c 3748 2019-06-28 01:11:13Z emaste $");
int
_dwarf_attr_alloc(Dwarf_Die die, Dwarf_Attribute *atp, Dwarf_Error *error)

View File

@ -26,7 +26,7 @@
#include "_libdwarf.h"
ELFTC_VCSID("$Id: libdwarf_reloc.c 3578 2017-09-14 02:21:28Z emaste $");
ELFTC_VCSID("$Id: libdwarf_reloc.c 3741 2019-06-07 06:32:01Z jkoshy $");
Dwarf_Unsigned
_dwarf_get_reloc_type(Dwarf_P_Debug dbg, int is64)

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: _libelf.h 3632 2018-10-10 21:12:43Z jkoshy $
* $Id: _libelf.h 3738 2019-05-05 21:49:06Z jkoshy $
*/
#ifndef __LIBELF_H_
@ -94,7 +94,7 @@ struct _Elf {
Elf_Kind e_kind; /* ELF_K_* */
Elf *e_parent; /* non-NULL for archive members */
unsigned char *e_rawfile; /* uninterpreted bytes */
size_t e_rawsize; /* size of uninterpreted bytes */
off_t e_rawsize; /* size of uninterpreted bytes */
unsigned int e_version; /* file version */
/*
@ -233,7 +233,7 @@ Elf *_libelf_open_object(int _fd, Elf_Cmd _c, int _reporterror);
Elf64_Xword _libelf_mips64el_r_info_tof(Elf64_Xword r_info);
Elf64_Xword _libelf_mips64el_r_info_tom(Elf64_Xword r_info);
struct _Libelf_Data *_libelf_release_data(struct _Libelf_Data *_d);
Elf *_libelf_release_elf(Elf *_e);
void _libelf_release_elf(Elf *_e);
Elf_Scn *_libelf_release_scn(Elf_Scn *_s);
int _libelf_setphnum(Elf *_e, void *_eh, int _elfclass, size_t _phnum);
int _libelf_setshnum(Elf *_e, void *_eh, int _elfclass, size_t _shnum);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: _libelf_config.h 3566 2017-08-31 02:28:40Z emaste $
* $Id: _libelf_config.h 3764 2019-06-28 21:44:46Z emaste $
*/
#if defined(__APPLE__) || defined(__DragonFly__)
@ -103,6 +103,12 @@
#define LIBELF_BYTEORDER ELFDATA2LSB
#define LIBELF_CLASS ELFCLASS64
#elif defined(__riscv64)
#define LIBELF_ARCH EM_RISCV
#define LIBELF_BYTEORDER ELFDATA2LSB
#define LIBELF_CLASS ELFCLASS64
#elif defined(__sparc__)
#define LIBELF_ARCH EM_SPARCV9

View File

@ -1,4 +1,4 @@
.\" Copyright (c) 2006-2008,2011 Joseph Koshy. All rights reserved.
.\" Copyright (c) 2006-2008,2011,2019 Joseph Koshy. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: elf.3 3643 2018-10-14 21:09:24Z jkoshy $
.\" $Id: elf.3 3743 2019-06-12 19:36:30Z jkoshy $
.\"
.Dd October 10, 2018
.Dd June 12, 2019
.Dt ELF 3
.Os
.Sh NAME
@ -266,36 +266,43 @@ The operating version for the data in this buffer.
.El
.Pp
.Vt Elf_Data
descriptors are usually associated with
descriptors are usually used in conjunction with
.Vt Elf_Scn
descriptors.
Existing data descriptors associated with an ELF section may be
structures are retrieved using the
.Fn elf_getdata
and
.Fn elf_rawdata
functions.
The
.Fn elf_newdata
function may be used to attach new data descriptors to an ELF section.
.It Vt Elf_Scn
.Vt Elf_Scn
descriptors represent a section in an ELF object.
descriptors represent sections in an ELF object.
These descriptors are opaque and contain no application modifiable
fields.
.Pp
They are retrieved using the
The
.Vt Elf_Scn
descriptor for a specific section in an ELF object can be
retrieved using the
.Fn elf_getscn
function.
An application may iterate through the existing sections of an ELF
object using the
The sections contained in an ELF object can be traversed using the
.Fn elf_nextscn
function.
New sections may be allocated using the
New sections are allocated using the
.Fn elf_newscn
function.
.Pp
The
.Vt Elf_Scn
descriptor is opaque and contains no application modifiable fields.
.Vt Elf_Data
descriptors associated with a given section can be retrieved
using the
.Fn elf_getdata
function.
New data descriptors can be added to a section
descriptor using the
.Fn elf_newdata
function.
The untranslated
.Dq file
representation of data in a section can be retrieved using the
.Fn elf_rawdata
function.
.El
.Ss Supported Elf Types
The following ELF datatypes are supported by the library.
@ -608,8 +615,11 @@ descriptor itself.
.Xr ar 5 ,
.Xr elf 5
.Sh HISTORY
The original ELF(3) API was developed for Unix System V.
The current implementation of the ELF(3) API appeared in
The original
.Nm
API was developed for
.At V .
The current implementation of the API appeared in
.Fx 7.0 .
.Sh AUTHORS
The ELF library was written by

View File

@ -32,7 +32,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: elf_data.c 3632 2018-10-10 21:12:43Z jkoshy $");
ELFTC_VCSID("$Id: elf_data.c 3732 2019-04-22 11:08:38Z jkoshy $");
Elf_Data *
elf_getdata(Elf_Scn *s, Elf_Data *ed)
@ -42,7 +42,7 @@ elf_getdata(Elf_Scn *s, Elf_Data *ed)
int elfclass, elftype;
size_t count, fsz, msz;
struct _Libelf_Data *d;
uint64_t sh_align, sh_offset, sh_size;
uint64_t sh_align, sh_offset, sh_size, raw_size;
_libelf_translator_function *xlate;
d = (struct _Libelf_Data *) ed;
@ -59,7 +59,8 @@ elf_getdata(Elf_Scn *s, Elf_Data *ed)
return (&d->d_data);
if (d != NULL)
return (&STAILQ_NEXT(d, d_next)->d_data);
return (STAILQ_NEXT(d, d_next) ?
&STAILQ_NEXT(d, d_next)->d_data : NULL);
if (e->e_rawfile == NULL) {
/*
@ -91,9 +92,10 @@ elf_getdata(Elf_Scn *s, Elf_Data *ed)
return (NULL);
}
raw_size = (uint64_t) e->e_rawsize;
if ((elftype = _libelf_xlate_shtype(sh_type)) < ELF_T_FIRST ||
elftype > ELF_T_LAST || (sh_type != SHT_NOBITS &&
(sh_offset > e->e_rawsize || sh_size > e->e_rawsize - sh_offset))) {
(sh_offset > raw_size || sh_size > raw_size - sh_offset))) {
LIBELF_SET_ERROR(SECTION, 0);
return (NULL);
}
@ -116,7 +118,8 @@ elf_getdata(Elf_Scn *s, Elf_Data *ed)
count = (size_t) (sh_size / fsz);
msz = _libelf_msize(elftype, elfclass, e->e_version);
if ((msz = _libelf_msize(elftype, elfclass, e->e_version)) == 0)
return (NULL);
if (count > 0 && msz > SIZE_MAX / count) {
LIBELF_SET_ERROR(RANGE, 0);
@ -215,7 +218,7 @@ elf_rawdata(Elf_Scn *s, Elf_Data *ed)
int elf_class;
uint32_t sh_type;
struct _Libelf_Data *d;
uint64_t sh_align, sh_offset, sh_size;
uint64_t sh_align, sh_offset, sh_size, raw_size;
if (s == NULL || (e = s->s_elf) == NULL || e->e_rawfile == NULL) {
LIBELF_SET_ERROR(ARGUMENT, 0);
@ -253,8 +256,9 @@ elf_rawdata(Elf_Scn *s, Elf_Data *ed)
return (NULL);
}
raw_size = (uint64_t) e->e_rawsize;
if (sh_type != SHT_NOBITS &&
(sh_offset > e->e_rawsize || sh_size > e->e_rawsize - sh_offset)) {
(sh_offset > raw_size || sh_size > raw_size - sh_offset)) {
LIBELF_SET_ERROR(SECTION, 0);
return (NULL);
}

View File

@ -34,7 +34,7 @@
#include <sys/mman.h>
#endif
ELFTC_VCSID("$Id: elf_end.c 3174 2015-03-27 17:13:41Z emaste $");
ELFTC_VCSID("$Id: elf_end.c 3738 2019-05-05 21:49:06Z jkoshy $");
int
elf_end(Elf *e)
@ -80,14 +80,14 @@ elf_end(Elf *e)
free(e->e_rawfile);
#if ELFTC_HAVE_MMAP
else if (e->e_flags & LIBELF_F_RAWFILE_MMAP)
(void) munmap(e->e_rawfile, e->e_rawsize);
(void) munmap(e->e_rawfile, (size_t) e->e_rawsize);
#endif
}
sv = e;
if ((e = e->e_parent) != NULL)
e->e_u.e_ar.e_nchildren--;
sv = _libelf_release_elf(sv);
_libelf_release_elf(sv);
}
return (0);

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: elf_flagdata.3 3639 2018-10-14 14:07:02Z jkoshy $
.\" $Id: elf_flagdata.3 3743 2019-06-12 19:36:30Z jkoshy $
.\"
.Dd December 3, 2011
.Dd June 12, 2019
.Dt ELF_FLAGDATA 3
.Os
.Sh NAME
@ -34,7 +34,7 @@
.Nm elf_flagphdr ,
.Nm elf_flagscn ,
.Nm elf_flagshdr
.Nd manipulate flags associated with ELF(3) data structures
.Nd manipulate flags associated with ELF data structures
.Sh LIBRARY
.Lb libelf
.Sh SYNOPSIS
@ -65,7 +65,9 @@ and
.Ar scn
denote the data structures whose flags need to be changed.
These values should have been returned by prior calls to
functions in the ELF(3) API set:
functions in the
.Xr elf 3
API set:
.Bl -bullet -compact
.It
Argument
@ -175,7 +177,9 @@ function and the
.Dv ELF_F_ARCHIVE
and
.Dv ELF_F_ARCHIVE_SYSV
flags are an extension to the ELF(3) API.
flags are an extension to the
.Xr elf 3
API.
.Sh ERRORS
These functions may fail with the following errors:
.Bl -tag -width "[ELF_E_RESOURCE]"

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: elf_getdata.3 3643 2018-10-14 21:09:24Z jkoshy $
.\" $Id: elf_getdata.3 3734 2019-04-22 14:10:49Z jkoshy $
.\"
.Dd January 26, 2011
.Dd April 22, 2019
.Dt ELF_GETDATA 3
.Os
.Sh NAME
@ -214,7 +214,12 @@ is incorrect.
.It Bq Er ELF_E_UNIMPL
The section type associated with section
.Ar scn
is currently unsupported by the library.
is not supported.
.It Bq Er ELF_E_VERSION
Section
.Ar scn
was associated with an ELF object with an unsupported
version.
.El
.Sh SEE ALSO
.Xr elf 3 ,

View File

@ -30,7 +30,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: elf_getident.c 3174 2015-03-27 17:13:41Z emaste $");
ELFTC_VCSID("$Id: elf_getident.c 3712 2019-03-16 22:23:34Z jkoshy $");
char *
elf_getident(Elf *e, size_t *sz)
@ -54,7 +54,7 @@ elf_getident(Elf *e, size_t *sz)
else if (e->e_kind == ELF_K_ELF)
*sz = EI_NIDENT;
else
*sz = e->e_rawsize;
*sz = (size_t) e->e_rawsize;
}
return ((char *) e->e_rawfile);

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: elf_next.3 3639 2018-10-14 14:07:02Z jkoshy $
.\" $Id: elf_next.3 3698 2019-02-28 06:34:42Z jkoshy $
.\"
.Dd June 17, 2006
.Dd February 27, 2019
.Dt ELF_NEXT 3
.Os
.Sh NAME
@ -88,6 +88,9 @@ Argument
was not associated with a containing
.Xr ar 1
archive.
.It Bq Er ELF_E_ARGUMENT
An error was encountered while parsing the archive containing argument
.Ar elf .
.El
.Sh SEE ALSO
.Xr elf 3 ,

View File

@ -30,7 +30,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: elf_next.c 3174 2015-03-27 17:13:41Z emaste $");
ELFTC_VCSID("$Id: elf_next.c 3710 2019-03-12 09:42:35Z jkoshy $");
Elf_Cmd
elf_next(Elf *e)
@ -60,5 +60,19 @@ elf_next(Elf *e)
parent->e_u.e_ar.e_next = (next >= (off_t) parent->e_rawsize) ?
(off_t) 0 : next;
/*
* Return an error if the 'e_next' field falls outside the current
* file.
*
* This check is performed after updating the parent descriptor's
* 'e_next' field so that the next call to elf_begin(3) will terminate
* traversal of a too-small archive even if client code forgets to
* check the return value from elf_next(3).
*/
if (next > (off_t) parent->e_rawsize) {
LIBELF_SET_ERROR(ARGUMENT, 0);
return (ELF_C_NULL);
}
return (ELF_C_READ);
}

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: elf_open.3 3643 2018-10-14 21:09:24Z jkoshy $
.\" $Id: elf_open.3 3743 2019-06-12 19:36:30Z jkoshy $
.\"
.Dd May 31, 2012
.Dd June 12, 2019
.Dt ELF_OPEN 3
.Os
.Sh NAME
@ -43,7 +43,9 @@ The functions
.Fn elf_open
and
.Fn elf_openmemory
are extensions to the ELF(3) API, for the internal use of the
are extensions to the
.Xr elf 3
API, for the internal use of the
Elftoolchain project.
Portable applications should not use these functions.
.Pp
@ -71,7 +73,9 @@ specifies the size of the memory area in bytes.
The function returns a pointer to a ELF descriptor if successful, or
NULL if an error occurred.
.Sh COMPATIBILITY
These functions are non-standard extensions to the ELF(3) API set.
These functions are non-standard extensions to the
.Xr elf 3
API set.
.Pp
The behavior of these functions differs from their counterparts
.Xr elf_begin 3

View File

@ -29,16 +29,25 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: elf_rand.c 3174 2015-03-27 17:13:41Z emaste $");
ELFTC_VCSID("$Id: elf_rand.c 3716 2019-03-18 22:01:01Z jkoshy $");
off_t
elf_rand(Elf *ar, off_t offset)
{
struct ar_hdr *arh;
off_t offset_of_member;
if (ar == NULL || ar->e_kind != ELF_K_AR ||
(offset & 1) || offset < SARMAG ||
(size_t) offset + sizeof(struct ar_hdr) >= ar->e_rawsize) {
offset >= ar->e_rawsize) {
LIBELF_SET_ERROR(ARGUMENT, 0);
return 0;
}
offset_of_member = offset + (off_t) sizeof(struct ar_hdr);
if (offset_of_member <= 0 || /* Numeric overflow. */
offset_of_member >= ar->e_rawsize) {
LIBELF_SET_ERROR(ARGUMENT, 0);
return 0;
}

View File

@ -28,15 +28,13 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: elf_rawfile.c 3174 2015-03-27 17:13:41Z emaste $");
ELFTC_VCSID("$Id: elf_rawfile.c 3712 2019-03-16 22:23:34Z jkoshy $");
char *
elf_rawfile(Elf *e, size_t *sz)
{
size_t size;
unsigned char *ptr;
size = e ? e->e_rawsize : 0;
ptr = NULL;
if (e == NULL)
@ -45,7 +43,7 @@ elf_rawfile(Elf *e, size_t *sz)
LIBELF_SET_ERROR(SEQUENCE, 0);
if (sz)
*sz = size;
*sz = e ? (size_t) e->e_rawsize : 0;
return ((char *) ptr);
}

View File

@ -36,7 +36,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: elf_scn.c 3632 2018-10-10 21:12:43Z jkoshy $");
ELFTC_VCSID("$Id: elf_scn.c 3712 2019-03-16 22:23:34Z jkoshy $");
static int
elfscn_cmp(struct _Elf_Scn *s1, struct _Elf_Scn *s2)
@ -71,10 +71,11 @@ _libelf_load_section_headers(Elf *e, void *ehdr)
assert((e->e_flags & LIBELF_F_SHDRS_LOADED) == 0);
#define CHECK_EHDR(E,EH) do { \
if (shoff > e->e_rawsize || \
uintmax_t rawsize = (uintmax_t) e->e_rawsize; \
if (shoff > (uintmax_t) e->e_rawsize || \
fsz != (EH)->e_shentsize || \
shnum > SIZE_MAX / fsz || \
fsz * shnum > e->e_rawsize - shoff) { \
fsz * shnum > rawsize - shoff) { \
LIBELF_SET_ERROR(HEADER, 0); \
return (0); \
} \

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: elf_update.3 3639 2018-10-14 14:07:02Z jkoshy $
.\" $Id: elf_update.3 3734 2019-04-22 14:10:49Z jkoshy $
.\"
.Dd August 14, 2011
.Dd April 22, 2019
.Dt ELF_UPDATE 3
.Os
.Sh NAME
@ -345,6 +345,10 @@ operation was requested after a prior call to
disassociated the ELF descriptor
.Ar elf
from its underlying file.
.It Bq Er ELF_E_UNIMPL
Argument
.Ar elf
contained a section with an unsupported ELF type.
.It Bq Er ELF_E_VERSION
Argument
.Ar elf

View File

@ -41,7 +41,7 @@
#include <sys/mman.h>
#endif
ELFTC_VCSID("$Id: elf_update.c 3632 2018-10-10 21:12:43Z jkoshy $");
ELFTC_VCSID("$Id: elf_update.c 3763 2019-06-28 21:43:27Z emaste $");
/*
* Layout strategy:
@ -142,7 +142,7 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t rc)
assert(sh_type != SHT_NULL && sh_type != SHT_NOBITS);
elftype = _libelf_xlate_shtype(sh_type);
if (elftype > ELF_T_LAST) {
if (elftype < ELF_T_FIRST || elftype > ELF_T_LAST) {
LIBELF_SET_ERROR(SECTION, 0);
return (0);
}
@ -221,11 +221,17 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t rc)
return (0);
}
/*
* The data buffer's ELF type, ELF class and ELF version
* should be supported.
*/
if ((msz = _libelf_msize(d->d_type, ec, e->e_version)) == 0)
return (0);
/*
* The buffer's size should be a multiple of the
* memory size of the underlying type.
*/
msz = _libelf_msize(d->d_type, ec, e->e_version);
if (d->d_size % msz) {
LIBELF_SET_ERROR(DATA, 0);
return (0);
@ -802,7 +808,8 @@ _libelf_write_scn(Elf *e, unsigned char *nf, struct _Elf_Extent *ex)
d = &ld->d_data;
msz = _libelf_msize(d->d_type, ec, e->e_version);
if ((msz = _libelf_msize(d->d_type, ec, e->e_version)) == 0)
return ((off_t) -1);
if ((uint64_t) rc < sh_off + d->d_off)
(void) memset(nf + rc,
@ -813,8 +820,8 @@ _libelf_write_scn(Elf *e, unsigned char *nf, struct _Elf_Extent *ex)
assert(d->d_buf != NULL);
assert(d->d_version == e->e_version);
assert(msz != 0);
assert(d->d_size % msz == 0);
assert(msz != 0);
nobjects = (size_t) (d->d_size / msz);
@ -854,7 +861,8 @@ _libelf_write_ehdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex)
assert(ehdr != NULL);
fsz = _libelf_fsize(ELF_T_EHDR, ec, e->e_version, (size_t) 1);
msz = _libelf_msize(ELF_T_EHDR, ec, e->e_version);
if ((msz = _libelf_msize(ELF_T_EHDR, ec, e->e_version)) == 0)
return ((off_t) -1);
em = _libelf_elfmachine(e);
@ -888,15 +896,17 @@ _libelf_write_phdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex)
Elf32_Ehdr *eh32;
Elf64_Ehdr *eh64;
Elf_Data dst, src;
size_t fsz, phnum;
size_t fsz, msz, phnum;
uint64_t phoff;
assert(ex->ex_type == ELF_EXTENT_PHDR);
ec = e->e_class;
ehdr = _libelf_ehdr(e, ec, 0);
phnum = e->e_u.e_elf.e_nphdr;
ehdr = _libelf_ehdr(e, ec, 0);
assert(ehdr != NULL);
phnum = e->e_u.e_elf.e_nphdr;
assert(phnum > 0);
if (ec == ELFCLASS32) {
@ -916,14 +926,15 @@ _libelf_write_phdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex)
(void) memset(&dst, 0, sizeof(dst));
(void) memset(&src, 0, sizeof(src));
if ((msz = _libelf_msize(ELF_T_PHDR, ec, e->e_version)) == 0)
return ((off_t) -1);
fsz = _libelf_fsize(ELF_T_PHDR, ec, e->e_version, phnum);
assert(fsz > 0);
src.d_buf = _libelf_getphdr(e, ec);
src.d_version = dst.d_version = e->e_version;
src.d_type = ELF_T_PHDR;
src.d_size = phnum * _libelf_msize(ELF_T_PHDR, ec,
e->e_version);
src.d_size = phnum * msz;
dst.d_size = fsz;
dst.d_buf = nf + ex->ex_start;
@ -948,13 +959,16 @@ _libelf_write_shdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex)
uint64_t shoff;
Elf32_Ehdr *eh32;
Elf64_Ehdr *eh64;
size_t fsz, nscn;
size_t fsz, msz, nscn;
Elf_Data dst, src;
assert(ex->ex_type == ELF_EXTENT_SHDR);
ec = e->e_class;
ehdr = _libelf_ehdr(e, ec, 0);
assert(ehdr != NULL);
nscn = e->e_u.e_elf.e_nscn;
if (ec == ELFCLASS32) {
@ -974,8 +988,11 @@ _libelf_write_shdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex)
(void) memset(&dst, 0, sizeof(dst));
(void) memset(&src, 0, sizeof(src));
if ((msz = _libelf_msize(ELF_T_SHDR, ec, e->e_version)) == 0)
return ((off_t) -1);
src.d_type = ELF_T_SHDR;
src.d_size = _libelf_msize(ELF_T_SHDR, ec, e->e_version);
src.d_size = msz;
src.d_version = dst.d_version = e->e_version;
fsz = _libelf_fsize(ELF_T_SHDR, ec, e->e_version, (size_t) 1);
@ -1087,7 +1104,7 @@ _libelf_write_elf(Elf *e, off_t newsize, struct _Elf_Extent_List *extents)
if (e->e_flags & LIBELF_F_RAWFILE_MMAP) {
assert(e->e_rawfile != NULL);
assert(e->e_cmd == ELF_C_RDWR);
if (munmap(e->e_rawfile, e->e_rawsize) < 0) {
if (munmap(e->e_rawfile, (size_t) e->e_rawsize) < 0) {
LIBELF_SET_ERROR(IO, errno);
goto error;
}
@ -1112,12 +1129,14 @@ _libelf_write_elf(Elf *e, off_t newsize, struct _Elf_Extent_List *extents)
assert((e->e_flags & LIBELF_F_RAWFILE_MALLOC) ||
(e->e_flags & LIBELF_F_RAWFILE_MMAP));
if (e->e_flags & LIBELF_F_RAWFILE_MALLOC) {
assert((e->e_flags & LIBELF_F_RAWFILE_MMAP) == 0);
free(e->e_rawfile);
e->e_rawfile = newfile;
newfile = NULL;
}
#if ELFTC_HAVE_MMAP
else if (e->e_flags & LIBELF_F_RAWFILE_MMAP) {
assert((e->e_flags & LIBELF_F_RAWFILE_MALLOC) == 0);
if ((e->e_rawfile = mmap(NULL, (size_t) newsize,
PROT_READ, MAP_PRIVATE, e->e_fd, (off_t) 0)) ==
MAP_FAILED) {
@ -1128,7 +1147,7 @@ _libelf_write_elf(Elf *e, off_t newsize, struct _Elf_Extent_List *extents)
#endif /* ELFTC_HAVE_MMAP */
/* Record the new size of the file. */
e->e_rawsize = (size_t) newsize;
e->e_rawsize = newsize;
} else {
/* File opened in ELF_C_WRITE mode. */
assert(e->e_rawfile == NULL);

View File

@ -21,13 +21,13 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: gelf.3 3643 2018-10-14 21:09:24Z jkoshy $
.\" $Id: gelf.3 3743 2019-06-12 19:36:30Z jkoshy $
.\"
.Dd September 1, 2006
.Dd June 12, 2019
.Dt GELF 3
.Os
.Sh NAME
.Nm GElf
.Nm gelf
.Nd class-independent API for ELF manipulation
.Sh LIBRARY
.Lb libelf
@ -192,7 +192,10 @@ Copy back an ELF symbol table entry.
.Xr elf 3 ,
.Xr elf 5
.Sh HISTORY
The GELF(3) API first appeared in System V Release 4.
The
.Nm
API first appeared in
.At V.4 .
This implementation of the API first appeared in
.Fx 7.0 .
.Sh AUTHORS

View File

@ -31,7 +31,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: gelf_cap.c 3177 2015-03-30 18:19:41Z emaste $");
ELFTC_VCSID("$Id: gelf_cap.c 3732 2019-04-22 11:08:38Z jkoshy $");
GElf_Cap *
gelf_getcap(Elf_Data *ed, int ndx, GElf_Cap *dst)
@ -67,9 +67,8 @@ gelf_getcap(Elf_Data *ed, int ndx, GElf_Cap *dst)
return (NULL);
}
msz = _libelf_msize(ELF_T_CAP, ec, e->e_version);
assert(msz > 0);
if ((msz = _libelf_msize(ELF_T_CAP, ec, e->e_version)) == 0)
return (NULL);
if (msz * (size_t) ndx >= d->d_data.d_size) {
LIBELF_SET_ERROR(ARGUMENT, 0);
@ -127,8 +126,8 @@ gelf_update_cap(Elf_Data *ed, int ndx, GElf_Cap *gc)
return (0);
}
msz = _libelf_msize(ELF_T_CAP, ec, e->e_version);
assert(msz > 0);
if ((msz = _libelf_msize(ELF_T_CAP, ec, e->e_version)) == 0)
return (0);
if (msz * (size_t) ndx >= d->d_data.d_size) {
LIBELF_SET_ERROR(ARGUMENT, 0);

View File

@ -31,7 +31,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: gelf_dyn.c 3177 2015-03-30 18:19:41Z emaste $");
ELFTC_VCSID("$Id: gelf_dyn.c 3732 2019-04-22 11:08:38Z jkoshy $");
GElf_Dyn *
gelf_getdyn(Elf_Data *ed, int ndx, GElf_Dyn *dst)
@ -67,9 +67,9 @@ gelf_getdyn(Elf_Data *ed, int ndx, GElf_Dyn *dst)
return (NULL);
}
msz = _libelf_msize(ELF_T_DYN, ec, e->e_version);
if ((msz = _libelf_msize(ELF_T_DYN, ec, e->e_version)) == 0)
return (NULL);
assert(msz > 0);
assert(ndx >= 0);
if (msz * (size_t) ndx >= d->d_data.d_size) {
@ -127,9 +127,9 @@ gelf_update_dyn(Elf_Data *ed, int ndx, GElf_Dyn *ds)
return (0);
}
msz = _libelf_msize(ELF_T_DYN, ec, e->e_version);
if ((msz = _libelf_msize(ELF_T_DYN, ec, e->e_version)) == 0)
return (0);
assert(msz > 0);
assert(ndx >= 0);
if (msz * (size_t) ndx >= d->d_data.d_size) {

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: gelf_getcap.3 3639 2018-10-14 14:07:02Z jkoshy $
.\" $Id: gelf_getcap.3 3734 2019-04-22 14:10:49Z jkoshy $
.\"
.Dd August 29, 2006
.Dd April 22, 2019
.Dt GELF_GETCAP 3
.Os
.Sh NAME
@ -113,6 +113,12 @@ was not associated with a section of type
.Dv SHT_SUNW_cap .
.It Bq Er ELF_E_RANGE
A value was not representable in the target type.
.It Bq Er ELF_E_VERSION
The
.Vt Elf_Data
descriptor denoted by argument
.Ar data
is associated with an ELF object with an unsupported version.
.El
.Sh SEE ALSO
.Xr elf 3 ,

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: gelf_getdyn.3 3639 2018-10-14 14:07:02Z jkoshy $
.\" $Id: gelf_getdyn.3 3734 2019-04-22 14:10:49Z jkoshy $
.\"
.Dd August 29, 2006
.Dd April 22, 2019
.Dt GELF_GETDYN 3
.Os
.Sh NAME
@ -115,6 +115,13 @@ was not associated with a section of type
.Dv SHT_DYNAMIC .
.It Bq Er ELF_E_RANGE
A value was not representable in the target type.
.It Bq Er ELF_E_VERSION
The
.Vt Elf_Data
descriptor denoted by argument
.Ar data
is associated with an ELF object with an unsupported version.
.El
.El
.Sh SEE ALSO
.Xr elf 3 ,

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: gelf_getmove.3 3639 2018-10-14 14:07:02Z jkoshy $
.\" $Id: gelf_getmove.3 3734 2019-04-22 14:10:49Z jkoshy $
.\"
.Dd August 29, 2006
.Dd April 22, 2019
.Dt GELF_GETMOVE 3
.Os
.Sh NAME
@ -112,6 +112,12 @@ Data descriptor
was not associated with a section containing move information.
.It Bq Er ELF_E_RANGE
A value was not representable in the target type.
.It Bq Er ELF_E_VERSION
The
.Vt Elf_Data
descriptor denoted by argument
.Ar data
is associated with an ELF object with an unsupported version.
.El
.Sh SEE ALSO
.Xr elf 3 ,

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: gelf_getrel.3 3639 2018-10-14 14:07:02Z jkoshy $
.\" $Id: gelf_getrel.3 3734 2019-04-22 14:10:49Z jkoshy $
.\"
.Dd August 29, 2006
.Dd April 22, 2019
.Dt GELF_GETREL 3
.Os
.Sh NAME
@ -113,6 +113,12 @@ was not associated with a section of type
.Dv SHT_REL .
.It Bq Er ELF_E_RANGE
A value was not representable in the target type.
.It Bq Er ELF_E_VERSION
The
.Vt Elf_Data
descriptor denoted by argument
.Ar data
is associated with an ELF object with an unsupported version.
.El
.Sh SEE ALSO
.Xr elf 3 ,

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: gelf_getrela.3 3639 2018-10-14 14:07:02Z jkoshy $
.\" $Id: gelf_getrela.3 3734 2019-04-22 14:10:49Z jkoshy $
.\"
.Dd August 29, 2006
.Dd April 22, 2019
.Dt GELF_GETRELA 3
.Os
.Sh NAME
@ -113,6 +113,12 @@ was not associated with a section of type
.Dv SHT_RELA .
.It Bq Er ELF_E_RANGE
A value was not representable in the target type.
.It Bq Er ELF_E_VERSION
The
.Vt Elf_Data
descriptor denoted by argument
.Ar data
is associated with an ELF object with an unsupported version.
.El
.Sh SEE ALSO
.Xr elf 3 ,

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: gelf_getsym.3 3639 2018-10-14 14:07:02Z jkoshy $
.\" $Id: gelf_getsym.3 3734 2019-04-22 14:10:49Z jkoshy $
.\"
.Dd August 29, 2006
.Dd April 22, 2019
.Dt GELF_GETSYM 3
.Os
.Sh NAME
@ -115,6 +115,12 @@ Data descriptor
was not associated with a section containing symbol information.
.It Bq Er ELF_E_RANGE
A value was not representable in the target type.
.It Bq Er ELF_E_VERSION
The
.Vt Elf_Data
descriptor denoted by argument
.Ar data
is associated with an ELF object with an unsupported version.
.El
.Sh SEE ALSO
.Xr elf 3 ,

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: gelf_getsyminfo.3 3639 2018-10-14 14:07:02Z jkoshy $
.\" $Id: gelf_getsyminfo.3 3734 2019-04-22 14:10:49Z jkoshy $
.\"
.Dd August 29, 2006
.Dd April 22, 2019
.Dt GELF_GETSYMINFO 3
.Os
.Sh NAME
@ -105,6 +105,12 @@ descriptor.
Data descriptor
.Ar data
was not associated with a section containing symbol information.
.It Bq Er ELF_E_VERSION
The
.Vt Elf_Data
descriptor denoted by argument
.Ar data
is associated with an ELF object with an unsupported version.
.El
.Sh SEE ALSO
.Xr elf 3 ,

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: gelf_getsymshndx.3 3639 2018-10-14 14:07:02Z jkoshy $
.\" $Id: gelf_getsymshndx.3 3734 2019-04-22 14:10:49Z jkoshy $
.\"
.Dd November 5, 2006
.Dd April 22, 2019
.Dt GELF_GETSYMSHNDX 3
.Os
.Sh NAME
@ -152,6 +152,14 @@ Data descriptor
and
.Ar xndxdata
were associated with different ELF objects.
.It Bq Er ELF_E_VERSION
The
.Vt Elf_Data
descriptors denoted by arguments
.Ar symdata
and
.Ar xndxdata
are associated with an ELF object with an unsupported version.
.El
.Sh SEE ALSO
.Xr elf 3 ,

View File

@ -31,7 +31,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: gelf_move.c 3177 2015-03-30 18:19:41Z emaste $");
ELFTC_VCSID("$Id: gelf_move.c 3732 2019-04-22 11:08:38Z jkoshy $");
GElf_Move *
gelf_getmove(Elf_Data *ed, int ndx, GElf_Move *dst)
@ -67,9 +67,9 @@ gelf_getmove(Elf_Data *ed, int ndx, GElf_Move *dst)
return (NULL);
}
msz = _libelf_msize(ELF_T_MOVE, ec, e->e_version);
if ((msz = _libelf_msize(ELF_T_MOVE, ec, e->e_version)) == 0)
return (NULL);
assert(msz > 0);
assert(ndx >= 0);
if (msz * (size_t) ndx >= d->d_data.d_size) {
@ -130,9 +130,9 @@ gelf_update_move(Elf_Data *ed, int ndx, GElf_Move *gm)
return (0);
}
msz = _libelf_msize(ELF_T_MOVE, ec, e->e_version);
if ((msz = _libelf_msize(ELF_T_MOVE, ec, e->e_version)) == 0)
return (0);
assert(msz > 0);
assert(ndx >= 0);
if (msz * (size_t) ndx >= d->d_data.d_size) {

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: gelf_newehdr.3 3643 2018-10-14 21:09:24Z jkoshy $
.\" $Id: gelf_newehdr.3 3743 2019-06-12 19:36:30Z jkoshy $
.\"
.Dd October 22, 2007
.Dd June 12, 2019
.Dt GELF_NEWEHDR 3
.Os
.Sh NAME
@ -134,7 +134,9 @@ The
function uses a type of
.Ft "void *"
for its returned value.
This differs from some other implementations of the ELF(3) API, which use an
This differs from some other implementations of the
.Xr elf 3
API, which use an
.Ft "unsigned long"
return type.
.Sh ERRORS

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: gelf_newphdr.3 3639 2018-10-14 14:07:02Z jkoshy $
.\" $Id: gelf_newphdr.3 3743 2019-06-12 19:36:30Z jkoshy $
.\"
.Dd October 22, 2007
.Dd June 12, 2019
.Dt GELF_NEWPHDR 3
.Os
.Sh NAME
@ -103,7 +103,9 @@ The
function uses a type of
.Ft "void *"
for its returned value.
This differs from some other implementations of the ELF(3) API, which use an
This differs from some other implementations of the
.Xr elf 3
API, which use an
.Ft "unsigned long"
return type.
.Sh ERRORS

View File

@ -31,7 +31,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: gelf_rel.c 3177 2015-03-30 18:19:41Z emaste $");
ELFTC_VCSID("$Id: gelf_rel.c 3739 2019-05-06 05:18:15Z jkoshy $");
GElf_Rel *
gelf_getrel(Elf_Data *ed, int ndx, GElf_Rel *dst)
@ -67,9 +67,9 @@ gelf_getrel(Elf_Data *ed, int ndx, GElf_Rel *dst)
return (NULL);
}
msz = _libelf_msize(ELF_T_REL, ec, e->e_version);
if ((msz = _libelf_msize(ELF_T_REL, ec, e->e_version)) == 0)
return (NULL);
assert(msz > 0);
assert(ndx >= 0);
if (msz * (size_t) ndx >= d->d_data.d_size) {
@ -132,9 +132,9 @@ gelf_update_rel(Elf_Data *ed, int ndx, GElf_Rel *dr)
return (0);
}
msz = _libelf_msize(ELF_T_REL, ec, e->e_version);
if ((msz = _libelf_msize(ELF_T_REL, ec, e->e_version)) == 0)
return (0);
assert(msz > 0);
assert(ndx >= 0);
if (msz * (size_t) ndx >= d->d_data.d_size) {
@ -147,7 +147,7 @@ gelf_update_rel(Elf_Data *ed, int ndx, GElf_Rel *dr)
LIBELF_COPY_U32(rel32, dr, r_offset);
if (ELF64_R_SYM(dr->r_info) > ELF32_R_SYM(~0UL) ||
if (ELF64_R_SYM(dr->r_info) > ELF32_R_SYM(~0U) ||
ELF64_R_TYPE(dr->r_info) > ELF32_R_TYPE(~0U)) {
LIBELF_SET_ERROR(RANGE, 0);
return (0);

View File

@ -31,7 +31,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: gelf_rela.c 3177 2015-03-30 18:19:41Z emaste $");
ELFTC_VCSID("$Id: gelf_rela.c 3739 2019-05-06 05:18:15Z jkoshy $");
GElf_Rela *
gelf_getrela(Elf_Data *ed, int ndx, GElf_Rela *dst)
@ -67,9 +67,9 @@ gelf_getrela(Elf_Data *ed, int ndx, GElf_Rela *dst)
return (NULL);
}
msz = _libelf_msize(ELF_T_RELA, ec, e->e_version);
if ((msz = _libelf_msize(ELF_T_RELA, ec, e->e_version)) == 0)
return (NULL);
assert(msz > 0);
assert(ndx >= 0);
if (msz * (size_t) ndx >= d->d_data.d_size) {
@ -134,9 +134,9 @@ gelf_update_rela(Elf_Data *ed, int ndx, GElf_Rela *dr)
return (0);
}
msz = _libelf_msize(ELF_T_RELA, ec, e->e_version);
if ((msz = _libelf_msize(ELF_T_RELA, ec, e->e_version)) == 0)
return (0);
assert(msz > 0);
assert(ndx >= 0);
if (msz * (size_t) ndx >= d->d_data.d_size) {
@ -149,7 +149,7 @@ gelf_update_rela(Elf_Data *ed, int ndx, GElf_Rela *dr)
LIBELF_COPY_U32(rela32, dr, r_offset);
if (ELF64_R_SYM(dr->r_info) > ELF32_R_SYM(~0UL) ||
if (ELF64_R_SYM(dr->r_info) > ELF32_R_SYM(~0U) ||
ELF64_R_TYPE(dr->r_info) > ELF32_R_TYPE(~0U)) {
LIBELF_SET_ERROR(RANGE, 0);
return (0);

View File

@ -31,7 +31,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: gelf_sym.c 3177 2015-03-30 18:19:41Z emaste $");
ELFTC_VCSID("$Id: gelf_sym.c 3732 2019-04-22 11:08:38Z jkoshy $");
GElf_Sym *
gelf_getsym(Elf_Data *ed, int ndx, GElf_Sym *dst)
@ -67,9 +67,9 @@ gelf_getsym(Elf_Data *ed, int ndx, GElf_Sym *dst)
return (NULL);
}
msz = _libelf_msize(ELF_T_SYM, ec, e->e_version);
if ((msz = _libelf_msize(ELF_T_SYM, ec, e->e_version)) == 0)
return (NULL);
assert(msz > 0);
assert(ndx >= 0);
if (msz * (size_t) ndx >= d->d_data.d_size) {
@ -129,9 +129,9 @@ gelf_update_sym(Elf_Data *ed, int ndx, GElf_Sym *gs)
return (0);
}
msz = _libelf_msize(ELF_T_SYM, ec, e->e_version);
if ((msz = _libelf_msize(ELF_T_SYM, ec, e->e_version)) == 0)
return (0);
assert(msz > 0);
assert(ndx >= 0);
if (msz * (size_t) ndx >= d->d_data.d_size) {

View File

@ -29,7 +29,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: gelf_syminfo.c 3174 2015-03-27 17:13:41Z emaste $");
ELFTC_VCSID("$Id: gelf_syminfo.c 3732 2019-04-22 11:08:38Z jkoshy $");
GElf_Syminfo *
gelf_getsyminfo(Elf_Data *ed, int ndx, GElf_Syminfo *dst)
@ -65,9 +65,9 @@ gelf_getsyminfo(Elf_Data *ed, int ndx, GElf_Syminfo *dst)
return (NULL);
}
msz = _libelf_msize(ELF_T_SYMINFO, ec, e->e_version);
if ((msz = _libelf_msize(ELF_T_SYMINFO, ec, e->e_version)) == 0)
return (NULL);
assert(msz > 0);
assert(ndx >= 0);
if (msz * (size_t) ndx >= d->d_data.d_size) {
@ -126,9 +126,9 @@ gelf_update_syminfo(Elf_Data *ed, int ndx, GElf_Syminfo *gs)
return (0);
}
msz = _libelf_msize(ELF_T_SYMINFO, ec, e->e_version);
if ((msz = _libelf_msize(ELF_T_SYMINFO, ec, e->e_version)) == 0)
return (0);
assert(msz > 0);
assert(ndx >= 0);
if (msz * (size_t) ndx >= d->d_data.d_size) {

View File

@ -29,7 +29,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: gelf_symshndx.c 3174 2015-03-27 17:13:41Z emaste $");
ELFTC_VCSID("$Id: gelf_symshndx.c 3732 2019-04-22 11:08:38Z jkoshy $");
GElf_Sym *
gelf_getsymshndx(Elf_Data *d, Elf_Data *id, int ndx, GElf_Sym *dst,
@ -69,9 +69,9 @@ gelf_getsymshndx(Elf_Data *d, Elf_Data *id, int ndx, GElf_Sym *dst,
return (NULL);
}
msz = _libelf_msize(ELF_T_WORD, ec, e->e_version);
if ((msz = _libelf_msize(ELF_T_WORD, ec, e->e_version)) == 0)
return (NULL);
assert(msz > 0);
assert(ndx >= 0);
if (msz * (size_t) ndx >= id->d_size) {
@ -121,9 +121,9 @@ gelf_update_symshndx(Elf_Data *d, Elf_Data *id, int ndx, GElf_Sym *gs,
return (0);
}
msz = _libelf_msize(ELF_T_WORD, ec, e->e_version);
if ((msz = _libelf_msize(ELF_T_WORD, ec, e->e_version)) == 0)
return (0);
assert(msz > 0);
assert(ndx >= 0);
if (msz * (size_t) ndx >= id->d_size) {

View File

@ -36,33 +36,26 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: libelf_allocate.c 3174 2015-03-27 17:13:41Z emaste $");
ELFTC_VCSID("$Id: libelf_allocate.c 3738 2019-05-05 21:49:06Z jkoshy $");
Elf *
_libelf_allocate_elf(void)
{
Elf *e;
if ((e = malloc(sizeof(*e))) == NULL) {
if ((e = calloc((size_t) 1, sizeof(*e))) == NULL) {
LIBELF_SET_ERROR(RESOURCE, errno);
return NULL;
}
e->e_activations = 1;
e->e_hdr.e_rawhdr = NULL;
e->e_byteorder = ELFDATANONE;
e->e_class = ELFCLASSNONE;
e->e_cmd = ELF_C_NULL;
e->e_fd = -1;
e->e_flags = 0;
e->e_kind = ELF_K_NONE;
e->e_parent = NULL;
e->e_rawfile = NULL;
e->e_rawsize = 0;
e->e_version = LIBELF_PRIVATE(version);
(void) memset(&e->e_u, 0, sizeof(e->e_u));
return (e);
}
@ -83,31 +76,25 @@ _libelf_init_elf(Elf *e, Elf_Kind kind)
}
}
#define FREE(P) do { \
if (P) \
free(P); \
} while (0)
Elf *
void
_libelf_release_elf(Elf *e)
{
Elf_Arhdr *arh;
switch (e->e_kind) {
case ELF_K_AR:
FREE(e->e_u.e_ar.e_symtab);
free(e->e_u.e_ar.e_symtab);
break;
case ELF_K_ELF:
switch (e->e_class) {
case ELFCLASS32:
FREE(e->e_u.e_elf.e_ehdr.e_ehdr32);
FREE(e->e_u.e_elf.e_phdr.e_phdr32);
free(e->e_u.e_elf.e_ehdr.e_ehdr32);
free(e->e_u.e_elf.e_phdr.e_phdr32);
break;
case ELFCLASS64:
FREE(e->e_u.e_elf.e_ehdr.e_ehdr64);
FREE(e->e_u.e_elf.e_phdr.e_phdr64);
free(e->e_u.e_elf.e_ehdr.e_ehdr64);
free(e->e_u.e_elf.e_phdr.e_phdr64);
break;
}
@ -115,8 +102,8 @@ _libelf_release_elf(Elf *e)
if (e->e_flags & LIBELF_F_AR_HEADER) {
arh = e->e_hdr.e_arhdr;
FREE(arh->ar_name);
FREE(arh->ar_rawname);
free(arh->ar_name);
free(arh->ar_rawname);
free(arh);
}
@ -127,8 +114,6 @@ _libelf_release_elf(Elf *e)
}
free(e);
return (NULL);
}
struct _Libelf_Data *

View File

@ -33,7 +33,7 @@
#include "_libelf.h"
#include "_libelf_ar.h"
ELFTC_VCSID("$Id: libelf_ar.c 3446 2016-05-03 01:31:17Z emaste $");
ELFTC_VCSID("$Id: libelf_ar.c 3712 2019-03-16 22:23:34Z jkoshy $");
#define LIBELF_NALLOC_SIZE 16
@ -123,8 +123,16 @@ _libelf_ar_gethdr(Elf *e)
arh = (struct ar_hdr *) (uintptr_t) e->e_hdr.e_rawhdr;
assert((uintptr_t) arh >= (uintptr_t) parent->e_rawfile + SARMAG);
assert((uintptr_t) arh <= (uintptr_t) parent->e_rawfile +
parent->e_rawsize - sizeof(struct ar_hdr));
/*
* There needs to be enough space remaining in the file for the
* archive header.
*/
if ((uintptr_t) arh > (uintptr_t) parent->e_rawfile +
(uintptr_t) parent->e_rawsize - sizeof(struct ar_hdr)) {
LIBELF_SET_ERROR(ARCHIVE, 0);
return (NULL);
}
if ((eh = malloc(sizeof(Elf_Arhdr))) == NULL) {
LIBELF_SET_ERROR(RESOURCE, 0);
@ -199,8 +207,8 @@ Elf *
_libelf_ar_open_member(int fd, Elf_Cmd c, Elf *elf)
{
Elf *e;
off_t next;
size_t nsz, sz;
off_t next, end;
struct ar_hdr *arh;
char *member, *namelen;
@ -217,6 +225,17 @@ _libelf_ar_open_member(int fd, Elf_Cmd c, Elf *elf)
assert((next & 1) == 0);
/*
* There needs to be enough space in the file to contain an
* ar(1) header.
*/
end = next + (off_t) sizeof(struct ar_hdr);
if ((uintmax_t) end < (uintmax_t) next || /* Overflow. */
end > (off_t) elf->e_rawsize) {
LIBELF_SET_ERROR(ARCHIVE, 0);
return (NULL);
}
arh = (struct ar_hdr *) (elf->e_rawfile + next);
/*
@ -228,6 +247,17 @@ _libelf_ar_open_member(int fd, Elf_Cmd c, Elf *elf)
return (NULL);
}
/*
* Check if the archive member that follows will fit in the
* containing archive.
*/
end += (off_t) sz;
if (end < next || /* Overflow. */
end > (off_t) elf->e_rawsize) {
LIBELF_SET_ERROR(ARCHIVE, 0);
return (NULL);
}
/*
* Adjust the size field for members in BSD archives using
* extended naming.
@ -286,7 +316,8 @@ Elf_Arsym *
_libelf_ar_process_bsd_symtab(Elf *e, size_t *count)
{
Elf_Arsym *symtab, *sym;
unsigned int n, nentries;
unsigned int n;
size_t nentries;
unsigned char *end, *p, *p0, *s, *s0;
const size_t entrysize = 2 * sizeof(long);
long arraysize, fileoffset, stroffset, strtabsize;
@ -343,7 +374,7 @@ _libelf_ar_process_bsd_symtab(Elf *e, size_t *count)
GET_LONG(p, fileoffset);
if (stroffset < 0 || fileoffset < 0 ||
(size_t) fileoffset >= e->e_rawsize)
(off_t) fileoffset >= e->e_rawsize)
goto symtaberror;
s = s0 + stroffset;

View File

@ -30,7 +30,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: libelf_convert.m4 3632 2018-10-10 21:12:43Z jkoshy $");
ELFTC_VCSID("$Id: libelf_convert.m4 3712 2019-03-16 22:23:34Z jkoshy $");
/* WARNING: GENERATED FROM __file__. */
@ -820,7 +820,7 @@ _libelf_cvt_GNUHASH64_tom(unsigned char *dst, size_t dsz, unsigned char *src,
if (dsz < srcsz) /* Destination lacks space. */
return (0);
nchains = srcsz / sizeof(uint32_t);
nchains = (uint32_t) (srcsz / sizeof(uint32_t));
chains = (uint32_t *) (uintptr_t) dst;
for (n = 0; n < nchains; n++) {
@ -901,7 +901,7 @@ _libelf_cvt_GNUHASH64_tof(unsigned char *dst, size_t dsz, unsigned char *src,
if (dsz < srcsz)
return (0);
nchains = srcsz / sizeof(uint32_t);
nchains = (uint32_t) (srcsz / sizeof(uint32_t));
for (n = 0; n < nchains; n++) {
t32 = *s32++;
if (byteswap)
@ -1078,15 +1078,8 @@ _libelf_translator_function *
_libelf_get_translator(Elf_Type t, int direction, int elfclass, int elfmachine)
{
assert(elfclass == ELFCLASS32 || elfclass == ELFCLASS64);
#if 0
assert(elfmachine >= EM_NONE && elfmachine < EM__LAST__);
#endif
assert(direction == ELF_TOFILE || direction == ELF_TOMEMORY);
if (t >= ELF_T_NUM ||
(elfclass != ELFCLASS32 && elfclass != ELFCLASS64) ||
(direction != ELF_TOFILE && direction != ELF_TOMEMORY))
return (NULL);
assert(t >= ELF_T_FIRST && t <= ELF_T_LAST);
/* TODO: Handle MIPS64 REL{,A} sections (ticket #559). */
(void) elfmachine;

View File

@ -28,7 +28,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: libelf_data.c 3174 2015-03-27 17:13:41Z emaste $");
ELFTC_VCSID("$Id: libelf_data.c 3737 2019-05-05 14:49:50Z jkoshy $");
int
_libelf_xlate_shtype(uint32_t sht)
@ -89,8 +89,14 @@ _libelf_xlate_shtype(uint32_t sht)
* OS, processor and user-defined section types) are
* legal, but since we do not know anything more about
* their semantics, we return a type of ELF_T_BYTE.
*
* The ELF specification uses 32 bit unsigned values for
* denoting section types, and defines SHT_HIUSER to be
* 0xFFFFFFFFUL (i.e., UINT32_MAX). Consequently, we only
* need to check that 'sht' is greater than or equal to
* SHT_LOOS.
*/
if (sht >= SHT_LOOS && sht <= SHT_HIUSER)
if (sht >= SHT_LOOS)
return (ELF_T_BYTE);
/*

View File

@ -31,7 +31,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: libelf_ehdr.c 3632 2018-10-10 21:12:43Z jkoshy $");
ELFTC_VCSID("$Id: libelf_ehdr.c 3732 2019-04-22 11:08:38Z jkoshy $");
/*
* Retrieve counts for sections, phdrs and the section string table index
@ -51,7 +51,12 @@ _libelf_load_extended(Elf *e, int ec, uint64_t shoff, uint16_t phnum,
fsz = _libelf_fsize(ELF_T_SHDR, ec, e->e_version, 1);
assert(fsz > 0);
if (e->e_rawsize < shoff + fsz) { /* raw file too small */
if (shoff + fsz < shoff) { /* Numeric overflow. */
LIBELF_SET_ERROR(HEADER, 0);
return (0);
}
if ((uint64_t) e->e_rawsize < shoff + fsz) {
LIBELF_SET_ERROR(HEADER, 0);
return (0);
}
@ -138,14 +143,13 @@ _libelf_ehdr(Elf *e, int ec, int allocate)
fsz = _libelf_fsize(ELF_T_EHDR, ec, e->e_version, (size_t) 1);
assert(fsz > 0);
if (e->e_cmd != ELF_C_WRITE && e->e_rawsize < fsz) {
if (e->e_cmd != ELF_C_WRITE && e->e_rawsize < (off_t) fsz) {
LIBELF_SET_ERROR(HEADER, 0);
return (NULL);
}
msz = _libelf_msize(ELF_T_EHDR, ec, EV_CURRENT);
assert(msz > 0);
if ((msz = _libelf_msize(ELF_T_EHDR, ec, EV_CURRENT)) == 0)
return (NULL);
if ((ehdr = calloc((size_t) 1, msz)) == NULL) {
LIBELF_SET_ERROR(RESOURCE, 0);

View File

@ -29,7 +29,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: libelf_extended.c 3174 2015-03-27 17:13:41Z emaste $");
ELFTC_VCSID("$Id: libelf_extended.c 3712 2019-03-16 22:23:34Z jkoshy $");
/*
* Retrieve section #0, allocating a new section if needed.
@ -57,7 +57,7 @@ _libelf_setshnum(Elf *e, void *eh, int ec, size_t shnum)
assert(scn->s_ndx == SHN_UNDEF);
if (ec == ELFCLASS32)
scn->s_shdr.s_shdr32.sh_size = shnum;
scn->s_shdr.s_shdr32.sh_size = (Elf32_Word) shnum;
else
scn->s_shdr.s_shdr64.sh_size = shnum;
@ -87,9 +87,9 @@ _libelf_setshstrndx(Elf *e, void *eh, int ec, size_t shstrndx)
assert(scn->s_ndx == SHN_UNDEF);
if (ec == ELFCLASS32)
scn->s_shdr.s_shdr32.sh_link = shstrndx;
scn->s_shdr.s_shdr32.sh_link = (Elf32_Word) shstrndx;
else
scn->s_shdr.s_shdr64.sh_link = shstrndx;
scn->s_shdr.s_shdr64.sh_link = (Elf64_Word) shstrndx;
(void) elf_flagshdr(scn, ELF_C_SET, ELF_F_DIRTY);
@ -116,9 +116,9 @@ _libelf_setphnum(Elf *e, void *eh, int ec, size_t phnum)
assert(scn->s_ndx == SHN_UNDEF);
if (ec == ELFCLASS32)
scn->s_shdr.s_shdr32.sh_info = phnum;
scn->s_shdr.s_shdr32.sh_info = (Elf32_Word) phnum;
else
scn->s_shdr.s_shdr64.sh_info = phnum;
scn->s_shdr.s_shdr64.sh_info = (Elf64_Word) phnum;
(void) elf_flagshdr(scn, ELF_C_SET, ELF_F_DIRTY);

View File

@ -31,7 +31,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: libelf_memory.c 3013 2014-03-23 06:16:59Z jkoshy $");
ELFTC_VCSID("$Id: libelf_memory.c 3738 2019-05-05 21:49:06Z jkoshy $");
/*
* Create an ELF descriptor for a memory image, optionally reporting
@ -54,7 +54,7 @@ _libelf_memory(unsigned char *image, size_t sz, int reporterror)
e->e_cmd = ELF_C_READ;
e->e_rawfile = image;
e->e_rawsize = sz;
e->e_rawsize = (off_t) sz;
#undef LIBELF_IS_ELF
#define LIBELF_IS_ELF(P) ((P)[EI_MAG0] == ELFMAG0 && \
@ -78,7 +78,7 @@ _libelf_memory(unsigned char *image, size_t sz, int reporterror)
if (error != ELF_E_NONE) {
if (reporterror) {
LIBELF_PRIVATE(error) = LIBELF_ERROR(error, 0);
(void) _libelf_release_elf(e);
_libelf_release_elf(e);
return (NULL);
}
} else {

View File

@ -30,7 +30,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: libelf_msize.m4 3174 2015-03-27 17:13:41Z emaste $");
ELFTC_VCSID("$Id: libelf_msize.m4 3732 2019-04-22 11:08:38Z jkoshy $");
/* WARNING: GENERATED FROM __file__. */
@ -87,6 +87,14 @@ static struct msize msize[ELF_T_NUM] = {
MSIZES(ELF_TYPE_LIST)
};
/*
* Returns the memory size of the specified ELF type 't' of ELF
* class 'ec' and ELF version 'version'.
*
* If the specified combination of ELF type, class, and version is
* unsupported then a value of 0 will be returned and the appropriate
* library error code set.
*/
size_t
_libelf_msize(Elf_Type t, int elfclass, unsigned int version)
{
@ -102,5 +110,10 @@ _libelf_msize(Elf_Type t, int elfclass, unsigned int version)
sz = (elfclass == ELFCLASS32) ? msize[t].msz32 : msize[t].msz64;
if (sz == 0) {
LIBELF_SET_ERROR(UNIMPL, 0);
return (0);
}
return (sz);
}

View File

@ -31,7 +31,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: libelf_phdr.c 3632 2018-10-10 21:12:43Z jkoshy $");
ELFTC_VCSID("$Id: libelf_phdr.c 3732 2019-04-22 11:08:38Z jkoshy $");
void *
_libelf_getphdr(Elf *e, int ec)
@ -77,14 +77,18 @@ _libelf_getphdr(Elf *e, int ec)
assert(fsz > 0);
if (phoff + fsz < phoff) { /* Numeric overflow. */
LIBELF_SET_ERROR(HEADER, 0);
return (NULL);
}
if ((uint64_t) e->e_rawsize < (phoff + fsz)) {
LIBELF_SET_ERROR(HEADER, 0);
return (NULL);
}
msz = _libelf_msize(ELF_T_PHDR, ec, EV_CURRENT);
assert(msz > 0);
if ((msz = _libelf_msize(ELF_T_PHDR, ec, EV_CURRENT)) == 0)
return (NULL);
if ((phdr = calloc(phnum, msz)) == NULL) {
LIBELF_SET_ERROR(RESOURCE, 0);
@ -125,9 +129,8 @@ _libelf_newphdr(Elf *e, int ec, size_t count)
assert(ec == ELFCLASS32 || ec == ELFCLASS64);
assert(e->e_version == EV_CURRENT);
msz = _libelf_msize(ELF_T_PHDR, ec, e->e_version);
assert(msz > 0);
if ((msz = _libelf_msize(ELF_T_PHDR, ec, e->e_version)) == 0)
return (NULL);
newphdr = NULL;
if (count > 0 && (newphdr = calloc(count, msz)) == NULL) {

View File

@ -29,7 +29,7 @@
#include "_libelf.h"
ELFTC_VCSID("$Id: libelf_xlate.c 3632 2018-10-10 21:12:43Z jkoshy $");
ELFTC_VCSID("$Id: libelf_xlate.c 3732 2019-04-22 11:08:38Z jkoshy $");
/*
* Translate to/from the file representation of ELF objects.
@ -83,9 +83,8 @@ _libelf_xlate(Elf_Data *dst, const Elf_Data *src, unsigned int encoding,
(src->d_type, (size_t) 1, src->d_version)) == 0)
return (NULL);
msz = _libelf_msize(src->d_type, elfclass, src->d_version);
assert(msz > 0);
if ((msz = _libelf_msize(src->d_type, elfclass, src->d_version)) == 0)
return (NULL);
if (src->d_size % (direction == ELF_TOMEMORY ? fsz : msz)) {
LIBELF_SET_ERROR(DATA, 0);

View File

@ -0,0 +1,31 @@
# Enable additional warnings.
CFLAGS+= -Wa,--fatal-warnings
CFLAGS+= -Wall
CFLAGS+= -Wcast-align
CFLAGS+= -Wcast-qual
CFLAGS+= -Wchar-subscripts
CFLAGS+= -Wconversion
CFLAGS+= -Werror
CFLAGS+= -Wextra
CFLAGS+= -Wformat=2
CFLAGS+= -Winline
CFLAGS+= -Wmissing-prototypes
CFLAGS+= -Wnested-externs
CFLAGS+= -Wempty-body
CFLAGS+= -Wformat-y2k
CFLAGS+= -Wformat-zero-length
CFLAGS+= -Wpointer-sign
CFLAGS+= -Wpointer-to-int-cast
CFLAGS+= -Wsign-compare
CFLAGS+= -Wunused-const-variable
CFLAGS+= -Wunused-parameter
CFLAGS+= -Wold-style-definition
CFLAGS+= -Wpointer-arith
CFLAGS+= -Wredundant-decls
CFLAGS+= -Wreturn-type
CFLAGS+= -Wshadow
CFLAGS+= -Wstrict-prototypes
CFLAGS+= -Wstrict-overflow
CFLAGS+= -Wswitch
CFLAGS+= -Wunused-parameter
CFLAGS+= -Wwrite-strings

View File

@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: elftc_bfd_find_target.3 3645 2018-10-15 20:17:14Z jkoshy $
.\" $Id: elftc_bfd_find_target.3 3752 2019-06-28 01:12:53Z emaste $
.\"
.Dd November 30, 2011
.Dd June 27, 2019
.Dt ELFTC_BFD_FIND_TARGET 3
.Os
.Sh NAME

View File

@ -36,7 +36,7 @@
#include "libelftc.h"
#include "_libelftc.h"
ELFTC_VCSID("$Id: elftc_string_table.c 2869 2013-01-06 13:29:18Z jkoshy $");
ELFTC_VCSID("$Id: elftc_string_table.c 3750 2019-06-28 01:12:10Z emaste $");
#define ELFTC_STRING_TABLE_DEFAULT_SIZE (4*1024)
#define ELFTC_STRING_TABLE_EXPECTED_STRING_SIZE 16

View File

@ -22,9 +22,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: elftc_string_table_create.3 3645 2018-10-15 20:17:14Z jkoshy $
.\" $Id: elftc_string_table_create.3 3750 2019-06-28 01:12:10Z emaste $
.\"
.Dd June 19, 2019
.Dd June 27, 2019
.Dt ELFTC_STRING_TABLE_CREATE 3
.Os
.Sh NAME

View File

@ -24,7 +24,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD: users/kaiwang27/elftc/libelftc.h 392 2009-05-31 19:17:46Z kaiwang27 $
* $Id: libelftc.h 3489 2016-08-31 00:12:15Z emaste $
* $Id: libelftc.h 3744 2019-06-28 00:41:47Z emaste $
*/
#ifndef _LIBELFTC_H_

View File

@ -30,7 +30,7 @@
#include "_libelftc.h"
ELFTC_VCSID("$Id: libelftc_bfdtarget.c 3516 2017-02-10 02:33:08Z emaste $");
ELFTC_VCSID("$Id: libelftc_bfdtarget.c 3752 2019-06-28 01:12:53Z emaste $");
struct _Elftc_Bfd_Target _libelftc_targets[] = {

View File

@ -3,7 +3,7 @@
# This script generates a project-wide version identifier for use by
# the `elftc_version()' API.
#
# $Id: make-toolchain-version 3414 2016-02-16 22:55:28Z jkoshy $
# $Id: make-toolchain-version 3731 2019-04-06 14:28:34Z jkoshy $
#
# Defaults.
@ -33,6 +33,32 @@ usage()
exit 1
}
# Determine the revision number for the source tree.
#
# - If CVS is detected, we use the string `unknown'.
# - If SVN is detected, we use the `svninfo' tool to determine the
# in-tree revision number.
# - Otherwise, we use `git --describe'.
get_revision_string()
{
v="unknown:unknown"
if [ -d CVS ]; then # Look for CVS (NetBSD).
v="cvs:unknown"
elif [ -d .svn ]; then # An SVN checkout (SourceForge or FreeBSD).
svnversion="$(svnversion 2>/dev/null)"
if [ -n "${svnversion}" ]; then
v="svn:${svnversion}"
fi
else # Try git (DragonflyBSD).
gitversion="$(git describe --all --dirty --long 2> /dev/null)"
if [ -n "${gitversion}" ]; then
v="git:${gitversion}"
fi
fi
echo "${v}"
}
#
# Parse options.
#
@ -51,37 +77,14 @@ done
[ -n "${top}" ] || usage
# Try to determine the in-tree revision number.
#
# This script attempts to handle the case where our sources have been
# incorporated into an operating system's base sources.
#
# - If SVN is detected, we use the `svninfo' tool to determine the
# in-tree revision number.
# - If CVS is detected, we use the string `unknown'.
# - Otherwise, we use `git --describe'.
curdir=`pwd`
cd ${top} || usage "ERROR: Cannot change directory to \"${top}\"."
if [ -d CVS ]; then # Look for CVS (NetBSD).
versionstring=" cvs:unknown"
else # Try git (DragonFlyBSD).
gitversion="$(git describe --all --dirty --long 2> /dev/null)"
if [ -n "${gitversion}" ]; then
versionstring=" git:${gitversion}"
else # Assume an SVN checkout (SourceForge or FreeBSD).
svnversion="$(svnversion)"
if [ -n "${svnversion}" ]; then
versionstring=" svn:$(svnversion)"
fi
fi
fi
if [ -z "${versionstring}" ]; then
echo "ERROR: cannot determine a revision number." 1>&2
# Determine the in-tree revision number.
versionstring="$(get_revision_string)" || {
echo "ERROR: cannot determine a revision number." 1>&2;
exit 1
fi
}
cd ${curdir} || usage "Cannot change back to ${curdir}."

View File

@ -52,7 +52,7 @@
#include "_elftc.h"
ELFTC_VCSID("$Id: nm.c 3504 2016-12-17 15:33:16Z kaiwang27 $");
ELFTC_VCSID("$Id: nm.c 3722 2019-03-23 17:01:58Z jkoshy $");
/* symbol information list */
STAILQ_HEAD(sym_head, sym_entry);
@ -1183,7 +1183,6 @@ read_elf(Elf *elf, const char *filename, Elf_Kind kind)
Elf_Arhdr *arhdr;
Elf_Scn *scn;
GElf_Shdr shdr;
GElf_Half i;
Dwarf_Line *lbuf;
Dwarf_Unsigned lineno;
Dwarf_Signed lcount, filecount;
@ -1198,7 +1197,7 @@ read_elf(Elf *elf, const char *filename, Elf_Kind kind)
struct var_info_entry *var;
const char *shname, *objname;
char *type_table, **sec_table, *sfile, **src_files;
size_t shstrndx, shnum, dynndx, strndx;
size_t i, shstrndx, shnum, dynndx, strndx;
int ret, rtn, e_err;
#define OBJNAME (objname == NULL ? filename : objname)

View File

@ -22,9 +22,9 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $Id: readelf.1 3642 2018-10-14 14:24:28Z jkoshy $
.\" $Id: readelf.1 3753 2019-06-28 01:13:13Z emaste $
.\"
.Dd May 30, 2019
.Dd June 27, 2019
.Dt READELF 1
.Os
.Sh NAME

View File

@ -52,7 +52,7 @@
#include "_elftc.h"
ELFTC_VCSID("$Id: readelf.c 3649 2018-11-24 03:26:23Z emaste $");
ELFTC_VCSID("$Id: readelf.c 3769 2019-06-29 15:15:02Z emaste $");
/* Backwards compatability for older FreeBSD releases. */
#ifndef STB_GNU_UNIQUE
@ -220,12 +220,12 @@ struct eflags_desc {
const char *desc;
};
struct mips_option {
struct flag_desc {
uint64_t flag;
const char *desc;
};
struct flag_desc {
struct mips_option {
uint64_t flag;
const char *desc;
};
@ -2381,7 +2381,7 @@ dump_eflags(struct readelf *re, uint64_t e_flags)
case 2: printf(", OpenPOWER ELF V2 ABI"); break;
default: break;
}
/* explicit fall through*/
/* FALLTHROUGH */
case EM_PPC:
edesc = powerpc_eflags_desc;
break;
@ -7228,13 +7228,13 @@ dump_object(struct readelf *re, int fd)
if ((re->elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) {
warnx("elf_begin() failed: %s", elf_errmsg(-1));
return;
goto done;
}
switch (elf_kind(re->elf)) {
case ELF_K_NONE:
warnx("Not an ELF file.");
return;
goto done;
case ELF_K_ELF:
dump_elf(re);
break;
@ -7243,10 +7243,11 @@ dump_object(struct readelf *re, int fd)
break;
default:
warnx("Internal: libelf returned unknown elf kind.");
return;
}
done:
elf_end(re->elf);
close(fd);
}
static void

View File

@ -6,5 +6,5 @@
const char *
elftc_version(void)
{
return "elftoolchain r3668M";
return "elftoolchain r3769";
}