+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.
/* 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
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);
+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.
/* 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
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);
{
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, ¬es_phdr);
+ int ndx = dwfl_report_core_segments (dwfl, elf, phnum, ¬es_phdr);
if (unlikely (ndx <= 0))
return ndx;
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. */
/* 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
/* 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);
/* 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
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;
/* 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);
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);
/* 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)
/* 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
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))
}
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))