X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org X-RZG-AUTH: :Ln4Re0+Ic/6oZXR1YgKryK8brksyK8dozXDwHXjf9xTKL3R4OlBCAU6/lWb5 X-RZG-CLASS-ID: mo00 From: Bruno Haible To: Dave Korn Subject: Re: weak symbols on Cygwin Date: Wed, 7 Apr 2010 11:06:10 +0200 User-Agent: KMail/1.9.9 Cc: Eric Blake , cygwin AT cygwin DOT com References: <4BBB31C6 DOT 7080703 AT redhat DOT com> <201004070141 DOT 36284 DOT bruno AT clisp DOT org> <4BBBF5C2 DOT 30102 AT gmail DOT com> In-Reply-To: <4BBBF5C2.30102@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201004071106.11471.bruno@clisp.org> 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 Hi Dave, > on ELF platforms, you can leave undefined references in an executable, to > be filled in by ld.so at runtime according to what the loader finds present > once it's loaded libc. > ... > On windows ... There's no run-time process of > scanning all available symbols from all loaded libraries against undefined > references in the executable. > ... > on Windows, all the library functions imported > from libc come in the form of import stubs from the (static) import library. > So weak references won't cause any of those symbols to be pulled in, even if > the library does provide them. But if something else in the program causes > them to be pulled in, the weak references will resolve to the imported > function. Thanks for these explanations. So, "#pragma weak" is very different on PE systems than on ELF systems. > > On ELF platforms, I use "#pragma weak" in order to detect whether a symbol > > is defined in the libraries which are linked in with the executable > > (including libc). > > This whole concept isn't going to translate directly to Windows platforms. > There's no interposing or providing missing definitions at runtime; if it's > not already there at final link time, it's not going to be there at runtime. > The only way windows can determine this sort of thing is through dlsym()ing > all the open libraries, I think. I was implicitly hoping that - gcc would collect all weak-declared symbols in some table, and generate code so that the reference to these symbols makes an indirection through this table, - the Cygwin runtime would call dlsym or GetProcAddress at startup and fill in addresses into said table. > What's the larger-scale goal you're trying to support by this method? Are > you after implementing some sort of plug-in architecture or something? I've got some code, written for ELF platforms, that detects whether the pthread library (often a separate library from libc) is linked, by doing #pragma weak pthread_cancel bool pthread_in_use = (pthread_cancel != NULL); This code breaks in Cygwin 1.7, because the autoconf test determines that gcc accepts #pragma weak. Not a big problem - I can surround that code with #ifdef __ELF__ Simply, it's an issue to be aware of. I'll suggest a documentation improvement for the GCC manual. Bruno -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple