]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Use elf_getphdrnum in libdw and libdwfl.
authorRoland McGrath <roland@redhat.com>
Fri, 8 Jan 2010 04:24:34 +0000 (20:24 -0800)
committerRoland McGrath <roland@redhat.com>
Fri, 8 Jan 2010 04:24:34 +0000 (20:24 -0800)
libdw/ChangeLog
libdw/dwarf_getcfi_elf.c
libdwfl/ChangeLog
libdwfl/core-file.c
libdwfl/dwfl_module_build_id.c
libdwfl/dwfl_module_getdwarf.c
libdwfl/dwfl_report_elf.c

index 0afa850704fca44647d75b41d3ad6823ee05812f..97f87da07d7600ab341fb085c74ac8f439b17c89 100644 (file)
@@ -1,3 +1,7 @@
+2010-01-07  Roland McGrath  <roland@redhat.com>
+
+       * dwarf_getcfi_elf.c (getcfi_phdr): Use elf_getphdrnum.
+
 2010-01-05  Roland McGrath  <roland@redhat.com>
 
        * dwarf_aggregate_size.c: New file.
index 949515e504531f5027a1f3815d6f3456d8d90ee5..64a2a885525237507bd544db6ce4660d553738d9 100644 (file)
@@ -1,5 +1,5 @@
 /* Get CFI from ELF file's exception-handling info.
-   Copyright (C) 2009 Red Hat, Inc.
+   Copyright (C) 2009-2010 Red Hat, Inc.
    This file is part of Red Hat elfutils.
 
    Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -208,9 +208,11 @@ getcfi_gnu_eh_frame (Elf *elf, const GElf_Ehdr *ehdr, const GElf_Phdr *phdr)
 static Dwarf_CFI *
 getcfi_phdr (Elf *elf, const GElf_Ehdr *ehdr)
 {
-  const uint_fast16_t phnum = ehdr->e_phnum;
+  size_t phnum;
+  if (unlikely (elf_getphdrnum (elf, &phnum) != 0))
+    return NULL;
 
-  for (uint_fast16_t i = 0; i < phnum; ++i)
+  for (size_t i = 0; i < phnum; ++i)
     {
       GElf_Phdr phdr_mem;
       GElf_Phdr *phdr = gelf_getphdr (elf, i, &phdr_mem);
index f66982559b68e08ea8c93c9cb3bd394fd0bc872a..d9e6e654d37c1c9041ebfb6114b4743e2e2a107c 100644 (file)
@@ -1,3 +1,10 @@
+2010-01-07  Roland McGrath  <roland@redhat.com>
+
+       * core-file.c (dwfl_core_file_report): Use elf_getphdrnum.
+       * dwfl_module_build_id.c (__libdwfl_find_build_id): Likewise.
+       * dwfl_module_getdwarf.c (open_elf, find_dynsym): Likewise.
+       * dwfl_report_elf.c (__libdwfl_report_elf): Likewise.
+
 2010-01-06  Roland McGrath  <roland@redhat.com>
 
        * relocate.c (relocate_getsym): For SHN_COMMON, zero st_value.
index ad1c78d8f7a6c524a323b1ce5e8ee4153d110946..1872d8abe45d5e5c865ed2a9dbcfc45a574e7793 100644 (file)
@@ -1,5 +1,5 @@
 /* Core file handling.
-   Copyright (C) 2008, 2009 Red Hat, Inc.
+   Copyright (C) 2008-2010 Red Hat, Inc.
    This file is part of Red Hat elfutils.
 
    Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -141,24 +141,17 @@ elf_begin_rand (Elf *parent, loff_t offset, loff_t size, loff_t *next)
 
 
 int
-dwfl_report_core_segments (Dwfl *dwfl, Elf *elf, const GElf_Ehdr *ehdr,
-                          GElf_Phdr *notes)
+dwfl_report_core_segments (Dwfl *dwfl, Elf *elf, size_t phnum, GElf_Phdr *notes)
 {
   if (unlikely (dwfl == NULL))
     return -1;
 
-  if (unlikely (elf == NULL) || unlikely (ehdr == NULL))
-    {
-      __libdw_seterrno (DWFL_E_LIBELF);
-      return -1;
-    }
-
   int result = 0;
 
   if (notes != NULL)
     notes->p_type = PT_NULL;
 
-  for (int ndx = 0; result >= 0 && ndx < ehdr->e_phnum; ++ndx)
+  for (size_t ndx = 0; result >= 0 && ndx < phnum; ++ndx)
     {
       GElf_Phdr phdr_mem;
       GElf_Phdr *phdr = gelf_getphdr (elf, ndx, &phdr_mem);
@@ -414,8 +407,15 @@ dwfl_core_file_report (Dwfl *dwfl, Elf *elf, const GElf_Ehdr *ehdr)
 {
   GElf_Phdr notes_phdr;
 
+  size_t phnum;
+  if (unlikely (ehdr == NULL) || unlikely (elf_getphdrnum (elf, &phnum) != 0))
+    {
+      __libdw_seterrno (DWFL_E_LIBELF);
+      return -1;
+    }
+
   /* First report each PT_LOAD segment.  */
