milewis1
2006-01-18 18:43:23 UTC
I'm having trouble using dlsym, specifically it crashes with a SIGSEGV
when I try to do something like the following (please keep in mind that
this is a overly simplified example and I have plenty of reasons why I
think doing it this way is best -- but I don't want to get into that
here).
I have an application that loads a library called ip.so. When the
application runs I specify what function in ip.so I want it to run on
the command line. ex: app Function1.
The application code looks like this:
app.c
-----------------------------------------------------------------------------
int main(int argc, char** argv)
{
...
handle = dlopen("ip.so",RTLD_LAZY|RTLD_GLOBAL);
entryfunc = (entryfuncptr)dlsym(handle,"Entry");
/* run a function */
(entryfunc)(argv[1]);
return 0;
}
ip.c:
------------------------------------------------------------------------------
void FindWithdladdr(void) { return; }
void Function1(void)
{
/* do something here */
}
void Function2(void)
{
/* do something else here */
}
void Entry(char* funcname)
{
Dl_info dli;
...
dladdr((const void*)FindWithdladdr,&dli);
dlsym(dli_fbase,funcname);
...
}
-----------------------------
Using gdb I find that I get the SIGSEGV inside the dlsym call,
specifically in do_lookup_x(). From what I've read and know this should
be possible, but it's obviously not working. I've also tried using
RTLD_DEFAULT in the dlsym call, but then it looks for the funcname in
the application and not the library and thusly can't find it.
Does anyone have any idea what I'm doing wrong? or if I'm trying to do
something impossible?
Thanks,
Mike
when I try to do something like the following (please keep in mind that
this is a overly simplified example and I have plenty of reasons why I
think doing it this way is best -- but I don't want to get into that
here).
I have an application that loads a library called ip.so. When the
application runs I specify what function in ip.so I want it to run on
the command line. ex: app Function1.
The application code looks like this:
app.c
-----------------------------------------------------------------------------
int main(int argc, char** argv)
{
...
handle = dlopen("ip.so",RTLD_LAZY|RTLD_GLOBAL);
entryfunc = (entryfuncptr)dlsym(handle,"Entry");
/* run a function */
(entryfunc)(argv[1]);
return 0;
}
ip.c:
------------------------------------------------------------------------------
void FindWithdladdr(void) { return; }
void Function1(void)
{
/* do something here */
}
void Function2(void)
{
/* do something else here */
}
void Entry(char* funcname)
{
Dl_info dli;
...
dladdr((const void*)FindWithdladdr,&dli);
dlsym(dli_fbase,funcname);
...
}
-----------------------------
Using gdb I find that I get the SIGSEGV inside the dlsym call,
specifically in do_lookup_x(). From what I've read and know this should
be possible, but it's obviously not working. I've also tried using
RTLD_DEFAULT in the dlsym call, but then it looks for the funcname in
the application and not the library and thusly can't find it.
Does anyone have any idea what I'm doing wrong? or if I'm trying to do
something impossible?
Thanks,
Mike