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]

[PATCH] Use __aeabi_atexit for ARM EABI


Hi,

This is a patch from the csl-arm branch. The original thread is here:

http://gcc.gnu.org/ml/gcc-patches/2004-11/msg00406.html

The patch makes g++ use __aeabi_atexit rather than __cxa_atexit for registering static object destructors, as suggested by the ARM EABI.

Tested on x86_64-linux and cross from i686-linux to arm-none-eabi.

OK for head?

ChangeLog (Paul Brook):

 * target-def.h (TARGET_CXX_ATEXIT_NAME): Define.
 (TARGET_CXX): Add TARGET_CXX_ATEXIT_NAME.
 * target.h (gcc_target): Add cxx.atexit_name.
 * targhooks.c (default_cxx_atexit_name): New function.
 * targhooks.h (default_cxx_atexit_name): Add prototype.
 * config/arm/arm.c (arm_cxx_atexit_name): New function.
 (TARGET_CXX_ATEXIT_NAME): Define.
 * cp/decl.c (get_atexit_node): Use targetm.cxx.atexit_name.
 * doc/tm.texi: Document TARGET_CXX_ATEXIT_NAME.

Index: gcc/target-def.h
===================================================================
RCS file: /home/gcc/repos/gcc/gcc/gcc/target-def.h,v
retrieving revision 1.119
diff -c -p -r1.119 target-def.h
*** gcc/target-def.h	12 Apr 2005 06:33:23 -0000	1.119
--- gcc/target-def.h	19 Apr 2005 14:08:48 -0000
*************** Foundation, 59 Temple Place - Suite 330,
*** 477,482 ****
--- 477,486 ----
  #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT hook_bool_void_true
  #endif
  
+ #ifndef TARGET_CXX_ATEXIT_NAME
+ #define TARGET_CXX_ATEXIT_NAME default_cxx_atexit_name
+ #endif
+ 
  #define TARGET_CXX				\
    {						\
      TARGET_CXX_GUARD_TYPE,			\
*************** Foundation, 59 Temple Place - Suite 330,
*** 488,493 ****
--- 492,498 ----
      TARGET_CXX_KEY_METHOD_MAY_BE_INLINE,	\
      TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY,	\
      TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT,        \
+     TARGET_CXX_ATEXIT_NAME			\
    }
  
  /* The whole shebang.  */
Index: gcc/target.h
===================================================================
RCS file: /home/gcc/repos/gcc/gcc/gcc/target.h,v
retrieving revision 1.131
diff -c -p -r1.131 target.h
*** gcc/target.h	12 Apr 2005 06:33:23 -0000	1.131
--- gcc/target.h	19 Apr 2005 13:51:34 -0000
*************** struct gcc_target
*** 603,608 ****
--- 603,611 ----
         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 the name of the function used to register static object
+        destructors.  */
+     const char * (*atexit_name) (void);
    } cxx;
  
    /* Leave the boolean fields at the end.  */
Index: gcc/targhooks.c
===================================================================
RCS file: /home/gcc/repos/gcc/gcc/gcc/targhooks.c,v
retrieving revision 2.38
diff -c -p -r2.38 targhooks.c
*** gcc/targhooks.c	12 Mar 2005 00:34:04 -0000	2.38
--- gcc/targhooks.c	19 Apr 2005 13:40:17 -0000
*************** hook_callee_copies_named (CUMULATIVE_ARG
*** 206,211 ****
--- 206,220 ----
    return named;
  }
  
+ /* The ia64/generic C++ ABI defines __cxa_atexit.  */
+ 
+ const char *
+ default_cxx_atexit_name (void)
+ {
+   return "__cxa_atexit";
+ }
+ 
+ 
  /* Emit any directives required to unwind this instruction.  */
  
  void
