Hi,

I meet a requirement to make all function calls to be indirect
function calling ( for I386 GCC compiler). I am not familiar with
frontend, so my first idea is

to hack it from backend, change the asm output for "call" and
"call_value" insn patterns, generate a related varible in data
section,

and when output call insn, output indirect call. For example,

for function A,  I create a "g_stub_function_ptr_A" varible in data
section, with initialized value "A", and when output call insn "A",

output (I am not familiar with X86 instruction set, so I assume that
there is "CALL EAX" instruction):
             MOV  EAX,  g_stub_function_ptr_A
             CALL  EAX

Will this idea works?

Any comments are welcome!

Ps: the orignal requirement is to make function stubs for unit test.

Assume the top level function is A, and it calls B,C,D functions,  B
calls E, E calls F....

So when testing function A, one needs to care the all call chains of
A, which makes the unit test hard to implement.

Now I have a scratch idea: make all function calls to be indirect
call, in other words, make all function calls to be function pointer
call.

So when testing function A, one can make stubs for B,C,D, and change
the called B,C,D to be  one's own defined B,C,D stubs, via asigning
the function pointer

to be one's own.

Reply via email to