Index: contrib/elftoolchain/libelf/_libelf.h =================================================================== --- contrib/elftoolchain/libelf/_libelf.h +++ contrib/elftoolchain/libelf/_libelf.h @@ -31,6 +31,8 @@ #include +#include + #include "_libelf_config.h" #include "_elftc.h" @@ -213,6 +215,7 @@ int (*_libelf_get_translator(Elf_Type _t, int _direction, int _elfclass)) (unsigned char *_dst, size_t dsz, unsigned char *_src, size_t _cnt, int _byteswap); +Elf_Data *_libelf_getdata(Elf_Scn *s, Elf_Data *ed, bool updating); void *_libelf_getphdr(Elf *_e, int _elfclass); void *_libelf_getshdr(Elf_Scn *_scn, int _elfclass); void _libelf_init_elf(Elf *_e, Elf_Kind _kind); @@ -222,6 +225,7 @@ size_t _libelf_msize(Elf_Type _t, int _elfclass, unsigned int _version); void *_libelf_newphdr(Elf *_e, int _elfclass, size_t _count); Elf *_libelf_open_object(int _fd, Elf_Cmd _c, int _reporterror); +Elf_Data *_libelf_rawdata(Elf_Scn *s, Elf_Data *ed, bool updating); struct _Libelf_Data *_libelf_release_data(struct _Libelf_Data *_d); Elf *_libelf_release_elf(Elf *_e); Elf_Scn *_libelf_release_scn(Elf_Scn *_s); Index: contrib/elftoolchain/libelf/elf_data.c =================================================================== --- contrib/elftoolchain/libelf/elf_data.c +++ contrib/elftoolchain/libelf/elf_data.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -35,7 +36,7 @@ ELFTC_VCSID("$Id: elf_data.c 3466 2016-05-11 18:35:44Z emaste $"); Elf_Data * -elf_getdata(Elf_Scn *s, Elf_Data *ed) +_libelf_getdata(Elf_Scn *s, Elf_Data *ed, bool updating) { Elf *e; unsigned int sh_type; @@ -94,7 +95,9 @@ 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))) { + (!updating && + (sh_offset > e->e_rawsize || + sh_size > e->e_rawsize - sh_offset)))) { LIBELF_SET_ERROR(SECTION, 0); return (NULL); } @@ -165,6 +168,12 @@ return (&d->d_data); } +Elf_Data * +elf_getdata(Elf_Scn *s, Elf_Data *ed) +{ + return (_libelf_getdata(s, ed, false)); +} + Elf_Data * elf_newdata(Elf_Scn *s) { @@ -209,7 +218,7 @@ */ Elf_Data * -elf_rawdata(Elf_Scn *s, Elf_Data *ed) +_libelf_rawdata(Elf_Scn *s, Elf_Data *ed, bool updating) { Elf *e; int elf_class; @@ -254,7 +263,9 @@ } if (sh_type != SHT_NOBITS && - (sh_offset > e->e_rawsize || sh_size > e->e_rawsize - sh_offset)) { + (!updating && + (sh_offset > e->e_rawsize || + sh_size > e->e_rawsize - sh_offset))) { LIBELF_SET_ERROR(SECTION, 0); return (NULL); } @@ -274,3 +285,9 @@ return (&d->d_data); } + +Elf_Data * +elf_rawdata(Elf_Scn *s, Elf_Data *ed) +{ + return (_libelf_rawdata(s, ed, false)); +} Index: contrib/elftoolchain/libelf/elf_update.c =================================================================== --- contrib/elftoolchain/libelf/elf_update.c +++ contrib/elftoolchain/libelf/elf_update.c @@ -182,7 +182,8 @@ * Otherwise, we need to bring in the section's data * from the underlying ELF object. */ - if (e->e_cmd != ELF_C_WRITE && elf_getdata(s, NULL) == NULL) + if (e->e_cmd != ELF_C_WRITE && + _libelf_getdata(s, NULL, true) == NULL) return (0); }