Browse Source

Merge branch 'freebsd/current/master' into hardened/current/master

* freebsd/current/master:
  Remove useless NULL check
  release: chase ports r519089 (rpi-firmware update)
  UPDATING: Add long-belated note about certs in base
  mlx5: Do not poke hardware for statistic after teardown is started.
  Add basic support for TCP/IP based hardware TLS offload to mlx5core.
  Remove duplicate g_debugflags declaration.
  sx: check for SX_LOCK_SHARED | SX_LOCK_WRITE_SPINNER when exclusive-locking
  nullfs: locklessly check for entries in null_hashget
  vfs: remove 'active' variable from _vdrop
  Import ELF Tool Chain snapshot at r3769
hardened/current/master
HardenedBSD Sync Service 5 months ago
parent
commit
43ee4e6249
97 changed files with 974 additions and 332 deletions
  1. +10
    -0
      UPDATING
  2. +22
    -0
      contrib/elftoolchain/.cirrus.yml
  3. +5
    -5
      contrib/elftoolchain/README.rst
  4. +1
    -1
      contrib/elftoolchain/addr2line/addr2line.c
  5. +40
    -4
      contrib/elftoolchain/common/elfdefinitions.h
  6. +3
    -1
      contrib/elftoolchain/common/native-elf-format
  7. +1
    -1
      contrib/elftoolchain/elfcopy/ascii.c
  8. +1
    -1
      contrib/elftoolchain/elfcopy/binary.c
  9. +1
    -1
      contrib/elftoolchain/elfcopy/elfcopy.h
  10. +1
    -1
      contrib/elftoolchain/elfcopy/main.c
  11. +1
    -1
      contrib/elftoolchain/elfcopy/sections.c
  12. +1
    -1
      contrib/elftoolchain/elfdump/elfdump.c
  13. +1
    -1
      contrib/elftoolchain/libdwarf/dwarf.h
  14. +2
    -2
      contrib/elftoolchain/libdwarf/dwarf_dump.c
  15. +1
    -1
      contrib/elftoolchain/libdwarf/libdwarf_attr.c
  16. +1
    -1
      contrib/elftoolchain/libdwarf/libdwarf_reloc.c
  17. +3
    -3
      contrib/elftoolchain/libelf/_libelf.h
  18. +7
    -1
      contrib/elftoolchain/libelf/_libelf_config.h
  19. +32
    -22
      contrib/elftoolchain/libelf/elf.3
  20. +11
    -7
      contrib/elftoolchain/libelf/elf_data.c
  21. +3
    -3
      contrib/elftoolchain/libelf/elf_end.c
  22. +9
    -5
      contrib/elftoolchain/libelf/elf_flagdata.3
  23. +8
    -3
      contrib/elftoolchain/libelf/elf_getdata.3
  24. +2
    -2
      contrib/elftoolchain/libelf/elf_getident.c
  25. +5
    -2
      contrib/elftoolchain/libelf/elf_next.3
  26. +15
    -1
      contrib/elftoolchain/libelf/elf_next.c
  27. +8
    -4
      contrib/elftoolchain/libelf/elf_open.3
  28. +11
    -2
      contrib/elftoolchain/libelf/elf_rand.c
  29. +2
    -4
      contrib/elftoolchain/libelf/elf_rawfile.c
  30. +4
    -3
      contrib/elftoolchain/libelf/elf_scn.c
  31. +6
    -2
      contrib/elftoolchain/libelf/elf_update.3
  32. +33
    -14
      contrib/elftoolchain/libelf/elf_update.c
  33. +7
    -4
      contrib/elftoolchain/libelf/gelf.3
  34. +5
    -6
      contrib/elftoolchain/libelf/gelf_cap.c
  35. +5
    -5
      contrib/elftoolchain/libelf/gelf_dyn.c
  36. +8
    -2
      contrib/elftoolchain/libelf/gelf_getcap.3
  37. +9
    -2
      contrib/elftoolchain/libelf/gelf_getdyn.3
  38. +8
    -2
      contrib/elftoolchain/libelf/gelf_getmove.3
  39. +8
    -2
      contrib/elftoolchain/libelf/gelf_getrel.3
  40. +8
    -2
      contrib/elftoolchain/libelf/gelf_getrela.3
  41. +8
    -2
      contrib/elftoolchain/libelf/gelf_getsym.3
  42. +8
    -2
      contrib/elftoolchain/libelf/gelf_getsyminfo.3
  43. +10
    -2
      contrib/elftoolchain/libelf/gelf_getsymshndx.3
  44. +5
    -5
      contrib/elftoolchain/libelf/gelf_move.c
  45. +5
    -3
      contrib/elftoolchain/libelf/gelf_newehdr.3
  46. +5
    -3
      contrib/elftoolchain/libelf/gelf_newphdr.3
  47. +6
    -6
      contrib/elftoolchain/libelf/gelf_rel.c
  48. +6
    -6
      contrib/elftoolchain/libelf/gelf_rela.c
  49. +5
    -5
      contrib/elftoolchain/libelf/gelf_sym.c
  50. +5
    -5
      contrib/elftoolchain/libelf/gelf_syminfo.c
  51. +5
    -5
      contrib/elftoolchain/libelf/gelf_symshndx.c
  52. +10
    -25
      contrib/elftoolchain/libelf/libelf_allocate.c
  53. +37
    -6
      contrib/elftoolchain/libelf/libelf_ar.c
  54. +4
    -11
      contrib/elftoolchain/libelf/libelf_convert.m4
  55. +8
    -2
      contrib/elftoolchain/libelf/libelf_data.c
  56. +10
    -6
      contrib/elftoolchain/libelf/libelf_ehdr.c
  57. +6
    -6
      contrib/elftoolchain/libelf/libelf_extended.c
  58. +3
    -3
      contrib/elftoolchain/libelf/libelf_memory.c
  59. +14
    -1
      contrib/elftoolchain/libelf/libelf_msize.m4
  60. +10
    -7
      contrib/elftoolchain/libelf/libelf_phdr.c
  61. +3
    -4
      contrib/elftoolchain/libelf/libelf_xlate.c
  62. +31
    -0
      contrib/elftoolchain/libelf/os.Linux.mk
  63. +2
    -2
      contrib/elftoolchain/libelftc/elftc_bfd_find_target.3
  64. +1
    -1
      contrib/elftoolchain/libelftc/elftc_string_table.c
  65. +2
    -2
      contrib/elftoolchain/libelftc/elftc_string_table_create.3
  66. +1
    -1
      contrib/elftoolchain/libelftc/libelftc.h
  67. +1
    -1
      contrib/elftoolchain/libelftc/libelftc_bfdtarget.c
  68. +32
    -29
      contrib/elftoolchain/libelftc/make-toolchain-version
  69. +2
    -3
      contrib/elftoolchain/nm/nm.c
  70. +2
    -2
      contrib/elftoolchain/readelf/readelf.1
  71. +8
    -7
      contrib/elftoolchain/readelf/readelf.c
  72. +1
    -1
      lib/libelftc/elftc_version.c
  73. +3
    -3
      release/arm/RPI-B.conf
  74. +5
    -3
      release/arm64/RPI3.conf
  75. +2
    -0
      sys/conf/files
  76. +23
    -1
      sys/dev/mlx5/device.h
  77. +2
    -1
      sys/dev/mlx5/driver.h
  78. +8
    -0
      sys/dev/mlx5/mlx5_core/mlx5_cmd.c
  79. +6
    -0
      sys/dev/mlx5/mlx5_core/mlx5_fw.c
  80. +2
    -0
      sys/dev/mlx5/mlx5_core/mlx5_main.c
  81. +120
    -0
      sys/dev/mlx5/mlx5_core/mlx5_tls.c
  82. +11
    -0
      sys/dev/mlx5/mlx5_en/en.h
  83. +3
    -2
      sys/dev/mlx5/mlx5_en/mlx5_en_main.c
  84. +161
    -6
      sys/dev/mlx5/mlx5_ifc.h
  85. +39
    -0
      sys/dev/mlx5/tls.h
  86. +2
    -0
      sys/fs/nullfs/null_subr.c
  87. +6
    -3
      sys/geom/geom.h
  88. +0
    -12
      sys/geom/geom_int.h
  89. +1
    -1
      sys/geom/geom_subr.c
  90. +1
    -1
      sys/geom/mirror/g_mirror_ctl.c
  91. +1
    -1
      sys/geom/part/g_part.c
  92. +1
    -1
      sys/geom/part/g_part_mbr.c
  93. +1
    -1
      sys/geom/part/g_part_vtoc8.c
  94. +6
    -0
      sys/kern/kern_sx.c
  95. +3
    -5
      sys/kern/vfs_subr.c
  96. +1
    -0
      sys/modules/mlx5/Makefile
  97. +1
    -2
      sys/netinet6/udp6_usrreq.c

