]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: Get orig_addralign the same way for 32/64 bit ELF in elf_compress
authorMark Wielaard <mark@klomp.org>
Mon, 18 May 2026 16:47:21 +0000 (18:47 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 21 May 2026 16:52:20 +0000 (18:52 +0200)
Depending on whether the ELF was 32 or 64 bit elf_compress would get
the original sh_addralign, as embedded in the Chdr, differenly. For
64bit ELF we would simply get the sh_addralign from the Shdr. For
32bit ELF we would take the (max) alignment of the underlying
Elf_Data, provided by __libelf_compress. Use the second method for
both since the Shdr might not have been setup yet, so what counts is
the Elf_Data alignment.

* libelf/elf_compress.c (elf_compress): Remove sh_addralign.
Set chdr.ch_addralign to orig_addralign in 64bit case.

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

index a2fa1f087658c577ba14a6159bcdf56c24dcfcf8..28c9b25f48115f74340ecce7e9a25ae05aeecf6b 100644 (file)
@@ -583,7 +583,6 @@ elf_compress (Elf_Scn *scn, int type, unsigned int flags)
 
   Elf64_Xword sh_flags;
   Elf64_Word sh_type;
-  Elf64_Xword sh_addralign;
   union shdr
   {
     Elf32_Shdr *s32;
@@ -597,7 +596,6 @@ elf_compress (Elf_Scn *scn, int type, unsigned int flags)
 
       sh_flags = shdr.s32->sh_flags;
       sh_type = shdr.s32->sh_type;
-      sh_addralign = shdr.s32->sh_addralign;
     }
   else
     {
@@ -607,7 +605,6 @@ elf_compress (Elf_Scn *scn, int type, unsigned int flags)
 
       sh_flags = shdr.s64->sh_flags;
       sh_type = shdr.s64->sh_type;
-      sh_addralign = shdr.s64->sh_addralign;
     }
 
   if ((sh_flags & SHF_ALLOC) != 0)
@@ -669,7 +666,7 @@ elf_compress (Elf_Scn *scn, int type, unsigned int flags)
          chdr.ch_type = type;
          chdr.ch_reserved = 0;
          chdr.ch_size = orig_size;
-         chdr.ch_addralign = sh_addralign;
+         chdr.ch_addralign = orig_addralign;
          if (elfdata != MY_ELFDATA)
            {
              CONVERT (chdr.ch_type);