]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
2005-08-13 Roland McGrath <roland@redhat.com>
authorRoland McGrath <roland@redhat.com>
Sat, 13 Aug 2005 20:56:07 +0000 (20:56 +0000)
committerRoland McGrath <roland@redhat.com>
Sat, 13 Aug 2005 20:56:07 +0000 (20:56 +0000)
* ia64_symbol.c (ia64_machine_flag_check): New function.
* libebl_ia64.h: Declare it.
* ia64_init.c (ia64_init): Use it.

libebl/ChangeLog
libebl/ia64_init.c
libebl/ia64_symbol.c
libebl/libebl_ia64.h
libelf/ChangeLog
libelf/elf_begin.c

index eb4cdae6dbe2430f3cbca7766b619609b26bd632..cb0d00954e2d012a3fd51de6c79af08d5909277f 100644 (file)
@@ -1,3 +1,9 @@
+2005-08-13  Roland McGrath  <roland@redhat.com>
+
+       * ia64_symbol.c (ia64_machine_flag_check): New function.
+       * libebl_ia64.h: Declare it.
+       * ia64_init.c (ia64_init): Use it.
+
 2005-08-13  Ulrich Drepper  <drepper@redhat.com>
 
        * libebl.h: Add ehdr parameter to ebl_bss_plt_p and
index 3cafe5de66bbd1e5560453d6211080548697211f..f5c3f364c55983fe0ff9d23350101c2bb5d9ca41 100644 (file)
@@ -37,6 +37,7 @@ ia64_init (elf, machine, eh, ehlen)
   eh->segment_type_name = ia64_segment_type_name;
   eh->dynamic_tag_name = ia64_dynamic_tag_name;
   eh->copy_reloc_p = ia64_copy_reloc_p;
+  eh->machine_flag_check = ia64_machine_flag_check;
   eh->destr = ia64_destr;
 
   return MODVERSION;
index 77ced76de1e7860fdc9e76d5c1110542f13c1bb7..2975285b86bda1477359389f56ae937a66b6b468 100644 (file)
@@ -185,3 +185,10 @@ ia64_copy_reloc_p (int reloc)
 {
   return reloc == R_IA64_COPY;
 }
+
+/* Check whether machine flags are valid.  */
+bool
+ia64_machine_flag_check (GElf_Word flags)
+{
+  return ((flags &~ EF_IA_64_ABI64) == 0);
+}
index 8dea650018449013d50284ac34c134d724453ffc..e5cf49deef1af2403a5f88164ee6e96efde2366b 100644 (file)
@@ -40,4 +40,8 @@ extern const char *ia64_dynamic_tag_name (int64_t tag, char *buf, size_t len);
 /* Check whether given relocation is a copy relocation.  */
 extern bool ia64_copy_reloc_p (int reloc);
 
+/* Check whether machine flags are valid.  */
+extern bool ia64_machine_flag_check (GElf_Word flags);
+
+
 #endif /* libebl_ia64.h */
index acb026ef2d5254f5f58d74709c050d8231c06028..67d4f39510ab37e6255a1e08a74420658c9727ef 100644 (file)
@@ -1,10 +1,3 @@
-2005-08-13  Ulrich Drepper  <drepper@redhat.com>
-
-       * elf_begin.c (get_shnum): Optimize memory handling.  Always read from
-       mapped file if available.  Fix access to 64-bit sh_size.  Recognize
-       overflow.
-       (file_read_elf): Likewise.
-
 2005-08-12  Roland McGrath  <roland@redhat.com>
 
        * elf32_offscn.c: Do not match empty sections at OFFSET unless
index 56c7a481521ce6cf84fb155b9ca3417c953d3543..404cbe832821b7a1abc1c19edfa78f55801e3c3d 100644 (file)
@@ -69,11 +69,6 @@ get_shnum (void *map_address, unsigned char *e_ident, int fildes, off_t offset,
     Elf64_Ehdr *e64;
     void *p;
   } ehdr;
-  union
-  {
-    Elf32_Ehdr e32;
-    Elf64_Ehdr e64;
-  } ehdr_mem;
   bool is32 = e_ident[EI_CLASS] == ELFCLASS32;
 
   /* Make the ELF header available.  */
