dlopen, function returning c string, segfault 
Author Message
 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



Sat, 02 Apr 2005 01:58:42 GMT  
 dlopen, function returning c string, segfault


Quote:
> 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;
> }

> Then I have a driver that simply dlopen's the resulting shared object
> and calls this function via something like printf("%s\n", f());

Huh? There is no dlopen() in ISO C. What's a shared object? I think you
seek a platform specific newsgroup you don't have a C language question.
Try a linux newsgroup maybe?


Sat, 02 Apr 2005 03:36:39 GMT  
 dlopen, function returning c string, segfault

Quote:

> 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):

... snip ...

> Then I have a driver that simply dlopen's the resulting shared
> object ...

You have failed to read the Welcome message, lurk, etc.  Shared
objects and dlopen() are not mentioned in the C standard anywhere,
nor is .so.  So you are off topic and need to go to an appropriate
group - probably something with Linux in its name.

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!



Sat, 02 Apr 2005 04:23:56 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. passing character strings to functions with return string

2. Help with dlopen() & dlsym() functions

3. Pointer to function returning pointer to function returning...

4. Segfault at function call?

5. Return a string from a function

6. Looking for a function which returns the position (integer) of a string in a line

7. Returning A String From a function

8. Function returning string

9. Returning strings from functions

10. Function that returns a string

11. Function returning string

12. Function Returning a String Literal

 

 
Powered by phpBB® Forum Software