diff options
author | Roland McGrath <roland@redhat.com> | 2010-01-07 20:24:34 -0800 |
---|---|---|
committer | Roland McGrath <roland@redhat.com> | 2010-01-07 20:24:34 -0800 |
commit | f95760aff004850544f83626404c134d6a07c630 (patch) | |
tree | 5e682173fecb47c8b33231819bc0e0f151b371c6 /libdwfl | |
parent | bd733cae5159e3a3c4c05f7685559fa3ae8b58c6 (diff) | |
download | elfutils-f95760aff004850544f83626404c134d6a07c630.tar.gz |
Use elf_getphdrnum in libdw and libdwfl.
Diffstat (limited to 'libdwfl')
-rw-r--r-- | libdwfl/ChangeLog | 7 | ||||
-rw-r--r-- | libdwfl/core-file.c | 24 | ||||
-rw-r--r-- | libdwfl/dwfl_module_build_id.c | 8 | ||||
-rw-r--r-- | libdwfl/dwfl_module_getdwarf.c | 46 | ||||
-rw-r--r-- | libdwfl/dwfl_report_elf.c | 11 |
5 files changed, 59 insertions, 37 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index f6698255..d9e6e654 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -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. diff --git a/libdwfl/core-file.c b/libdwfl/core-file.c index ad1c78d8..1872d8ab 100644 --- a/libdwfl/core-file.c +++ b/libdwfl/core-file.c @@ -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, ¬es_phdr); + int ndx = dwfl_report_core_segments (dwfl, elf, phnum, ¬es_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. */ diff --git a/libdwfl/dwfl_module_build_id.c b/libdwfl/dwfl_module_build_id.c index 07a62ba4..9dc7f678 100644 --- a/libdwfl/dwfl_module_build_id.c +++ b/libdwfl/dwfl_module_build_id.c @@ -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); diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c index f48fabe7..b084673e 100644 --- a/libdwfl/dwfl_module_getdwarf.c +++ b/libdwfl/dwfl_module_getdwarf.c @@ -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) diff --git a/libdwfl/dwfl_report_elf.c b/libdwfl/dwfl_report_elf.c index 52b0c57d..062a647f 100644 --- a/libdwfl/dwfl_report_elf.c +++ b/libdwfl/dwfl_report_elf.c @@ -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)) |