1

I was referring to this thread. I have the same problem, wrapping a function call which is defined in the same file. Starting answers of the thread says that it seems impossible to do this but in the last someone has mentioned, it can be achieved by using -u flag. I have spent much more time to figure out how to do that, but I am not able to achieve wrapping a call of the same file. Is it really possible? Can somebody explain that?

Community
  • 1
  • 1
Harsh Panchal
  • 53
  • 1
  • 7

2 Answers2

1

EDIT: removed comment about (irrelevant) -U (capital) switch.

The linker is only responsible for symbol resolution between different translation unit. Within the same translation unit, it is the responsibility of the compiler to resolve the symbols.

Therefore, the -u flag, is "too late" when it comes to function calls within the same translation unit.

(keep in mind that in the same translation unit, the optimizer is free to inline function, so there may not even be a function call to wrap..)

Try looking at the following switches for gcc. It may assist you:

 -finstrument-functions

It allows you to automatically call a function before/after function starts/end.

yosim
  • 503
  • 2
  • 8
0

GNU gcc/ld - wrapping a call to symbol with caller and callee defined in the same object file

I have added code snippet that shows how you can intercept the function call.

Community
  • 1
  • 1
Ritesh
  • 1,809
  • 1
  • 14
  • 16