c-decl.c (static_ctors): Move to c-common.c.

* 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
This commit is contained in:
Mark Mitchell 2007-02-26 21:14:24 +00:00 committed by Mark Mitchell
parent 7276d36825
commit 57a4c089e2
7 changed files with 99 additions and 36 deletions

View 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.

View 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"

View 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 */

View 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. */

View 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.

View 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 ();

View 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