[fpc-devel] estimating function code size
Gennadiy Poryev
core at barvinok.net
Wed Jan 18 13:54:06 CET 2012
Hi all,
In my project (win32) I need to estimate the number of machine code bytes of a certain function.
The most straightforward option was to look for $c3 which is ret, and it worked on optimization levels O0 and O1. O2 and O3 seem to prefer $c2 $04 $00 (retn 4) instead.
Then here comes win64, where the function end is marked by $c3 (ret) regardless of optimization level.
And it turned out the opcode for mov eax,ebx also has $c3 in it.
For now, I use O3 level and patterns $c2 $04 $00 and $5d c3 00 (pop rbp, ret) for win32 and win64 respectively, in hope that the function is always geting padded to (but not equal to) nearest $20 in size.
This is far from deploying a full-fledged disassembler but is still not simple and elegant solution.
I remember back in TP days there were methods for this, by using labels and addressing them with absolute keyword to obtain offset delta.
I wonder if some similar trick can be used here, or if there are some built-in function to do just that?
Thanks in advance.
// Gennadiy
More information about the fpc-devel
mailing list