+2014-11-22 Mark Wielaard <mjw@redhat.com>
+
+ * ppc64_symbol.c (ppc64_bss_plt_p): Remove ehdr argument.
+ * ppc_symbol.c (find_dyn_got): Likewise. Use elf_getphdrnum.
+ (ppc_check_special_symbol): Call find_dyn_got without ehdr.
+ (ppc_bss_plt_p): Remove ehdr argument.
+
2014-11-17 Mark Wielaard <mjw@redhat.com>
* ppc64_init.c (ppc64_init): Check section name is not NULL.
/* Check if backend uses a bss PLT in this file. */
bool
-ppc64_bss_plt_p (Elf *elf __attribute__ ((unused)),
- GElf_Ehdr *ehdr __attribute__ ((unused)))
+ppc64_bss_plt_p (Elf *elf __attribute__ ((unused)))
{
return true;
}
/* PPC specific symbolic name handling.
- Copyright (C) 2004, 2005, 2007 Red Hat, Inc.
+ Copyright (C) 2004, 2005, 2007, 2014 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 2004.
/* Look for DT_PPC_GOT. */
static bool
-find_dyn_got (Elf *elf, GElf_Ehdr *ehdr, GElf_Addr *addr)
+find_dyn_got (Elf *elf, GElf_Addr *addr)
{
- for (int i = 0; i < ehdr->e_phnum; ++i)
+ size_t phnum;
+ if (elf_getphdrnum (elf, &phnum) != 0)
+ return false;
+
+ for (size_t i = 0; i < phnum; ++i)
{
GElf_Phdr phdr_mem;
GElf_Phdr *phdr = gelf_getphdr (elf, i, &phdr_mem);
{
/* In -msecure-plt mode, DT_PPC_GOT is present and must match. */
GElf_Addr gotaddr;
- if (find_dyn_got (elf, ehdr, &gotaddr))
+ if (find_dyn_got (elf, &gotaddr))
return sym->st_value == gotaddr;
/* In -mbss-plt mode, any place in the section is valid. */
/* Check if backend uses a bss PLT in this file. */
bool
-ppc_bss_plt_p (Elf *elf, GElf_Ehdr *ehdr)
+ppc_bss_plt_p (Elf *elf)
{
GElf_Addr addr;
- return ! find_dyn_got (elf, ehdr, &addr);
+ return ! find_dyn_got (elf, &addr);
}
+2014-11-22 Mark Wielaard <mjw@redhat.com>
+
+ * link_map.c (consider_executable): Use elf_getphdrnum.
+ (dwfl_link_map_report): Likewise.
+
2014-11-18 Mark Wielaard <mjw@redhat.com>
* dwfl_module_getdwarf.c (find_symtab): Sanity check the data buffer,
/* Report modules by examining dynamic linker data structures.
- Copyright (C) 2008-2013 Red Hat, Inc.
+ Copyright (C) 2008-2014 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
address where &r_debug was written at runtime. */
GElf_Xword align = mod->dwfl->segment_align;
GElf_Addr d_val_vaddr = 0;
- for (uint_fast16_t i = 0; i < ehdr.e_phnum; ++i)
+ size_t phnum;
+ if (elf_getphdrnum (mod->main.elf, &phnum) != 0)
+ return 0;
+
+ for (size_t i = 0; i < phnum; ++i)
{
GElf_Phdr phdr_mem;
GElf_Phdr *phdr = gelf_getphdr (mod->main.elf, i, &phdr_mem);
__libdwfl_seterrno (DWFL_E_LIBELF);
return false;
}
- if (ehdr->e_phnum != phnum || ehdr->e_phentsize != phent)
+ size_t e_phnum;
+ if (elf_getphdrnum (elf, &e_phnum) != 0)
+ {
+ elf_end (elf);
+ close (fd);
+ __libdwfl_seterrno (DWFL_E_LIBELF);
+ return false;
+ }
+ if (e_phnum != phnum || ehdr->e_phentsize != phent)
{
elf_end (elf);
close (fd);
+2014-11-22 Mark Wielaard <mjw@redhat.com>
+
+ * ebl-hooks.h (bss_plt_p): Remove ehdr argument.
+ * eblbsspltp.c (ebl_bss_plt_p): Likewise.
+ * eblopenbackend.c (default_bss_plt_p): Likewise.
+ * libebl.h (ebl_bss_plt_p): Likewise.
+
2014-11-17 Mark Wielaard <mjw@redhat.com>
* ebldebugscnp.c (ebl_debugscn_p): Check name is not NULL.
bool EBLHOOK(check_st_other_bits) (unsigned char st_other);
/* Check if backend uses a bss PLT in this file. */
-bool EBLHOOK(bss_plt_p) (Elf *, GElf_Ehdr *);
+bool EBLHOOK(bss_plt_p) (Elf *);
/* Return location expression to find return value given the
DW_AT_type DIE of a DW_TAG_subprogram DIE. */
/* Check if backend uses a bss PLT.
- Copyright (C) 2005 Red Hat, Inc.
+ Copyright (C) 2005, 2014 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
bool
-ebl_bss_plt_p (ebl, ehdr)
+ebl_bss_plt_p (ebl)
Ebl *ebl;
- GElf_Ehdr *ehdr;
{
- return ebl == NULL ? false : ebl->bss_plt_p (ebl->elf, ehdr);
+ return ebl == NULL ? false : ebl->bss_plt_p (ebl->elf);
}
static bool default_check_st_other_bits (unsigned char st_other);
static bool default_check_special_section (Ebl *, int,
const GElf_Shdr *, const char *);
-static bool default_bss_plt_p (Elf *elf, GElf_Ehdr *ehdr);
+static bool default_bss_plt_p (Elf *elf);
static int default_return_value_location (Dwarf_Die *functypedie,
const Dwarf_Op **locops);
static ssize_t default_register_info (Ebl *ebl,
static bool
-default_bss_plt_p (Elf *elf __attribute__ ((unused)),
- GElf_Ehdr *ehdr __attribute__ ((unused)))
+default_bss_plt_p (Elf *elf __attribute__ ((unused)))
{
return false;
}
bool remove_comment, bool only_remove_debug);
/* Check if backend uses a bss PLT in this file. */
-extern bool ebl_bss_plt_p (Ebl *ebl, GElf_Ehdr *ehdr);
+extern bool ebl_bss_plt_p (Ebl *ebl);
/* Return size of entry in SysV-style hash table. */
extern int ebl_sysvhash_entrysize (Ebl *ebl);
+2014-11-22 Mark Wielaard <mjw@redhat.com>
+
+ * elflint.c (check_sections): Call ebl_bss_plt_p without ehdr.
+ * findtextrel.c (process_file): Use elf_getphdrnum.
+ * readelf.c (process_elf_file): Remove redundant ehdr->e_phoff check.
+ (print_phdr): Check phnum.
+ * size.c (show_segments): Use elf_getphdrnum.
+ * strip.c (handle_elf): Likewise.
+ * unstrip.c (copy_elf): Likewise.
+ (copy_elided_sections): Likewise.
+ (handle_file): Likewise.
+
2014-11-18 Mark Wielaard <mjw@redhat.com>
* readelf.c (print_cfa_program): Fix sanity check of DW_FORM_block
GElf_Word good_type = special_sections[s].type;
if (IS_KNOWN_SPECIAL (s, ".plt", false)
- && ebl_bss_plt_p (ebl, ehdr))
+ && ebl_bss_plt_p (ebl))
good_type = SHT_NOBITS;
/* In a debuginfo file, any normal section can be SHT_NOBITS.
/* Locate source files or functions which caused text relocations.
- Copyright (C) 2005-2010, 2012 Red Hat, Inc.
+ Copyright (C) 2005-2010, 2012, 2014 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 2005.
if (segments == NULL)
error (1, errno, gettext ("while reading ELF file"));
- for (int i = 0; i < ehdr->e_phnum; ++i)
+ size_t phnum;
+ if (elf_getphdrnum (elf, &phnum) != 0)
+ error (1, 0, gettext ("cannot get program header count: %s"),
+ elf_errmsg (-1));
+
+
+ for (size_t i = 0; i < phnum; ++i)
{
GElf_Phdr phdr_mem;
GElf_Phdr *phdr = gelf_getphdr (elf, i, &phdr_mem);
if (phdr == NULL)
{
error (0, 0,
- gettext ("cannot get program header index at offset %d: %s"),
+ gettext ("cannot get program header index at offset %zd: %s"),
i, elf_errmsg (-1));
result = 1;
goto next;
if (segments == NULL)
{
error (0, 0, gettext ("\
-cannot get program header index at offset %d: %s"),
+cannot get program header index at offset %zd: %s"),
i, elf_errmsg (-1));
result = 1;
goto next;
gettext ("cannot determine number of program headers: %s"),
elf_errmsg (-1));
- /* If there isn't actually a program header then set phnum to zero.
- Don't do any extra work. gelf_getphdr will always return NULL. */
- if (ehdr->e_phoff == 0)
- phnum = 0;
-
/* For an ET_REL file, libdwfl has adjusted the in-core shdrs
and may have applied relocation to some sections.
So we need to get a fresh Elf handle on the file to display those. */
static void
print_phdr (Ebl *ebl, GElf_Ehdr *ehdr)
{
- if (ehdr->e_phnum == 0 || ehdr->e_phoff == 0)
+ if (phnum == 0)
/* No program header, this is OK in relocatable objects. */
return;
static void
show_segments (Elf *elf, const char *fullname)
{
- GElf_Ehdr ehdr_mem;
- GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
- if (ehdr == NULL)
+ size_t phnum;
+ if (elf_getphdrnum (elf, &phnum) != 0)
INTERNAL_ERROR (fullname);
GElf_Off total = 0;
bool first = true;
- for (size_t cnt = 0; cnt < ehdr->e_phnum; ++cnt)
+ for (size_t cnt = 0; cnt < phnum; ++cnt)
{
GElf_Phdr phdr_mem;
GElf_Phdr *phdr;
error (EXIT_FAILURE, 0,
gettext ("cannot get section header string table index"));
+ /* Get the number of phdrs in the old file. */
+ size_t phnum;
+ if (elf_getphdrnum (elf, &phnum) != 0)
+ error (EXIT_FAILURE, 0, gettext ("cannot get number of phdrs"));
+
/* We now create a new ELF descriptor for the same file. We
construct it almost exactly in the same way with some information
dropped. */
if (unlikely (gelf_newehdr (newelf, gelf_getclass (elf)) == 0)
|| (ehdr->e_type != ET_REL
- && unlikely (gelf_newphdr (newelf, ehdr->e_phnum) == 0)))
+ && unlikely (gelf_newphdr (newelf, phnum) == 0)))
{
error (0, 0, gettext ("cannot create new file '%s': %s"),
output_fname, elf_errmsg (-1));
/* Copy over the old program header if needed. */
if (ehdr->e_type != ET_REL)
- for (cnt = 0; cnt < ehdr->e_phnum; ++cnt)
+ for (cnt = 0; cnt < phnum; ++cnt)
{
GElf_Phdr phdr_mem;
GElf_Phdr *phdr = gelf_getphdr (elf, cnt, &phdr_mem);
debugelf = elf_begin (debug_fd, ELF_C_WRITE_MMAP, NULL);
if (unlikely (gelf_newehdr (debugelf, gelf_getclass (elf)) == 0)
|| (ehdr->e_type != ET_REL
- && unlikely (gelf_newphdr (debugelf, ehdr->e_phnum) == 0)))
+ && unlikely (gelf_newphdr (debugelf, phnum) == 0)))
{
error (0, 0, gettext ("cannot create new file '%s': %s"),
debug_fname, elf_errmsg (-1));
/* Copy over the old program header if needed. */
if (ehdr->e_type != ET_REL)
- for (cnt = 0; cnt < ehdr->e_phnum; ++cnt)
+ for (cnt = 0; cnt < phnum; ++cnt)
{
GElf_Phdr phdr_mem;
GElf_Phdr *phdr = gelf_getphdr (elf, cnt, &phdr_mem);
#define ELF_CHECK(call, msg) \
do \
{ \
- if (!(call)) \
+ if (unlikely (!(call))) \
error (EXIT_FAILURE, 0, msg, elf_errmsg (-1)); \
} while (0)
ELF_CHECK (gelf_update_ehdr (outelf, ehdr),
_("cannot copy ELF header: %s"));
- if (ehdr->e_phnum > 0)
+ size_t phnum;
+ ELF_CHECK (elf_getphdrnum (inelf, &phnum) == 0,
+ _("cannot get number of program headers: %s"));
+
+ if (phnum > 0)
{
- ELF_CHECK (gelf_newphdr (outelf, ehdr->e_phnum),
+ ELF_CHECK (gelf_newphdr (outelf, phnum),
_("cannot create program headers: %s"));
GElf_Phdr phdr_mem;
- for (uint_fast16_t i = 0; i < ehdr->e_phnum; ++i)
+ for (size_t i = 0; i < phnum; ++i)
ELF_CHECK (gelf_update_phdr (outelf, i,
gelf_getphdr (inelf, i, &phdr_mem)),
_("cannot copy program header: %s"));
}
while (skip_reloc);
- if (stripped_ehdr->e_phnum > 0)
- ELF_CHECK (gelf_newphdr (unstripped, stripped_ehdr->e_phnum),
+ size_t phnum;
+ ELF_CHECK (elf_getphdrnum (stripped, &phnum) == 0,
+ _("cannot get number of program headers: %s"));
+
+ if (phnum > 0)
+ ELF_CHECK (gelf_newphdr (unstripped, phnum),
_("cannot create program headers: %s"));
/* Copy each program header from the stripped file. */
- for (uint_fast16_t i = 0; i < stripped_ehdr->e_phnum; ++i)
+ for (size_t i = 0; i < phnum; ++i)
{
GElf_Phdr phdr_mem;
GElf_Phdr *phdr = gelf_getphdr (stripped, i, &phdr_mem);
Elf *stripped, const GElf_Ehdr *stripped_ehdr,
Elf *unstripped)
{
+ size_t phnum;
+ ELF_CHECK (elf_getphdrnum (stripped, &phnum) == 0,
+ _("cannot get number of program headers: %s"));
+
/* Determine the address bias between the debuginfo file and the main
file, which may have been modified by prelinking. */
GElf_Addr bias = 0;
if (unstripped != NULL)
- for (uint_fast16_t i = 0; i < stripped_ehdr->e_phnum; ++i)
+ for (size_t i = 0; i < phnum; ++i)
{
GElf_Phdr phdr_mem;
GElf_Phdr *phdr = gelf_getphdr (stripped, i, &phdr_mem);