X-Spam-Check-By: sourceware.org Message-ID: <458CA19A.DD0291F3@dessent.net> Date: Fri, 22 Dec 2006 19:25:14 -0800 From: Brian Dessent X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: Is it possible to directly call a function in a dlopen library References: <89c3ea2b0612212204g4cf5ee2bg4b90780aaab85c0f AT mail DOT gmail DOT com> <458C0887 DOT 6080201 AT cygwin DOT com> <89c3ea2b0612221906l7e99c12m2776e0c2b13f5568 AT mail DOT gmail DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Reply-To: cygwin AT cygwin DOT com Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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/