diff mbox

[c++] typeinfo for target types

Message ID alpine.DEB.2.02.1404131018180.27848@stedding.saclay.inria.fr
State New
Headers show

Commit Message

Marc Glisse April 13, 2014, 8:41 a.m. UTC
Hello,

this patch generates typeinfo for target types. On x86_64, it adds these 6 
lines to nm -C libsupc++.a. A follow-up patch will be needed to export and 
version those in the shared library.

+0000000000000000 V typeinfo for __float128
+0000000000000000 V typeinfo for __float128 const*
+0000000000000000 V typeinfo for __float128*
+0000000000000000 V typeinfo name for __float128
+0000000000000000 V typeinfo name for __float128 const*
+0000000000000000 V typeinfo name for __float128*

Bootstrap and testsuite on x86_64-linux-gnu (a bit of noise in 
tsan/tls_race.c).

2014-04-13  Marc Glisse  <marc.glisse@inria.fr>

 	PR libstdc++/43622
gcc/c-family/
 	* c-common.c (registered_builtin_types): Make non-static.
 	* c-common.h (registered_builtin_types): Declare.
gcc/cp/
 	* rtti.c (emit_support_tinfo_1): New function, extracted from
 	emit_support_tinfos.
 	(emit_support_tinfos): Call it and iterate on registered_builtin_types.

Comments

Jason Merrill April 14, 2014, 4:16 a.m. UTC | #1
On 04/13/2014 04:41 AM, Marc Glisse wrote:
> this patch generates typeinfo for target types. On x86_64, it adds these
> 6 lines to nm -C libsupc++.a. A follow-up patch will be needed to export
> and version those in the shared library.

This looks fine, but shouldn't be checked in without that other patch.

Jason
Richard Henderson April 23, 2014, 6:46 p.m. UTC | #2
On 04/13/2014 01:41 AM, Marc Glisse wrote:
> Hello,
> 
> this patch generates typeinfo for target types. On x86_64, it adds these 6
> lines to nm -C libsupc++.a. A follow-up patch will be needed to export and
> version those in the shared library.
> 
> +0000000000000000 V typeinfo for __float128
> +0000000000000000 V typeinfo for __float128 const*
> +0000000000000000 V typeinfo for __float128*
> +0000000000000000 V typeinfo name for __float128
> +0000000000000000 V typeinfo name for __float128 const*
> +0000000000000000 V typeinfo name for __float128*
> 
> Bootstrap and testsuite on x86_64-linux-gnu (a bit of noise in tsan/tls_race.c).
> 
> 2014-04-13  Marc Glisse  <marc.glisse@inria.fr>
> 
>     PR libstdc++/43622
> gcc/c-family/
>     * c-common.c (registered_builtin_types): Make non-static.
>     * c-common.h (registered_builtin_types): Declare.
> gcc/cp/
>     * rtti.c (emit_support_tinfo_1): New function, extracted from
>     emit_support_tinfos.
>     (emit_support_tinfos): Call it and iterate on registered_builtin_types.
> 

This is causing aarch64 builds to break.  Any c++ compilation aborts at

#0  fancy_abort (file=0x14195c8 "../../git-rh/gcc/cp/mangle.c", line=2303,
    function=0x1419ff8 <write_builtin_type(tree_node*)::__FUNCTION__>
    "write_builtin_type") at ../../git-rh/gcc/diagnostic.c:1190
#1  0x00000000007ce2b4 in write_builtin_type (
    type=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>)
    at ../../git-rh/gcc/cp/mangle.c:2303
#2  0x00000000007cc85c in write_type (
    type=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>)
    at ../../git-rh/gcc/cp/mangle.c:1969
#3  0x00000000007d4d98 in mangle_special_for_type (
    type=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>,
    code=0x1419a98 "TI") at ../../git-rh/gcc/cp/mangle.c:3569
#4  0x00000000007d4dcc in mangle_typeinfo_for_type (
    type=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>)
    at ../../git-rh/gcc/cp/mangle.c:3585
#5  0x000000000070618c in get_tinfo_decl (
    type=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>)
    at ../../git-rh/gcc/cp/rtti.c:422
#6  0x0000000000709ff0 in emit_support_tinfo_1 (
    bltn=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>)
    at ../../git-rh/gcc/cp/rtti.c:1485
#7  0x000000000070a344 in emit_support_tinfos ()
    at ../../git-rh/gcc/cp/rtti.c:1550

Presumably the backend needs to grow some mangling support for its builtins,
but in the meantime can we do something less drastic than abort?  Isn't this
only really an issue if someone tries to access one of these types via typeinfo?