-  int ndx = dwfl_report_core_segments (dwfl, elf, ehdr, &notes_phdr);
+  int ndx = dwfl_report_core_segments (dwfl, elf, phnum, &notes_phdr);
   if (unlikely (ndx <= 0))
     return ndx;
 
@@ -430,7 +430,7 @@ dwfl_core_file_report (Dwfl *dwfl, Elf *elf, const GElf_Ehdr *ehdr)
        return seg;
       ndx = seg > ndx ? seg : ndx + 1;
     }
-  while (ndx < ehdr->e_phnum);
+  while (ndx < (int) phnum);
 
   /* Next, we should follow the chain from DT_DEBUG.  */
 
index 07a62ba42f47586abe7baf720338dedfb1ef06de..9dc7f6780b731c12620c75782d0c661ec18a9c2e 100644 (file)
@@ -1,5 +1,5 @@
 /* Return build ID information for a module.
-   Copyright (C) 2007, 2008, 2009 Red Hat, Inc.
+   Copyright (C) 2007-2010 Red Hat, Inc.
    This file is part of Red Hat elfutils.
 
    Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -107,12 +107,14 @@ __libdwfl_find_build_id (Dwfl_Module *mod, bool set, Elf *elf)
       /* No sections, have to look for phdrs.  */
       GElf_Ehdr ehdr_mem;
       GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
-      if (unlikely (ehdr == NULL))
+      size_t phnum;
+      if (unlikely (ehdr == NULL)
+         || unlikely (elf_getphdrnum (elf, &phnum) != 0))
        {
          __libdwfl_seterrno (DWFL_E_LIBELF);
          return -1;
        }
