Calling dlsym()-ed function causes segfault

N

nirnimesh

I'm intercepting a library function call using LD_PRELOAD and in-turn
calling the orignial library function. Essentially,

intercept.cc:
void (*real_func)(void) = (void (*) (void)) dlsym(RTLD_NEXT,
"_mangled_name_of_func_");
real_func(); //! Calling the original function -- SEGFAULT

This is compiled as:
g++ -shared -fPIC -Wall -o libintercept.so intercept.cc -ldl

When I run it as:
LD_PRELOAD=libintercept.so progname
it leads to a SEGFAULT at the place where real_func() is called. I've
checked to ensure that dlsym() succeeds. In fact, I've also checked
that dladdr() gives the correct function and file name for the resolved
library. The trouble, I guess, is with resolving some things since
things work OK if I replace the call to real_func() with the actual
code implemented in func().

Any leads to what's going wrong?

Machine: FC4-x86_64 with gcc-4.0.0

Regards
Nirnimesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top