r~
Marc Glisse April 23, 2014, 7:43 p.m. UTC | #3
On Wed, 23 Apr 2014, Richard Henderson wrote:

> On 04/13/2014 01:41 AM, Marc Glisse wrote:
>> Hello,
>>
>> this patch generates typeinfo for target types. On x86_64, it adds these 6
>> lines to nm -C libsupc++.a. A follow-up patch will be needed to export and
>> version those in the shared library.
>>
>> +0000000000000000 V typeinfo for __float128
>> +0000000000000000 V typeinfo for __float128 const*
>> +0000000000000000 V typeinfo for __float128*
>> +0000000000000000 V typeinfo name for __float128
>> +0000000000000000 V typeinfo name for __float128 const*
>> +0000000000000000 V typeinfo name for __float128*
>>
>> Bootstrap and testsuite on x86_64-linux-gnu (a bit of noise in tsan/tls_race.c).
>>
>> 2014-04-13  Marc Glisse  <marc.glisse@inria.fr>
>>
>>     PR libstdc++/43622
>> gcc/c-family/
>>     * c-common.c (registered_builtin_types): Make non-static.
>>     * c-common.h (registered_builtin_types): Declare.
>> gcc/cp/
>>     * rtti.c (emit_support_tinfo_1): New function, extracted from
>>     emit_support_tinfos.
>>     (emit_support_tinfos): Call it and iterate on registered_builtin_types.
>>
>
> This is causing aarch64 builds to break.

If it is causing too much trouble, we could ifdef out the last 2 lines of 
emit_support_tinfos and revert the libstdc++ changes (or even revert the 
whole thing).

> Any c++ compilation aborts at

That's surprising, the code I touched is only ever supposed to run while 
compiling one file in libsupc++, if I understand correctly.

> #0  fancy_abort (file=0x14195c8 "../../git-rh/gcc/cp/mangle.c", line=2303,
>    function=0x1419ff8 <write_builtin_type(tree_node*)::__FUNCTION__>
>    "write_builtin_type") at ../../git-rh/gcc/diagnostic.c:1190
> #1  0x00000000007ce2b4 in write_builtin_type (
>    type=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>)
>    at ../../git-rh/gcc/cp/mangle.c:2303
> #2  0x00000000007cc85c in write_type (
>    type=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>)
>    at ../../git-rh/gcc/cp/mangle.c:1969
> #3  0x00000000007d4d98 in mangle_special_for_type (
>    type=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>,
>    code=0x1419a98 "TI") at ../../git-rh/gcc/cp/mangle.c:3569
> #4  0x00000000007d4dcc in mangle_typeinfo_for_type (
>    type=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>)
>    at ../../git-rh/gcc/cp/mangle.c:3585
> #5  0x000000000070618c in get_tinfo_decl (
>    type=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>)
>    at ../../git-rh/gcc/cp/rtti.c:422
> #6  0x0000000000709ff0 in emit_support_tinfo_1 (
>    bltn=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>)
>    at ../../git-rh/gcc/cp/rtti.c:1485
> #7  0x000000000070a344 in emit_support_tinfos ()
>    at ../../git-rh/gcc/cp/rtti.c:1550
>
> Presumably the backend needs to grow some mangling support for its builtins,

aarch64 has complicated builtins... __builtin_aarch64_simd_df uses 
double_aarch64_type_node which is not the same as double_type_node. I 
mostly looked at the x86 backend, so I didn't notice that aarch64 
registers a lot more builtins.

> but in the meantime can we do something less drastic than abort?

Sounds good, but I am not sure how exactly. We could use a separate hook 
(register_builtin_type_for_typeinfo?) so back-ends have to explicitly say 
they want typeinfo, but it is ugly having to register types multiple 
times. We could add a parameter to the existing register_builtin_type 
saying whether we want typeinfo, but that means updating all back-ends. We 
could get the mangling functions to take a parameter that says whether 
errors should be fatal and skip generating the typeinfo when we can't 
mangle, but there is no convenient way to communicate this mangling 
failure (0 bytes written?).

Would mangling the aarch64 builtins be a lot of work? Did other platforms 
break as well?

> Isn't this only really an issue if someone tries to access one of these 
> types via typeinfo?

Yes.
Richard Henderson April 23, 2014, 8:35 p.m. UTC | #4
On 04/23/2014 12:43 PM, Marc Glisse wrote:
>> Any c++ compilation aborts at
> 
> That's surprising, the code I touched is only ever supposed to run while
> compiling one file in libsupc++, if I understand correctly.

Ah, well, perhaps it's one of the first built for stage1 libstdc++.
I admit to not digging much deeper.  ;-)

