On Thu, 2014-06-12 at 14:30 +0200, Mark Wielaard wrote: > On Tue, 2014-06-10 at 15:31 +0200, Thilo Schulz wrote: > > > I was wondering whether we want to check scn->rawdata.s directly, or if > > > we could rely on ELF_F_FILEDATA being set for scn->flags? > > > > Seems reasonable though I don't know the code as well as you do I guess. > > I wish I understood the code very well :) But now that I wrote the > testcase and you pointed out the second bug, I am not sure of the fix > anymore. It does seem to fix the first issue, but then you immediately > hit the second. > > > As a further note: A similar bug, albeit for slightly different reasons, > > occurs > > when adding relocations. Adding a relocation with elf_newdata() then > > elf_update() > > results in the old data being "forgotten" if there was no elf_getdata() > > call > > before to load that data into memory. The cause is a bit different because > > in > > this case, there was not a call to elf_rawdata() before and this still > > happened. I imagine, this might also be a problem for string tables. > > Indeed. The attached testcase shows both issues. Calling elf_getdata() > and then elf_newdata() works as expected. But elf_newdata drops all > existing data when elf_rawdata is called before and elf_newdata keeps > the size, but not the actual content bytes of existing data of a section > if elf_getdata isn't called before. > > Still scratching my head a little how to resolve both issues properly.
Sorry this took 9 months... But I believe these issues have finally been resolved in current git elfutils. At least my testcase now works as expected. Hope it also now works for your code. Cheers, Mark