+ 10
- 0
UPDATING View File

@@ -26,6 +26,16 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 13.x IS SLOW:
disable the most expensive debugging functionality run
"ln -s 'abort:false,junk:false' /etc/malloc.conf".)

20191205:
The root certificates of the Mozilla CA Certificate Store have been
imported into the base system and can be managed with the certctl(8)
utility. If you have installed the security/ca_root_nss port or package
with the ETCSYMLINK option (the default), be advised that there may be
differences between those included in the port and those included in
base due to differences in nss branch used as well as general update
frequency. Note also that certctl(8) cannot manage certs in the
format used by the security/ca_root_nss port.

20191120:
The amd(8) automount daemon has been disabled by default, and will be
removed in the future. As of FreeBSD 10.1 the autofs(5) is available

+ 22
- 0
contrib/elftoolchain/.cirrus.yml 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

+ 5
- 5
contrib/elftoolchain/README.rst 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

+ 1
- 1
contrib/elftoolchain/addr2line/addr2line.c 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;

+ 40
- 4
contrib/elftoolchain/common/elfdefinitions.h 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.

+ 3
- 1
contrib/elftoolchain/common/native-elf-format 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";
}

+ 1
- 1
contrib/elftoolchain/elfcopy/ascii.c 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);

+ 1
- 1
contrib/elftoolchain/elfcopy/binary.c 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

