Use a virtual continuation
register to handle exotic returns from procedures
#929
Labels
continuation
register to handle exotic returns from procedures
#929
The Reko regression suite has a binary
subjects\Elf\ARM\angr-685\RTOSDemo
, with an implementation ofmemcpy
. In the beginning of the disassembled ARM procedure, it saves thelr
register on the stack:Right before it returns, it restores the registers on the stack:
Note how the
r1
registers receives the value oflr
that was pushed on the stack. Thebx
instruction is thus reallybx lr
, i.e. a simple return to caller.Reko turns this into the following:
and
I've seen many binaries that do similar things across multiple architectures. For instance, on M68k, I've seen
which pops off the caller's return address into
a0
and then jumps to it.Insipired by the
fp
register used to keep track of the start of the procedure's frame, I'm considering introducing a new pseudo-register called%continuation
, which will keep track of the return address of a procedure. On M68k, we would inject a statement likeMem0[sp:word32] = %continuation
in the procedure entry block. The M68k example above would become:which, after value propagation, becomes:
The pattern
call %continuation; return
can then be replaced with a simplereturn
For the original ARM example, the code would look like (ignoring extraneous code):
which after value propagation becomes:
The text was updated successfully, but these errors were encountered: