This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: Add SymbianOS "notshared" attribute
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 4 Nov 2004 16:17:32 -0800
- Subject: PATCH: Add SymbianOS "notshared" attribute
- Reply-to: mark at codesourcery dot com
This patch adds support for __declspec(notshared), which is used on
Symbian OS as an equivalent to __attribute__((visibility("hidden")))
on class types.
Tested lightly, applied on the csl-arm-branch and on the mainline.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
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 Mark Mitchell <mark@codesourcery.com>
* testsuite/g++.dg/ext/visibility/symbian1.C: New test.
Index: config/arm/arm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/arm/arm.c,v
retrieving revision 1.303.2.61
diff -c -5 -p -r1.303.2.61 arm.c
*** config/arm/arm.c 3 Nov 2004 19:11:05 -0000 1.303.2.61
--- config/arm/arm.c 4 Nov 2004 23:34:32 -0000
*************** static unsigned long arm_compute_save_re
*** 111,120 ****
--- 111,121 ----
static unsigned long arm_compute_save_reg_mask (void);
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);
static int arm_comp_type_attributes (tree, tree);
static void arm_set_default_type_attributes (tree);
*************** const struct attribute_spec arm_attribut
*** 2611,2620 ****
--- 2612,2622 ----
{ "dllexport", 0, 0, true, false, false, NULL },
{ "interfacearm", 0, 0, true, false, false, arm_handle_fndecl_attribute },
#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 }
};
/* Handle an attribute requiring a FUNCTION_DECL;
*************** arm_handle_isr_attribute (tree *node, tr
*** 2690,2699 ****
--- 2692,2724 ----
}
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). */
static int
arm_comp_type_attributes (tree type1, tree type2)
Index: testsuite/g++.dg/ext/visibility/symbian1.C
===================================================================
RCS file: testsuite/g++.dg/ext/visibility/symbian1.C
diff -N testsuite/g++.dg/ext/visibility/symbian1.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/ext/visibility/symbian1.C 4 Nov 2004 23:34:32 -0000
***************
*** 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; }
+
Index: doc/extend.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/extend.texi,v
retrieving revision 1.228
diff -c -5 -p -r1.228 extend.texi
*** doc/extend.texi 1 Nov 2004 18:24:28 -0000 1.228
--- doc/extend.texi 5 Nov 2004 00:14:32 -0000
*************** main (void)
*** 3305,3314 ****
--- 3305,3337 ----
If you replaced @code{short_a} with @code{short} in the variable
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:
@code{ms_struct} and @code{gcc_struct}