[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: BFD assumes ELF phdrs in core files are just after ELF header
From: |
Nick Clifton |
Subject: |
Re: BFD assumes ELF phdrs in core files are just after ELF header |
Date: |
Fri, 15 Dec 2000 10:52:43 -0800 |
Hi Mirek,
: BFD in binutils 2.10.1 (affects gdb 5.0 as well) assumes that
: program headers in ELF core files immediatelly follow the ELF
: header. To reproduce, look at the attached core file:
:
: but 'objdump -p core' says:
:
: SHLIB off 0x00000000 vaddr 0x00000001 paddr 0x00002000 align 2**12
: filesz 0x0804e000 memsz 0x00000000 flags --- 1000
: 0x7 off 0x00000000 vaddr 0x00000001 paddr 0x00003000 align 2**12
: filesz 0xbf7c2000 memsz 0x00000000 flags ---
: This is completely bogus, and is made from the data directly following the
: ELF header, which is in fact occupied by the note segment.
Thanks for reporting this.
: Possible fix (completely untested! - not even that it compiles):
: ----------------------------------------------------------------
: --- elfcore.h.orig Fri Dec 15 14:54:50 2000
: +++ elfcore.h Fri Dec 15 14:56:32 2000
: @@ -193,6 +193,8 @@
:
: elf_tdata (abfd)->phdr = i_phdrp;
:
: + if (bfd_seek (abfd, i_ehdrp->e_phoff, SEEK_SET) != 0)
: + return NULL;
: /* Read and convert to internal form. */
: for (phindex = 0; phindex < i_ehdrp->e_phnum; ++phindex)
: {
: ----------------------------------------------------------------
This works, but I have actually checked in a slight variation which
uses 'goto wrong' so that an error code is set before the function
exits.
Cheers
Nick
2000-12-15 Miloslav Trmac <address@hidden>
* elfcore.h (elf_core_file_p): Move to the start of the program
headers before attempting to read them.
Index: bfd/elfcore.h
===================================================================
RCS file: /cvs/src//src/bfd/elfcore.h,v
retrieving revision 1.4
diff -p -r1.4 elfcore.h
*** elfcore.h 2000/06/19 01:22:37 1.4
--- elfcore.h 2000/12/15 18:51:11
*************** elf_core_file_p (abfd)
*** 182,187 ****
--- 182,191 ----
if (i_ehdrp->e_phentsize != sizeof (Elf_External_Phdr))
goto wrong;
+ /* Move to the start of the program headers. */
+ if (bfd_seek (abfd, i_ehdrp->e_phoff, SEEK_SET) != 0)
+ goto wrong;
+
/* Allocate space for the program headers. */
i_phdrp = (Elf_Internal_Phdr *)
bfd_alloc (abfd, sizeof (*i_phdrp) * i_ehdrp->e_phnum);