Merge from upstream libelf 0.188

This commit is contained in:
Chris Webb 2022-11-02 20:43:36 +00:00
commit cf90fc56dc
26 changed files with 150 additions and 65 deletions

View File

@ -30,9 +30,6 @@
#ifndef _COMMON_H
#define _COMMON_H 1
#include <ar.h>
#include <byteswap.h>
#include <endian.h>
#include <stdlib.h>
#include <string.h>
@ -154,7 +151,7 @@ libelf_release_all (Elf *elf)
: bswap_64 (Var))))
#if __BYTE_ORDER == __LITTLE_ENDIAN
#if BYTE_ORDER == LITTLE_ENDIAN
# define MY_ELFDATA ELFDATA2LSB
#else
# define MY_ELFDATA ELFDATA2MSB

117
src/elf.h
View File

@ -358,8 +358,9 @@ typedef struct
#define EM_BPF 247 /* Linux BPF -- in-kernel virtual machine */
#define EM_CSKY 252 /* C-SKY */
#define EM_LOONGARCH 258 /* LoongArch */
#define EM_NUM 253
#define EM_NUM 259
/* Old spellings/synonyms. */
@ -443,7 +444,8 @@ typedef struct
#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
#define SHT_GROUP 17 /* Section group */
#define SHT_SYMTAB_SHNDX 18 /* Extended section indices */
#define SHT_NUM 19 /* Number of defined types. */
#define SHT_RELR 19 /* RELR relative relocations */
#define SHT_NUM 20 /* Number of defined types. */
#define SHT_LOOS 0x60000000 /* Start OS-specific. */
#define SHT_GNU_ATTRIBUTES 0x6ffffff5 /* Object attributes. */
#define SHT_GNU_HASH 0x6ffffff6 /* GNU-style hash table. */
@ -504,6 +506,7 @@ typedef struct
/* Legal values for ch_type (compression algorithm). */
#define ELFCOMPRESS_ZLIB 1 /* ZLIB/DEFLATE algorithm. */
#define ELFCOMPRESS_ZSTD 2 /* Zstandard algorithm. */
#define ELFCOMPRESS_LOOS 0x60000000 /* Start of OS-specific. */
#define ELFCOMPRESS_HIOS 0x6fffffff /* End of OS-specific. */
#define ELFCOMPRESS_LOPROC 0x70000000 /* Start of processor-specific. */
@ -662,6 +665,11 @@ typedef struct
Elf64_Sxword r_addend; /* Addend */
} Elf64_Rela;
/* RELR relocation table entry */
typedef Elf32_Word Elf32_Relr;
typedef Elf64_Xword Elf64_Relr;
/* How to extract and insert information held in the r_info field. */
#define ELF32_R_SYM(val) ((val) >> 8)
@ -801,6 +809,7 @@ typedef struct
#define NT_S390_GS_BC 0x30c /* s390 guarded storage
broadcast control block. */
#define NT_S390_RI_CB 0x30d /* s390 runtime instrumentation. */
#define NT_S390_PV_CPU_DATA 0x30e /* s390 protvirt cpu dump data. */
#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */
#define NT_ARM_TLS 0x401 /* ARM TLS register */
#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */
@ -822,6 +831,15 @@ typedef struct
#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. */
#define NT_LOONGARCH_CPUCFG 0xa00 /* LoongArch CPU config registers. */
#define NT_LOONGARCH_CSR 0xa01 /* LoongArch control and
status registers. */
#define NT_LOONGARCH_LSX 0xa02 /* LoongArch Loongson SIMD
Extension registers. */
#define NT_LOONGARCH_LASX 0xa03 /* LoongArch Loongson Advanced
SIMD Extension registers. */
#define NT_LOONGARCH_LBT 0xa04 /* LoongArch Loongson Binary
Translation registers. */
/* Legal values for the note segment descriptor types for object files. */
@ -887,7 +905,10 @@ typedef struct
#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/
#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */
#define DT_SYMTAB_SHNDX 34 /* Address of SYMTAB_SHNDX section */
#define DT_NUM 35 /* Number used */
#define DT_RELRSZ 35 /* Total size of RELR relative relocations */
#define DT_RELR 36 /* Address of RELR relative relocations */
#define DT_RELRENT 37 /* Size of one RELR relative relocaction */
#define DT_NUM 38 /* Number used */
#define DT_LOOS 0x6000000d /* Start of OS-specific */
#define DT_HIOS 0x6ffff000 /* End of OS-specific */
#define DT_LOPROC 0x70000000 /* Start of processor-specific */
@ -1044,7 +1065,8 @@ typedef struct
/* Legal values for vd_flags (version information flags). */
#define VER_FLG_BASE 0x1 /* Version definition of file itself */
#define VER_FLG_WEAK 0x2 /* Weak version identifier */
#define VER_FLG_WEAK 0x2 /* Weak version identifier. Also
used by vna_flags below. */
/* Versym symbol index values. */
#define VER_NDX_LOCAL 0 /* Symbol is local. */
@ -1122,10 +1144,6 @@ typedef struct
} Elf64_Vernaux;
/* Legal values for vna_flags. */
#define VER_FLG_WEAK 0x2 /* Weak version identifier */
/* Auxiliary vector. */
/* This vector is normally only used by the program interpreter. The
@ -2893,6 +2911,9 @@ enum
#define R_AARCH64_TLSDESC 1031 /* TLS Descriptor. */
#define R_AARCH64_IRELATIVE 1032 /* STT_GNU_IFUNC relocation. */
/* MTE memory tag segment type. */
#define PT_AARCH64_MEMTAG_MTE (PT_LOPROC + 2)
/* AArch64 specific values for the Dyn d_tag field. */
#define DT_AARCH64_BTI_PLT (DT_LOPROC + 1)
#define DT_AARCH64_PAC_PLT (DT_LOPROC + 3)
@ -3918,6 +3939,8 @@ enum
#define EF_RISCV_FLOAT_ABI_SINGLE 0x0002
#define EF_RISCV_FLOAT_ABI_DOUBLE 0x0004
#define EF_RISCV_FLOAT_ABI_QUAD 0x0006
#define EF_RISCV_RVE 0x0008
#define EF_RISCV_TSO 0x0010
/* RISC-V relocations. */
#define R_RISCV_NONE 0
@ -3978,6 +4001,19 @@ enum
#define R_RISCV_NUM 59
/* RISC-V specific values for the st_other field. */
#define STO_RISCV_VARIANT_CC 0x80 /* Function uses variant calling
convention */
/* RISC-V specific values for the sh_type field. */
#define SHT_RISCV_ATTRIBUTES (SHT_LOPROC + 3)
/* RISC-V specific values for the p_type field. */
#define PT_RISCV_ATTRIBUTES (PT_LOPROC + 3)
/* RISC-V specific values for the d_tag field. */
#define DT_RISCV_VARIANT_CC (DT_LOPROC + 1)
/* BPF specific declarations. */
#define R_BPF_NONE 0 /* No reloc */
@ -4056,6 +4092,71 @@ enum
#define R_NDS32_TLS_TPOFF 102
#define R_NDS32_TLS_DESC 119
/* LoongArch ELF Flags */
#define EF_LARCH_ABI 0x07
#define EF_LARCH_ABI_LP64D 0x03
/* LoongArch specific dynamic relocations */
#define R_LARCH_NONE 0
#define R_LARCH_32 1
#define R_LARCH_64 2
#define R_LARCH_RELATIVE 3
#define R_LARCH_COPY 4
#define R_LARCH_JUMP_SLOT 5
#define R_LARCH_TLS_DTPMOD32 6
#define R_LARCH_TLS_DTPMOD64 7
#define R_LARCH_TLS_DTPREL32 8
#define R_LARCH_TLS_DTPREL64 9
#define R_LARCH_TLS_TPREL32 10
#define R_LARCH_TLS_TPREL64 11
#define R_LARCH_IRELATIVE 12
/* Reserved for future relocs that the dynamic linker must understand. */
/* used by the static linker for relocating .text. */
#define R_LARCH_MARK_LA 20
#define R_LARCH_MARK_PCREL 21
#define R_LARCH_SOP_PUSH_PCREL 22
#define R_LARCH_SOP_PUSH_ABSOLUTE 23
#define R_LARCH_SOP_PUSH_DUP 24
#define R_LARCH_SOP_PUSH_GPREL 25
#define R_LARCH_SOP_PUSH_TLS_TPREL 26
#define R_LARCH_SOP_PUSH_TLS_GOT 27
#define R_LARCH_SOP_PUSH_TLS_GD 28
#define R_LARCH_SOP_PUSH_PLT_PCREL 29
#define R_LARCH_SOP_ASSERT 30
#define R_LARCH_SOP_NOT 31
#define R_LARCH_SOP_SUB 32
#define R_LARCH_SOP_SL 33
#define R_LARCH_SOP_SR 34
#define R_LARCH_SOP_ADD 35
#define R_LARCH_SOP_AND 36
#define R_LARCH_SOP_IF_ELSE 37
#define R_LARCH_SOP_POP_32_S_10_5 38
#define R_LARCH_SOP_POP_32_U_10_12 39
#define R_LARCH_SOP_POP_32_S_10_12 40
#define R_LARCH_SOP_POP_32_S_10_16 41
#define R_LARCH_SOP_POP_32_S_10_16_S2 42
#define R_LARCH_SOP_POP_32_S_5_20 43
#define R_LARCH_SOP_POP_32_S_0_5_10_16_S2 44
#define R_LARCH_SOP_POP_32_S_0_10_10_16_S2 45
#define R_LARCH_SOP_POP_32_U 46
/* used by the static linker for relocating non .text. */
#define R_LARCH_ADD8 47
#define R_LARCH_ADD16 48
#define R_LARCH_ADD24 49
#define R_LARCH_ADD32 50
#define R_LARCH_ADD64 51
#define R_LARCH_SUB8 52
#define R_LARCH_SUB16 53
#define R_LARCH_SUB24 54
#define R_LARCH_SUB32 55
#define R_LARCH_SUB64 56
#define R_LARCH_GNU_VTINHERIT 57
#define R_LARCH_GNU_VTENTRY 58
/* ARCompact/ARCv2 specific relocs. */
#define R_ARC_NONE 0x0
#define R_ARC_8 0x1

