dlopen, function returning c string, segfault
I'm puzzled by the following problem, and would appreciate it if
someone could explain to me what's going on?
I have the following code that's being compiled into a shared object
(.so - under Linux using gcc 2.95):
static char buf[] = "Something";
char* f()
{
printf("%s\n", buf);
return buf;
Quote:
}
Then I have a driver that simply dlopen's the resulting shared object
and calls this function via something like printf("%s\n", f()); So far
everything works fine. The puzzle appears when I comment out the line
in this function (f()) that has printf(...) in it, if I do that and
recompile it, then when I run the driver again it segfaults on dlopen!
Not even on the call to f, but on dlopen itself. What is the problem
and what am I missing?
Thanks a lot for your help.
Dmitriy