> Would mangling the aarch64 builtins be a lot of work? Did other platforms break as well? 

I've no idea on difficulty.  I've not yet checked other platforms.


r~
Richard Henderson April 23, 2014, 9:12 p.m. UTC | #5
On 04/23/2014 12:43 PM, Marc Glisse wrote:
> Would mangling the aarch64 builtins be a lot of work? Did other platforms break
> as well?

Hmm.  Apparently, aarch64 already *has* mangling support, but it's broken.

The node is built with DFmode in aarch64_init_simd_builtins, but then (not)
matched with V2DFmode in aarch64_mangle_type and its table.

The same appears to be true with every single one of the aarch64 backend types,
so I have no idea what is intended here.  I'm going to have to leave this to
the ARM maintainers to clear up.


r~
Kyrylo Tkachov April 24, 2014, 8:47 a.m. UTC | #6
On 23/04/14 21:35, Richard Henderson wrote:
> On 04/23/2014 12:43 PM, Marc Glisse wrote:
>>> Any c++ compilation aborts at
>> That's surprising, the code I touched is only ever supposed to run while
>> compiling one file in libsupc++, if I understand correctly.
> Ah, well, perhaps it's one of the first built for stage1 libstdc++.
> I admit to not digging much deeper.  ;-)
>
>> Would mangling the aarch64 builtins be a lot of work? Did other platforms break as well?
> I've no idea on difficulty.  I've not yet checked other platforms.

This affects arm as well. The same ICE in mangle.c.
The arm and aarch64 mangling code is very similar...

Kyrill

>
>
> r~
>
Ramana Radhakrishnan April 24, 2014, 10:38 a.m. UTC | #7
On Wed, Apr 23, 2014 at 8:43 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Wed, 23 Apr 2014, Richard Henderson wrote:
>
>> On 04/13/2014 01:41 AM, Marc Glisse wrote:
>>>
>>> Hello,
>>>
>>> this patch generates typeinfo for target types. On x86_64, it adds these
>>> 6
>>> lines to nm -C libsupc++.a. A follow-up patch will be needed to export
>>> and
>>> version those in the shared library.
>>>
>>> +0000000000000000 V typeinfo for __float128
>>> +0000000000000000 V typeinfo for __float128 const*
>>> +0000000000000000 V typeinfo for __float128*
>>> +0000000000000000 V typeinfo name for __float128
>>> +0000000000000000 V typeinfo name for __float128 const*
>>> +0000000000000000 V typeinfo name for __float128*
>>>
>>> Bootstrap and testsuite on x86_64-linux-gnu (a bit of noise in
>>> tsan/tls_race.c).
>>>
>>> 2014-04-13  Marc Glisse  <marc.glisse@inria.fr>
>>>
>>>     PR libstdc++/43622
>>> gcc/c-family/
>>>     * c-common.c (registered_builtin_types): Make non-static.
>>>     * c-common.h (registered_builtin_types): Declare.
>>> gcc/cp/
>>>     * rtti.c (emit_support_tinfo_1): New function, extracted from
>>>     emit_support_tinfos.
>>>     (emit_support_tinfos): Call it and iterate on
>>> registered_builtin_types.
>>>
>>
>> This is causing aarch64 builds to break.
>
>
> If it is causing too much trouble, we could ifdef out the last 2 lines of
> emit_support_tinfos and revert the libstdc++ changes (or even revert the
> whole thing).
>
>
>> Any c++ compilation aborts at
>
>
> That's surprising, the code I touched is only ever supposed to run while
> compiling one file in libsupc++, if I understand correctly.
>
>
>> #0  fancy_abort (file=0x14195c8 "../../git-rh/gcc/cp/mangle.c", line=2303,
>>    function=0x1419ff8 <write_builtin_type(tree_node*)::__FUNCTION__>
>>    "write_builtin_type") at ../../git-rh/gcc/diagnostic.c:1190
>> #1  0x00000000007ce2b4 in write_builtin_type (
>>    type=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>)
>>    at ../../git-rh/gcc/cp/mangle.c:2303
>> #2  0x00000000007cc85c in write_type (
>>    type=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>)
>>    at ../../git-rh/gcc/cp/mangle.c:1969
>> #3  0x00000000007d4d98 in mangle_special_for_type (
>>    type=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>,
>>    code=0x1419a98 "TI") at ../../git-rh/gcc/cp/mangle.c:3569
>> #4  0x00000000007d4dcc in mangle_typeinfo_for_type (
>>    type=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>)
>>    at ../../git-rh/gcc/cp/mangle.c:3585
>> #5  0x000000000070618c in get_tinfo_decl (
>>    type=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>)
>>    at ../../git-rh/gcc/cp/rtti.c:422
>> #6  0x0000000000709ff0 in emit_support_tinfo_1 (
>>    bltn=<real_type 0x7fb1653540 __builtin_aarch64_simd_df>)
>>    at ../../git-rh/gcc/cp/rtti.c:1485
>> #7  0x000000000070a344 in emit_support_tinfos ()
>>    at ../../git-rh/gcc/cp/rtti.c:1550
>>
>> Presumably the backend needs to grow some mangling support for its
>> builtins,
>
>
> aarch64 has complicated builtins... __builtin_aarch64_simd_df uses
> double_aarch64_type_node which is not the same as double_type_node. I mostly
> looked at the x86 backend, so I didn't notice that aarch64 registers a lot
> more builtins.
>
>
>> but in the meantime can we do something less drastic than abort?
>
>
> Sounds good, but I am not sure how exactly. We could use a separate hook
> (register_builtin_type_for_typeinfo?) so back-ends have to explicitly say
> they want typeinfo, but it is ugly having to register types multiple times.
> We could add a parameter to the existing register_builtin_type saying
> whether we want typeinfo, but that means updating all back-ends.

