file_read_elf tries to read the Ehdr and Shdrs from a mapped
address. If the addresses are correctly aligned it will use direct
reads, otherwise it will use memcpy to copy the values out, unless
ALLOW_UNALIGNED is set (or a writable copy is needed). The Ehdr is
small and the memcpy is as efficient for . For the Shdrs keeping an
unaligned pointer means more complicated code is needed whenever a
possible unaligned access is needed. So drop ALLOW_UNALIGNED.

            * libelf/elf_begin.c (file_read_elf): Drop all
            ALLOW_UNALIGNED conditions.

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

diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
index 54385d817805..27278e93cb5f 100644
--- a/libelf/elf_begin.c
+++ b/libelf/elf_begin.c
@@ -332,8 +332,7 @@ file_read_elf (int fildes, void *map_address, unsigned char 
*e_ident,
       /* This is a 32-bit binary.  */
       if (map_address != NULL && e_ident[EI_DATA] == MY_ELFDATA
          && cmd != ELF_C_READ_MMAP /* We need a copy to be able to write.  */
-         && (ALLOW_UNALIGNED
-             || (ehdr & (__alignof__ (Elf32_Ehdr) - 1)) == 0))
+         && (ehdr & (__alignof__ (Elf32_Ehdr) - 1)) == 0)
        {
          /* We can use the mmapped memory.  */
          elf->state.elf32.ehdr = (Elf32_Ehdr *) ehdr;
@@ -368,8 +367,7 @@ file_read_elf (int fildes, void *map_address, unsigned char 
*e_ident,
       Elf32_Off e_shoff = elf->state.elf32.ehdr->e_shoff;
       if (map_address != NULL && e_ident[EI_DATA] == MY_ELFDATA
          && cmd != ELF_C_READ_MMAP /* We need a copy to be able to write.  */
-         && (ALLOW_UNALIGNED
-             || (((ehdr + e_shoff) & (__alignof__ (Elf32_Shdr) - 1)) == 0)))
+         && ((ehdr + e_shoff) & (__alignof__ (Elf32_Shdr) - 1)) == 0)
        {
          if (unlikely (scncnt > 0 && e_shoff >= maxsize)
              || unlikely (maxsize - e_shoff
@@ -423,8 +421,7 @@ file_read_elf (int fildes, void *map_address, unsigned char 
*e_ident,
       /* This is a 64-bit binary.  */
       if (map_address != NULL && e_ident[EI_DATA] == MY_ELFDATA
          && cmd != ELF_C_READ_MMAP /* We need a copy to be able to write.  */
-         && (ALLOW_UNALIGNED
-             || (ehdr & (__alignof__ (Elf64_Ehdr) - 1)) == 0))
+         && (ehdr & (__alignof__ (Elf64_Ehdr) - 1)) == 0)
        {
          /* We can use the mmapped memory.  */
          elf->state.elf64.ehdr = (Elf64_Ehdr *) ehdr;
@@ -459,8 +456,7 @@ file_read_elf (int fildes, void *map_address, unsigned char 
*e_ident,
       Elf64_Off e_shoff = elf->state.elf64.ehdr->e_shoff;
       if (map_address != NULL && e_ident[EI_DATA] == MY_ELFDATA
          && cmd != ELF_C_READ_MMAP /* We need a copy to be able to write.  */
-         && (ALLOW_UNALIGNED
-             || (((ehdr + e_shoff) & (__alignof__ (Elf64_Shdr) - 1)) == 0)))
+         && ((ehdr + e_shoff) & (__alignof__ (Elf64_Shdr) - 1)) == 0)
        {
          if (unlikely (scncnt > 0 && e_shoff >= maxsize)
              || unlikely (maxsize - e_shoff
-- 
2.56.1

Reply via email to