From 46b9ff5ef895d3bd0409e131c2948ecb4d63f9bb Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 25 Apr 2005 19:35:18 +0000 Subject: [PATCH] * target-def.h (TARGET_CXX_USE_AEABI_ATEXIT): Define. * target.h (struct gcc_target): Add cxx.use_aeabi_atexit. * config/arm/arm.c (arm_cxx_atexit_name): New function. (TARGET_CXX_USE_AEABI_ATEXIT): New macro. * cp/decl.c (get_atexit_node): Reorder arguments for __aeabi_atexit. (register_dtor_fn): Likewise. * doc/tm.texi: Document TARGET_CXX_USE_AEABI_ATEXIT. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@98732 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 10 ++++++++++ gcc/config/arm/arm.c | 15 +++++++++++++++ gcc/cp/decl.c | 31 ++++++++++++++++++++++++++----- gcc/doc/tm.texi | 6 ++++++ gcc/target-def.h | 5 +++++ gcc/target.h | 3 +++ 6 files changed, 65 insertions(+), 5 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d99ba07d345..fea482b414c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2005-04-05 Paul Brook + + * target-def.h (TARGET_CXX_USE_AEABI_ATEXIT): Define. + * target.h (struct gcc_target): Add cxx.use_aeabi_atexit. + * config/arm/arm.c (arm_cxx_atexit_name): New function. + (TARGET_CXX_USE_AEABI_ATEXIT): New macro. + * cp/decl.c (get_atexit_node): Reorder arguments for __aeabi_atexit. + (register_dtor_fn): Likewise. + * doc/tm.texi: Document TARGET_CXX_USE_AEABI_ATEXIT. + 2005-04-25 Ian Lance Taylor * c-common.def (EXPR_STMT): Remove, moved to C++ frontend. diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 7349b1e2dc2..8189909f2eb 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -174,6 +174,7 @@ static bool arm_cxx_cdtor_returns_this (void); static bool arm_cxx_key_method_may_be_inline (void); static void arm_cxx_determine_class_data_visibility (tree); static bool arm_cxx_class_data_always_comdat (void); +static bool arm_cxx_use_aeabi_atexit (void); static void arm_init_libfuncs (void); static unsigned HOST_WIDE_INT arm_shift_truncation_mask (enum machine_mode); @@ -308,6 +309,9 @@ static unsigned HOST_WIDE_INT arm_shift_truncation_mask (enum machine_mode); #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_USE_AEABI_ATEXIT +#define TARGET_CXX_USE_AEABI_ATEXIT arm_cxx_use_aeabi_atexit + #undef TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY #define TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY \ arm_cxx_determine_class_data_visibility @@ -14354,6 +14358,17 @@ arm_cxx_class_data_always_comdat (void) return !TARGET_AAPCS_BASED; } + +/* The EABI says __aeabi_atexit should be used to register static + destructors. */ + +static bool +arm_cxx_use_aeabi_atexit (void) +{ + return TARGET_AAPCS_BASED; +} + + void arm_set_return_address (rtx source, rtx scratch) { diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 60b478ee3df..91f57ef0de5 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4998,6 +4998,7 @@ get_atexit_node (void) tree fn_type; tree fn_ptr_type; const char *name; + bool use_aeabi_atexit; if (atexit_node) return atexit_node; @@ -5011,6 +5012,7 @@ get_atexit_node (void) We build up the argument types and then then function type itself. */ + use_aeabi_atexit = targetm.cxx.use_aeabi_atexit (); /* First, build the pointer-to-function type for the first argument. */ arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node); @@ -5018,12 +5020,23 @@ get_atexit_node (void) fn_ptr_type = build_pointer_type (fn_type); /* Then, build the rest of the argument types. */ arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node); - arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types); - arg_types = tree_cons (NULL_TREE, fn_ptr_type, arg_types); + if (use_aeabi_atexit) + { + arg_types = tree_cons (NULL_TREE, fn_ptr_type, arg_types); + arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types); + } + else + { + arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types); + arg_types = tree_cons (NULL_TREE, fn_ptr_type, arg_types); + } /* And the final __cxa_atexit type. */ fn_type = build_function_type (integer_type_node, arg_types); fn_ptr_type = build_pointer_type (fn_type); - name = "__cxa_atexit"; + if (use_aeabi_atexit) + name = "__aeabi_atexit"; + else + name = "__cxa_atexit"; } else { @@ -5184,8 +5197,16 @@ register_dtor_fn (tree decl) args = tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, get_dso_handle_node (), 0), NULL_TREE); - args = tree_cons (NULL_TREE, null_pointer_node, args); - args = tree_cons (NULL_TREE, cleanup, args); + if (targetm.cxx.use_aeabi_atexit ()) + { + args = tree_cons (NULL_TREE, cleanup, args); + args = tree_cons (NULL_TREE, null_pointer_node, args); + } + else + { + args = tree_cons (NULL_TREE, null_pointer_node, args); + args = tree_cons (NULL_TREE, cleanup, args); + } } else args = tree_cons (NULL_TREE, cleanup, NULL_TREE); diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 42c5b0f1c9c..771461618cc 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -8735,6 +8735,12 @@ classes whose virtual table will be emitted in only one translation unit will not be COMDAT. @end deftypefn +@deftypefn {Target Hook} bool TARGET_CXX_USE_AEABI_ATEXIT (void) +This hook returns true if @code{__aeabi_atexit} (as defined by the ARM EABI) +should be used to register static destructors when @option{-fuse-cxa-atexit} +is in effect. The default is to return false to use @code{__cxa_atexit}. +@end deftypefn + @node Misc @section Miscellaneous Parameters @cindex parameters, miscellaneous diff --git a/gcc/target-def.h b/gcc/target-def.h index 44e3791f0ab..6e8a578341e 100644 --- a/gcc/target-def.h +++ b/gcc/target-def.h @@ -477,6 +477,10 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT hook_bool_void_true #endif +#ifndef TARGET_CXX_USE_AEABI_ATEXIT +#define TARGET_CXX_USE_AEABI_ATEXIT hook_bool_void_false +#endif + #define TARGET_CXX \ { \ TARGET_CXX_GUARD_TYPE, \ @@ -488,6 +492,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. TARGET_CXX_KEY_METHOD_MAY_BE_INLINE, \ TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY, \ TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT, \ + TARGET_CXX_USE_AEABI_ATEXIT \ } /* The whole shebang. */ diff --git a/gcc/target.h b/gcc/target.h index 2cb4db278a0..1786379ed55 100644 --- a/gcc/target.h +++ b/gcc/target.h @@ -603,6 +603,9 @@ struct gcc_target class data for classes whose virtual table will be emitted in only one translation unit will not be COMDAT. */ bool (*class_data_always_comdat) (void); + /* Returns true if __aeabi_atexit should be used to register static + destructors. */ + bool (*use_aeabi_atexit) (void); } cxx; /* Leave the boolean fields at the end. */ -- 2.11.4.GIT