Well some of these scalar types are not really user visible which is
where I believe the problem is coming from and prima-facie I don't
think we should be inventing mangling for some of these "internal"
types.

>  We could
> get the mangling functions to take a parameter that says whether errors
> should be fatal and skip generating the typeinfo when we can't mangle, but
> there is no convenient way to communicate this mangling failure (0 bytes
> written?).
>
> Would mangling the aarch64 builtins be a lot of work? Did other platforms
> break as well?
>

It's not a lot of work but I'd like to make sure we're doing the right
thing on both AArch32 and AArch64. So, for now can we just revert this
till the thing is sorted out.

regards
Ramana

>
>> Isn't this only really an issue if someone tries to access one of these
>> types via typeinfo?
>
>
> Yes.
>
> --
> Marc Glisse
diff mbox

Patch

Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 209345)
+++ gcc/c-family/c-common.c	(working copy)
@@ -3462,21 +3462,21 @@  c_common_fixed_point_type_for_size (unsi
 	     "fixed-point types that have too many integral and "
 	     "fractional bits together");
       return 0;
     }
 
   return c_common_type_for_mode (mode, satp);
 }
 
 /* Used for communication between c_common_type_for_mode and
    c_register_builtin_type.  */
-static GTY(()) tree registered_builtin_types;
+tree registered_builtin_types;
 
 /* Return a data type that has machine mode MODE.
    If the mode is an integer,
    then UNSIGNEDP selects between signed and unsigned types.
    If the mode is a fixed-point mode,
    then UNSIGNEDP selects between saturating and nonsaturating types.  */
 
 tree
 c_common_type_for_mode (enum machine_mode mode, int unsignedp)
 {
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 209345)
+++ gcc/c-family/c-common.h	(working copy)
@@ -1006,20 +1006,24 @@  extern void do_warn_double_promotion (tr
 extern void set_underlying_type (tree);
 extern void record_locally_defined_typedef (tree);
 extern void maybe_record_typedef_use (tree);
 extern void maybe_warn_unused_local_typedefs (void);
 extern vec<tree, va_gc> *make_tree_vector (void);
 extern void release_tree_vector (vec<tree, va_gc> *);
 extern vec<tree, va_gc> *make_tree_vector_single (tree);
 extern vec<tree, va_gc> *make_tree_vector_from_list (tree);
 extern vec<tree, va_gc> *make_tree_vector_copy (const vec<tree, va_gc> *);
 
+/* Used for communication between c_common_type_for_mode and
+   c_register_builtin_type.  */
+extern GTY(()) tree registered_builtin_types;
+
 /* In c-gimplify.c  */
 extern void c_genericize (tree);
 extern int c_gimplify_expr (tree *, gimple_seq *, gimple_seq *);
 extern tree c_build_bind_expr (location_t, tree, tree);
 
 /* In c-pch.c  */
 extern void pch_init (void);
 extern void pch_cpp_save_state (void);
 extern int c_common_valid_pch (cpp_reader *pfile, const char *name, int fd);
 extern void c_common_read_pch (cpp_reader *pfile, const char *name, int fd,
Index: gcc/cp/rtti.c
===================================================================
--- gcc/cp/rtti.c	(revision 209345)
+++ gcc/cp/rtti.c	(working copy)
@@ -1458,20 +1458,58 @@  create_tinfo_types (void)
 		    FIELD_DECL, NULL_TREE, integer_type_node),
 	build_decl (BUILTINS_LOCATION,
 		    FIELD_DECL, NULL_TREE, type_info_ptr_type),
 	build_decl (BUILTINS_LOCATION,
 		    FIELD_DECL, NULL_TREE, type_info_ptr_type),
 	NULL);
 
   pop_abi_namespace ();
 }
 
