libelf: Fixup SHF_COMPRESSED sh_addralign in elf_update if necessary.
authorMark Wielaard <mark@klomp.org>
Wed, 19 Aug 2020 21:41:24 +0000 (23:41 +0200)
committerMark Wielaard <mark@klomp.org>
Wed, 19 Aug 2020 21:47:40 +0000 (23:47 +0200)
commit55c5c9a568ed707bcea1388bf3a525212d8cf4b8
tree68be81a4525baf3477099a083d7dd1821403c5bb
parent15495182302edbe0142101ec3a09e478901ab994
libelf: Fixup SHF_COMPRESSED sh_addralign in elf_update if necessary.

In elf_getdata.c we have the following to compensate for possibly
bad sh_addralign values of compressed sections:

      /* Compressed data has a header, but then compressed data.
         Make sure to set the alignment of the header explicitly,
         don't trust the file alignment for the section, it is
         often wrong.  */
      if ((flags & SHF_COMPRESSED) != 0)
        {
          entsize = 1;
          align = __libelf_type_align (elf->class, ELF_T_CHDR);
        }

Which makes sure the d_data alignment is correct for the Chdr struct
at the start of the compressed section.

But this means that if a user just reads such a compressed section
without changing it, and then tries to write it out again using
elf_update they get an error message about d_align and sh_addralign
being out of sync.

We already correct obviously incorrect sh_entsize fields.
Do the same for the sh_addralign field of a SHF_COMPRESSED section.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libelf/ChangeLog
libelf/elf32_updatenull.c