summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog15
-rw-r--r--gcc/c-common.c60
-rw-r--r--gcc/c-common.h7
-rw-r--r--gcc/c-decl.c42
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/decl2.c2
-rw-r--r--gcc/cp/semantics.c4
7 files changed, 99 insertions, 36 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c71aec1f10e..8388cef151c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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.
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 6d1606c0b0e..0cd4d1a8eb4 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -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"
diff --git a/gcc/c-common.h b/gcc/c-common.h
index 4e25ede957c..e52b83208af 100644
--- a/gcc/c-common.h
+++ b/gcc/c-common.h
@@ -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 */
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index ec567a5451d..a84dea67f30 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -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. */
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a9f4d254c47..2bf12bd9230 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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.
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 1feb3a7661f..a1664b81bcd 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -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 ();
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 71c16e07e11..6ffc9650fd2 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -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