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: Define __GXX_WEAK__ to 0 when using -fno-weak


On a system in which weak symbols are supported (and, hence,
SUPPORTS_WEAK is defined), but when -fno-weak is being used, we still
define __GXX_WEAK__ to 1, which results in libsupc++ using
pointer-comparison to determine typeinfo identity, rather than
string-comparison.  Fixed with the attached patch.  I also added
documentation for a few predefined preprocessor symbols which were not
otherwise documented.

Tested on x86_64-unknown-linux-gnu, applied on the mainline.

(Personally, I'd be happy to remove -fno-weak entirely, and just say
that wehther or not you get weak/COMDAT symbols depends purely on
whether or not your system supports that.  But, that's another
debate...)

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2005-05-01  Mark Mitchell  <mark@codesourcery.com>

	* c-cppbuiltin.c (c_cpp_builtins): Do not define __GXX_WEAK__ to 1
	if !flag_weak.
	* doc/cpp.texi (__DEPRECATED): Document.
	(__EXCEPTIONS): Likewise.
	(__GXX_WEAK__): Likewise.

2005-05-01  Mark Mitchell  <mark@codesourcery.com>

	* g++.dg/cpp/weak.C: New test.

Index: c-cppbuiltin.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-cppbuiltin.c,v
retrieving revision 1.29
diff -c -5 -p -r1.29 c-cppbuiltin.c
*** c-cppbuiltin.c	21 Jan 2005 16:57:02 -0000	1.29
--- c-cppbuiltin.c	1 May 2005 19:41:36 -0000
*************** c_cpp_builtins (cpp_reader *pfile)
*** 326,336 ****
    /* For stddef.h.  They require macros defined in c-common.c.  */
    c_stddef_cpp_builtins ();
  
    if (c_dialect_cxx ())
      {
!       if (SUPPORTS_ONE_ONLY)
  	cpp_define (pfile, "__GXX_WEAK__=1");
        else
  	cpp_define (pfile, "__GXX_WEAK__=0");
        if (warn_deprecated)
  	cpp_define (pfile, "__DEPRECATED");
--- 326,336 ----
    /* For stddef.h.  They require macros defined in c-common.c.  */
    c_stddef_cpp_builtins ();
  
    if (c_dialect_cxx ())
      {
!       if (flag_weak && SUPPORTS_ONE_ONLY) 
  	cpp_define (pfile, "__GXX_WEAK__=1");
        else
  	cpp_define (pfile, "__GXX_WEAK__=0");
        if (warn_deprecated)
  	cpp_define (pfile, "__DEPRECATED");
Index: doc/cpp.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/cpp.texi,v
retrieving revision 1.81
diff -c -5 -p -r1.81 cpp.texi
*** doc/cpp.texi	28 Apr 2005 00:24:11 -0000	1.81
--- doc/cpp.texi	1 May 2005 19:41:36 -0000
*************** Defined to the maximum value of the @cod
*** 2079,2093 ****
--- 2079,2113 ----
  @code{intmax_t} types
  respectively.  They exist to make the standard header given numerical limits
  work correctly.  You should not use these macros directly; instead, include
  the appropriate headers.
  
+ @item __DEPRECATED
+ This macro is defined, with value 1, when compiling a C++ source file
+ with warnings about deprecated constructs enabled.  These warnings are
+ enabled by default, but can be disabled with @option{-Wno-deprecated}.
+ 
+ @item __EXCEPTIONS
+ This macro is defined, with value 1, when compiling a C++ source file
+ with exceptions enabled.  If @option{-fno-exceptions} was used when
+ compiling the file, then this macro will not be defined.
+ 
  @item __USING_SJLJ_EXCEPTIONS__
  This macro is defined, with value 1, if the compiler uses the old
  mechanism based on @code{setjmp} and @code{longjmp} for exception
  handling.
  
+ @item __GXX_WEAK__
+ This macro is defined when compiling a C++ source file.  It has the
+ value 1 if the compiler will use weak symbols, COMDAT sections, or
+ other similar techniques to collapse symbols with ``vague linkage''
+ that are defined in multiple translation units.  If the compiler will
+ not collapse such symbols, this macro is defined with value 0.  In
+ general, user code should not need to make use of this macro; the
+ purpose of this macro is to ease implementation of the C++ runtime
+ library provided with G++.
+ 
  @item __NEXT_RUNTIME__
  This macro is defined, with value 1, if (and only if) the NeXT runtime
  (as in @option{-fnext-runtime}) is in use for Objective-C@.  If the GNU
  runtime is used, this macro is not defined, so that you can use this
  macro to determine which runtime (NeXT or GNU) is being used.
Index: testsuite/g++.dg/cpp/weak.C
===================================================================
RCS file: testsuite/g++.dg/cpp/weak.C
diff -N testsuite/g++.dg/cpp/weak.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/cpp/weak.C	1 May 2005 19:41:36 -0000
***************
*** 0 ****
--- 1,5 ----
+ // { dg-options "-fno-weak" }
+ 
+ #if __GXX_WEAK__
+ #error "__GXX_WEAK__ defined when -fno-weak in use"
+ #endif


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