Is it possible to directly call a function in a dlopen library

Brian Dessent brian@dessent.net
Sat Dec 23 04:01:00 GMT 2006


andy wang wrote:

> On the module2.dll, I just want to directly call myfunc1 without using
> dlsym(), is that possible?  I was just wondering that I just dlopen
> module1 and module2, then directly call the function without dlsym().
> I know that it is not a strictly cygwin-related question :-)

It's not possible to do without calling dlsym (or GetProcAddress) in the
general case.  How else would you get the entry point for the
procedure?  The only way to "directly" (that's such a vague word) call
the function is to actually link against it at link time, and skip the
whole dlopen/dlsym business entirely.

There is sort of a way to obfuscate the LoadLibrary/dlopen and
dlsym/GetProcAddress calls, which is used by Cygwin itself.  See the
file autoload.cc.  But this is quite a hack, it involves some assembler
trickery and is self-modifying code which means you probably have to
arrange for these stubs to go into a different section than the standard
.text section.  It's also unportable as heck which means it ties your
code to gcc+GNU assembler+Windows, meaning that there is little chance
your app would ever compile under Microsoft Visual Studio or under gcc
on *nix, unless you added some fallback code to use standard
dlopen/dlsym stuff.  But if you're going to do that there's no point
going to all the trouble anyway.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list