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


   Date: Mon, 15 Nov 1999 16:59:31 -0500 (EST)
   From: Lynn Winebarger <owinebar@free-expression.org>

   First let me see if my assumption about static relocs can be
   verified: a reloc affects at most one immediate operand of an
   instruction.

That is true on the i386, and on most chips.  On the PowerPC a reloc
can affect both the branch address and the branch prediction bit.
There may be a few other minor exceptions.

      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).  

Given the howto structure, you can call bfd_get_reloc_size to get the
number of bytes that it affects.

      Anyway, dynamic relocs aren't very well documented in the bfd manual
   (at least the last version I got).  Nor are the various types of relocs
   (e.g BFD_RELOC_386_JUMP_SLOT).

BFD_RELOC_386_JUMP_SLOT is a special instruction which marks a
procedure linkage table entry in an i386 dynamically linked executable
or shared library.  On the i386, a procedure linkage table entry is a
16 byte sequence used to locate a function at run time.  This is used
to permit the dynamic linker to only spend the time to locate a
function if it is actually called.  This speeds up program start
times.  See elf_i386_plt_entry in bfd/elf32-i386.c.

Note that BFD_RELOC_386_JUMP_SLOT is ELF specific.

      Detecting dynamic relocs in data will be done in objdump.c code, so I
   can probably bring that back to binutils' objdump.c.  Do dynamic relocs
   appear as in code, or just data?

Dynamic relocs can appear in both code and data.

   Date: Mon, 15 Nov 1999 18:54:55 -0500 (EST)
   From: Lynn Winebarger <owinebar@free-expression.org>

      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).  

I'm not sure I completely understand your question.  Certainly the
value at the address to which edx points could be initialized using a
reloc.  Also, the offset off of edx could be set by a reloc.  I don't
think a C compiler is likely to ever generate such a case, but it
could be done in assembly code.

      Another question: can dynamic relocs affect instructions?  (the shared
   libraries I've looked at don't, but that's not decisive)

Yes, dynamic relocs can affect instructions.  You should be able to
see an example by making a shared library without using -fpic when
compiling the code.

Ian

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