Hello. It's improvement that I consider still useful even though we're not going to use it for profiled bootstrap.
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. Ready for trunk? Thanks, Martin
>From 1a32e0b41b291bef3d58126754834f6c41148ace Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Wed, 16 Aug 2017 10:22:57 +0200 Subject: [PATCH] Append PWD to path when using -fprofile-generate=/some/path. gcc/ChangeLog: 2017-10-27 Martin Liska <mli...@suse.cz> * coverage.c (coverage_init): Append absolute path of object file. * doc/invoke.texi: Document the behavior. --- gcc/coverage.c | 20 ++++++++++++++++++-- gcc/doc/invoke.texi | 3 +++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/gcc/coverage.c b/gcc/coverage.c index 8a56a677f15..c66651f1045 100644 --- a/gcc/coverage.c +++ b/gcc/coverage.c @@ -1220,8 +1220,24 @@ coverage_init (const char *filename) g->get_passes ()->get_pass_profile ()->static_pass_number; g->get_dumps ()->dump_start (profile_pass_num, NULL); - if (!profile_data_prefix && !IS_ABSOLUTE_PATH (filename)) - profile_data_prefix = getpwd (); + if (!IS_ABSOLUTE_PATH (filename)) + { + if (profile_data_prefix) + { + const char *pwd = getpwd (); + unsigned l1 = strlen (profile_data_prefix); + unsigned l2 = strlen (pwd); + + char *b = XNEWVEC (char, l1 + l2 + 2); + memcpy (b, profile_data_prefix, l1); + b[l1] = '/'; + memcpy (b + l1 + 1, pwd, l2); + b[l1 + l2 + 1] = '\0'; + profile_data_prefix = b; + } + else + profile_data_prefix = getpwd (); + } if (profile_data_prefix) prefix_len = strlen (profile_data_prefix); diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 71b2445f70f..682ab570584 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -10915,6 +10915,9 @@ and used by @option{-fprofile-use} and @option{-fbranch-probabilities} and its related options. Both absolute and relative paths can be used. By default, GCC uses the current directory as @var{path}, thus the profile data file appears in the same directory as the object file. +In order to prevent filename clashing, if object file name is not an absolute +path, current working directory path is appended to @var{path} +and used as a destination for @file{@var{sourcename}.gcda} file. @item -fprofile-generate @itemx -fprofile-generate=@var{path} -- 2.14.2