public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [rfa] Sign extend elf entry point (sometimes)
@ 2000-06-22 23:50 Andrew Cagney
  2000-06-23  1:06 ` Alan Modra
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Cagney @ 2000-06-22 23:50 UTC (permalink / raw)
  To: BINUTILS Patches

Ok?

The attatched sign extens the ELF header entry point when that is the
convention for the target.
GDB gets mighty confused when its entry point is unsigned yet symbol
table values are signed.

	Andrew

(It also replaces the corresponding bfd_get_start_address(xxx)= with a
bfd_set_start_address()).
Fri Jun 23 16:41:25 2000  Andrew Cagney  <cagney@b1.cygnus.com>

	* elfcode.h (elf_object_p): Use bfd_set_start_address and not
 	bfd_get_start_address.
	(elf_swap_ehdr_in): Sign extend e_entry when applicable.
	(elf_swap_ehdr_out): Ditto.

Index: elfcode.h
===================================================================
RCS file: /cvs/cvsfiles/devo/bfd/elfcode.h,v
retrieving revision 1.241
diff -p -r1.241 elfcode.h
*** elfcode.h	2000/04/28 13:37:45	1.241
--- elfcode.h	2000/06/23 06:44:34
***************
*** 1,6 ****
  /* ELF executable support for BFD.
!    Copyright 1991, 92, 93, 94, 95, 96, 97, 98, 1999 Free Software
!    Foundation, Inc.
  
     Written by Fred Fish @ Cygnus Support, from information published
     in "UNIX System V Release 4, Programmers Guide: ANSI C and
--- 1,6 ----
  /* ELF executable support for BFD.
!    Copyright 1991, 92, 93, 94, 95, 96, 97, 98, 1999, 2000 Free
!    Software Foundation, Inc.
  
     Written by Fred Fish @ Cygnus Support, from information published
     in "UNIX System V Release 4, Programmers Guide: ANSI C and
*************** elf_swap_ehdr_in (abfd, src, dst)
*** 246,256 ****
       const Elf_External_Ehdr *src;
       Elf_Internal_Ehdr *dst;
  {
    memcpy (dst->e_ident, src->e_ident, EI_NIDENT);
    dst->e_type = bfd_h_get_16 (abfd, (bfd_byte *) src->e_type);
    dst->e_machine = bfd_h_get_16 (abfd, (bfd_byte *) src->e_machine);
    dst->e_version = bfd_h_get_32 (abfd, (bfd_byte *) src->e_version);
!   dst->e_entry = get_word (abfd, (bfd_byte *) src->e_entry);
    dst->e_phoff = get_word (abfd, (bfd_byte *) src->e_phoff);
    dst->e_shoff = get_word (abfd, (bfd_byte *) src->e_shoff);
    dst->e_flags = bfd_h_get_32 (abfd, (bfd_byte *) src->e_flags);
--- 246,260 ----
       const Elf_External_Ehdr *src;
       Elf_Internal_Ehdr *dst;
  {
+   int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
    memcpy (dst->e_ident, src->e_ident, EI_NIDENT);
    dst->e_type = bfd_h_get_16 (abfd, (bfd_byte *) src->e_type);
    dst->e_machine = bfd_h_get_16 (abfd, (bfd_byte *) src->e_machine);
    dst->e_version = bfd_h_get_32 (abfd, (bfd_byte *) src->e_version);
!   if (signed_vma)
!     dst->e_entry = get_signed_word (abfd, (bfd_byte *) src->e_entry);
!   else
!     dst->e_entry = get_word (abfd, (bfd_byte *) src->e_entry);
    dst->e_phoff = get_word (abfd, (bfd_byte *) src->e_phoff);
    dst->e_shoff = get_word (abfd, (bfd_byte *) src->e_shoff);
    dst->e_flags = bfd_h_get_32 (abfd, (bfd_byte *) src->e_flags);
*************** elf_swap_ehdr_out (abfd, src, dst)
*** 271,282 ****
       const Elf_Internal_Ehdr *src;
       Elf_External_Ehdr *dst;
  {
    memcpy (dst->e_ident, src->e_ident, EI_NIDENT);
    /* note that all elements of dst are *arrays of unsigned char* already... */
    bfd_h_put_16 (abfd, src->e_type, dst->e_type);
    bfd_h_put_16 (abfd, src->e_machine, dst->e_machine);
    bfd_h_put_32 (abfd, src->e_version, dst->e_version);
!   put_word (abfd, src->e_entry, dst->e_entry);
    put_word (abfd, src->e_phoff, dst->e_phoff);
    put_word (abfd, src->e_shoff, dst->e_shoff);
    bfd_h_put_32 (abfd, src->e_flags, dst->e_flags);
--- 275,290 ----
       const Elf_Internal_Ehdr *src;
       Elf_External_Ehdr *dst;
  {
+   int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
    memcpy (dst->e_ident, src->e_ident, EI_NIDENT);
    /* note that all elements of dst are *arrays of unsigned char* already... */
    bfd_h_put_16 (abfd, src->e_type, dst->e_type);
    bfd_h_put_16 (abfd, src->e_machine, dst->e_machine);
    bfd_h_put_32 (abfd, src->e_version, dst->e_version);
!   if (signed_vma)
!     put_signed_word (abfd, src->e_entry, dst->e_entry);
!   else
!     put_word (abfd, src->e_entry, dst->e_entry);
    put_word (abfd, src->e_phoff, dst->e_phoff);
    put_word (abfd, src->e_shoff, dst->e_shoff);
    bfd_h_put_32 (abfd, src->e_flags, dst->e_flags);
*************** elf_object_p (abfd)
*** 613,619 ****
      }
  
    /* Remember the entry point specified in the ELF file header. */
!   bfd_get_start_address (abfd) = i_ehdrp->e_entry;
  
    /* Allocate space for a copy of the section header table in
       internal form, seek to the section header table in the file,
--- 621,627 ----
      }
  
    /* Remember the entry point specified in the ELF file header. */
!   bfd_set_start_address (abfd, i_ehdrp->e_entry);
  
    /* Allocate space for a copy of the section header table in
       internal form, seek to the section header table in the file,

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [rfa] Sign extend elf entry point (sometimes)
  2000-06-22 23:50 [rfa] Sign extend elf entry point (sometimes) Andrew Cagney
@ 2000-06-23  1:06 ` Alan Modra
  2000-07-10 23:06   ` Andrew Cagney
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2000-06-23  1:06 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: BINUTILS Patches

On Fri, 23 Jun 2000, Andrew Cagney wrote:

> Ok?

Yes.

-- 
Linuxcare.  Support for the Revolution.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [rfa] Sign extend elf entry point (sometimes)
  2000-06-23  1:06 ` Alan Modra
