]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-decl.c (static_ctors): Move to c-common.c.
authorMark Mitchell <mark@codesourcery.com>
Mon, 26 Feb 2007 21:14:24 +0000 (21:14 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Mon, 26 Feb 2007 21:14:24 +0000 (21:14 +0000)
* c-decl.c (static_ctors): Move to c-common.c.
(static_dtors): Likewise.
(finish_function): Use c_record_cdtor_fn.
(build_cdtor): Move to c-common.c.
(c_write_global_declarations): Use c_build_cdtor_fns.
* c-common.h (static_ctors): Declare.
(static_dtors): Likewise.
(c_record_cdtor_fn): Likewise.
(c_build_cdtor_fns): Likewise.
* c-common.c (static_ctors): New variable.
(static_dtors): Likewise.
(c_record_cdtor_fn): New function.
(build_cdtor): Move from c-decl.c
(c_build_cdtor_fns): New function.

* semantics.c (expand_or_defer_fn): Call c_record_cdtor_fn.
* decl2.c (cp_write_gloabl_declarations): Call c_build_cdtor_fns.

From-SVN: r122341

gcc/ChangeLog
gcc/c-common.c
gcc/c-common.h
gcc/c-decl.c
gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/cp/semantics.c

index c71aec1f10ed2ee07b4ade2b2f7304f352401126..8388cef151cb8d786c1c6c20f7b9638a16ed66e2 100644 (file)
@@ -1,5 +1,20 @@
 2007-02-26  Mark Mitchell  <mark@codesourcery.com>
 
+       * c-decl.c (static_ctors): Move to c-common.c.
+       (static_dtors): Likewise.
+       (finish_function): Use c_record_cdtor_fn.
+       (build_cdtor): Move to c-common.c.
+       (c_write_global_declarations): Use c_build_cdtor_fns.
+       * c-common.h (static_ctors): Declare.
+       (static_dtors): Likewise.
+       (c_record_cdtor_fn): Likewise.
+       (c_build_cdtor_fns): Likewise.
+       * c-common.c (static_ctors): New variable.
+       (static_dtors): Likewise.
+       (c_record_cdtor_fn): New function.
+       (build_cdtor): Move from c-decl.c
+       (c_build_cdtor_fns): New function.
+
        * output.h (assemble_addr_to_section): Declare.
        (get_cdtor_priority_section): Likewise.
        * varasm.c (assemble_addr_to_section): New function.
index 6d1606c0b0eded556d6fba0d40b794aa18bdda20..0cd4d1a8eb4e63e4e414a2919f984ec4b586c93c 100644 (file)
@@ -663,6 +663,11 @@ const struct attribute_spec c_common_format_attribute_table[] =
   { NULL,                     0, 0, false, false, false, NULL }
 };
 
+/* Functions called automatically at the beginning and end of execution.  */
+
+tree static_ctors;
+tree static_dtors;
+
 /* Push current bindings for the function name VAR_DECLS.  */
 
 void
@@ -6875,4 +6880,59 @@ warn_for_unused_label (tree label)
     }
 }
 
+/* If FNDECL is a static constructor or destructor, add it to the list
+   of functions to be called by the file scope initialization
+   function.  */
+
+void
+c_record_cdtor_fn (tree fndecl)
+{
+  if (targetm.have_ctors_dtors)
+    return;
+
+  if (DECL_STATIC_CONSTRUCTOR (fndecl))
+    static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
+  if (DECL_STATIC_DESTRUCTOR (fndecl))
+    static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
+}
+
+/* Synthesize a function which calls all the global ctors or global
+   dtors in this file.  This is only used for targets which do not
+   support .ctors/.dtors sections.  FIXME: Migrate into cgraph.  */
+static void
+build_cdtor (int method_type, tree cdtors)
+{
+  tree body = 0;
+
+  if (!cdtors)
+    return;
+
+  for (; cdtors; cdtors = TREE_CHAIN (cdtors))
+    append_to_statement_list (build_function_call (TREE_VALUE (cdtors), 0),
+                             &body);
+
+  cgraph_build_static_cdtor (method_type, body, DEFAULT_INIT_PRIORITY);
+}
+
+/* Generate functions to call static constructors and destructors
+   for targets that do not support .ctors/.dtors sections.  These
+   functions have magic names which are detected by collect2.  */
+
+void
+c_build_cdtor_fns (void)
+{
+  if (!targetm.have_ctors_dtors)
+    {
+      build_cdtor ('I', static_ctors); 
+      static_ctors = NULL_TREE;
+      build_cdtor ('D', static_dtors); 
+      static_dtors = NULL_TREE;
+    }
+  else
+    {
+      gcc_assert (!static_ctors);
+      gcc_assert (!static_dtors);
+    }
+}
+
 #include "gt-c-common.h"
index 4e25ede957c3f9917fced0c7fa008f06996116da..e52b83208af56458534ce1a96ab0d99f6c12b20d 100644 (file)
@@ -988,4 +988,11 @@ extern tree c_omp_remap_decl (tree, bool);
 #define GCC_DIAG_STYLE __gcc_cdiag__
 #endif
 
