- gcov_info_value = build_gcov_info ();
-
- gcov_info = build (VAR_DECL, TREE_TYPE (gcov_info_value),
- NULL_TREE, NULL_TREE);
- DECL_INITIAL (gcov_info) = gcov_info_value;
-
- TREE_STATIC (gcov_info) = 1;
- ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 0);
- DECL_NAME (gcov_info) = get_identifier (name);
-
- /* Build structure. */
- assemble_variable (gcov_info, 0, 0, 0);
-
- /* Build the constructor function to invoke __gcov_init. */
- ctor_name = concat (IDENTIFIER_POINTER (get_file_function_name ('I')),
- "_GCOV", NULL);
- ctor = build_decl (FUNCTION_DECL, get_identifier (ctor_name),
- build_function_type (void_type_node, NULL_TREE));
- free (ctor_name);
- DECL_EXTERNAL (ctor) = 0;
-
- /* It can be a static function as long as collect2 does not have
- to scan the object file to find its ctor/dtor routine. */
- TREE_PUBLIC (ctor) = ! targetm.have_ctors_dtors;
- TREE_USED (ctor) = 1;
- DECL_RESULT (ctor) = build_decl (RESULT_DECL, NULL_TREE, void_type_node);
- DECL_UNINLINABLE (ctor) = 1;
-
- ctor = (*lang_hooks.decls.pushdecl) (ctor);
- rest_of_decl_compilation (ctor, 0, 1, 0);
- announce_function (ctor);
- current_function_decl = ctor;
- DECL_INITIAL (ctor) = error_mark_node;
- make_decl_rtl (ctor, NULL);
- init_function_start (ctor);
- (*lang_hooks.decls.pushlevel) (0);
- expand_function_start (ctor, 0);
-
- /* Actually generate the code to call __gcov_init. */
- gcov_info_address = force_reg (Pmode, XEXP (DECL_RTL (gcov_info), 0));
- emit_library_call (gcov_init_libfunc, LCT_NORMAL, VOIDmode, 1,
- gcov_info_address, Pmode);
-
- expand_function_end ();
- (*lang_hooks.decls.poplevel) (1, 0, 1);
-
- rest_of_compilation (ctor);
-
- if (! quiet_flag)
- fflush (asm_out_file);
- current_function_decl = NULL_TREE;
-
- if (targetm.have_ctors_dtors)
- (* targetm.asm_out.constructor) (XEXP (DECL_RTL (ctor), 0),
- DEFAULT_INIT_PRIORITY);
+static void
+coverage_obj_finish (VEC(constructor_elt,gc) *ctor)
+{
+ unsigned n_functions = VEC_length(constructor_elt, ctor);
+ tree fn_info_ary_type = build_array_type
+ (build_qualified_type (gcov_fn_info_ptr_type, TYPE_QUAL_CONST),
+ build_index_type (size_int (n_functions - 1)));
+ tree fn_info_ary = build_decl (BUILTINS_LOCATION, VAR_DECL, NULL_TREE,
+ fn_info_ary_type);
+ char name_buf[32];
+
+ TREE_STATIC (fn_info_ary) = 1;
+ ASM_GENERATE_INTERNAL_LABEL (name_buf, "LPBX", 1);
+ DECL_NAME (fn_info_ary) = get_identifier (name_buf);
+ DECL_INITIAL (fn_info_ary) = build_constructor (fn_info_ary_type, ctor);
+ varpool_finalize_decl (fn_info_ary);
+
+ DECL_INITIAL (gcov_info_var)
+ = build_info (TREE_TYPE (gcov_info_var), fn_info_ary);
+ varpool_finalize_decl (gcov_info_var);