1
1
/* ELF core file support for BFD.
2
2
Copyright 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2005, 2007,
3
2008 Free Software Foundation, Inc.
3
2008, 2010 Free Software Foundation, Inc.
5
5
This file is part of BFD, the Binary File Descriptor library.
184
184
if (i_ehdrp->e_phentsize != sizeof (Elf_External_Phdr))
187
/* If the program header count is PN_XNUM(0xffff), the actual
188
count is in the first section header. */
189
if (i_ehdrp->e_shoff != 0 && i_ehdrp->e_phnum == PN_XNUM)
191
Elf_External_Shdr x_shdr;
192
Elf_Internal_Shdr i_shdr;
193
bfd_signed_vma where = i_ehdrp->e_shoff;
195
if (where != (file_ptr) where)
198
/* Seek to the section header table in the file. */
199
if (bfd_seek (abfd, (file_ptr) where, SEEK_SET) != 0)
202
/* Read the first section header at index 0, and convert to internal
204
if (bfd_bread (&x_shdr, sizeof (x_shdr), abfd) != sizeof (x_shdr))
206
elf_swap_shdr_in (abfd, &x_shdr, &i_shdr);
208
if (i_shdr.sh_info != 0)
210
i_ehdrp->e_phnum = i_shdr.sh_info;
211
if (i_ehdrp->e_phnum != i_shdr.sh_info)
216
/* Sanity check that we can read all of the program headers.
217
It ought to be good enough to just read the last one. */
218
if (i_ehdrp->e_phnum > 1)
220
Elf_External_Phdr x_phdr;
221
Elf_Internal_Phdr i_phdr;
222
bfd_signed_vma where;
224
/* Check that we don't have a totally silly number of
226
if (i_ehdrp->e_phnum > (unsigned int) -1 / sizeof (x_phdr)
227
|| i_ehdrp->e_phnum > (unsigned int) -1 / sizeof (i_phdr))
230
where = i_ehdrp->e_phoff + (i_ehdrp->e_phnum - 1) * sizeof (x_phdr);
231
if (where != (file_ptr) where)
233
if ((bfd_size_type) where <= i_ehdrp->e_phoff)
236
if (bfd_seek (abfd, (file_ptr) where, SEEK_SET) != 0)
238
if (bfd_bread (&x_phdr, sizeof (x_phdr), abfd) != sizeof (x_phdr))
187
242
/* Move to the start of the program headers. */
188
243
if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_phoff, SEEK_SET) != 0)