+ 1
- 1
contrib/elftoolchain/elfcopy/elfcopy.h 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>

+ 1
- 1
contrib/elftoolchain/elfcopy/main.c 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
{

+ 1
- 1
contrib/elftoolchain/elfcopy/sections.c 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);

+ 1
- 1
contrib/elftoolchain/elfdump/elfdump.c 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"

+ 1
- 1
contrib/elftoolchain/libdwarf/dwarf.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_

+ 2
- 2
contrib/elftoolchain/libdwarf/dwarf_dump.c 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);
}

+ 1
- 1
contrib/elftoolchain/libdwarf/libdwarf_attr.c 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)

+ 1
- 1
contrib/elftoolchain/libdwarf/libdwarf_reloc.c 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)

+ 3
- 3
contrib/elftoolchain/libelf/_libelf.h 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);

+ 7
- 1
contrib/elftoolchain/libelf/_libelf_config.h 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

+ 32
- 22
contrib/elftoolchain/libelf/elf.3 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

+ 11
- 7
contrib/elftoolchain/libelf/elf_data.c 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);
}

+ 3
- 3
contrib/elftoolchain/libelf/elf_end.c 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);

+ 9
- 5
contrib/elftoolchain/libelf/elf_flagdata.3 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]"

+ 8
- 3
contrib/elftoolchain/libelf/elf_getdata.3 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 ,

+ 2
- 2
contrib/elftoolchain/libelf/elf_getident.c 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);

+ 5
- 2
contrib/elftoolchain/libelf/elf_next.3 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 ,

+ 15
- 1
contrib/elftoolchain/libelf/elf_next.c 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);
}

+ 8
- 4
contrib/elftoolchain/libelf/elf_open.3 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

+ 11
- 2
contrib/elftoolchain/libelf/elf_rand.c 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;
}

+ 2
- 4
contrib/elftoolchain/libelf/elf_rawfile.c 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);
}

+ 4
- 3
contrib/elftoolchain/libelf/elf_scn.c 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); \
} \

+ 6
- 2
contrib/elftoolchain/libelf/elf_update.3 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

+ 33
- 14
contrib/elftoolchain/libelf/elf_update.c 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;
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);

+ 7
- 4
contrib/elftoolchain/libelf/gelf.3 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

+ 5
- 6
contrib/elftoolchain/libelf/gelf_cap.c 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);

+ 5
- 5
contrib/elftoolchain/libelf/gelf_dyn.c 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) {

+ 8
- 2
contrib/elftoolchain/libelf/gelf_getcap.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_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 ,

+ 9
- 2
contrib/elftoolchain/libelf/gelf_getdyn.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 ,

+ 8
- 2
contrib/elftoolchain/libelf/gelf_getmove.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 ,

+ 8
- 2
contrib/elftoolchain/libelf/gelf_getrel.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 ,

+ 8
- 2
contrib/elftoolchain/libelf/gelf_getrela.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 ,

+ 8
- 2
contrib/elftoolchain/libelf/gelf_getsym.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 ,

+ 8
- 2
contrib/elftoolchain/libelf/gelf_getsyminfo.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 ,

+ 10
- 2
contrib/elftoolchain/libelf/gelf_getsymshndx.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 ,

+ 5
- 5
contrib/elftoolchain/libelf/gelf_move.c 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) {

+ 5
- 3
contrib/elftoolchain/libelf/gelf_newehdr.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_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

+ 5
- 3
contrib/elftoolchain/libelf/gelf_newphdr.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_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

+ 6
- 6
contrib/elftoolchain/libelf/gelf_rel.c 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);

+ 6
- 6
contrib/elftoolchain/libelf/gelf_rela.c 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);

+ 5
- 5
contrib/elftoolchain/libelf/gelf_sym.c 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) {

+ 5
- 5
contrib/elftoolchain/libelf/gelf_syminfo.c 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) {

+ 5
- 5
contrib/elftoolchain/libelf/gelf_symshndx.c 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) {

+ 10
- 25
contrib/elftoolchain/libelf/libelf_allocate.c 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 *

+ 37
- 6
contrib/elftoolchain/libelf/libelf_ar.c 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;

+ 4
- 11
contrib/elftoolchain/libelf/libelf_convert.m4 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;

+ 8
- 2
contrib/elftoolchain/libelf/libelf_data.c 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);

/*

+ 10
- 6
contrib/elftoolchain/libelf/libelf_ehdr.c 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);

+ 6
- 6
contrib/elftoolchain/libelf/libelf_extended.c 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);


+ 3
- 3
contrib/elftoolchain/libelf/libelf_memory.c 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 {

+ 14
- 1
contrib/elftoolchain/libelf/libelf_msize.m4 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)
{