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/mingw32/c++] Fix PR target/38054 (Assertion failed in change_decl_assembler_name)


The problem here is that although target-specific mangling of symbols
declared by user are handled by targetm.mangle_decl_assembler_name,
compiler generated C++ thunk decls are not. When the Windows target
i386_pe_encode_section_info sees a stdcall symbol lacking the expected
stdcall decoration decoration, it generates the new name and calls
change_decl_assembler_name. This change of assembler name is too late
Indeed it is unnecessary and as this bug report shows, potentially
dangerous. For Ada, we just need to ensure that the RTL name for Stdcall
Import's are correctly decorated.

This fixes, by letting targets modify the mangled thunk name in the C++
front end (ie.in cp/mangles.c:mangle_thunk), and removing the call to
change_decl_assembler_name in the winnt.c encode_section_info code.

Bootstrap and regtested on i686-pc-mingw32

ChangeLog

2008-11-09  Danny Smith  <dannysmith@users.sourceforge.net>
	PR target/38054
	* config/i386/winnt.c (i386_pe_encode_section_info): Don't
	 change_decl_assembler_name.

cp/Changelog

	PR target/38054
	* mangle.c (mangle_thunk): Allow target to modify mangled name.


Index: cp/mangle.c
===================================================================
--- cp/mangle.c	(revision 141713)
+++ cp/mangle.c	(working copy)
@@ -2889,6 +2889,8 @@
   write_encoding (fn_decl);

   result = finish_mangling_get_identifier (/*warn=*/false);
+  /*  Allow target to modify mangled name.  */
+  result = targetm.mangle_decl_assembler_name (fn_decl, result);
   if (DEBUG_MANGLE)
     fprintf (stderr, "mangle_thunk = %s\n\n", IDENTIFIER_POINTER (result));
   return result;
Index: config/i386/winnt.c
===================================================================
--- config/i386/winnt.c	(revision 141542)
+++ config/i386/winnt.c	(working copy)
@@ -265,20 +265,12 @@
 	     Check and do it know.  */
          tree new_id;
          tree old_id = DECL_ASSEMBLER_NAME (decl);
-     	  const char* asm_str = IDENTIFIER_POINTER (old_id);
-          /* Do not change the identifier if a verbatim asmspec
-	     or if stdcall suffix already added. */
-      	  if (*asm_str == '*' || strchr (asm_str, '@'))
-            break;
-	  if ((new_id = i386_pe_maybe_mangle_decl_assembler_name (decl, old_id)))
-	    {
-	      /* These attributes must be present on first declaration,
-		 change_decl_assembler_name will warn if they are added
-		 later and the decl has been referenced, but duplicate_decls
-		 should catch the mismatch first.  */
-	      change_decl_assembler_name (decl, new_id);
-	      XSTR (symbol, 0) = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
-	    }
+     	 const char* asm_str = IDENTIFIER_POINTER (old_id);
+         /* Do not change the identifier if a verbatim asmspec
+	    or if stdcall suffix already added. */
+      	 if (!(*asm_str == '*' || strchr (asm_str, '@'))
+             && (new_id = i386_pe_maybe_mangle_decl_assembler_name
(decl, old_id)))
+	   XSTR (symbol, 0) = IDENTIFIER_POINTER (new_id);
 	}
       break;


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