Index: gcc/targhooks.h
===================================================================
RCS file: /home/gcc/repos/gcc/gcc/gcc/targhooks.h,v
retrieving revision 2.27
diff -c -p -r2.27 targhooks.h
*** gcc/targhooks.h	8 Mar 2005 21:01:42 -0000	2.27
--- gcc/targhooks.h	19 Apr 2005 13:52:51 -0000
*************** extern unsigned HOST_WIDE_INT default_sh
*** 36,41 ****
--- 36,42 ----
  
  extern tree default_cxx_guard_type (void);
  extern tree default_cxx_get_cookie_size (tree);
+ extern const char * default_cxx_atexit_name (void);
  
  extern bool hook_pass_by_reference_must_pass_in_stack
    (CUMULATIVE_ARGS *, enum machine_mode mode, tree, bool);
Index: gcc/config/arm/arm.c
===================================================================
RCS file: /home/gcc/repos/gcc/gcc/gcc/config/arm/arm.c,v
retrieving revision 1.442
diff -c -p -r1.442 arm.c
*** gcc/config/arm/arm.c	12 Apr 2005 06:33:25 -0000	1.442
--- gcc/config/arm/arm.c	19 Apr 2005 19:46:58 -0000
*************** static bool arm_cxx_cdtor_returns_this (
*** 174,179 ****
--- 174,180 ----
  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 const char * arm_cxx_atexit_name (void);
  static void arm_init_libfuncs (void);
  static unsigned HOST_WIDE_INT arm_shift_truncation_mask (enum machine_mode);
  
*************** static unsigned HOST_WIDE_INT arm_shift_
*** 308,313 ****
--- 309,317 ----
  #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_ATEXIT_NAME
+ #define TARGET_CXX_ATEXIT_NAME arm_cxx_atexit_name
+ 
  #undef TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY
  #define TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY \
    arm_cxx_determine_class_data_visibility
*************** arm_cxx_class_data_always_comdat (void)
*** 14346,14351 ****
--- 14350,14369 ----
       vague linkage if the class has no key function.  */
    return !TARGET_AAPCS_BASED;
  }
+ 
+ 
+ /* The EABI wants us to use __aeabi_atexit for registering static object
+    destructors.  */
+ 
+ static const char *
+ arm_cxx_atexit_name (void)
+ {
+   if (TARGET_AAPCS_BASED)
+     return "__aeabi_atexit";
+   else
+     return default_cxx_atexit_name ();
+ }
+ 
  
  void
  arm_set_return_address (rtx source, rtx scratch)
Index: gcc/cp/decl.c
===================================================================
RCS file: /home/gcc/repos/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1385
diff -c -p -r1.1385 decl.c
*** gcc/cp/decl.c	9 Apr 2005 03:18:14 -0000	1.1385
--- gcc/cp/decl.c	19 Apr 2005 13:40:18 -0000
*************** get_atexit_node (void)
*** 5020,5026 ****
        /* 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";
      }
    else
      {
--- 5020,5026 ----
        /* 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 = targetm.cxx.atexit_name ();
      }
    else
      {
Index: gcc/doc/tm.texi
===================================================================
RCS file: /home/gcc/repos/gcc/gcc/gcc/doc/tm.texi,v
retrieving revision 1.423
diff -c -p -r1.423 tm.texi
*** gcc/doc/tm.texi	15 Apr 2005 10:24:13 -0000	1.423
--- gcc/doc/tm.texi	19 Apr 2005 19:48:20 -0000
*************** classes whose virtual table will be emit
*** 8735,8740 ****
--- 8735,8746 ----
  unit will not be COMDAT.
  @end deftypefn
  
+ @deftypefn {Target Hook} const char * TARGET_CXX_ATEXIT_NAME (void)
+ This hook returns the name of the function to use for registering
+ static destructors when -fuse-cxa-atexit is in effect.
+ The default is @code{"__cxa_atexit"}.
+ @end deftypefn
+ 
  @node Misc
  @section Miscellaneous Parameters
  @cindex parameters, miscellaneous

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