[Patch] Fix PR/18997 weak symbol bug on cygwin

Danny Smith danny_smith_0000@yahoo.co.nz
Thu Dec 16 02:35:00 GMT 2004


PR/18997 is a target bug caused by the enablement of weak-linkage
support on windows targets by this patch:

http://gcc.gnu.org/ml/gcc-cvs/2004-11/msg00265.html

2004-11-06  Aaron W. LaFramboise  <aaronavay62@aaronwl.com>

	PR target/18106
	* config/i386/cygming.h
	[HAVE_GAS_WEAK] (ASM_WEAKEN_LABEL): Macro defined.

Reverting that patch fixes this PR and also makes a huge difference to
the cygwin g++ testsuite results. 

Cygwin's pthread functions live in the cygwin1.dll shared system
library, They are alway available, so weak linkage is not necessary.
Weak linkage doesn't actually work with these dll symbols. Even though
the symbols are in a shared libary, they are accessed through an "import
lib" which BFD sees as an archive (because it has the same format as a
static archive). Binutils follows the SVR4 ABI wrt weak symbols in
archives: An undefined weak symbol is not considered to be a reference
when pulling files out of an archive. Thus, all these weak pthread
symbols are left as null pointers. Although GCC says
SUPPORTS_WEAK is true, the actual support in bintils is still a work in
progress. 

I would be disappointed if we are forced to revert the patch that
enabled weak linkage on the gcc side, because once weak works correctly
it opens ups new opportunities. I would prefer that the unnecessary weak
attribute just be removed from the pthread functions for cygwin. This
has to be done both within GCC build itself and in libstdc++. Since
cygwin uses newlib as its C library, the override of
_GLIBCXX_GTHREAD_USE_WEAK would go in config/os/newlib/os_defines.h.
Probably not a good place, but where else (a builtin predefine?).

The followin patch fixes the regression. Bootstrapped and tested on
i686-pc-cygwin (c,c++). 

gcc/ChangeLog

	* config/i386/cygwin.h (GTHREAD_USE_WEAK): Define to 0.

libstdc++-v3/ChangeLog

	* config/os/newlib/os_defines.h (_GLIBCXX_GTHREAD_USE_WEAK):
	Define to 0 for __CYGWIN__.


Index: gcc/gcc/config/i386/cygwin.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/cygwin.h,v
retrieving revision 1.85
diff -c -3 -p -r1.85 cygwin.h
*** gcc/gcc/config/i386/cygwin.h	26 Sep 2003 03:28:27 -0000	1.85
--- gcc/gcc/config/i386/cygwin.h	16 Dec 2004 02:05:02 -0000
*************** do \
*** 228,230 ****
--- 228,234 ----
    } \
  while (0)
  #endif
+ 
+ /* Binutils does not handle weak symbols from dlls correctly.  For now,
+    do not use them unnecessarily in gthr-posix.h.  */
+ #define GTHREAD_USE_WEAK 0
Index: gcc/libstdc++-v3/config/os/newlib/os_defines.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/os/newlib/os_defines.h,v
retrieving revision 1.2
diff -c -3 -p -r1.2 os_defines.h
*** gcc/libstdc++-v3/config/os/newlib/os_defines.h	5 Jul 2003 04:05:32 -0000	1.2
--- gcc/libstdc++-v3/config/os/newlib/os_defines.h	16 Dec 2004 02:05:02 -0000
***************
*** 33,36 ****
--- 33,40 ----
  // System-specific #define, typedefs, corrections, etc, go here.  This
  // file will come before all others.
  
+ #ifdef __CYGWIN__
+ #define _GLIBCXX_GTHREAD_USE_WEAK 0
+ #endif
+ 
  #endif

Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com



More information about the Gcc-patches mailing list