Click here to Skip to main content
15,881,844 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can anyone please help me to overcome from the problem given below?

Define a wrapper for functions that are in the same file (e.g. foo and bar, both in the same file – foo.c):

Since the 2 functions foo() and bar() in the same file, the assembler resolves the call before the linker has a chance to wrap it to __ wrap_bar()

As mention in the man page of --wrap=symbol (You may wish to provide a "__real_malloc" function as well, so that links without the --wrap option will succeed. If you do this, you should not put the definition of "__real_malloc" in the same file as "__wrap_malloc"; if you do, the assembler may resolve the call before the linker has a chance to wrap it to "malloc".)

Function foobar() is defined in bar.c file and it is calling the wrapped functions __wrap_foo() and __wrap_bar() (wrapped as expected by the linker).

Function __wrap_foo() calls the function foo() and function __wrap_bar() calls function bar()

Functions foo() and bar() are defined in foo.c file. Function foo() calls the function bar().

The call of these gives the output as below:

foobar calling to foo() ===> wrap-foo ===> foo calling to bar ===> bar

and

foorbar calling to bar() ===> wrap-bar ===> bar

While the expected output is as below:

foobar calling to foo() ===> wrap-foo ===> foo calling to bar ===> wrap-bar ===> bar

and

foorbar calling to bar() ===> wrap-bar ===> bar
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900