I'm transpiling a high-level programming language (Java) into C and in order to add support for stack bounds checking I need to know the stack frame size of every (transpiled) method I'm invoking. I'm trying to do this for multiple gcc target platforms and the only way to do this is using a gcc plugin, since only the compiler has this information internally.
I want the code to look something like this:
void my_transpiled_method_xyz() {....__checkBounds(other_transpiled_method_zxd_frame_size);other_transpiled_method_zxd();...}
Hereby the frame size variable can be declared as an extern const int
for example.
I've looked around on information regarding making a simple gcc plugin and I've succeeded at doing so, but I can't find any information on how to expose the information I want. I know that I need to do it in one of the last passes, because stack frame size can change between passes (-O0 and -O2 produce different stack frame sizes).
I'm also a bit confused on how to expose the stack frame size, because if the information is only available at the end, how can I make sure that the variable I expose gets inlined into the instruction, since its a constant variable and I don't want to waste memory. I might have to rerun some passes to make sure that happens, which complicates it further. I have also searched through gcc source code on where the stack frame size is available, to no avail.