Index: contrib/elftoolchain/libelf/_libelf.h =================================================================== --- contrib/elftoolchain/libelf/_libelf.h +++ contrib/elftoolchain/libelf/_libelf.h @@ -29,6 +29,8 @@ #ifndef __LIBELF_H_ #define __LIBELF_H_ +#include + #include #include "_libelf_config.h" @@ -229,6 +231,8 @@ int _libelf_setshnum(Elf *_e, void *_eh, int _elfclass, size_t _shnum); int _libelf_setshstrndx(Elf *_e, void *_eh, int _elfclass, size_t _shstrndx); +Elf_Data * _libelf_getdata(Elf_Scn *s, Elf_Data *ed, bool updating); +Elf_Data * _libelf_rawdata(Elf_Scn *s, Elf_Data *ed, bool updating); Elf_Data *_libelf_xlate(Elf_Data *_d, const Elf_Data *_s, unsigned int _encoding, int _elfclass, int _direction); int _libelf_xlate_shtype(uint32_t _sht); Index: contrib/elftoolchain/libelf/elf_data.c =================================================================== --- contrib/elftoolchain/libelf/elf_data.c +++ contrib/elftoolchain/libelf/elf_data.c @@ -29,13 +29,14 @@ #include #include #include +#include #include "_libelf.h" 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); } @@ -166,6 +169,12 @@ } Elf_Data * +elf_getdata(Elf_Scn *s, Elf_Data *ed) +{ + return (_libelf_getdata(s, ed, false)); +} + +Elf_Data * elf_newdata(Elf_Scn *s) { Elf *e; @@ -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); }