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]

[C++ PATCH] Use default visibility for cp/rtti.c __cxxabiv1::* symbols (PR c++/35368)


Hi!

The following patch ensures all __cxxabiv1 namespace rtti.c generated
symbols have default visibility, even if e.g. #pragma GCC visibility
push(hidden) is in effect.
Bootstrapped/regtested on x86_64-linux, ok for trunk/4.3?

2008-02-26  Jakub Jelinek  <jakub@redhat.com>

	PR c++/35368
	* rtti.c: Include c-pragma.h.
	(push_abi_namespace, pop_abi_namespace): New functions.
	(build_dynamic_cast_1, tinfo_base_init, get_pseudo_ti_index,
	create_tinfo_types, emit_support_tinfos): Use them.
	* Make-lang.in (cp/rtti.o): Depend on $(C_PRAGMA_H).

	* g++.dg/ext/visibility/typeinfo2.C: New test.
	* g++.dg/ext/visibility/typeinfo3.C: New test.

--- gcc/cp/rtti.c.jj	2008-02-11 14:45:57.000000000 +0100
+++ gcc/cp/rtti.c	2008-02-26 17:42:21.000000000 +0100
@@ -1,6 +1,6 @@
 /* RunTime Type Identification
    Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-   2005, 2006, 2007
+   2005, 2006, 2007, 2008
    Free Software Foundation, Inc.
    Mostly written by Jason Merrill (jason@cygnus.com).
 
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3.  
 #include "toplev.h"
 #include "convert.h"
 #include "target.h"
+#include "c-pragma.h"
 
 /* C++ returns type information to the user in struct type_info
    objects. We also use type information to implement dynamic_cast and
@@ -124,6 +125,19 @@ static bool typeinfo_in_lib_p (tree);
 
 static int doing_runtime = 0;
 
+static void
+push_abi_namespace (void)
+{
+  push_nested_namespace (abi_node);
+  push_visibility ("default");
+}
+
+static void
+pop_abi_namespace (void)
+{
+  pop_visibility ();
+  pop_nested_namespace (abi_node);
+}
 
 /* Declare language defined type_info type and a pointer to const
    type_info.  This is incomplete here, and will be completed when
@@ -669,10 +683,9 @@ build_dynamic_cast_1 (tree type, tree ex
 	    {
 	      tree tmp;
 	      tree tinfo_ptr;
-	      tree ns = abi_node;
 	      const char *name;
 
-	      push_nested_namespace (ns);
+	      push_abi_namespace ();
 	      tinfo_ptr = xref_tag (class_type,
 				    get_identifier ("__class_type_info"),
 				    /*tag_scope=*/ts_current, false);
@@ -689,7 +702,7 @@ build_dynamic_cast_1 (tree type, tree ex
 	      tmp = build_function_type (ptr_type_node, tmp);
 	      dcast_fn = build_library_fn_ptr (name, tmp);
 	      DECL_IS_PURE (dcast_fn) = 1;
-	      pop_nested_namespace (ns);
+	      pop_abi_namespace ();
 	      dynamic_cast_node = dcast_fn;
 	    }
 	  result = build_cxx_call (dcast_fn, 4, elems);
@@ -848,10 +861,10 @@ tinfo_base_init (tinfo_s *ti, tree targe
   if (!vtable_ptr)
     {
       tree real_type;
-      push_nested_namespace (abi_node);
+      push_abi_namespace ();
       real_type = xref_tag (class_type, ti->name,
 			    /*tag_scope=*/ts_current, false);
-      pop_nested_namespace (abi_node);
+      pop_abi_namespace ();
 
       if (!COMPLETE_TYPE_P (real_type))
 	{
@@ -1268,14 +1281,14 @@ get_pseudo_ti_index (tree type)
 					     TK_BASE_TYPE)->type,
 				  array_domain);
 
-	      push_nested_namespace (abi_node);
+	      push_abi_namespace ();
 	      create_pseudo_type_info
 		(ix, "__vmi_class_type_info",
 		 build_decl (FIELD_DECL, NULL_TREE, integer_type_node),
 		 build_decl (FIELD_DECL, NULL_TREE, integer_type_node),
 		 build_decl (FIELD_DECL, NULL_TREE, base_array),
 		 NULL);
-	      pop_nested_namespace (abi_node);
+	      pop_abi_namespace ();
 	      break;
 	    }
 	}
@@ -1298,7 +1311,7 @@ create_tinfo_types (void)
 
   VEC_safe_grow (tinfo_s, gc, tinfo_descs, TK_FIXED);
 
