This is the mail archive of the gdb-patches@sourceware.cygnus.com mailing list for the GDB project.


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

Re: [rfc] For mips, sign-extended ecoff offsets


Alan Modra wrote:
> 
> On Mon, 19 Jun 2000, Andrew Cagney wrote:
> 
> > The attatched patch changes the MIPS ELF32 backend so that it is more
> > likely to return a sign-extended offset.  At present the ELF backend
> > returns sign-extended symbol table values but not sign extended debug
> > information.
> 
> Hi Andrew,
>    Would it be better to just change ecoff_swap_sym_in?  It seems like
> this would achieve what you want, and not risk breaking quite so much.
> I'm worried about what happens if things like PDR.adr get changed from
> 0xa0000000 to 0xffffffffa0000000.

Thats why I'm asking :-) Remember though, on the MIPS platform, if
``PDR.adr'' is an address then, the canonical form of the value
``0xa0000000'' obtained from an elf32 binary is 0xffffffffa00000000. 
GDB and BFD have, for too many years, been bribed and cajoled into
perpetuated the lie that MIPS doesn't sign extend addresses.   GDB's now
decided to come clean on this matter (and purge an amazing amount of
bogus code :-).

Any way I've attached a revised patch.  I wasn't ruthless enough the
first time....  With this revision the linker appears to work :-) 
Testing is continuing.

I guess the question for BFD people is, is this the correct approach to
fixing this bug?

	Andrew
Mon Jun 19 20:53:14 2000  Andrew Cagney  <cagney@b1.cygnus.com>

	* ecoffswap.h (ecoff_get_off, ecoff_put_off): Add ECOFF_SIGNED_32
 	and ECOF_SIGNED_64 to list ways to extract an offset.
	* elf64-mips.c (ECOFF_SIGNED_64): Define instead of ECOFF_64.
	* elf32-mips.c (ECOFF_SIGNED_32): Define instead of ECOFF_32.

Index: ecoffswap.h
===================================================================
RCS file: /cvs/cvsfiles/devo/bfd/ecoffswap.h,v
retrieving revision 1.19
diff -p -r1.19 ecoffswap.h
*** ecoffswap.h	1996/03/12 22:41:13	1.19
--- ecoffswap.h	2000/06/20 01:02:48
*************** Foundation, Inc., 59 Temple Place - Suit
*** 27,36 ****
     on them in gdb by naming the including source file; e.g.,
     'coff-mips.c':ecoff_swap_hdr_in.
  
!    Before including this header file, one of ECOFF_32 or ECOFF_64 must
!    be defined.  These are checked when swapping information that
!    depends upon the target size.  This code works for 32 bit and 64
!    bit ECOFF, but may need to be generalized in the future.
  
     Some header file which defines the external forms of these
     structures must also be included before including this header file.
--- 27,37 ----
     on them in gdb by naming the including source file; e.g.,
     'coff-mips.c':ecoff_swap_hdr_in.
  
!    Before including this header file, one of ECOFF_32, ECOFF_64,
!    ECOF_SIGNED_32 or ECOFF_SIGNED_64 must be defined.  These are
!    checked when swapping information that depends upon the target
!    size.  This code works for 32 bit and 64 bit ECOFF, but may need to
!    be generalized in the future.
  
     Some header file which defines the external forms of these
     structures must also be included before including this header file.
*************** Foundation, Inc., 59 Temple Place - Suit
*** 50,55 ****
--- 51,64 ----
  #define ecoff_get_off bfd_h_get_64
  #define ecoff_put_off bfd_h_put_64
  #endif
+ #ifdef ECOFF_SIGNED_32
+ #define ecoff_get_off bfd_h_get_signed_32
+ #define ecoff_put_off bfd_h_put_signed_32
+ #endif
+ #ifdef ECOFF_SIGNED_64
+ #define ecoff_get_off bfd_h_get_signed_64
+ #define ecoff_put_off bfd_h_put_signed_64
+ #endif
  
  /* ECOFF auxiliary information swapping routines.  These are the same
     for all ECOFF targets, so they are defined in ecofflink.c.  */
*************** ecoff_swap_fdr_in (abfd, ext_copy, inter
*** 185,191 ****
    
    intern->adr           = ecoff_get_off (abfd, (bfd_byte *)ext->f_adr);
    intern->rss           = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rss);
! #ifdef ECOFF_64
    if (intern->rss == 0xffffffff)
      intern->rss = -1;
  #endif
--- 194,200 ----
    
    intern->adr           = ecoff_get_off (abfd, (bfd_byte *)ext->f_adr);
    intern->rss           = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rss);
