When e_shstrndx is SHN_XINDEX then elf_getshdrstrndx will try to get
the value from the section zero sh_link. If the section zero shdr
hasn't been read in yet then if the file is mmapped in and the section
headers are aligned correctly, or the arch supports ALLOW_UNALIGNED,
the value is read directly, otherwise the sh_link value is read
through pread. The case where section zero hasn't been read in yet,
the ELF file is mmapped and the section headers are not aligned
correctly is very rare and there is no real benefit of avoiding the
pread. So remove the ALLOW_UNALIGNED condition.

        * libelf/elf_getshdrshdrstrndx.c (elf_getshdrstrndx): Drop
        ALLOW_UNALIGNED condition.

Signed-off-by: Mark Wielaard <[email protected]>
---
 libelf/elf_getshdrstrndx.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/libelf/elf_getshdrstrndx.c b/libelf/elf_getshdrstrndx.c
index 424e7adc1459..34c75e9310f4 100644
--- a/libelf/elf_getshdrstrndx.c
+++ b/libelf/elf_getshdrstrndx.c
@@ -105,10 +105,9 @@ elf_getshdrstrndx (Elf *elf, size_t *dst)
 
              if (elf->map_address != NULL
                  && elf->state.elf32.ehdr->e_ident[EI_DATA] == MY_ELFDATA
-                 && (ALLOW_UNALIGNED
-                     || (((size_t) ((char *) elf->map_address
-                          + elf->start_offset + offset))
-                         & (__alignof__ (Elf32_Shdr) - 1)) == 0))
+                 && (((size_t) ((char *) elf->map_address
+                                + elf->start_offset + offset))
+                     & (__alignof__ (Elf32_Shdr) - 1)) == 0)
                {
                  /* First see whether the information in the ELF header is
                     valid and it does not ask for too much.  */
@@ -171,10 +170,9 @@ elf_getshdrstrndx (Elf *elf, size_t *dst)
 
              if (elf->map_address != NULL
                  && elf->state.elf64.ehdr->e_ident[EI_DATA] == MY_ELFDATA
-                 && (ALLOW_UNALIGNED
-                     || (((size_t) ((char *) elf->map_address
-                          + elf->start_offset + offset))
-                         & (__alignof__ (Elf64_Shdr) - 1)) == 0))
+                 && (((size_t) ((char *) elf->map_address
+                                + elf->start_offset + offset))
+                     & (__alignof__ (Elf64_Shdr) - 1)) == 0)
                {
                  /* First see whether the information in the ELF header is
                     valid and it does not ask for too much.  */
-- 
2.56.1

Reply via email to