-  push_nested_namespace (abi_node);
+  push_abi_namespace ();
 
   /* Create the internal type_info structure. This is used as a base for
      the other structures.  */
@@ -1376,7 +1389,7 @@ create_tinfo_types (void)
 	build_decl (FIELD_DECL, NULL_TREE, type_info_ptr_type),
 	NULL);
 
-  pop_nested_namespace (abi_node);
+  pop_abi_namespace ();
 }
 
 /* Emit the type_info descriptors which are guaranteed to be in the runtime
@@ -1404,11 +1417,11 @@ emit_support_tinfos (void)
   int ix;
   tree bltn_type, dtor;
 
-  push_nested_namespace (abi_node);
+  push_abi_namespace ();
   bltn_type = xref_tag (class_type,
 			get_identifier ("__fundamental_type_info"),
 			/*tag_scope=*/ts_current, false);
-  pop_nested_namespace (abi_node);
+  pop_abi_namespace ();
   if (!COMPLETE_TYPE_P (bltn_type))
     return;
   dtor = CLASSTYPE_DESTRUCTORS (bltn_type);
--- gcc/cp/Make-lang.in.jj	2008-02-11 14:45:57.000000000 +0100
+++ gcc/cp/Make-lang.in	2008-02-26 17:29:57.000000000 +0100
@@ -264,7 +264,7 @@ cp/tree.o: cp/tree.c $(CXX_TREE_H) $(TM_
   $(TARGET_H) debug.h $(TREE_FLOW_H)
 cp/ptree.o: cp/ptree.c $(CXX_TREE_H) $(TM_H)
 cp/rtti.o: cp/rtti.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h convert.h \
-  $(TARGET_H) gt-cp-rtti.h
+  $(TARGET_H) $(C_PRAGMA_H) gt-cp-rtti.h
 cp/except.o: cp/except.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) $(RTL_H) except.h \
   toplev.h cp/cfns.h $(EXPR_H) libfuncs.h $(TREE_INLINE_H) $(TARGET_H)
 cp/expr.o: cp/expr.c $(CXX_TREE_H) $(TM_H) $(RTL_H) $(FLAGS_H) $(EXPR_H) \
--- gcc/testsuite/g++.dg/ext/visibility/typeinfo2.C.jj	2008-02-26 17:53:03.000000000 +0100
+++ gcc/testsuite/g++.dg/ext/visibility/typeinfo2.C	2008-02-26 18:01:13.000000000 +0100
@@ -0,0 +1,23 @@
+// PR c++/35368
+// { dg-require-visibility "" }
+
+#pragma GCC visibility push (hidden)
+
+struct A
+{
+  A();
+  virtual ~A() { }
+};
+
+A::A()
+{
+}
+
+void foo(A *a)
+{
+  delete a;
+}
+
+// { dg-final { scan-not-hidden "_ZTVN10__cxxabiv117__class_type_infoE" } }
+// { dg-final { scan-hidden "_ZTI1A" } }
+// { dg-final { scan-hidden "_ZTV1A" } }
--- gcc/testsuite/g++.dg/ext/visibility/typeinfo3.C.jj	2008-02-26 17:53:03.000000000 +0100
+++ gcc/testsuite/g++.dg/ext/visibility/typeinfo3.C	2008-02-26 18:04:38.000000000 +0100
@@ -0,0 +1,24 @@
+// PR c++/35368
+// { dg-require-visibility "" }
+
+#pragma GCC visibility push (hidden)
+
+#include <typeinfo>
+
+const std::type_info& info1 = typeid(int []);
+const std::type_info& info2 = typeid(int);
+enum E { e = 0 };
+const std::type_info& info3 = typeid(E);
+struct S { S (); };
+const std::type_info& info4 = typeid(S);
+const std::type_info& info5 = typeid(int *);
+
+// { dg-final { scan-not-hidden "_ZTVN10__cxxabiv117__array_type_infoE" } }
+// { dg-final { scan-not-hidden "_ZTVN10__cxxabiv116__enum_type_infoE" } }
+// { dg-final { scan-hidden "_ZTI1S" } }
+// { dg-final { scan-hidden "_ZTS1S" } }
+// { dg-final { scan-hidden "info1" } }
+// { dg-final { scan-hidden "info2" } }
+// { dg-final { scan-hidden "info3" } }
+// { dg-final { scan-hidden "info4" } }
+// { dg-final { scan-hidden "info5" } }

	Jakub


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