diff options
Diffstat (limited to 'rtemstoolkit/elftoolchain/libelf/libelf_ehdr.c')
-rw-r--r-- | rtemstoolkit/elftoolchain/libelf/libelf_ehdr.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/rtemstoolkit/elftoolchain/libelf/libelf_ehdr.c b/rtemstoolkit/elftoolchain/libelf/libelf_ehdr.c index affe541..6630e6e 100644 --- a/rtemstoolkit/elftoolchain/libelf/libelf_ehdr.c +++ b/rtemstoolkit/elftoolchain/libelf/libelf_ehdr.c @@ -24,8 +24,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> - #include <assert.h> #include <gelf.h> #include <libelf.h> @@ -33,7 +31,7 @@ #include "_libelf.h" -LIBELF_VCSID("$Id: libelf_ehdr.c 1677 2011-07-28 04:35:53Z jkoshy $"); +ELFTC_VCSID("$Id: libelf_ehdr.c 3575 2017-09-14 02:13:36Z emaste $"); /* * Retrieve counts for sections, phdrs and the section string table index @@ -45,7 +43,8 @@ _libelf_load_extended(Elf *e, int ec, uint64_t shoff, uint16_t phnum, { Elf_Scn *scn; size_t fsz; - int (*xlator)(char *_d, size_t _dsz, char *_s, size_t _c, int _swap); + int (*xlator)(unsigned char *_d, size_t _dsz, unsigned char *_s, + size_t _c, int _swap); uint32_t shtype; assert(STAILQ_EMPTY(&e->e_u.e_elf.e_scn)); @@ -62,8 +61,8 @@ _libelf_load_extended(Elf *e, int ec, uint64_t shoff, uint16_t phnum, return (0); xlator = _libelf_get_translator(ELF_T_SHDR, ELF_TOMEMORY, ec); - (*xlator)((char *) &scn->s_shdr, sizeof(scn->s_shdr), - e->e_rawfile + shoff, (size_t) 1, + (*xlator)((unsigned char *) &scn->s_shdr, sizeof(scn->s_shdr), + (unsigned char *) e->e_rawfile + shoff, (size_t) 1, e->e_byteorder != LIBELF_PRIVATE(byteorder)); #define GET_SHDR_MEMBER(M) ((ec == ELFCLASS32) ? scn->s_shdr.s_shdr32.M : \ @@ -74,7 +73,7 @@ _libelf_load_extended(Elf *e, int ec, uint64_t shoff, uint16_t phnum, return (0); } - e->e_u.e_elf.e_nscn = GET_SHDR_MEMBER(sh_size); + e->e_u.e_elf.e_nscn = (size_t) GET_SHDR_MEMBER(sh_size); e->e_u.e_elf.e_nphdr = (phnum != PN_XNUM) ? phnum : GET_SHDR_MEMBER(sh_info); e->e_u.e_elf.e_strndx = (strndx != SHN_XINDEX) ? strndx : @@ -92,7 +91,7 @@ _libelf_load_extended(Elf *e, int ec, uint64_t shoff, uint16_t phnum, eh->e_ident[EI_MAG3] = ELFMAG3; \ eh->e_ident[EI_CLASS] = ELFCLASS##SZ; \ eh->e_ident[EI_DATA] = ELFDATANONE; \ - eh->e_ident[EI_VERSION] = LIBELF_PRIVATE(version); \ + eh->e_ident[EI_VERSION] = LIBELF_PRIVATE(version) & 0xFFU; \ eh->e_machine = EM_NONE; \ eh->e_type = ELF_K_NONE; \ eh->e_version = LIBELF_PRIVATE(version); \ @@ -105,7 +104,8 @@ _libelf_ehdr(Elf *e, int ec, int allocate) size_t fsz, msz; uint16_t phnum, shnum, strndx; uint64_t shoff; - int (*xlator)(char *_d, size_t _dsz, char *_s, size_t _c, int _swap); + int (*xlator)(unsigned char *_d, size_t _dsz, unsigned char *_s, + size_t _c, int _swap); assert(ec == ELFCLASS32 || ec == ELFCLASS64); @@ -167,13 +167,9 @@ _libelf_ehdr(Elf *e, int ec, int allocate) return (ehdr); xlator = _libelf_get_translator(ELF_T_EHDR, ELF_TOMEMORY, ec); - (*xlator)(ehdr, msz, e->e_rawfile, (size_t) 1, + (*xlator)((unsigned char*) ehdr, msz, e->e_rawfile, (size_t) 1, e->e_byteorder != LIBELF_PRIVATE(byteorder)); - /* - * If extended numbering is being used, read the correct - * number of sections and program header entries. - */ if (ec == ELFCLASS32) { phnum = ((Elf32_Ehdr *) ehdr)->e_phnum; shnum = ((Elf32_Ehdr *) ehdr)->e_shnum; @@ -193,12 +189,19 @@ _libelf_ehdr(Elf *e, int ec, int allocate) return (NULL); } - if (shnum != 0 || shoff == 0LL) { /* not using extended numbering */ + /* + * If extended numbering is being used, read the correct + * number of sections and program header entries. + */ + if ((shnum == 0 && shoff != 0) || phnum == PN_XNUM || strndx == SHN_XINDEX) { + if (_libelf_load_extended(e, ec, shoff, phnum, strndx) == 0) + return (NULL); + } else { + /* not using extended numbering */ e->e_u.e_elf.e_nphdr = phnum; e->e_u.e_elf.e_nscn = shnum; e->e_u.e_elf.e_strndx = strndx; - } else if (_libelf_load_extended(e, ec, shoff, phnum, strndx) == 0) - return (NULL); + } return (ehdr); } |