This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Re: using relocs in disassembler
- To: binutils at sourceware dot cygnus dot com
- Subject: Re: using relocs in disassembler
- From: Lynn Winebarger <owinebar at free-expression dot org>
- Date: Tue, 16 Nov 1999 07:49:05 -0500 (EST)
On 15 Nov 1999, Ian Lance Taylor wrote:
> 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.
>
Yeah, I noticed that when I went back to the manual (doh!). The source
code (reloc.c) does mention the possibility of variable sized relocs,
though it doesn't mention when that could happen.
> 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.
>
This kind of code can be generated by a large switch statement in C.
A label is produced for each case of the switch, and the case to jump to
is determined by looking up the case in a table of labels, and jumping.
Depending on what kind of jump is used, the table entry could require a
pc-relative displacement. (Though I can't think of any time this would
require a reloc - that's sort of the point of the pc-relative
displacement).
Another (more likely) example is a functional language where tail calls
are optimized. In this case, I might set a variable to a closure, then
apply that variable in tail position. Tail calls should never cost more
than a jump in a tail recursion optimized language, so you might very well
want to use a dynamic relocation that sets the variable to the pc-relative
offset of a dynamically loaded piece of code. Whether or not this is
actually supported by system tools, I don't know.
Thanks for the info.
Lynn