diff options
author | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-02-26 21:14:24 +0000 |
---|---|---|
committer | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-02-26 21:14:24 +0000 |
commit | 2970ab3d17c41b33da12f9d80a5f83990d475645 (patch) | |
tree | 57f11202334c7de856e122ac7abb9d371c2ac950 /gcc/c-common.c | |
parent | aad3c56bea2a83446623e50abd2a5d49850b3835 (diff) | |
download | gcc-2970ab3d17c41b33da12f9d80a5f83990d475645.tar.gz |
* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@122341 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r-- | gcc/c-common.c | 60 |
1 files changed, 60 insertions, 0 deletions
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" |