This is the mail archive of the binutils@sourceware.cygnus.com 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]

Re: using relocs in disassembler


On Tue, 16 Nov 1999, Alan Modra wrote:

> On Mon, 15 Nov 1999, Lynn Winebarger wrote:
> 
> > relocs.  First let me see if my assumption about static relocs can be
> > verified: a reloc affects at most one immediate operand of an
> 
> You could have more than one reloc affecting an instruction. eg. x86
> "movl $addr1,addr2"  Other architectures may allow even more (vax ?)
> 
    Right, but each of those relocs would only affect one operand, right?
I'm also assuming a reloc wouldn't affect addressing mode information
(e.g. in i386 code I shouldn't have to worry about the ModR/M byte being
affected by a reloc).

> >    Now, I guess my question also applies to some static relocs: when a
> > reloc appears in data, how can I tell how much data is taken up by the
> > reloc, and exactly what I should replace it with.  I'm guessing, if it's
> > data, the data would become a pointer to the symbol (or the value of the
> > symbol).  
> 
> Think of a reloc record as just being a formula telling you how to modify
> existing instruction or data bytes.  As far as I know, a reloc never
> changes the size of an instruction in an object file.
   
    The problem is that I don't want to have to take into account the file
type, so I can't make assumptions about how to apply the reloc.  I don't
want to replace the data with the result of the relocation, I want to 
replace it with a scheme representation of the symbol reference (I'm
representing the disassembly/data with tagged list).  So all I really need
to know is how many bytes the reloc affects.  For example, right now, if
there's a block of data passed to disassemble_bytes, then I would return
a list like this
'(data 1 2 3 4 5 6 34 120  ...)
Now lets assume there's a reloc that starts at the 5th byte, so I would
want to return
'(data 1 2 3 4 (symbol-ref <name> <number-of-bytes>) 34 120 ...)
if, for example, the reloc affects only 2 bytes.  The problem then, is how
do I tell how many bytes the reloc affects.  In the i386, it could be
2, 4, or 6 bytes (all legitimate sizes of pointers).  Other architectures
could introduce other sizes (say 8 bytes).  
   I guess another small question I have would be whether I would need to
worry about a reloc for an offset, say I have the code


movl eax, (edx)
jmp eax

Could the value edx points to (an offset from the current EIP) be set up
by a reloc (such a thing could be set up by a tail recursion optimizing
compiler for a functional language, I think, or perhaps an implementation
of object methods).  
   Another question: can dynamic relocs affect instructions?  (the shared
libraries I've looked at don't, but that's not decisive)

Lynn




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