Please add support for EXTENDED_ARG in jumps
Closed this issue · 2 comments
Hi,
Currently, EXTENDED_ARG in jumps are not supported (see: https://github.com/haypo/bytecode/blob/master/bytecode/concrete.py#L395).
Without this feature, it's impossible to craft python object code >64Ko.
Please add support for EXTENDED_ARG in jumps if it's not too difficult to do :)
For example, with this feature, my brainfuck-to-python-bytecode will be able to run any BF program >64Ko (like hanoi.bf
).
Oh. I didn't expect such quick feedback on a project which is a little bit older than a PoC :-)
byteplay doesn't seem to support jump > 2^16-1 neither:
if jump > 0xFFFF:
raise NotImplementedError("Extended jumps not implemented")
codetransformers has no specific code to handle long jumps, so I guess that it fails too.
I checked CPython: it implements what I planned to do, it uses a loop. Extract of assemble_jump_offsets() of Python/compile.c:
/* XXX: This is an awful hack that could hurt performance, but
on the bright side it should work until we come up
with a better solution.
The issue is that in the first loop blocksize() is called
which calls instrsize() which requires i_oparg be set
appropriately. There is a bootstrap problem because
i_oparg is calculated in the second loop above.
So we loop until we stop seeing new EXTENDED_ARGs.
The only EXTENDED_ARGs that could be popping up are
ones in jump instructions. So this should converge
fairly quickly.
*/
Fixed. Thanks for the report.