Using callgrind should work as expected. To test this, I set up a simple project using a simple library and the main Makefile function file:
CFLAGS=-fpic
exe:exe.o lib.so
cc -o exe exe.o lib.so
lib.so:lib.o
cc -shared lib.o -o lib.so
clean:
rm -f exe lib.so *.o
lib.c is a simple library containing 2 functions:
#include <stdio.h>
void someOtherFunction() { printf("someOtherFunction\n"); }
void someFunction() { printf("someFunction\n"); someOtherFunction(); }
exe.c is a very simple executable file:
int someFunction();
void main() { someFunction(); }
Use the Makefile to create the executable and run it with valgrind as follows:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD valgrind --tool=callgrind ./exe
If you look at the output of callgrind, you will find the profiling data for both functions in the shared library. If you do not see these functions, you can use a non-standard environment that does not support this function. I am using Linux Mint 11 x64 with the latest fixes.