-      for (uint_fast16_t i = 0; result == 0 && i < ehdr_mem.e_phnum; ++i)
+      for (size_t i = 0; result == 0 && i < phnum; ++i)
        {
          GElf_Phdr phdr_mem;
          GElf_Phdr *phdr = gelf_getphdr (elf, i, &phdr_mem);
index f48fabe740a1ccd9ee0f92264a743f4d2c320fbf..b084673ebaffb6353523071ad1350c243cd09328 100644 (file)
@@ -1,5 +1,5 @@
 /* Find debugging and symbol information for a module in libdwfl.
-   Copyright (C) 2005, 2006, 2007, 2008, 2009 Red Hat, Inc.
+   Copyright (C) 2005-2010 Red Hat, Inc.
    This file is part of Red Hat elfutils.
 
    Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -95,19 +95,25 @@ open_elf (Dwfl_Module *mod, struct dwfl_file *file)
      sh_addr of any program sections refer to.  */
   file->bias = 0;
   if (mod->e_type != ET_EXEC)
-    for (uint_fast16_t i = 0; i < ehdr->e_phnum; ++i)
-      {
-       GElf_Phdr ph_mem;
-       GElf_Phdr *ph = gelf_getphdr (file->elf, i, &ph_mem);
-       if (ph == NULL)
-         goto elf_error;
-       if (ph->p_type == PT_LOAD)
-         {
-           file->bias = ((mod->low_addr & -ph->p_align)
-                         - (ph->p_vaddr & -ph->p_align));
-           break;
-         }
-      }
+    {
+      size_t phnum;
+      if (unlikely (elf_getphdrnum (file->elf, &phnum) != 0))
+       goto elf_error;
+
+      for (size_t i = 0; i < phnum; ++i)
+       {
+         GElf_Phdr ph_mem;
+         GElf_Phdr *ph = gelf_getphdr (file->elf, i, &ph_mem);
+         if (ph == NULL)
+           goto elf_error;
+         if (ph->p_type == PT_LOAD)
+           {
+             file->bias = ((mod->low_addr & -ph->p_align)
+                           - (ph->p_vaddr & -ph->p_align));
+             break;
+           }
+       }
+    }
 
   mod->e_type = ehdr->e_type;
 
@@ -285,11 +291,11 @@ load_symtab (struct dwfl_file *file, struct dwfl_file **symfile,
 /* Translate addresses into file offsets.
    OFFS[*] start out zero and remain zero if unresolved.  */
 static void
-find_offsets (Elf *elf, const GElf_Ehdr *ehdr, size_t n,
+find_offsets (Elf *elf, size_t phnum, size_t n,
              GElf_Addr addrs[n], GElf_Off offs[n])
 {
   size_t unsolved = n;
-  for (uint_fast16_t i = 0; i < ehdr->e_phnum; ++i)
+  for (size_t i = 0; i < phnum; ++i)
     {
       GElf_Phdr phdr_mem;
       GElf_Phdr *phdr = gelf_getphdr (elf, i, &phdr_mem);
@@ -313,7 +319,11 @@ find_dynsym (Dwfl_Module *mod)
   GElf_Ehdr ehdr_mem;
   GElf_Ehdr *ehdr = gelf_getehdr (mod->main.elf, &ehdr_mem);
 
-  for (uint_fast16_t i = 0; i < ehdr->e_phnum; ++i)
+  size_t phnum;
+  if (unlikely (elf_getphdrnum (mod->main.elf, &phnum) != 0))
+    return;
+
+  for (size_t i = 0; i < phnum; ++i)
     {
       GElf_Phdr phdr_mem;
       GElf_Phdr *phdr = gelf_getphdr (mod->main.elf, i, &phdr_mem);
@@ -380,7 +390,7 @@ find_dynsym (Dwfl_Module *mod)
 
          /* Translate pointers into file offsets.  */
          GElf_Off offs[i_max] = { 0, };
-         find_offsets (mod->main.elf, ehdr, i_max, addrs, offs);
+         find_offsets (mod->main.elf, phnum, i_max, addrs, offs);
 
          /* Figure out the size of the symbol table.  */
          if (offs[i_hash] != 0)
index 52b0c57d8136e12320bf3a6204da183112def385..062a647fd214f9f3b0b7f7069b382a2fdf9bace4 100644 (file)
@@ -1,5 +1,5 @@
 /* Report a module to libdwfl based on ELF program headers.
-   Copyright (C) 2005, 2007, 2009 Red Hat, Inc.
+   Copyright (C) 2005-2010 Red Hat, Inc.
    This file is part of Red Hat elfutils.
 
    Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -187,8 +187,11 @@ __libdwfl_report_elf (Dwfl *dwfl, const char *name, const char *file_name,
       base = 0;
 
     case ET_DYN:
-    default:
-      for (uint_fast16_t i = 0; i < ehdr->e_phnum; ++i)
+    default:;
+      size_t phnum;
+      if (unlikely (elf_getphdrnum (elf, &phnum) != 0))
+       goto elf_error;
+      for (size_t i = 0; i < phnum; ++i)
        {
          GElf_Phdr phdr_mem, *ph = gelf_getphdr (elf, i, &phdr_mem);
          if (unlikely (ph == NULL))
@@ -203,7 +206,7 @@ __libdwfl_report_elf (Dwfl *dwfl, const char *name, const char *file_name,
        }
       bias = base;
 
-      for (uint_fast16_t i = ehdr->e_phnum; i-- > 0;)
+      for (size_t i = phnum; i-- > 0;)
        {
          GElf_Phdr phdr_mem, *ph = gelf_getphdr (elf, i, &phdr_mem);
          if (unlikely (ph == NULL))