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] Fix PR c++/14808 (and 54 g++ testsuite failures)


Hello,

PR c++/14808 is specific to PE-COFF targets and is due to the way
linkonce sections are handled by the BFD backend (in bfd/coffcode.h) for
as and ld. 

Fo PE-COFF targets, only one symbol in a linkonce section has comdat
status. That symbol has the same name as the "section symbol" (eg, as
implemented by GNU binutils, a linkonce section named .text$_Z3foo is
expected to contain the symbol _Z3foo which is treated as comdat). This
causes problems in cp/method.c(use_thunk) when we put both an inline
virtual symbol and the thunk to it in the same linkonce section.

The following patch fixes by introducing a new macro that decides if it
is safe to use a local alias for a virtual thunk. By default, this macro
is true iff the target supports aliases. Cygwin and mingw32 override
this so that one_only symbols do not use local aliases.  

In addition to fixing this PR, the patch also fixes 54 g++ testsuite
failures (all execution tests for code involving either MI or covariant
thunks). So a new testcase is probably not necessary. A diff of g++ sum
logs is attached. 

A simpler patch would just avoid local aliases for _all_ virtual
functions, dependent on a target macro. In the absence of any
performance data, I would be happy with that too.


Danny
 

ChangeLog

 * defaults.h (TARGET_USE_LOCAL_THUNK_ALIAS_P): New macro. Default
 to 1 if ASM_OUTPUT_DEF is defined.
 * doc/tm.texi (TARGET_USE_LOCAL_THUNK_ALIAS_P): Document.
 * config/i386/cygming.h (TARGET_USE_LOCAL_THUNK_ALIAS_P): Define.
 Set to non-zero iff not a one_only decl.

cp/ChangeLog

 * method.c (use_thunk): Test TARGET_USE_LOCAL_THUNK_ALIAS_P rather than
 ASM_OUTPUT_DEF.
 

Index: defaults.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/defaults.h,v
retrieving revision 1.132
diff -c -3 -p -r1.132 defaults.h
*** defaults.h 15 Mar 2004 18:51:53 -0000 1.132
--- defaults.h 7 Apr 2004 19:50:31 -0000
*************** do { fputs (integer_asm_op (POINTER_SIZE
*** 484,489 ****
--- 484,499 ----
  #define TARGET_VTABLE_DATA_ENTRY_DISTANCE 1
  #endif
  
+ /* Decide whether it is safe to use a local alias for a virtual function
+    when constructing thunks.  */
+ #ifndef TARGET_USE_LOCAL_THUNK_ALIAS_P
+ #ifdef ASM_OUTPUT_DEF
+ #define TARGET_USE_LOCAL_THUNK_ALIAS_P(DECL) 1
+ #else
+ #define TARGET_USE_LOCAL_THUNK_ALIAS_P(DECL) 0
+ #endif
+ #endif
+ 
  /* Select a format to encode pointers in exception handling data.  We
     prefer those that result in fewer dynamic relocations.  Assume no
     special support here and encode direct references.  */
Index: doc/tm.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/tm.texi,v
retrieving revision 1.316
diff -c -3 -p -r1.316 tm.texi
*** doc/tm.texi 24 Mar 2004 00:13:30 -0000 1.316
--- doc/tm.texi 7 Apr 2004 19:51:00 -0000
*************** The parameter @var{path} is the include 
*** 9207,9209 ****
--- 9207,9217 ----
  systems, this is used for Framework includes, which have semantics
  that are different from @option{-I}.
  @end deftypefn
+ 
+ @deftypefn {Target Hook} bool TARGET_USE_LOCAL_THUNK_ALIAS_P (tree @var{fndecl})
+ This target hook returns @code{true} if it is safe to use a local alias
+ for a virtual function @var{fndecl} when constructing thunks,
+ @code{false} otherwise. By default, the hook returns @code{true} for all
+ functions, if a target supports aliases (ie. defines
+ @code{ASM_OUTPUT_DEF}), @code{false} otherwise,
+ @end deftypefn
Index: config/i386/cygming.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/cygming.h,v
retrieving revision 1.13
diff -c -3 -p -r1.13 cygming.h
*** config/i386/cygming.h 31 Jan 2004 08:02:54 -0000 1.13
--- config/i386/cygming.h 7 Apr 2004 19:51:02 -0000
*************** extern int i386_pe_dllimport_name_p (con
*** 382,387 ****
--- 382,392 ----
        ASM_OUTPUT_DEF (STREAM, alias, IDENTIFIER_POINTER (TARGET)); \
      } while (0)
  
+ /* Decide whether it is safe to use a local alias for a virtual function
+    when constructing thunks.  */
+ #undef TARGET_USE_LOCAL_THUNK_ALIAS_P
+ #define TARGET_USE_LOCAL_THUNK_ALIAS_P(DECL) (!DECL_ONE_ONLY (DECL))
+ 
  #undef TREE
  
  #ifndef BUFSIZ
Index: cp/method.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/method.c,v
retrieving revision 1.279
diff -c -3 -p -r1.279 method.c
*** cp/method.c 12 Mar 2004 17:09:01 -0000 1.279
--- cp/method.c 7 Apr 2004 19:51:03 -0000
*************** use_thunk (tree thunk_fndecl, bool emit_
*** 363,373 ****
    if (!emit_p)
      return;
  
! #ifdef ASM_OUTPUT_DEF
!   alias = make_alias_for_thunk (function);
! #else
!   alias = function;
! #endif
  
    fixed_offset = THUNK_FIXED_OFFSET (thunk_fndecl);
    virtual_offset = THUNK_VIRTUAL_OFFSET (thunk_fndecl);
--- 363,372 ----
    if (!emit_p)
      return;
  
!   if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function))
!    alias = make_alias_for_thunk (function);
!   else
!    alias = function;
  
    fixed_offset = THUNK_FIXED_OFFSET (thunk_fndecl);
    virtual_offset = THUNK_VIRTUAL_OFFSET (thunk_fndecl);
*************** use_thunk (tree thunk_fndecl, bool emit_
*** 401,408 ****
  
    push_to_top_level ();
  
! #ifdef ASM_OUTPUT_DEF
!   if (targetm.have_named_sections)
      {
        resolve_unique_section (function, 0, flag_function_sections);
  
--- 400,407 ----
  
    push_to_top_level ();
  
!   if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function)
!       && targetm.have_named_sections)
      {
        resolve_unique_section (function, 0, flag_function_sections);
  
*************** use_thunk (tree thunk_fndecl, bool emit_
*** 414,420 ****
     DECL_SECTION_NAME (thunk_fndecl) = DECL_SECTION_NAME (function);
   }
      }
- #endif
  
    /* The back-end expects DECL_INITIAL to contain a BLOCK, so we
       create one.  */
--- 413,418 ----

Attachment: g++.sum.diff
Description: Text document


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