Tuesday, 15 May 2012

algorithm - Best way to compute offsets with moving targets -



algorithm - Best way to compute offsets with moving targets -

it seems there should standardized solution this. problem want able compute whether or not should utilize near jump or far jump. in:

jump_to_near: ; ... lots of ops ... jump_to_near: e9 24 ff ff ff jmpq 1f22 <jump_to_far> eb f9 jmp 1ff9 <jump_to_near>

the near jump opcode seems 2 bytes, while far jump opcode five. question is, how can know 1 utilize if jump-to label comes after actual opcode? there standardized algorithm computing tight dependencies this, in particular given case there may lots of jumps changing opcode size of 1 may impact other jumps.

i not saying solution, several compilers domain specific languages have written, have used next strategy success:

for forwards jumps assume target can reached short jump.

later, during back-patching, if target turns out not reachable after using short jump, mark jump requiring near jump , start code-gen on routine in question.

-

it possible (yes, have done this) emit near jumps (the long form) , record info needs fixed in block in case later find out can , want convert particular jump near short form.

-

the first strategy far simpler implement.

algorithm assembly

No comments:

Post a Comment