LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   using ld -wrap function to instrument (https://www.linuxquestions.org/questions/programming-9/using-ld-wrap-function-to-instrument-790444/)

cgopi24@gmail.com 02-20-2010 02:37 PM

using ld -wrap function to instrument
 
Hi All,

I am trying the wrap feature for the first time. I followed the instruction as mentioned in this link

http://sourceware.org/ml/binutils/2000-09/msg00083.html

but I am getting an error saying "undefine reference to __wrap_malloc

I followed all the steps, but the post was a decade old, I am sure something has changed? or am I missing something.

Appreciate your time in help me out!

ForzaItalia2006 02-22-2010 07:48 AM

Hey,

I checked this feature on my system, and it works perfectly. This is what I did:

Code:

#include <stdio.h>
#include <stdlib.h>

void *__real_malloc(size_t);

void *__wrap_malloc(size_t c)
{
        printf("My MALLOC called: %d\n", c);
        return __real_malloc(c);
}

int main (int argc, char *argv[])
{
        void *ptr = malloc(12);

        return 0;
}

And I compiled & run the code with:

Code:

[gcc wrap]$ gcc wrap.c -o wrap -Wl,-wrap,malloc
[gcc wrap]$ ./wrap
My MALLOC called: 12

I'm using

* gcc 4.4.3
* binutils 2.20.0.20091101


Maybe, you could post your code ...

- Andi -

littlefang 12-03-2010 01:04 AM

May be your code needs extern “C”


All times are GMT -5. The time now is 11:20 AM.