From 505970fc3324e2a0c00f5d82d66f62bae133e282 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Wed, 1 Sep 2004 03:45:30 +0000 Subject: [PATCH] target-def.h (TARGET_CXX): Add TARGET_CXX_EXPORT_CLASS_DATA. * target-def.h (TARGET_CXX): Add TARGET_CXX_EXPORT_CLASS_DATA. * target.h (cxx): Add export_class_data. * config/arm/arm.c (arm_cxx_export_class_data): New function. (TARGET_CXX_EXPORT_CLASS_DATA): Use it. * testsuite/g++.dg/ext/visibility/arm1.C: New test. * cp-tree.h (DECL_CONSTRUCTION_VTABLE_P): New macro. * class.c (build_ctor_vtbl_group): Set DECL_CONSTRUCTION_VTABLE_P. * decl2.c (determine_visibility): Honor TARGET_CXX_EXPORT_CLASS_DATA. * g++.dg/ext/visibility/arm1.C: New test. From-SVN: r86867 --- gcc/ChangeLog | 8 ++++++++ gcc/config/arm/arm.c | 27 +++++++++++++++++++++++++++ gcc/config/arm/bpabi.h | 2 +- gcc/cp/ChangeLog | 5 +++++ gcc/cp/class.c | 1 + gcc/cp/cp-tree.h | 7 +++++++ gcc/cp/decl2.c | 21 ++++++++++++++------- gcc/doc/tm.texi | 8 ++++++++ gcc/target-def.h | 23 ++++++++++++++--------- gcc/target.h | 4 ++++ gcc/testsuite/ChangeLog | 4 ++++ 11 files changed, 93 insertions(+), 17 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 67301eb8157..55d646e834d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2004-08-31 Mark Mitchell + + * target-def.h (TARGET_CXX): Add TARGET_CXX_EXPORT_CLASS_DATA. + * target.h (cxx): Add export_class_data. + * config/arm/arm.c (arm_cxx_export_class_data): New function. + (TARGET_CXX_EXPORT_CLASS_DATA): Use it. + * testsuite/g++.dg/ext/visibility/arm1.C: New test. + 2004-08-31 Kaz Kojima * config/sh/sh.c (output_branch): Check the insn length possibly diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 9d9acb2d39f..52566be805a 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -172,6 +172,8 @@ static bool arm_cxx_guard_mask_bit (void); static tree arm_get_cookie_size (tree); static bool arm_cookie_has_size (void); static bool arm_cxx_cdtor_returns_this (void); +static bool arm_cxx_key_method_may_be_inline (void); +static bool arm_cxx_export_class_data (void); static void arm_init_libfuncs (void); @@ -296,6 +298,12 @@ static void arm_init_libfuncs (void); #undef TARGET_CXX_CDTOR_RETURNS_THIS #define TARGET_CXX_CDTOR_RETURNS_THIS arm_cxx_cdtor_returns_this +#undef TARGET_CXX_KEY_METHOD_MAY_BE_INLINE +#define TARGET_CXX_KEY_METHOD_MAY_BE_INLINE arm_cxx_key_method_may_be_inline + +#undef TARGET_CXX_EXPORT_CLASS_DATA +#define TARGET_CXX_EXPORT_CLASS_DATA arm_cxx_export_class_data + struct gcc_target targetm = TARGET_INITIALIZER; /* Obstack for minipool constant handling. */ @@ -14204,6 +14212,25 @@ arm_cxx_cdtor_returns_this (void) return TARGET_AAPCS_BASED; } +/* The EABI says that an inline function may never be the key + method. */ + +static bool +arm_cxx_key_method_may_be_inline (void) +{ + return !TARGET_AAPCS_BASED; +} + +/* The EABI says that the virtual table, etc., for a class must be + exported if it has a key method. The EABI does not specific the + behavior if there is no key method, but there is no harm in + exporting the class data in that case too. */ + +static bool +arm_cxx_export_class_data (void) +{ + return TARGET_AAPCS_BASED; +} void arm_set_return_address (rtx source, rtx scratch) diff --git a/gcc/config/arm/bpabi.h b/gcc/config/arm/bpabi.h index 4831dfb61bc..60d6e75b73a 100644 --- a/gcc/config/arm/bpabi.h +++ b/gcc/config/arm/bpabi.h @@ -46,7 +46,7 @@ "%{static:-Bstatic} %{shared:-shared} %{symbolic:-Bsymbolic} " \ "-X" -#if defined (__thumb__) && !defined (__THUMB_INTERWORK) +#if defined (__thumb__) && !defined (__THUMB_INTERWORK__) #define RENAME_LIBRARY_SET ".thumb_set" #else #define RENAME_LIBRARY_SET ".set" diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0a0fdfd4ff5..929bde0077e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2004-08-31 Mark Mitchell + * cp-tree.h (DECL_CONSTRUCTION_VTABLE_P): New macro. + * class.c (build_ctor_vtbl_group): Set DECL_CONSTRUCTION_VTABLE_P. + * decl2.c (determine_visibility): Honor + TARGET_CXX_EXPORT_CLASS_DATA. + * class.c (key_method): Rename to ... (determine_key_method): ... this. (finish_struct_1): Adjust accordingly. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 84c75878888..957151d33eb 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -6996,6 +6996,7 @@ build_ctor_vtbl_group (tree binfo, tree t) constructing the addresses of secondary vtables in the construction vtable group. */ vtbl = build_vtable (t, id, ptr_type_node); + DECL_CONSTRUCTION_VTABLE_P (vtbl) = 1; list = build_tree_list (vtbl, NULL_TREE); accumulate_vtbl_inits (binfo, TYPE_BINFO (TREE_TYPE (binfo)), binfo, t, list); diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index a6db5532023..35eb3a7766c 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -74,6 +74,7 @@ struct diagnostic_context; 5: C_IS_RESERVED_WORD (in IDENTIFIER_NODE) DECL_VTABLE_OR_VTT_P (in VAR_DECL) 6: IDENTIFIER_REPO_CHOSEN (in IDENTIFIER_NODE) + DECL_CONSTRUCTION_VTABLE_P (in VAR_DECL) Usage of TYPE_LANG_FLAG_?: 0: TYPE_DEPENDENT_P @@ -1992,6 +1993,12 @@ struct lang_decl GTY(()) /* 1 iff VAR_DECL node NODE is virtual table or VTT. */ #define DECL_VTABLE_OR_VTT_P(NODE) TREE_LANG_FLAG_5 (VAR_DECL_CHECK (NODE)) +/* Returns 1 iff VAR_DECL is a construction virtual table. + DECL_VTABLE_OR_VTT_P will be true in this case and must be checked + before using this macro. */ +#define DECL_CONSTRUCTION_VTABLE_P(NODE) \ + TREE_LANG_FLAG_6 (VAR_DECL_CHECK (NODE)) + /* 1 iff NODE is function-local, but for types. */ #define LOCAL_CLASS_P(NODE) \ (decl_function_context (TYPE_MAIN_DECL (NODE)) != NULL_TREE) diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index d02180a44af..c26d48fe954 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1655,17 +1655,24 @@ determine_visibility (tree decl) the visibility of their containing class. */ if (class_type) { - if (TARGET_DLLIMPORT_DECL_ATTRIBUTES - && lookup_attribute ("dllexport", TYPE_ATTRIBUTES (class_type))) + if (targetm.cxx.export_class_data () + && (DECL_TINFO_P (decl) + || (DECL_VTABLE_OR_VTT_P (decl) + /* Construction virtual tables are not emitted + because they cannot be referred to from other + object files; their name is not standardized by + the ABI. */ + && !DECL_CONSTRUCTION_VTABLE_P (decl)))) + DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT; + else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES + && lookup_attribute ("dllexport", TYPE_ATTRIBUTES (class_type))) { DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT; DECL_VISIBILITY_SPECIFIED (decl) = 1; - return; } - - if (TREE_CODE (decl) == FUNCTION_DECL - && DECL_DECLARED_INLINE_P (decl) - && visibility_options.inlines_hidden) + else if (TREE_CODE (decl) == FUNCTION_DECL + && DECL_DECLARED_INLINE_P (decl) + && visibility_options.inlines_hidden) { DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN; DECL_VISIBILITY_SPECIFIED (decl) = 1; diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index d1e59cf424a..bba444c0fbe 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -8538,6 +8538,14 @@ some variants of the ABI, an inline function can never be the key method. The default is to return @code{true}. @end deftypefn +@deftypefn {Target Hook} bool TARGET_CXX_EXPORT_CLASS_DATA (void) +If this hook returns false (the default), then virtual tables and RTTI +data structures will have the ELF visibility of their containing +class. If this hook returns true, then these data structures will +have ELF ``default'' visibility, independently of the visibility of +the containing class. +@end deftypefn + @node Misc @section Miscellaneous Parameters @cindex parameters, miscellaneous diff --git a/gcc/target-def.h b/gcc/target-def.h index e49d05584ed..3b4c11b0694 100644 --- a/gcc/target-def.h +++ b/gcc/target-def.h @@ -441,15 +441,20 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define TARGET_CXX_KEY_METHOD_MAY_BE_INLINE hook_bool_void_true #endif -#define TARGET_CXX \ - { \ - TARGET_CXX_GUARD_TYPE, \ - TARGET_CXX_GUARD_MASK_BIT, \ - TARGET_CXX_GET_COOKIE_SIZE, \ - TARGET_CXX_COOKIE_HAS_SIZE, \ - TARGET_CXX_IMPORT_EXPORT_CLASS, \ - TARGET_CXX_CDTOR_RETURNS_THIS, \ - TARGET_CXX_KEY_METHOD_MAY_BE_INLINE \ +#ifndef TARGET_CXX_EXPORT_CLASS_DATA +#define TARGET_CXX_EXPORT_CLASS_DATA hook_bool_void_false +#endif + +#define TARGET_CXX \ + { \ + TARGET_CXX_GUARD_TYPE, \ + TARGET_CXX_GUARD_MASK_BIT, \ + TARGET_CXX_GET_COOKIE_SIZE, \ + TARGET_CXX_COOKIE_HAS_SIZE, \ + TARGET_CXX_IMPORT_EXPORT_CLASS, \ + TARGET_CXX_CDTOR_RETURNS_THIS, \ + TARGET_CXX_KEY_METHOD_MAY_BE_INLINE, \ + TARGET_CXX_EXPORT_CLASS_DATA \ } /* The whole shebang. */ diff --git a/gcc/target.h b/gcc/target.h index 57b38cf25f4..035aeed4426 100644 --- a/gcc/target.h +++ b/gcc/target.h @@ -521,6 +521,10 @@ struct gcc_target itself. Returning true is the behavior required by the Itanium C++ ABI. */ bool (*key_method_may_be_inline) (void); + /* Returns true if all class data (virtual tables, type info, + etc.) should be exported from the current DLL, even when the + associated class is not exported. */ + bool (*export_class_data) (void); } cxx; /* Leave the boolean fields at the end. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 04f794bcea9..203f6a6fffd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2004-08-31 Mark Mitchell + + * g++.dg/ext/visibility/arm1.C: New test. + 2004-08-31 Geoffrey Keating * gcc.dg/funcdef-storage-1.c: Add dg-options to suppress -- 2.30.2