diff options
| author | Mark Wielaard <[email protected]> | 2019-02-03 19:05:13 +0100 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2019-02-28 22:41:14 +0100 |
| commit | b9d1678951e13e934759a643040da752573f765f (patch) | |
| tree | aeb7bf4b5aab4e415efdb37e20a5728ebfbbe438 /libelf/elf32_updatefile.c | |
| parent | 92ded1f11c0622cd9e1943bb85e1bdbdc4fb4802 (diff) | |
libelf: There is just one ELF version.
Remove (partially defined out) code and data structures dealing with
multiple ELF versions. There hasn't been a new ELF version in the
last 20 years. Simplify the code a bit by just assuming there will
only be one version (EV_CURRENT == 1).
Simplifies elf_version, gets rid of __libelf_version_initialized.
Removes one (or more) array (version) dimension from various tables
and accessor functions (__elf_xfctstom, shtype_map, __libelf_data_type,
__libelf_type_aligns and __libelf_type_sizes).
Signed-off-by: Mark Wielaard <[email protected]>`
Diffstat (limited to 'libelf/elf32_updatefile.c')
| -rw-r--r-- | libelf/elf32_updatefile.c | 70 |
1 files changed, 16 insertions, 54 deletions
diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c index 284bacc9..2899c6fb 100644 --- a/libelf/elf32_updatefile.c +++ b/libelf/elf32_updatefile.c @@ -143,13 +143,8 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum) if (unlikely (change_bo)) { /* Today there is only one version of the ELF header. */ -#if EV_NUM != 2 - xfct_t fctp; - fctp = __elf_xfctstom[__libelf_version - 1][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_EHDR]; -#else -# undef fctp -# define fctp __elf_xfctstom[0][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_EHDR] -#endif +#undef fctp +#define fctp __elf_xfctstom[ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_EHDR] /* Do the real work. */ (*fctp) ((char *) elf->map_address + elf->start_offset, ehdr, @@ -189,13 +184,8 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum) if (unlikely (change_bo)) { /* Today there is only one version of the ELF header. */ -#if EV_NUM != 2 - xfct_t fctp; - fctp = __elf_xfctstom[__libelf_version - 1][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_PHDR]; -#else -# undef fctp -# define fctp __elf_xfctstom[0][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_PHDR] -#endif +#undef fctp +#define fctp __elf_xfctstom[ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_PHDR] /* Do the real work. */ (*fctp) (elf->map_address + elf->start_offset + ehdr->e_phoff, @@ -238,12 +228,8 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum) + ehdr->e_shoff); char *const shdr_end = shdr_start + shnum * ehdr->e_shentsize; -#if EV_NUM != 2 - xfct_t shdr_fctp = __elf_xfctstom[__libelf_version - 1][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_SHDR]; -#else -# undef shdr_fctp -# define shdr_fctp __elf_xfctstom[0][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_SHDR] -#endif +#undef shdr_fctp +#define shdr_fctp __elf_xfctstom[ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_SHDR] #define shdr_dest ((ElfW2(LIBELFBITS,Shdr) *) shdr_start) /* Get all sections into the array and sort them. */ @@ -358,13 +344,8 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum) && dl->data.d.d_size != 0 && dl->data.d.d_type != ELF_T_BYTE)) { -#if EV_NUM != 2 - xfct_t fctp; - fctp = __elf_xfctstom[__libelf_version - 1][dl->data.d.d_version - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][dl->data.d.d_type]; -#else -# undef fctp -# define fctp __elf_xfctstom[0][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][dl->data.d.d_type] -#endif +#undef fctp +#define fctp __elf_xfctstom[ELFW(ELFCLASS, LIBELFBITS) - 1][dl->data.d.d_type] size_t align; align = __libelf_type_align (ELFW(ELFCLASS,LIBELFBITS), @@ -559,13 +540,8 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum) if (unlikely (change_bo)) { /* Today there is only one version of the ELF header. */ -#if EV_NUM != 2 - xfct_t fctp; - fctp = __elf_xfctstom[__libelf_version - 1][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_EHDR]; -#else -# undef fctp -# define fctp __elf_xfctstom[0][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_EHDR] -#endif +#undef fctp +#define fctp __elf_xfctstom[ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_EHDR] /* Write the converted ELF header in a temporary buffer. */ (*fctp) (&tmp_ehdr, ehdr, sizeof (ElfW2(LIBELFBITS,Ehdr)), 1); @@ -618,13 +594,8 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum) if (unlikely (change_bo)) { /* Today there is only one version of the ELF header. */ -#if EV_NUM != 2 - xfct_t fctp; - fctp = __elf_xfctstom[__libelf_version - 1][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_PHDR]; -#else -# undef fctp -# define fctp __elf_xfctstom[0][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_PHDR] -#endif +#undef fctp +#define fctp __elf_xfctstom[ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_PHDR] /* Allocate sufficient memory. */ tmp_phdr = (ElfW2(LIBELFBITS,Phdr) *) @@ -679,12 +650,8 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum) return 1; off_t shdr_offset = elf->start_offset + ehdr->e_shoff; -#if EV_NUM != 2 - xfct_t shdr_fctp = __elf_xfctstom[__libelf_version - 1][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_SHDR]; -#else -# undef shdr_fctp -# define shdr_fctp __elf_xfctstom[0][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_SHDR] -#endif +#undef shdr_fctp +#define shdr_fctp __elf_xfctstom[ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_SHDR] ElfW2(LIBELFBITS,Shdr) *shdr_data; ElfW2(LIBELFBITS,Shdr) *shdr_data_mem = NULL; @@ -769,13 +736,8 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum) if (unlikely (change_bo)) { -#if EV_NUM != 2 - xfct_t fctp; - fctp = __elf_xfctstom[__libelf_version - 1][dl->data.d.d_version - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][dl->data.d.d_type]; -#else -# undef fctp -# define fctp __elf_xfctstom[0][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][dl->data.d.d_type] -#endif +#undef fctp +#define fctp __elf_xfctstom[ELFW(ELFCLASS, LIBELFBITS) - 1][dl->data.d.d_type] buf = tmpbuf; if (dl->data.d.d_size > MAX_TMPBUF) |
