From a79b1d933a7c38b74ee89cb3bcdd55d6f2cc8ccc Mon Sep 17 00:00:00 2001
From: mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 5 Nov 2004 00:18:51 +0000
Subject: [PATCH] 	* config/arm/arm.c (arm_handle_notshared_attribute):
 New function. 	* doc/extend.texi: Document "notshared" attribute.

	* testsuite/g++.dg/ext/visibility/symbian1.C: New test.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@90099 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog                                 |  5 ++++
 gcc/config/arm/arm.c                          | 25 +++++++++++++++++++
 gcc/doc/extend.texi                           | 23 +++++++++++++++++
 gcc/testsuite/ChangeLog                       |  4 +++
 .../g++.dg/ext/visibility/symbian1.C          | 22 ++++++++++++++++
 5 files changed, 79 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/ext/visibility/symbian1.C

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 59b2a1b76fb0..239dceccacf8 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2004-11-04  Mark Mitchell  <mark@codesourcery.com>
+
+	* config/arm/arm.c (arm_handle_notshared_attribute): New function.
+	* doc/extend.texi: Document "notshared" attribute.
+	
 2004-11-04  Kazu Hirata  <kazu@cs.umass.edu>
 
 	* tree-phinodes.c (make_phi_node): Make it static.
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 498218d077b2..730877bdc237 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -114,6 +114,7 @@ static unsigned long arm_isr_value (tree);
 static unsigned long arm_compute_func_type (void);
 static tree arm_handle_fndecl_attribute (tree *, tree, tree, int, bool *);
 static tree arm_handle_isr_attribute (tree *, tree, tree, int, bool *);
+static tree arm_handle_notshared_attribute (tree *, tree, tree, int, bool *);
 static void arm_output_function_epilogue (FILE *, HOST_WIDE_INT);
 static void arm_output_function_prologue (FILE *, HOST_WIDE_INT);
 static void thumb_output_function_prologue (FILE *, HOST_WIDE_INT);
@@ -2589,6 +2590,7 @@ const struct attribute_spec arm_attribute_table[] =
 #elif TARGET_DLLIMPORT_DECL_ATTRIBUTES
   { "dllimport",    0, 0, false, false, false, handle_dll_attribute },
   { "dllexport",    0, 0, false, false, false, handle_dll_attribute },
+  { "notshared",    0, 0, false, true, false, arm_handle_notshared_attribute },
 #endif
   { NULL,           0, 0, false, false, false, NULL }
 };
@@ -2668,6 +2670,29 @@ arm_handle_isr_attribute (tree *node, tree name, tree args, int flags,
   return NULL_TREE;
 }
 
+/* Handle the "notshared" attribute.  This attribute is another way of
+   requesting hidden visibility.  ARM's compiler supports
+   "__declspec(notshared)"; we support the same thing via an
+   attribute.  */
+
+static tree
+arm_handle_notshared_attribute (tree *node, 
+				tree name ATTRIBUTE_UNUSED, 
+				tree args ATTRIBUTE_UNUSED, 
+				int flags ATTRIBUTE_UNUSED, 
+				bool *no_add_attrs)
+{
+  tree decl = TYPE_NAME (*node);
+
+  if (decl)
+    {
+      DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
+      DECL_VISIBILITY_SPECIFIED (decl) = 1;
+      *no_add_attrs = false;
+    }
+  return NULL_TREE;
+}
+
 /* Return 0 if the attributes for two types are incompatible, 1 if they
    are compatible, and 2 if they are nearly compatible (which causes a
    warning to be generated).  */
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index a4cbb2f69c0a..0e5e970e3984 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -3307,6 +3307,29 @@ declaration, the above program would abort when compiled with
 @option{-fstrict-aliasing}, which is on by default at @option{-O2} or
 above in recent GCC versions.
 
+@subsection ARM Type Attributes
+
+On those ARM targets that support @code{dllimport} (such as Symbian
+OS), you can use the @code{notshared} attribute to indicate that the 
+virtual table and other similar data for a class should not be
+exported from a DLL.  For example:
+
+@smallexample
+class __declspec(notshared) C @{
+public:
+  __declspec(dllimport) C(); 
+  virtual void f();
+@}
+
+__declspec(dllexport)
+C::C() @{@}
+@end smallexample
+
+In this code, @code{C::C} is exported from the current DLL, but the
+virtual table for @code{C} is not exported.  (You can use
+@code{__attribute__} instead of @code{__declspec} if you prefer, but
+most Symbian OS code uses @code{__declspec}.)
+
 @subsection i386 Type Attributes
 
 Two attributes are currently defined for i386 configurations:
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4e27d5110d6e..69f4038729a0 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2004-11-04  Mark Mitchell  <mark@codesourcery.com>
+
+	* testsuite/g++.dg/ext/visibility/symbian1.C: New test.
+	
 2004-11-04  Eric Botcazou  <ebotcazou@libertysurf.fr>
 
 	* gcc.dg/pragma-align.c (sixteen): Use 8-byte alignment
diff --git a/gcc/testsuite/g++.dg/ext/visibility/symbian1.C b/gcc/testsuite/g++.dg/ext/visibility/symbian1.C
new file mode 100644
index 000000000000..864ab2bb9eb5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/visibility/symbian1.C
@@ -0,0 +1,22 @@
+// { dg-do compile { target arm*-*-symbianelf* } }
+// Class data should not be exported.
+// { dg-final { scan-hidden "_ZTV2K3" } }
+// But the constructor and destructor should be exported.
+// { dg-final { scan-not-hidden "_ZN2K3C2Ev" } }
+// { dg-final { scan-not-hidden "_ZN2K3D0Ev" } }
+
+class __declspec(notshared) K3 {
+public:
+  __declspec(dllimport) K3();
+  __declspec(dllimport) virtual ~K3();
+  virtual int m1();
+};
+
+__declspec(dllexport)
+  K3::K3(){}
+
+__declspec(dllexport)
+  K3::~K3(){}
+
+int K3::m1() { return 1; }
+
-- 
GitLab