View File

@ -32,7 +32,6 @@
#endif
#include <assert.h>
#include <endian.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
@ -74,9 +73,9 @@ elfw2(LIBELFBITS,checksum) (Elf *elf)
is the same. */
ident = elf->state.ELFW(elf,LIBELFBITS).ehdr->e_ident;
same_byte_order = ((ident[EI_DATA] == ELFDATA2LSB
&& __BYTE_ORDER == __LITTLE_ENDIAN)
&& BYTE_ORDER == LITTLE_ENDIAN)
|| (ident[EI_DATA] == ELFDATA2MSB
&& __BYTE_ORDER == __BIG_ENDIAN));
&& BYTE_ORDER == BIG_ENDIAN));
/* If we don't have native byte order, we will likely need to
convert the data with xlate functions. We do it upfront instead

View File

@ -34,10 +34,8 @@
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <system.h>
#include "libelfP.h"
#include "common.h"

View File

@ -34,9 +34,7 @@
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <unistd.h>
#include <system.h>
#include "libelfP.h"
#include "common.h"

View File

@ -37,10 +37,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <system.h>
#include "libelfP.h"

View File

@ -32,12 +32,10 @@
#endif
#include <assert.h>
#include <endian.h>
#include <libelf.h>
#include <stdbool.h>
#include <string.h>
#include <system.h>
#include "libelfP.h"
#include "elf-knowledge.h"

View File

@ -32,7 +32,6 @@
#endif
#include <assert.h>
#include <endian.h>
#include <string.h>
#include "libelfP.h"
@ -83,8 +82,8 @@ elfw2(LIBELFBITS, xlatetof) (Elf_Data *dest, const Elf_Data *src,
and vice versa since the function only has to copy and/or
change the byte order.
*/
if ((__BYTE_ORDER == __LITTLE_ENDIAN && encode == ELFDATA2LSB)
|| (__BYTE_ORDER == __BIG_ENDIAN && encode == ELFDATA2MSB))
if ((BYTE_ORDER == LITTLE_ENDIAN && encode == ELFDATA2LSB)
|| (BYTE_ORDER == BIG_ENDIAN && encode == ELFDATA2MSB))
{
/* We simply have to copy since the byte order is the same. */
if (src->d_buf != dest->d_buf)

View File

@ -32,7 +32,6 @@
#endif
#include <assert.h>
#include <endian.h>
#include <string.h>
#include "libelfP.h"

View File

@ -39,11 +39,8 @@
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <system.h>
#include "libelfP.h"
#include "common.h"
@ -977,7 +974,8 @@ __libelf_next_arhdr_wrlock (Elf *elf)
atoll depending on the size of the types. We are also prepared
for the case where the whole field in the `struct ar_hdr' is
filled in which case we cannot simply use atol/l but instead have
to create a temporary copy. */
to create a temporary copy. Note that all fields use decimal
encoding, except ar_mode which uses octal. */
#define INT_FIELD(FIELD) \
do \
@ -997,10 +995,30 @@ __libelf_next_arhdr_wrlock (Elf *elf)
} \
while (0)
#define OCT_FIELD(FIELD) \
do \
{ \
char buf[sizeof (ar_hdr->FIELD) + 1]; \
const char *string = ar_hdr->FIELD; \
if (ar_hdr->FIELD[sizeof (ar_hdr->FIELD) - 1] != ' ') \
{ \
*((char *) mempcpy (buf, ar_hdr->FIELD, sizeof (ar_hdr->FIELD))) \
= '\0'; \
string = buf; \
} \
if (sizeof (elf_ar_hdr->FIELD) <= sizeof (long int)) \
elf_ar_hdr->FIELD \
= (__typeof (elf_ar_hdr->FIELD)) strtol (string, NULL, 8); \
else \
elf_ar_hdr->FIELD \
= (__typeof (elf_ar_hdr->FIELD)) strtoll (string, NULL, 8); \
} \
while (0)
INT_FIELD (ar_date);
INT_FIELD (ar_uid);
INT_FIELD (ar_gid);
INT_FIELD (ar_mode);
OCT_FIELD (ar_mode);
INT_FIELD (ar_size);
if (elf_ar_hdr->ar_size < 0)

View File

@ -31,8 +31,6 @@
# include <config.h>
#endif
#include <unistd.h>
#include "libelfP.h"

View File

@ -31,14 +31,12 @@
#endif
#include <libelf.h>
#include <system.h>
#include "libelfP.h"
#include "common.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <zlib.h>
/* Cleanup and return result. Don't leak memory. */

View File

@ -34,7 +34,6 @@
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <sys/mman.h>
#include "libelfP.h"

View File

@ -32,7 +32,6 @@
#endif
#include <assert.h>
#include <libintl.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

View File

@ -32,16 +32,12 @@
#endif
#include <assert.h>
#include <byteswap.h>
#include <endian.h>
#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <system.h>
#include <dl-hash.h>
#include "libelfP.h"
@ -65,7 +61,7 @@ read_number_entries (uint64_t *nump, Elf *elf, size_t *offp, bool index64_p)
*offp += w;
if (__BYTE_ORDER == __LITTLE_ENDIAN)
if (BYTE_ORDER == LITTLE_ENDIAN)
*nump = index64_p ? bswap_64 (u.ret64) : bswap_32 (u.ret32);
else
*nump = index64_p ? u.ret64 : u.ret32;
@ -270,7 +266,7 @@ elf_getarsym (Elf *elf, size_t *ptr)
if (index64_p)
{
uint64_t tmp = (*u64)[cnt];
if (__BYTE_ORDER == __LITTLE_ENDIAN)
if (BYTE_ORDER == LITTLE_ENDIAN)
tmp = bswap_64 (tmp);
arsym[cnt].as_off = tmp;
@ -290,7 +286,7 @@ elf_getarsym (Elf *elf, size_t *ptr)
goto out;
}
}
else if (__BYTE_ORDER == __LITTLE_ENDIAN)
else if (BYTE_ORDER == LITTLE_ENDIAN)
arsym[cnt].as_off = bswap_32 ((*u32)[cnt]);
else
arsym[cnt].as_off = (*u32)[cnt];

View File

@ -35,10 +35,8 @@
#include <errno.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include "libelfP.h"
#include <system.h>
#include "common.h"
#include "elf-knowledge.h"

View File

@ -35,9 +35,7 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <system.h>
#include "libelfP.h"
#include "common.h"

View File

@ -35,9 +35,7 @@
#include <errno.h>
#include <gelf.h>
#include <stddef.h>
#include <unistd.h>
#include <system.h>
#include "libelfP.h"
#include "common.h"

View File

@ -32,10 +32,8 @@
#endif
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <system.h>
#include "libelfP.h"
#include "common.h"

View File

@ -33,8 +33,6 @@
#include <libelf.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include "libelfP.h"

View File

@ -52,6 +52,7 @@
# define rwlock_unlock(lock) ((void) (lock))
#endif /* USE_LOCKS */
#include <libintl.h>
/* gettext helper macros. */
#define N_(Str) Str
#define _(Str) dgettext ("elfutils", Str)

View File

@ -32,7 +32,6 @@
# include <config.h>
#endif
#include <byteswap.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>

View File

@ -39,6 +39,7 @@
#include <stdio.h>
#include <string.h>
#include <system.h>
/* Helper Macros to write 32 bit and 64 bit functions. */
#define __elfw2_(Bits, Name) __elf##Bits##_##Name

View File

@ -30,6 +30,5 @@
#endif
#define crc32 attribute_hidden __libelf_crc32
#define LIB_SYSTEM_H 1
#include <libelf.h>
#include "crc32.c"

View File

@ -35,7 +35,6 @@
#include <gelf.h>
#include <libelf.h>
#include <nlist.h>
#include <unistd.h>
#include "libelfP.h"

View File

@ -35,20 +35,22 @@
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/param.h>
#include <endian.h>
#include <byteswap.h>
#include <unistd.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#if __BYTE_ORDER == __LITTLE_ENDIAN
#include <byteswap.h>
#include <endian.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <unistd.h>
#if BYTE_ORDER == LITTLE_ENDIAN
# define LE32(n) (n)
# define LE64(n) (n)
# define BE32(n) bswap_32 (n)
# define BE64(n) bswap_64 (n)
#elif __BYTE_ORDER == __BIG_ENDIAN
#elif BYTE_ORDER == BIG_ENDIAN
# define BE32(n) (n)
# define BE64(n) (n)
# define LE32(n) bswap_32 (n)