diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2807eb23f85d60704637db38a7eb8c0886b26203..f7eecc45d12cd5c5776eb157671fcd4959e213a4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-04-18 Martin Liska <mliska@suse.cz> + + PR gcov-profile/78783 + * gcov-tool.c (gcov_output_files): Validate that destination + file is either removed by the tool or by a user. + 2017-04-14 Andrew Burgess <andrew.burgess@embecosm.com> Guy Benyei <guybe@mellanox.com> diff --git a/gcc/gcov-tool.c b/gcc/gcov-tool.c index cadf09377ddb56997c92fca8c2efc818ed895e3a..80c08354857b69d5dd9478fc8fa3fc375462845b 100644 --- a/gcc/gcov-tool.c +++ b/gcc/gcov-tool.c @@ -46,6 +46,7 @@ extern int gcov_profile_normalize (struct gcov_info*, gcov_type); extern int gcov_profile_scale (struct gcov_info*, float, int, int); extern struct gcov_info* gcov_read_profile_dir (const char*, int); extern void gcov_do_dump (struct gcov_info *, int); +extern const char *gcov_get_filename (struct gcov_info *list); extern void gcov_set_verbose (void); /* Set to verbose output mode. */ @@ -114,6 +115,14 @@ gcov_output_files (const char *out, struct gcov_info *profile) if (ret) fatal_error (input_location, "Cannot change directory to %s", out); + /* Verify that output file does not exist (either was removed by + unlink_profile_data or removed by user). */ + const char *filename = gcov_get_filename (profile); + + if (access (filename, F_OK) != -1) + fatal_error (input_location, "output file %s already exists in folder %s", + filename, out); + gcov_do_dump (profile, 0); ret = chdir (pwd); diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog index 1dc5469cd8c7a2e7168fe2687611ab86e6bb21f0..593cd09db8be94b4a13f0cbe54aa0d2acb7c315a 100644 --- a/libgcc/ChangeLog +++ b/libgcc/ChangeLog @@ -1,3 +1,8 @@ +2017-04-18 Martin Liska <mliska@suse.cz> + + PR gcov-profile/78783 + * libgcov-driver.c (gcov_get_filename): New function. + 2017-04-07 Jeff Law <law@redhat.com> * Makefile.in: Swap definition of LIBGCC_LINKS and inclusion of diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c index 70fe69f26b5b1563ae8f25dd66a642f81322b2f1..c3b2fd4d5ce4db3fd85cd3e901df7e314a4b94d3 100644 --- a/libgcc/libgcov-driver.c +++ b/libgcc/libgcov-driver.c @@ -852,6 +852,15 @@ gcov_do_dump (struct gcov_info *list, int run_counted) free (gf.filename); } +#if IN_GCOV_TOOL +const char * +__attribute__ ((unused)) +gcov_get_filename (struct gcov_info *list) +{ + return list->filename; +} +#endif + #if !IN_GCOV_TOOL void __gcov_dump_one (struct gcov_root *root)