! #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    if (intern->rss == 0xffffffff)
      intern->rss = -1;
  #endif
*************** ecoff_swap_fdr_in (abfd, ext_copy, inter
*** 197,207 ****
    intern->cline         = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cline);
    intern->ioptBase      = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ioptBase);
    intern->copt          = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_copt);
! #ifdef ECOFF_32
    intern->ipdFirst      = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_ipdFirst);
    intern->cpd           = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_cpd);
  #endif
! #ifdef ECOFF_64
    intern->ipdFirst      = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ipdFirst);
    intern->cpd           = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cpd);
  #endif
--- 206,216 ----
    intern->cline         = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cline);
    intern->ioptBase      = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ioptBase);
    intern->copt          = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_copt);
! #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
    intern->ipdFirst      = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_ipdFirst);
    intern->cpd           = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_cpd);
  #endif
! #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    intern->ipdFirst      = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ipdFirst);
    intern->cpd           = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cpd);
  #endif
*************** ecoff_swap_fdr_out (abfd, intern_copy, e
*** 262,272 ****
    bfd_h_put_32 (abfd, intern->cline, (bfd_byte *)ext->f_cline);
    bfd_h_put_32 (abfd, intern->ioptBase, (bfd_byte *)ext->f_ioptBase);
    bfd_h_put_32 (abfd, intern->copt, (bfd_byte *)ext->f_copt);
! #ifdef ECOFF_32
    bfd_h_put_16 (abfd, intern->ipdFirst, (bfd_byte *)ext->f_ipdFirst);
    bfd_h_put_16 (abfd, intern->cpd, (bfd_byte *)ext->f_cpd);
  #endif
! #ifdef ECOFF_64
    bfd_h_put_32 (abfd, intern->ipdFirst, (bfd_byte *)ext->f_ipdFirst);
    bfd_h_put_32 (abfd, intern->cpd, (bfd_byte *)ext->f_cpd);
  #endif
--- 271,281 ----
    bfd_h_put_32 (abfd, intern->cline, (bfd_byte *)ext->f_cline);
    bfd_h_put_32 (abfd, intern->ioptBase, (bfd_byte *)ext->f_ioptBase);
    bfd_h_put_32 (abfd, intern->copt, (bfd_byte *)ext->f_copt);
! #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
    bfd_h_put_16 (abfd, intern->ipdFirst, (bfd_byte *)ext->f_ipdFirst);
    bfd_h_put_16 (abfd, intern->cpd, (bfd_byte *)ext->f_cpd);
  #endif
! #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    bfd_h_put_32 (abfd, intern->ipdFirst, (bfd_byte *)ext->f_ipdFirst);
    bfd_h_put_32 (abfd, intern->cpd, (bfd_byte *)ext->f_cpd);
  #endif
*************** ecoff_swap_pdr_in (abfd, ext_copy, inter
*** 341,347 ****
    intern->lnHigh        = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnHigh);
    intern->cbLineOffset  = ecoff_get_off (abfd, (bfd_byte *)ext->p_cbLineOffset);
  
! #ifdef ECOFF_64
    intern->gp_prologue = bfd_h_get_8 (abfd, (bfd_byte *) ext->p_gp_prologue);
    if (bfd_header_big_endian (abfd))
      {
--- 350,356 ----
    intern->lnHigh        = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnHigh);
    intern->cbLineOffset  = ecoff_get_off (abfd, (bfd_byte *)ext->p_cbLineOffset);
  
! #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    intern->gp_prologue = bfd_h_get_8 (abfd, (bfd_byte *) ext->p_gp_prologue);
    if (bfd_header_big_endian (abfd))
      {
*************** ecoff_swap_pdr_out (abfd, intern_copy, e
*** 400,406 ****
    bfd_h_put_32 (abfd, intern->lnHigh, (bfd_byte *)ext->p_lnHigh);
    ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->p_cbLineOffset);
  
! #ifdef ECOFF_64
    bfd_h_put_8 (abfd, intern->gp_prologue, (bfd_byte *) ext->p_gp_prologue);
    if (bfd_header_big_endian (abfd))
      {
--- 409,415 ----
    bfd_h_put_32 (abfd, intern->lnHigh, (bfd_byte *)ext->p_lnHigh);
    ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->p_cbLineOffset);
  
! #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    bfd_h_put_8 (abfd, intern->gp_prologue, (bfd_byte *) ext->p_gp_prologue);
    if (bfd_header_big_endian (abfd))
      {
*************** ecoff_swap_ext_in (abfd, ext_copy, inter
*** 629,638 ****
    }
    intern->reserved = 0;
  
! #ifdef ECOFF_32
    intern->ifd           = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->es_ifd);
  #endif
! #ifdef ECOFF_64
    intern->ifd           = bfd_h_get_signed_32 (abfd, (bfd_byte *)ext->es_ifd);
  #endif
  
--- 638,647 ----
    }
    intern->reserved = 0;
  
! #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
    intern->ifd           = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->es_ifd);
  #endif
