]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Use gelf_fsize instead of relying on shdr->sh_entsize
authorPetr Machata <pmachata@redhat.com>
Wed, 23 Mar 2011 14:33:45 +0000 (15:33 +0100)
committerPetr Machata <pmachata@redhat.com>
Wed, 23 Mar 2011 14:33:45 +0000 (15:33 +0100)
libdwfl/ChangeLog
libdwfl/relocate.c
src/ChangeLog
src/readelf.c

index 0cbeb85023998830f7c40e6d1cb639d2bc4c3624..5a002b15de0baa30725f26474ea691d46a5bd717 100644 (file)
@@ -1,3 +1,8 @@
+2011-03-23  Petr Machata  <pmachata@redhat.com>
+
+       * relocate.c (relocate_section): Use gelf_fsize instead of relying
+       on shdr->sh_entsize.
+
 2011-02-11  Roland McGrath  <roland@redhat.com>
 
        * linux-kernel-modules.c (try_kernel_name): Try .gz, .bz2, .xz
index 95206f479b8a85ccf7260bbb7a6eb79bbdfb129a..c7a92ef06a377a7f08817daa2eba48300e0ab33b 100644 (file)
@@ -1,5 +1,5 @@
 /* Relocate debug information.
-   Copyright (C) 2005-2010 Red Hat, Inc.
+   Copyright (C) 2005-2011 Red Hat, Inc.
    This file is part of Red Hat elfutils.
 
    Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -478,7 +478,10 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
       }
   }
 
-  size_t nrels = shdr->sh_size / shdr->sh_entsize;
+  size_t sh_entsize
+    = gelf_fsize (relocated, shdr->sh_type == SHT_REL ? ELF_T_REL : ELF_T_RELA,
+                 1, EV_CURRENT);
+  size_t nrels = shdr->sh_size / sh_entsize;
   size_t complete = 0;
   if (shdr->sh_type == SHT_REL)
     for (size_t relidx = 0; !result && relidx < nrels; ++relidx)
@@ -580,7 +583,7 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
          nrels = next;
        }
 
-      shdr->sh_size = reldata->d_size = nrels * shdr->sh_entsize;
+      shdr->sh_size = reldata->d_size = nrels * sh_entsize;
       gelf_update_shdr (scn, shdr);
     }
 
index a6a599920c7c9a70c835d6ed14683d874c173e6a..ead1235c03ec40ffcc5b7792677c1a8533ebd720 100644 (file)
@@ -1,3 +1,9 @@
+2011-03-23  Petr Machata  <pmachata@redhat.com>
+
+       * readelf.c (handle_dynamic, handle_relocs_rel)
+       (handle_relocs_rela, handle_versym, print_liblist):
+       Use gelf_fsize instead of relying on shdr->sh_entsize.
+
 2011-02-11  Roland McGrath  <roland@redhat.com>
 
        * elfcmp.c (verbose): New variable.
index a42bc6802ed19c197451730d230312079699bf8e..a92de144f6b34dfb347168e1966d019ab5b24c71 100644 (file)
@@ -1,5 +1,5 @@
 /* Print information from ELF file in human-readable form.
-   Copyright (C) 1999-2010 Red Hat, Inc.
+   Copyright (C) 1999-2011 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 1999.
 
@@ -1349,6 +1349,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
   Elf_Data *data;
   size_t cnt;
   size_t shstrndx;
+  size_t sh_entsize;
 
   /* Get the data of the section.  */
   data = elf_getdata (scn, NULL);
@@ -1360,6 +1361,8 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
     error (EXIT_FAILURE, 0,
           gettext ("cannot get section header string table index"));
 
+  sh_entsize = gelf_fsize (ebl->elf, ELF_T_DYN, 1, EV_CURRENT);
+
   glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem);
   if (glink == NULL)
     error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"),
