This is the mail archive of the gdb-patches@sources.redhat.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: [PATCH RFA] objfile_relocate() changes


Kevin Buettner writes:
 > In the patch below, there's a big hunk of code which is being replaced
 > by a smaller and simpler hunk of code.  The big hunk of code that's
 > getting replaced has at least two problems with it.
 > 
 > The first is that SECT_OFF_TEXT, SECT_OFF_DATA, and SECT_OFF_BSS can
 > be -1 if the corresponding section doesn't exist in the objfile.  In
 > the code below, this is bad because these values are used as array
 > indices via the ANOFFSET macro and the arrays in question are not
 > designed to accomodate negative indices.
 > 
 > The second problem with this code is that it is a mistake to assume
 > that all sections with (e.g.) SEC_CODE set in the bfd flags should be
 > relocated by the amount given by SECT_OFF_TEXT.  (I am working on
 > a target where this is causing problems.)
 > 
 > It is far better to get the correct index for use with the ANOFFSET
 > macro.  (Which is what the smaller, simpler hunk of code does.)
 > 
 > I have one concern about my patch...  The `index' field is supposed to
 > be a private bfd field.  There are already several places in the gdb
 > sources where we use it though.  If we're going to persist in using
 > it, I think we ought to expose this field by adding a suitable macro
 > definition for bfd_get_section_index to bfd-in.h and then revise the
 > gdb sources accordingly.

Probably so. 

 > 
 > Comments?
 > 
 > Okay to commit?
 > 


OK. Thanks for getting rid of another few instances of SECT_OFF_*

Elena

 > 	* objfiles.c (objfile_relocate): Don't assume that offsets
 > 	associated with one of SECT_OFF_TEXT, SECT_OFF_DATA, or
 > 	SECT_OFF_BSS will be adequate for relocating all of the
 > 	sections in an objfile.
 > 
 > Index: objfiles.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/objfiles.c,v
 > retrieving revision 1.9
 > diff -u -p -r1.9 objfiles.c
 > --- objfiles.c	2000/08/07 15:02:48	1.9
 > +++ objfiles.c	2000/09/09 20:40:20
 > @@ -650,25 +650,10 @@ objfile_relocate (struct objfile *objfil
 >  
 >      ALL_OBJFILE_OSECTIONS (objfile, s)
 >        {
 > -	flagword flags;
 > -
 > -	flags = bfd_get_section_flags (abfd, s->the_bfd_section);
 > -
 > -	if (flags & SEC_CODE)
 > -	  {
 > -	    s->addr += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
 > -	    s->endaddr += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
 > -	  }
 > -	else if (flags & (SEC_DATA | SEC_LOAD))
 > -	  {
 > -	    s->addr += ANOFFSET (delta, SECT_OFF_DATA (objfile));
 > -	    s->endaddr += ANOFFSET (delta, SECT_OFF_DATA (objfile));
 > -	  }
 > -	else if (flags & SEC_ALLOC)
 > -	  {
 > -	    s->addr += ANOFFSET (delta, SECT_OFF_BSS (objfile));
 > -	    s->endaddr += ANOFFSET (delta, SECT_OFF_BSS (objfile));
 > -	  }
 > +      	int idx = s->the_bfd_section->index;
 > +	
 > +	s->addr += ANOFFSET (delta, idx);
 > +	s->endaddr += ANOFFSET (delta, idx);
 >        }
 >    }
 >  
 > 

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