+/* Functions called automatically at the beginning and end of execution.  */
+extern GTY (()) tree static_ctors;
+extern GTY (()) tree static_dtors;
+
+extern void c_record_cdtor_fn (tree);
+extern void c_build_cdtor_fns (void);
+
 #endif /* ! GCC_C_COMMON_H */
index ec567a5451d9f4188b6e835f0f78c5311222a75a..a84dea67f30e1995c300d4c818f9157f08d8c93b 100644 (file)
@@ -411,11 +411,6 @@ static bool keep_next_level_flag;
 
 static bool next_is_function_body;
 
-/* Functions called automatically at the beginning and end of execution.  */
-
-static GTY(()) tree static_ctors;
-static GTY(()) tree static_dtors;
-
 /* Forward declarations.  */
 static tree lookup_name_in_scope (tree, struct c_scope *);
 static tree c_make_fname_decl (tree, int);
@@ -6776,14 +6771,9 @@ finish_function (void)
      info for the epilogue.  */
   cfun->function_end_locus = input_location;
 
-  /* If we don't have ctors/dtors sections, and this is a static
-     constructor or destructor, it must be recorded now.  */
-  if (DECL_STATIC_CONSTRUCTOR (fndecl)
-      && !targetm.have_ctors_dtors)
-    static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
-  if (DECL_STATIC_DESTRUCTOR (fndecl)
-      && !targetm.have_ctors_dtors)
-    static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
+  /* Keep track of functions declared with the "constructor" and
+     "destructor" attribute.  */
+  c_record_cdtor_fn (fndecl);
 
   /* Finalize the ELF visibility for the function.  */
   c_determine_visibility (fndecl);
@@ -7812,24 +7802,6 @@ finish_declspecs (struct c_declspecs *specs)
   return specs;
 }
 
-/* Synthesize a function which calls all the global ctors or global
-   dtors in this file.  This is only used for targets which do not
-   support .ctors/.dtors sections.  FIXME: Migrate into cgraph.  */
-static void
-build_cdtor (int method_type, tree cdtors)
-{
-  tree body = 0;
-
-  if (!cdtors)
-    return;
-
-  for (; cdtors; cdtors = TREE_CHAIN (cdtors))
-    append_to_statement_list (build_function_call (TREE_VALUE (cdtors), 0),
-                             &body);
-
-  cgraph_build_static_cdtor (method_type, body, DEFAULT_INIT_PRIORITY);
-}
-
 /* A subroutine of c_write_global_declarations.  Perform final processing
    on one file scope's declarations (or the external scope's declarations),
    GLOBALS.  */
@@ -7923,11 +7895,9 @@ c_write_global_declarations (void)
     c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
   c_write_global_declarations_1 (BLOCK_VARS (ext_block));
 
-  /* Generate functions to call static constructors and destructors
-     for targets that do not support .ctors/.dtors sections.  These
-     functions have magic names which are detected by collect2.  */
-  build_cdtor ('I', static_ctors); static_ctors = 0;
-  build_cdtor ('D', static_dtors); static_dtors = 0;
+  /* Call functions declared with the "constructor" or "destructor"
+     attribute.  */
+  c_build_cdtor_fns ();
 
   /* We're done parsing; proceed to optimize and emit assembly.
      FIXME: shouldn't be the front end's responsibility to call this.  */
index a9f4d254c476c719e509ae59216e3f07aa190311..2bf12bd923034b5f05fde9aee55676b9b34149c4 100644 (file)
@@ -1,3 +1,8 @@
+2007-02-26  Mark Mitchell  <mark@codesourcery.com>
+
+       * semantics.c (expand_or_defer_fn): Call c_record_cdtor_fn.
+       * decl2.c (cp_write_gloabl_declarations): Call c_build_cdtor_fns.
+
 2007-02-25  Mark Mitchell  <mark@codesourcery.com>
 
        * cp-tree.h (static_ctors): Remove.
index 1feb3a7661fbe672f7d138d29487b0bdcf4dd7a8..a1664b81bcd94a44d62d625a7f4aed1b29f30ecc 100644 (file)
@@ -3289,6 +3289,8 @@ cp_write_global_declarations (void)
   if (priority_info_map)
     splay_tree_delete (priority_info_map);
 
+  c_build_cdtor_fns ();
+
   /* Generate any missing aliases.  */
   maybe_apply_pending_pragma_weaks ();
 
index 71c16e07e11833dcd15b27aabfdf0f3247224c2c..6ffc9650fd2d1991ae3c2eb1eb40cb7670aab347 100644 (file)
@@ -3159,6 +3159,10 @@ expand_or_defer_fn (tree fn)
       return;
     }
 
+  /* Keep track of functions declared with the "constructor" and
+     "destructor" attribute.  */
+  c_record_cdtor_fn (fn);
+
   /* We make a decision about linkage for these functions at the end
      of the compilation.  Until that point, we do not want the back
      end to output them -- but we do want it to see the bodies of