@ 2000-07-10 23:06   ` Andrew Cagney
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Cagney @ 2000-07-10 23:06 UTC (permalink / raw)
  To: Alan Modra; +Cc: BINUTILS Patches

Alan Modra wrote:
> 
> On Fri, 23 Jun 2000, Andrew Cagney wrote:
> 
> > Ok?
> 
> Yes.

Thanks.  I've checked it in (the patch is re attatched as I assume
you've forgotten what it was you approved :-).

	Andrew
Tue Jul 11 16:03:04 2000  Andrew Cagney  <cagney@b1.cygnus.com>

	* elfcode.h (elf_object_p): Use bfd_set_start_address and not
 	bfd_get_start_address.
	(elf_swap_ehdr_in): Sign extend e_entry when applicable.
	(elf_swap_ehdr_out): Ditto.

Index: elfcode.h
===================================================================
RCS file: /cvs/src/src/bfd/elfcode.h,v
retrieving revision 1.12
diff -p -r1.12 elfcode.h
*** elfcode.h	2000/07/04 02:18:06	1.12
--- elfcode.h	2000/07/11 06:04:05
***************
*** 1,6 ****
  /* ELF executable support for BFD.
!    Copyright 1991, 92, 93, 94, 95, 96, 97, 98, 1999 Free Software
!    Foundation, Inc.
  
     Written by Fred Fish @ Cygnus Support, from information published
     in "UNIX System V Release 4, Programmers Guide: ANSI C and
--- 1,6 ----
  /* ELF executable support for BFD.
!    Copyright 1991, 92, 93, 94, 95, 96, 97, 98, 1999, 2000 Free
!    Software Foundation, Inc.
  
     Written by Fred Fish @ Cygnus Support, from information published
     in "UNIX System V Release 4, Programmers Guide: ANSI C and
*************** elf_swap_ehdr_in (abfd, src, dst)
*** 246,256 ****
       const Elf_External_Ehdr *src;
       Elf_Internal_Ehdr *dst;
  {
    memcpy (dst->e_ident, src->e_ident, EI_NIDENT);
    dst->e_type = bfd_h_get_16 (abfd, (bfd_byte *) src->e_type);
    dst->e_machine = bfd_h_get_16 (abfd, (bfd_byte *) src->e_machine);
    dst->e_version = bfd_h_get_32 (abfd, (bfd_byte *) src->e_version);
!   dst->e_entry = get_word (abfd, (bfd_byte *) src->e_entry);
    dst->e_phoff = get_word (abfd, (bfd_byte *) src->e_phoff);
    dst->e_shoff = get_word (abfd, (bfd_byte *) src->e_shoff);
    dst->e_flags = bfd_h_get_32 (abfd, (bfd_byte *) src->e_flags);
--- 246,260 ----
       const Elf_External_Ehdr *src;
       Elf_Internal_Ehdr *dst;
  {
+   int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
    memcpy (dst->e_ident, src->e_ident, EI_NIDENT);
    dst->e_type = bfd_h_get_16 (abfd, (bfd_byte *) src->e_type);
    dst->e_machine = bfd_h_get_16 (abfd, (bfd_byte *) src->e_machine);
    dst->e_version = bfd_h_get_32 (abfd, (bfd_byte *) src->e_version);
!   if (signed_vma)
!     dst->e_entry = get_signed_word (abfd, (bfd_byte *) src->e_entry);
!   else
!     dst->e_entry = get_word (abfd, (bfd_byte *) src->e_entry);
    dst->e_phoff = get_word (abfd, (bfd_byte *) src->e_phoff);
    dst->e_shoff = get_word (abfd, (bfd_byte *) src->e_shoff);
    dst->e_flags = bfd_h_get_32 (abfd, (bfd_byte *) src->e_flags);
*************** elf_swap_ehdr_out (abfd, src, dst)
*** 271,282 ****
       const Elf_Internal_Ehdr *src;
       Elf_External_Ehdr *dst;
  {
    memcpy (dst->e_ident, src->e_ident, EI_NIDENT);
    /* note that all elements of dst are *arrays of unsigned char* already... */
    bfd_h_put_16 (abfd, src->e_type, dst->e_type);
    bfd_h_put_16 (abfd, src->e_machine, dst->e_machine);
    bfd_h_put_32 (abfd, src->e_version, dst->e_version);
!   put_word (abfd, src->e_entry, dst->e_entry);
    put_word (abfd, src->e_phoff, dst->e_phoff);
    put_word (abfd, src->e_shoff, dst->e_shoff);
    bfd_h_put_32 (abfd, src->e_flags, dst->e_flags);
--- 275,290 ----
       const Elf_Internal_Ehdr *src;
       Elf_External_Ehdr *dst;
  {
+   int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
    memcpy (dst->e_ident, src->e_ident, EI_NIDENT);
    /* note that all elements of dst are *arrays of unsigned char* already... */
    bfd_h_put_16 (abfd, src->e_type, dst->e_type);
    bfd_h_put_16 (abfd, src->e_machine, dst->e_machine);
    bfd_h_put_32 (abfd, src->e_version, dst->e_version);
!   if (signed_vma)
!     put_signed_word (abfd, src->e_entry, dst->e_entry);
!   else
!     put_word (abfd, src->e_entry, dst->e_entry);
    put_word (abfd, src->e_phoff, dst->e_phoff);
    put_word (abfd, src->e_shoff, dst->e_shoff);
    bfd_h_put_32 (abfd, src->e_flags, dst->e_flags);
*************** elf_object_p (abfd)
*** 613,619 ****
      }
  
    /* Remember the entry point specified in the ELF file header. */
!   bfd_get_start_address (abfd) = i_ehdrp->e_entry;
  
    /* Allocate space for a copy of the section header table in
       internal form, seek to the section header table in the file,
--- 621,627 ----
      }
  
    /* Remember the entry point specified in the ELF file header. */
!   bfd_set_start_address (abfd, i_ehdrp->e_entry);
  
    /* Allocate space for a copy of the section header table in
       internal form, seek to the section header table in the file,

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-07-10 23:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-22 23:50 [rfa] Sign extend elf entry point (sometimes) Andrew Cagney
2000-06-23  1:06 ` Alan Modra
2000-07-10 23:06   ` Andrew Cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).