@@ -1369,15 +1372,15 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
 \nDynamic segment contains %lu entry:\n Addr: %#0*" PRIx64 "  Offset: %#08" PRIx64 "  Link to section: [%2u] '%s'\n",
                    "\
 \nDynamic segment contains %lu entries:\n Addr: %#0*" PRIx64 "  Offset: %#08" PRIx64 "  Link to section: [%2u] '%s'\n",
-                   shdr->sh_size / shdr->sh_entsize),
-         (unsigned long int) (shdr->sh_size / shdr->sh_entsize),
+                   shdr->sh_size / sh_entsize),
+         (unsigned long int) (shdr->sh_size / sh_entsize),
          class == ELFCLASS32 ? 10 : 18, shdr->sh_addr,
          shdr->sh_offset,
          (int) shdr->sh_link,
          elf_strptr (ebl->elf, shstrndx, glink->sh_name));
   fputs_unlocked (gettext ("  Type              Value\n"), stdout);
 
-  for (cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
+  for (cnt = 0; cnt < shdr->sh_size / sh_entsize; ++cnt)
     {
       GElf_Dyn dynmem;
       GElf_Dyn *dyn = gelf_getdyn (data, cnt, &dynmem);
@@ -1524,7 +1527,8 @@ static void
 handle_relocs_rel (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr)
 {
   int class = gelf_getclass (ebl->elf);
-  int nentries = shdr->sh_size / shdr->sh_entsize;
+  size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_REL, 1, EV_CURRENT);
+  int nentries = shdr->sh_size / sh_entsize;
 
   /* Get the data of the section.  */
   Elf_Data *data = elf_getdata (scn, NULL);
@@ -1710,7 +1714,8 @@ static void
 handle_relocs_rela (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr)
 {
   int class = gelf_getclass (ebl->elf);
-  int nentries = shdr->sh_size / shdr->sh_entsize;
+  size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_RELA, 1, EV_CURRENT);
+  int nentries = shdr->sh_size / sh_entsize;
 
   /* Get the data of the section.  */
   Elf_Data *data = elf_getdata (scn, NULL);
@@ -2569,6 +2574,7 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
   GElf_Shdr glink_mem;
   GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
                                   &glink_mem);
+  size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_HALF, 1, EV_CURRENT);
   if (glink == NULL)
     error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"),
           elf_ndxscn (scn));
@@ -2578,17 +2584,17 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
 \nVersion symbols section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 "  Offset: %#08" PRIx64 "  Link to section: [%2u] '%s'",
                    "\
 \nVersion symbols section [%2u] '%s' contains %d entries:\n Addr: %#0*" PRIx64 "  Offset: %#08" PRIx64 "  Link to section: [%2u] '%s'",
-                   shdr->sh_size / shdr->sh_entsize),
+                   shdr->sh_size / sh_entsize),
          (unsigned int) elf_ndxscn (scn),
          elf_strptr (ebl->elf, shstrndx, shdr->sh_name),
-         (int) (shdr->sh_size / shdr->sh_entsize),
+         (int) (shdr->sh_size / sh_entsize),
          class == ELFCLASS32 ? 10 : 18, shdr->sh_addr,
          shdr->sh_offset,
          (unsigned int) shdr->sh_link,
          elf_strptr (ebl->elf, shstrndx, glink->sh_name));
 
   /* Now we can finally look at the actual contents of this section.  */
-  for (unsigned int cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
+  for (unsigned int cnt = 0; cnt < shdr->sh_size / sh_entsize; ++cnt)
     {
       if (cnt % 2 == 0)
        printf ("\n %4d:", cnt);
@@ -2920,7 +2926,8 @@ print_liblist (Ebl *ebl)
 
       if (shdr != NULL && shdr->sh_type == SHT_GNU_LIBLIST)
        {
-         int nentries = shdr->sh_size / shdr->sh_entsize;
+         size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_LIB, 1, EV_CURRENT);
+         int nentries = shdr->sh_size / sh_entsize;
          printf (ngettext ("\
 \nLibrary list section [%2zu] '%s' at offset %#0" PRIx64 " contains %d entry:\n",
                            "\