! #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    intern->ifd           = bfd_h_get_signed_32 (abfd, (bfd_byte *)ext->es_ifd);
  #endif
  
*************** ecoff_swap_ext_out (abfd, intern_copy, e
*** 663,669 ****
  			| (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_BIG : 0)
  			| (intern->weakext ? EXT_BITS1_WEAKEXT_BIG : 0));
      ext->es_bits2[0] = 0;
! #ifdef ECOFF_64
      ext->es_bits2[1] = 0;
      ext->es_bits2[2] = 0;
  #endif
--- 672,678 ----
  			| (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_BIG : 0)
  			| (intern->weakext ? EXT_BITS1_WEAKEXT_BIG : 0));
      ext->es_bits2[0] = 0;
! #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
      ext->es_bits2[1] = 0;
      ext->es_bits2[2] = 0;
  #endif
*************** ecoff_swap_ext_out (abfd, intern_copy, e
*** 672,687 ****
  			| (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_LITTLE : 0)
  			| (intern->weakext ? EXT_BITS1_WEAKEXT_LITTLE : 0));
      ext->es_bits2[0] = 0;
! #ifdef ECOFF_64
      ext->es_bits2[1] = 0;
      ext->es_bits2[2] = 0;
  #endif
    }
  
! #ifdef ECOFF_32
    bfd_h_put_signed_16 (abfd, intern->ifd, (bfd_byte *)ext->es_ifd);
  #endif
! #ifdef ECOFF_64
    bfd_h_put_signed_32 (abfd, intern->ifd, (bfd_byte *)ext->es_ifd);
  #endif
  
--- 681,696 ----
  			| (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_LITTLE : 0)
  			| (intern->weakext ? EXT_BITS1_WEAKEXT_LITTLE : 0));
      ext->es_bits2[0] = 0;
! #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
      ext->es_bits2[1] = 0;
      ext->es_bits2[2] = 0;
  #endif
    }
  
! #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
    bfd_h_put_signed_16 (abfd, intern->ifd, (bfd_byte *)ext->es_ifd);
  #endif
! #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    bfd_h_put_signed_32 (abfd, intern->ifd, (bfd_byte *)ext->es_ifd);
  #endif
  
Index: elf32-mips.c
===================================================================
RCS file: /cvs/cvsfiles/devo/bfd/elf32-mips.c,v
retrieving revision 1.176
diff -p -r1.176 elf32-mips.c
*** elf32-mips.c	2000/05/29 16:45:57	1.176
--- elf32-mips.c	2000/06/20 01:03:07
*************** Foundation, Inc., 59 Temple Place - Suit
*** 40,46 ****
  #include "coff/internal.h"
  #include "coff/ecoff.h"
  #include "coff/mips.h"
! #define ECOFF_32
  #include "ecoffswap.h"
  
  /* This structure is used to hold .got information when linking.  It
--- 40,46 ----
  #include "coff/internal.h"
  #include "coff/ecoff.h"
  #include "coff/mips.h"
! #define ECOFF_SIGNED_32
  #include "ecoffswap.h"
  
  /* This structure is used to hold .got information when linking.  It
Index: elf64-mips.c
===================================================================
RCS file: /cvs/cvsfiles/devo/bfd/elf64-mips.c,v
retrieving revision 1.18
diff -p -r1.18 elf64-mips.c
*** elf64-mips.c	1999/12/10 10:49:53	1.18
--- elf64-mips.c	2000/06/20 01:03:09
*************** Foundation, Inc., 59 Temple Place - Suit
*** 45,51 ****
  #include "coff/ecoff.h"
  /* The 64 bit versions of the mdebug data structures are in alpha.h.  */
  #include "coff/alpha.h"
! #define ECOFF_64
  #include "ecoffswap.h"
  
  static void mips_elf64_swap_reloc_in
--- 45,51 ----
  #include "coff/ecoff.h"
  /* The 64 bit versions of the mdebug data structures are in alpha.h.  */
  #include "coff/alpha.h"
! #define ECOFF_SIGNED_64
  #include "ecoffswap.h"
  
  static void mips_elf64_swap_reloc_in

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