This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Weak symbols on Windows PECOFF (-mingw and -cygwin)


I have attached a simple patch that adds weak symbol support to Windows,
*-mingw32 and *-cygwin specifically.  It mirrors the way that most other
targets provide weak symbols.

binutils has actually provided weak symbol support for i386 PECOFF for a
long time now.  However, until recently, there were subtle bugs and a
lack of conformance to the PECOFF specification that prevented it from
being a good idea to enable weak symbols GCC.

Older binutils versions will still handle the .weak directive, and will
emit objects compatible with recent binutils, so I don't think its
necessary to make this conditional on a particular binutils version.

Its my understanding that as this change is target-specific, a
maintainer is permitted to accept it even in stage 3.  There is minimal
risk of breakage, limited to cases where software that previously did
not use weak symbols now detect that GCC supports weak symbols.  Given
the general usefulness of weak symbols, I think it would be worthwhile
to take this risk to include them in GCC 4.0.

I have tested weak symbols extensively on i686-pc-mingw32 over the past
few months.  On i686-pc-mingw32, there are no testsuite regressions, and
all of the weak symbol tests pass.  Combinations of attribute weak,
attribute alias, functions/variables, and C++ mangling all seem to work
properly according to testing done by hand.

I have a copyright assignment but no CVS access.

Aaron W. LaFramboise

2004-10-19  Aaron W. LaFramboise <aaronavay62@aaronwl.com>

	* config/i386/cygming.h (ASM_WEAKEN_LABEL): Define.

Index: gcc/gcc/config/i386/cygming.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/cygming.h,v
retrieving revision 1.22
diff -c -3 -p -r1.22 cygming.h
*** gcc/gcc/config/i386/cygming.h       18 Oct 2004 03:48:57 -0000      1.22
--- gcc/gcc/config/i386/cygming.h       19 Oct 2004 19:46:35 -0000
*************** extern int i386_pe_dllimport_name_p (con
*** 396,401 ****
--- 396,413 ----
        ASM_OUTPUT_DEF (STREAM, alias, IDENTIFIER_POINTER (TARGET));    \
      } while (0)
  
+ /* GNU as supports weak symbols on PECOFF. */
+ #ifdef HAVE_GAS_WEAK
+ #define ASM_WEAKEN_LABEL(FILE, NAME)  \
+   do                                  \
+     {                                 \
+       fputs ("\t.weak\t", (FILE));    \
+       assemble_name ((FILE), (NAME)); \
+       fputc ('\n', (FILE));           \
+     }                                 \
+   while (0)
+ #endif /* HAVE_GAS_WEAK */
+ 
  /* Decide whether it is safe to use a local alias for a virtual function
     when constructing thunks.  */
  #undef TARGET_USE_LOCAL_THUNK_ALIAS_P

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]