mirror of
https://github.com/gcc-mirror/gcc.git
synced 2026-05-06 14:59:39 +02:00
gcov-profile/121074 - hold onto gcov file for less time
The following fixes the issue of two open gcov files at the same time, one from -ftest-coverage, opened/closed by coverage_init/finish and one from -fauto-profile, attempted to be opened by pass_ipa_auto_profile. The solution is to open the coverage files only during pass_ipa_tree_profile. PR gcov-profile/121074 * coverage.h (coverage_init_file): Declare. (coverage_finish_file): Likewise. * coverage.cc (coverage_init_file): New function, split out actual file opening and writing from ... (coverage_init): ... here. (coverage_finish_file): Likewise for file closing, from ... (coverage_finish): ... here. * tree-profile.cc (tree_profiling): Call coverage_init_file and coverage_finish_file here.
This commit is contained in:
@@ -1248,6 +1248,33 @@ coverage_obj_finish (vec<constructor_elt, va_gc> *ctor,
|
||||
varpool_node::finalize_decl (gcov_info_var);
|
||||
}
|
||||
|
||||
/* Open the coverage files. */
|
||||
|
||||
void
|
||||
coverage_init_file (void)
|
||||
{
|
||||
if (flag_test_coverage && !flag_compare_debug)
|
||||
{
|
||||
if (!gcov_open (bbg_file_name, -1))
|
||||
{
|
||||
error ("cannot open %s", bbg_file_name);
|
||||
bbg_file_name = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
gcov_write_unsigned (GCOV_NOTE_MAGIC);
|
||||
gcov_write_unsigned (GCOV_VERSION);
|
||||
gcov_write_unsigned (bbg_file_stamp);
|
||||
/* Use an arbitrary checksum */
|
||||
gcov_write_unsigned (0);
|
||||
gcov_write_string (remap_profile_filename (getpwd ()));
|
||||
|
||||
/* Do not support has_unexecuted_blocks for Ada. */
|
||||
gcov_write_unsigned (strcmp (lang_hooks.name, "GNU Ada") != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Perform file-level initialization. Read in data file, generate name
|
||||
of notes file. */
|
||||
|
||||
@@ -1330,34 +1357,15 @@ coverage_init (const char *filename)
|
||||
memcpy (bbg_file_name, original_filename, original_len);
|
||||
strcpy (bbg_file_name + original_len, GCOV_NOTE_SUFFIX);
|
||||
}
|
||||
|
||||
if (!gcov_open (bbg_file_name, -1))
|
||||
{
|
||||
error ("cannot open %s", bbg_file_name);
|
||||
bbg_file_name = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
gcov_write_unsigned (GCOV_NOTE_MAGIC);
|
||||
gcov_write_unsigned (GCOV_VERSION);
|
||||
gcov_write_unsigned (bbg_file_stamp);
|
||||
/* Use an arbitrary checksum */
|
||||
gcov_write_unsigned (0);
|
||||
gcov_write_string (remap_profile_filename (getpwd ()));
|
||||
|
||||
/* Do not support has_unexecuted_blocks for Ada. */
|
||||
gcov_write_unsigned (strcmp (lang_hooks.name, "GNU Ada") != 0);
|
||||
}
|
||||
}
|
||||
|
||||
g->get_dumps ()->dump_finish (profile_pass_num);
|
||||
}
|
||||
|
||||
/* Performs file-level cleanup. Close notes file, generate coverage
|
||||
variables and constructor. */
|
||||
/* Close the coverage files. */
|
||||
|
||||
void
|
||||
coverage_finish (void)
|
||||
coverage_finish_file (void)
|
||||
{
|
||||
if (bbg_file_name && gcov_close ())
|
||||
unlink (bbg_file_name);
|
||||
@@ -1367,7 +1375,14 @@ coverage_finish (void)
|
||||
/* Only remove the da file, if we're emitting coverage code and
|
||||
cannot uniquely stamp it. If we can stamp it, libgcov will DTRT. */
|
||||
unlink (da_file_name);
|
||||
}
|
||||
|
||||
/* Performs file-level cleanup. Close notes file, generate coverage
|
||||
variables and constructor. */
|
||||
|
||||
void
|
||||
coverage_finish (void)
|
||||
{
|
||||
/* Global GCDA checksum that aggregates all functions. */
|
||||
unsigned object_checksum = 0;
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ along with GCC; see the file COPYING3. If not see
|
||||
|
||||
extern void coverage_init (const char *);
|
||||
extern void coverage_finish (void);
|
||||
extern void coverage_init_file (void);
|
||||
extern void coverage_finish_file (void);
|
||||
extern void coverage_remove_note_file (void);
|
||||
|
||||
/* Start outputting coverage information for the current
|
||||
|
||||
@@ -1856,6 +1856,8 @@ tree_profiling (void)
|
||||
{
|
||||
struct cgraph_node *node;
|
||||
|
||||
coverage_init_file ();
|
||||
|
||||
/* Verify whether we can utilize atomic update operations. */
|
||||
bool can_support_atomic = targetm.have_libatomic;
|
||||
unsigned HOST_WIDE_INT gcov_type_size
|
||||
@@ -2071,6 +2073,7 @@ tree_profiling (void)
|
||||
|
||||
del_node_map ();
|
||||
end_branch_prob ();
|
||||
coverage_finish_file ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user