I have an object file (for which I don't have access to the source).
For good reasons, I need to duplicate a call path. For example, this object file might have the following symbols:
_FuncA
_FuncB
_FuncC
_FuncA calls _FuncB, which in turns calls _FuncC. FuncC might increment a global variable defined in the C source code counter.
I want to modify this object file and duplicate _FuncA, _FuncB, and _FuncC.
The result would be an object file with the following symbols:
_FuncA
_FuncB
_FuncC
_FuncA_copy
_FuncB_copy
_FuncC_copy
_FuncA_copy would need to call _FuncB_copy, which in turns calls _FuncC_copy. And I need _FuncC_copy to still reference the same global variable counter and increment it.
What I have so far:
It seems like the objcopy command will let you add new symbols using the flag --add-symbol <name>=[<section>:]<value>[,<flags>].
This seems like it would help me create _FuncA_copy, _FuncB_copy, _FuncC_copy. But is there anyway to modify the function call inside _FuncA_copy to _FuncB to go to _FuncB_copy instead?
Is there a better way to do this?