This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: moving instructions to another address
- From: Nick Clifton <nick at nickclifton dot clara dot co dot uk>
- To: Sebastian Wick <sebastian at sebastianwick dot net>, binutils at sourceware dot org
- Date: Fri, 07 Jun 2013 13:54:44 +0100
- Subject: Re: moving instructions to another address
- References: <dffb9ec01e31c6b982e59e5b5b75753e at sebastianwick dot net>
Hi Sebastian,
> I'm not sure if this is the right place to ask but I'll do it
> nevertheless.
It is certainly a good place to ask. You might also want to try asking
on the gdb mailing list, since this is the sort of thing that debuggers do.
Currently I try to write a library which can hook into any function you
know the address of. That means that the lib overwrites to first few
instructions of the function with a jmp (or something similar) to
another function. If you want to call the original function you need to
execute the instructions which are overwritten by the jmp instruction.
The lib currently mmaps memory and writes them there (trampoline). This
somehow worked well but I'm sure that moving instruction to another
address may cause undefined behavior. Is there something in binutils I
can use to make it safe?
Sorry no.
And is it even possible?
Possible yes. But to do it in a clean portable way that will continue
to work as operating systems evolve - probably not.
There are similar sorts of things that you might want to consider -
overlays for example, or ifuncs, or even the breakpoint mechanism used
by debuggers.
Cheers
Nick