summaryrefslogtreecommitdiffstats
path: root/libelf
diff options
context:
space:
mode:
Diffstat (limited to 'libelf')
-rw-r--r--libelf/ChangeLog28
-rw-r--r--libelf/elf.h106
-rw-r--r--libelf/elf_compress.c12
-rw-r--r--libelf/elf_getdata.c2
-rw-r--r--libelf/elf_getphdrnum.c20
-rw-r--r--libelf/elf_strptr.c2
6 files changed, 151 insertions, 19 deletions
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index dde6c81d..8f6d2d2d 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,31 @@
+2020-06-04 Mark Wielaard <[email protected]>
+
+ * elf.h: Update from glibc.
+
+2020-05-08 Mark Wielaard <[email protected]>
+
+ * elf_strptr.c (elf_strptr): Check shdr is not NULL.
+
+2020-05-08 Mark Wielaard <[email protected]>
+
+ * elf_getdata.c (__libelf_set_rawdata_wrlock): Check
+ __gelf_getehdr_rdlock return value.
+
+2020-04-25 Mark Wielaard <[email protected]>
+
+ * elf_compress.c (__libelf_compress): Remove free (out_buf).
+
+2020-03-18 Omar Sandoval <[email protected]>
+
+ * elf_getphdrnum.c (__elf_getphdrnum_rdlock): Call
+ __elf{32,64}_getshdr_rdlock if the shdr is not cached.
+
+2019-03-20 Matthias Maennich <[email protected]>
+
+ * elf_compress.c (__libelf_compress): Always call deflate_cleanup
+ in failure path. Call deflateEnd only once.
+ (__libelf_decompress): Call inflateEnd only once.
+
2019-06-18 Mark Wielaard <[email protected]>
* common.h (allocate_elf): Use int64_t instead of off_t for offset.
diff --git a/libelf/elf.h b/libelf/elf.h
index 01648bdb..197b557d 100644
--- a/libelf/elf.h
+++ b/libelf/elf.h
@@ -1,5 +1,5 @@
/* This file defines standard ELF types, structures, and macros.
- Copyright (C) 1995-2019 Free Software Foundation, Inc.
+ Copyright (C) 1995-2020 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -14,7 +14,7 @@
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
+ <https://www.gnu.org/licenses/>. */
#ifndef _ELF_H
#define _ELF_H 1
@@ -330,7 +330,7 @@ typedef struct
#define EM_CLOUDSHIELD 192 /* CloudShield */
#define EM_COREA_1ST 193 /* KIPO-KAIST Core-A 1st gen. */
#define EM_COREA_2ND 194 /* KIPO-KAIST Core-A 2nd gen. */
-#define EM_ARC_COMPACT2 195 /* Synopsys ARCompact V2 */
+#define EM_ARCV2 195 /* Synopsys ARCv2 ISA. */
#define EM_OPEN8 196 /* Open8 RISC */
#define EM_RL78 197 /* Renesas RL78 */
#define EM_VIDEOCORE5 198 /* Broadcom VideoCore V */
@@ -721,6 +721,7 @@ typedef struct
#define PT_GNU_EH_FRAME 0x6474e550 /* GCC .eh_frame_hdr segment */
#define PT_GNU_STACK 0x6474e551 /* Indicates stack executability */
#define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */
+#define PT_GNU_PROPERTY 0x6474e553 /* GNU property */
#define PT_LOSUNW 0x6ffffffa
#define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */
#define PT_SUNWSTACK 0x6ffffffb /* Stack segment */
@@ -809,9 +810,16 @@ typedef struct
#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */
#define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension
registers */
+#define NT_ARM_PAC_MASK 0x406 /* ARM pointer authentication
+ code masks. */
+#define NT_ARM_PACA_KEYS 0x407 /* ARM pointer authentication
+ address keys. */
+#define NT_ARM_PACG_KEYS 0x408 /* ARM pointer authentication
+ generic key. */
#define NT_VMCOREDD 0x700 /* Vmcore Device Dump Note. */
#define NT_MIPS_DSP 0x800 /* MIPS DSP ASE registers. */
#define NT_MIPS_FP_MODE 0x801 /* MIPS floating-point mode. */
+#define NT_MIPS_MSA 0x802 /* MIPS SIMD registers. */
/* Legal values for the note segment descriptor types for object files. */
@@ -987,6 +995,9 @@ typedef struct
#define DF_1_SINGLETON 0x02000000 /* Singleton symbols are used. */
#define DF_1_STUB 0x04000000
#define DF_1_PIE 0x08000000
+#define DF_1_KMOD 0x10000000
+#define DF_1_WEAKFILTER 0x20000000
+#define DF_1_NOCOMMON 0x40000000
/* Flags for the feature selection in DT_FEATURE_1. */
#define DTF_1_PARINIT 0x00000001
@@ -1308,6 +1319,12 @@ typedef struct
/* Application-specific semantics, hi */
#define GNU_PROPERTY_HIUSER 0xffffffff
+/* AArch64 specific GNU properties. */
+#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000
+
+#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0)
+#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1U << 1)
+
/* The x86 instruction sets indicated by the corresponding bits are
used in program. Their support in the hardware is optional. */
#define GNU_PROPERTY_X86_ISA_1_USED 0xc0000000
@@ -1705,6 +1722,7 @@ typedef struct
#define SHT_MIPS_EH_REGION 0x70000027
#define SHT_MIPS_XLATE_OLD 0x70000028
#define SHT_MIPS_PDR_EXCEPTION 0x70000029
+#define SHT_MIPS_XHASH 0x7000002b
/* Legal values for sh_flags field of Elf32_Shdr. */
@@ -1952,7 +1970,9 @@ typedef struct
in a PIE as it stores a relative offset from the address of the tag
rather than an absolute address. */
#define DT_MIPS_RLD_MAP_REL 0x70000035
-#define DT_MIPS_NUM 0x36
+/* GNU-style hash table with xlat. */
+#define DT_MIPS_XHASH 0x70000036
+#define DT_MIPS_NUM 0x37
/* Legal values for DT_MIPS_FLAGS Elf32_Dyn entry. */
@@ -2854,6 +2874,13 @@ enum
#define R_AARCH64_TLSDESC 1031 /* TLS Descriptor. */
#define R_AARCH64_IRELATIVE 1032 /* STT_GNU_IFUNC relocation. */
+/* AArch64 specific values for the Dyn d_tag field. */
+#define DT_AARCH64_VARIANT_PCS (DT_LOPROC + 5)
+#define DT_AARCH64_NUM 6
+
+/* AArch64 specific values for the st_other field. */
+#define STO_AARCH64_VARIANT_PCS 0x80
+
/* ARM relocs. */
#define R_ARM_NONE 0 /* No reloc */
@@ -3926,8 +3953,9 @@ enum
#define R_RISCV_SET16 55
#define R_RISCV_SET32 56
#define R_RISCV_32_PCREL 57
+#define R_RISCV_IRELATIVE 58
-#define R_RISCV_NUM 58
+#define R_RISCV_NUM 59
/* BPF specific declarations. */
@@ -4007,6 +4035,74 @@ enum
#define R_NDS32_TLS_TPOFF 102
#define R_NDS32_TLS_DESC 119
+/* ARCompact/ARCv2 specific relocs. */
+#define R_ARC_NONE 0x0
+#define R_ARC_8 0x1
+#define R_ARC_16 0x2
+#define R_ARC_24 0x3
+#define R_ARC_32 0x4
+#define R_ARC_B26 0x5
+#define R_ARC_B22_PCREL 0x6
+#define R_ARC_H30 0x7
+#define R_ARC_N8 0x8
+#define R_ARC_N16 0x9
+#define R_ARC_N24 0xA
+#define R_ARC_N32 0xB
+#define R_ARC_SDA 0xC
+#define R_ARC_SECTOFF 0xD
+#define R_ARC_S21H_PCREL 0xE
+#define R_ARC_S21W_PCREL 0xF
+#define R_ARC_S25H_PCREL 0x10
+#define R_ARC_S25W_PCREL 0x11
+#define R_ARC_SDA32 0x12
+#define R_ARC_SDA_LDST 0x13
+#define R_ARC_SDA_LDST1 0x14
+#define R_ARC_SDA_LDST2 0x15
+#define R_ARC_SDA16_LD 0x16
+#define R_ARC_SDA16_LD1 0x17
+#define R_ARC_SDA16_LD2 0x18
+#define R_ARC_S13_PCREL 0x19
+#define R_ARC_W 0x1A
+#define R_ARC_32_ME 0x1B
+#define R_ARC_N32_ME 0x1C
+#define R_ARC_SECTOFF_ME 0x1D
+#define R_ARC_SDA32_ME 0x1E
+#define R_ARC_W_ME 0x1F
+#define R_ARC_H30_ME 0x20
+#define R_ARC_SECTOFF_U8 0x21
+#define R_ARC_SECTOFF_S9 0x22
+#define R_AC_SECTOFF_U8 0x23
+#define R_AC_SECTOFF_U8_1 0x24
+#define R_AC_SECTOFF_U8_2 0x25
+#define R_AC_SECTOFF_S9 0x26
+#define R_AC_SECTOFF_S9_1 0x27
+#define R_AC_SECTOFF_S9_2 0x28
+#define R_ARC_SECTOFF_ME_1 0x29
+#define R_ARC_SECTOFF_ME_2 0x2A
+#define R_ARC_SECTOFF_1 0x2B
+#define R_ARC_SECTOFF_2 0x2C
+#define R_ARC_PC32 0x32
+#define R_ARC_GOTPC32 0x33
+#define R_ARC_PLT32 0x34
+#define R_ARC_COPY 0x35
+#define R_ARC_GLOB_DAT 0x36
+#define R_ARC_JUMP_SLOT 0x37
+#define R_ARC_RELATIVE 0x38
+#define R_ARC_GOTOFF 0x39
+#define R_ARC_GOTPC 0x3A
+#define R_ARC_GOT32 0x3B
+
+#define R_ARC_TLS_DTPMOD 0x42
+#define R_ARC_TLS_DTPOFF 0x43
+#define R_ARC_TLS_TPOFF 0x44
+#define R_ARC_TLS_GD_GOT 0x45
+#define R_ARC_TLS_GD_LD 0x46
+#define R_ARC_TLS_GD_CALL 0x47
+#define R_ARC_TLS_IE_GOT 0x48
+#define R_ARC_TLS_DTPOFF_S9 0x4a
+#define R_ARC_TLS_LE_S9 0x4a
+#define R_ARC_TLS_LE_32 0x4b
+
__END_DECLS
#endif /* elf.h */
diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c
index 244467b5..e5d3d2e0 100644
--- a/libelf/elf_compress.c
+++ b/libelf/elf_compress.c
@@ -113,9 +113,8 @@ __libelf_compress (Elf_Scn *scn, size_t hsize, int ei_data,
int zrc = deflateInit (&z, Z_BEST_COMPRESSION);
if (zrc != Z_OK)
{
- free (out_buf);
__libelf_seterrno (ELF_E_COMPRESS_ERROR);
- return NULL;
+ return deflate_cleanup(NULL, NULL);
}
Elf_Data cdata;
@@ -197,13 +196,13 @@ __libelf_compress (Elf_Scn *scn, size_t hsize, int ei_data,
}
while (flush != Z_FINISH); /* More data blocks. */
- zrc = deflateEnd (&z);
- if (zrc != Z_OK)
+ if (zrc != Z_STREAM_END)
{
__libelf_seterrno (ELF_E_COMPRESS_ERROR);
return deflate_cleanup (NULL, NULL);
}
+ deflateEnd (&z);
*new_size = used;
return out_buf;
}
@@ -251,16 +250,15 @@ __libelf_decompress (void *buf_in, size_t size_in, size_t size_out)
}
zrc = inflateReset (&z);
}
- if (likely (zrc == Z_OK))
- zrc = inflateEnd (&z);
if (unlikely (zrc != Z_OK) || unlikely (z.avail_out != 0))
{
free (buf_out);
+ buf_out = NULL;
__libelf_seterrno (ELF_E_DECOMPRESS_ERROR);
- return NULL;
}
+ inflateEnd(&z);
return buf_out;
}
diff --git a/libelf/elf_getdata.c b/libelf/elf_getdata.c
index 40fe1694..0d8f8d2e 100644
--- a/libelf/elf_getdata.c
+++ b/libelf/elf_getdata.c
@@ -271,6 +271,8 @@ __libelf_set_rawdata_wrlock (Elf_Scn *scn)
{
GElf_Ehdr ehdr_mem;
GElf_Ehdr *ehdr = __gelf_getehdr_rdlock (elf, &ehdr_mem);
+ if (unlikely (ehdr == NULL))
+ return 1;
entsize = SH_ENTSIZE_HASH (ehdr);
}
else
diff --git a/libelf/elf_getphdrnum.c b/libelf/elf_getphdrnum.c
index f91cba98..53617dfc 100644
--- a/libelf/elf_getphdrnum.c
+++ b/libelf/elf_getphdrnum.c
@@ -63,15 +63,23 @@ __elf_getphdrnum_rdlock (Elf *elf, size_t *dst)
if (elf->class == ELFCLASS32)
{
- if (likely (scns->cnt > 0
- && elf->state.elf32.scns.data[0].shdr.e32 != NULL))
- *dst = scns->data[0].shdr.e32->sh_info;
+ if (likely (scns->cnt > 0))
+ {
+ Elf_Scn *scn = &elf->state.elf32.scns.data[0];
+ Elf32_Shdr *shdr = scn->shdr.e32 ?: __elf32_getshdr_rdlock (scn);
+ if (shdr)
+ *dst = shdr->sh_info;
+ }
}
else
{
- if (likely (scns->cnt > 0
- && elf->state.elf64.scns.data[0].shdr.e64 != NULL))
- *dst = scns->data[0].shdr.e64->sh_info;
+ if (likely (scns->cnt > 0))
+ {
+ Elf_Scn *scn = &elf->state.elf64.scns.data[0];
+ Elf64_Shdr *shdr = scn->shdr.e64 ?: __elf64_getshdr_rdlock (scn);
+ if (shdr)
+ *dst = shdr->sh_info;
+ }
}
}
diff --git a/libelf/elf_strptr.c b/libelf/elf_strptr.c
index e72a3a36..c7271707 100644
--- a/libelf/elf_strptr.c
+++ b/libelf/elf_strptr.c
@@ -145,7 +145,7 @@ elf_strptr (Elf *elf, size_t idx, size_t offset)
else
{
Elf64_Shdr *shdr = strscn->shdr.e64 ?: __elf64_getshdr_rdlock (strscn);
- if (unlikely (shdr->sh_type != SHT_STRTAB))
+ if (unlikely (shdr == NULL || shdr->sh_type != SHT_STRTAB))
{
/* This is no string section. */
__libelf_seterrno (ELF_E_INVALID_SECTION);