This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] BFD sets wrong start address during format detection


(Please CC me on replies as I'm not suscribed to binutils@)

Hi,

I've hit a strange issue yesterday. I was working with a GDB targeted
for elf32-shl and inferior calls made by GDB were failing. GDB uses the
ELF entry point address in some way to do these inferior calls. In fact,
the BFD was telling GDB that the entry point was 0xffffffff88002000
instead of 0x88002000.
I first thought that BFD misdetected my file as being elf32-sh64 which
does sign extension. In fact, the file was correctly detected as
elf32-shl, but in the process of testing the binary, the entry point
address of the struct bfd* was overwritten during the elf32-sh64 backend
test that happened afterwards.
The attached patch fixes this issue for me. It moves the entry point
recording down after the last point of failure, so that it's done only
when the backend actually matches the file.
Does that seem safe ?

Fred.
2005-11-23  FrÃdÃric Riss  <frederic.riss@st.com>

                * elfcode.h: (elf_object_p): Delay the setting of start_address 
		until we're sure the backend matches the binary.


--- elfcode.h.orig	2005-11-23 09:35:53.000000000 +0100
+++ elfcode.h	2005-11-23 09:36:12.000000000 +0100
@@ -599,9 +599,6 @@ elf_object_p (bfd *abfd)
 	goto got_no_match;
     }
 
-  /* Remember the entry point specified in the ELF file header.  */
-  bfd_set_start_address (abfd, i_ehdrp->e_entry);
-
   if (i_ehdrp->e_shoff != 0)
     {
       /* Seek to the section header table in the file.  */
@@ -747,6 +744,9 @@ elf_object_p (bfd *abfd)
 	goto got_wrong_format_error;
     }
 
+  /* Remember the entry point specified in the ELF file header.  */
+  bfd_set_start_address (abfd, i_ehdrp->e_entry);
+
   /* If we have created any reloc sections that are associated with
      debugging sections, mark the reloc sections as debugging as well.  */
   for (s = abfd->sections; s != NULL; s = s->next)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]