+/* Helper for emit_support_tinfos. Emits the type_info descriptor of
+   a single type.  */
+
+void
+emit_support_tinfo_1 (tree bltn)
+{
+  tree types[3];
+
+  if (bltn == NULL_TREE)
+    return;
+  types[0] = bltn;
+  types[1] = build_pointer_type (bltn);
+  types[2] = build_pointer_type (cp_build_qualified_type (bltn,
+							  TYPE_QUAL_CONST));
+
+  for (int i = 0; i < 3; ++i)
+    {
+      tree tinfo = get_tinfo_decl (types[i]);
+      TREE_USED (tinfo) = 1;
+      mark_needed (tinfo);
+      /* The C++ ABI requires that these objects be COMDAT.  But,
+	 On systems without weak symbols, initialized COMDAT
+	 objects are emitted with internal linkage.  (See
+	 comdat_linkage for details.)  Since we want these objects
+	 to have external linkage so that copies do not have to be
+	 emitted in code outside the runtime library, we make them
+	 non-COMDAT here.  
+
+	 It might also not be necessary to follow this detail of the
+	 ABI.  */
+      if (!flag_weak || ! targetm.cxx.library_rtti_comdat ())
+	{
+	  gcc_assert (TREE_PUBLIC (tinfo) && !DECL_COMDAT (tinfo));
+	  DECL_INTERFACE_KNOWN (tinfo) = 1;
+	}
+    }
+}
+
 /* Emit the type_info descriptors which are guaranteed to be in the runtime
    support.  Generating them here guarantees consistency with the other
    structures.  We use the following heuristic to determine when the runtime
    is being generated.  If std::__fundamental_type_info is defined, and its
    destructor is defined, then the runtime is being built.  */
 
 void
 emit_support_tinfos (void)
 {
   /* Dummy static variable so we can put nullptr in the array; it will be
@@ -1500,56 +1538,23 @@  emit_support_tinfos (void)
 			get_identifier ("__fundamental_type_info"),
 			/*tag_scope=*/ts_current, false);
   pop_abi_namespace ();
   if (!COMPLETE_TYPE_P (bltn_type))
     return;
   dtor = CLASSTYPE_DESTRUCTORS (bltn_type);
   if (!dtor || DECL_EXTERNAL (dtor))
     return;
   doing_runtime = 1;
   for (ix = 0; fundamentals[ix]; ix++)
-    {
-      tree bltn = *fundamentals[ix];
-      tree types[3];
-      int i;
-
-      if (bltn == NULL_TREE)
-	continue;
-      types[0] = bltn;
-      types[1] = build_pointer_type (bltn);
-      types[2] = build_pointer_type (cp_build_qualified_type (bltn,
-							      TYPE_QUAL_CONST));
-
-      for (i = 0; i < 3; ++i)
-	{
-	  tree tinfo;
-
-	  tinfo = get_tinfo_decl (types[i]);
-	  TREE_USED (tinfo) = 1;
-	  mark_needed (tinfo);
-	  /* The C++ ABI requires that these objects be COMDAT.  But,
-	     On systems without weak symbols, initialized COMDAT
-	     objects are emitted with internal linkage.  (See
-	     comdat_linkage for details.)  Since we want these objects
-	     to have external linkage so that copies do not have to be
-	     emitted in code outside the runtime library, we make them
-	     non-COMDAT here.  
-
-	     It might also not be necessary to follow this detail of the
-	     ABI.  */
-	  if (!flag_weak || ! targetm.cxx.library_rtti_comdat ())
-	    {
-	      gcc_assert (TREE_PUBLIC (tinfo) && !DECL_COMDAT (tinfo));
-	      DECL_INTERFACE_KNOWN (tinfo) = 1;
-	    }
-	}
-    }
+    emit_support_tinfo_1 (*fundamentals[ix]);
+  for (tree t = registered_builtin_types; t; t = TREE_CHAIN (t))
+    emit_support_tinfo_1 (TREE_VALUE (t));
 }
 
 /* Finish a type info decl. DECL_PTR is a pointer to an unemitted
    tinfo decl.  Determine whether it needs emitting, and if so
    generate the initializer.  */
 
 bool
 emit_tinfo_decl (tree decl)
 {
   tree type = TREE_TYPE (DECL_NAME (decl));