@@ -88,17 +83,11 @@ get_shnum (void *map_address, unsigned char *e_ident, int fildes, off_t offset,
       /* We have to read the data from the file.  */
       size_t len = is32 ? sizeof (Elf32_Ehdr) : sizeof (Elf64_Ehdr);
 
-      if (likely (map_address != NULL))
-       ehdr.p = memcpy (&ehdr_mem, (char *) map_address + offset, len);
-      else
-       {
-         /* Fill it.  */
-         if ((size_t) TEMP_FAILURE_RETRY (pread (fildes, &ehdr_mem, len,
-                                                 offset)) != len)
-           /* Failed reading.  */
-           return (size_t) -1l;
-         ehdr.p = &ehdr_mem;
-       }
+      ehdr.p = alloca (len);
+      /* Fill it.  */
+      if ((size_t) pread (fildes, ehdr.p, len, offset) != len)
+       /* Failed reading.  */
+       return (size_t) -1l;
 
       if (e_ident[EI_DATA] != MY_ELFDATA)
        {
@@ -131,27 +120,18 @@ get_shnum (void *map_address, unsigned char *e_ident, int fildes, off_t offset,
                  || (((size_t) ((char *) map_address + offset))
                      & (__alignof__ (Elf32_Ehdr) - 1)) == 0))
            /* We can directly access the memory.  */
-           result = ((Elf32_Shdr *) ((char *) map_address + ehdr.e32->e_shoff
+           result = ((Elf32_Shdr *) ((char *) map_address
+                                     + ehdr.e32->e_shoff
                                      + offset))->sh_size;
          else
            {
              Elf32_Word size;
 
-             if (likely (map_address != NULL))
-               /* gcc will optimize the memcpy to a simple memory
-                  access while taking care of alignment issues.  */
-               memcpy (&size, &((Elf32_Shdr *) ((char *) map_address
-                                                + ehdr.e32->e_shoff
-                                                + offset))->sh_size,
-                       sizeof (Elf32_Word));
-             else
-               if (TEMP_FAILURE_RETRY (pread (fildes, &size,
-                                              sizeof (Elf32_Word),
-                                              offset + ehdr.e32->e_shoff
-                                              + offsetof (Elf32_Shdr,
-                                                          sh_size)))
-                   != sizeof (Elf32_Word))
-                 return (size_t) -1l;
+             if (pread (fildes, &size, sizeof (Elf32_Word),
+                        offset + ehdr.e32->e_shoff
+                        + offsetof (Elf32_Shdr, sh_size))
+                 != sizeof (Elf32_Word))
+               return (size_t) -1l;
 
              if (e_ident[EI_DATA] != MY_ELFDATA)
                CONVERT (size);
@@ -171,41 +151,29 @@ get_shnum (void *map_address, unsigned char *e_ident, int fildes, off_t offset,
            /* Cannot read the first section header.  */
            return (size_t) -1l;
 
-         Elf64_Xword size;
          if (likely (map_address != NULL) && e_ident[EI_DATA] == MY_ELFDATA
              && (ALLOW_UNALIGNED
                  || (((size_t) ((char *) map_address + offset))
                      & (__alignof__ (Elf64_Ehdr) - 1)) == 0))
            /* We can directly access the memory.  */
-           size = ((Elf64_Shdr *) ((char *) map_address + ehdr.e64->e_shoff
-                                   + offset))->sh_size;
+           result = ((Elf64_Shdr *) ((char *) map_address
+                                     + ehdr.e64->e_shoff
+                                     + offset))->sh_size;
          else
            {
-             if (likely (map_address != NULL))
-               /* gcc will optimize the memcpy to a simple memory
-                  access while taking care of alignment issues.  */
-               memcpy (&size, &((Elf64_Shdr *) ((char *) map_address
-                                                + ehdr.e64->e_shoff
-                                                + offset))->sh_size,
-                       sizeof (Elf64_Xword));
-             else
-               if (TEMP_FAILURE_RETRY (pread (fildes, &size,
-                                              sizeof (Elf64_Word),
-                                              offset + ehdr.e64->e_shoff
-                                              + offsetof (Elf64_Shdr,
-                                                          sh_size)))
-                   != sizeof (Elf64_Xword))
-                 return (size_t) -1l;
+             Elf64_Word size;
+
+             if (pread (fildes, &size, sizeof (Elf64_Word),
+                        offset + ehdr.e64->e_shoff
+                        + offsetof (Elf64_Shdr, sh_size))
+                 != sizeof (Elf64_Word))
+               return (size_t) -1l;
 
              if (e_ident[EI_DATA] != MY_ELFDATA)
                CONVERT (size);
-           }
-
-         if (size > ~((GElf_Word) 0))
-           /* Invalid value, it is too large.  */
-           return (size_t) -1l;
 
-         result = size;
+             result = size;
+           }
        }
     }
 
@@ -220,7 +188,6 @@ file_read_elf (int fildes, void *map_address, off_t offset, size_t maxsize,
 {
   /* We only read the ELF header now.  */
   unsigned char *e_ident;
-  unsigned char e_ident_mem[EI_NIDENT];
   size_t scncnt;
   Elf *elf;
 
@@ -230,10 +197,9 @@ file_read_elf (int fildes, void *map_address, off_t offset, size_t maxsize,
     e_ident = (unsigned char *) map_address + offset;
   else
     {
-      e_ident = e_ident_mem;
+      e_ident = (unsigned char *) alloca (EI_NIDENT);
 
-      if (TEMP_FAILURE_RETRY (pread (fildes, e_ident, EI_NIDENT, offset))
-         != EI_NIDENT)
+      if (pread (fildes, e_ident, EI_NIDENT, offset) != EI_NIDENT)
        {
          __libelf_seterrno (ELF_E_READ_ERROR);
          return NULL;
@@ -314,21 +280,14 @@ file_read_elf (int fildes, void *map_address, off_t offset, size_t maxsize,
        }
       else
        {
-         if (likely (map_address != NULL))
-           /* Copy the data.  */
-           memcpy (&elf->state.elf32.ehdr_mem,
-                   (char *) map_address + offset, sizeof (Elf32_Ehdr));
-         else
-           /* Read the data.  */
-           if (TEMP_FAILURE_RETRY (pread (elf->fildes,
-                                          &elf->state.elf32.ehdr_mem,
-                                          sizeof (Elf32_Ehdr), offset))
-               != sizeof (Elf32_Ehdr))
-             {
-               /* We must be able to read the ELF header.  */
-               __libelf_seterrno (ELF_E_INVALID_FILE);
-               return NULL;
-             }
+         /* Read the data.  */
+         if (pread (elf->fildes, &elf->state.elf32.ehdr_mem,
+                    sizeof (Elf32_Ehdr), offset) != sizeof (Elf32_Ehdr))
+           {
+             /* We must be able to read the ELF header.  */
+             __libelf_seterrno (ELF_E_INVALID_FILE);
+             return NULL;
+           }
 
          if (e_ident[EI_DATA] != MY_ELFDATA)
            {
@@ -406,16 +365,9 @@ file_read_elf (int fildes, void *map_address, off_t offset, size_t maxsize,
        }
       else
        {
-         if (likely (map_address != NULL))
-           /* Copy the data.  */
-           memcpy (&elf->state.elf64.ehdr_mem,
-                   (char *) map_address + offset, sizeof (Elf64_Ehdr));
-         else
-           /* Read the data.  */
-           if (TEMP_FAILURE_RETRY (pread (elf->fildes,
-                                          &elf->state.elf64.ehdr_mem,
-                                          sizeof (Elf64_Ehdr), offset))
-               != sizeof (Elf64_Ehdr))
+         /* Read the data.  */
+         if (pread (elf->fildes, &elf->state.elf64.ehdr_mem,
+                    sizeof (Elf64_Ehdr), offset) != sizeof (Elf64_Ehdr))
            {
              /* We must be able to read the ELF header.  */
              __libelf_seterrno (ELF_E_INVALID_FILE);