diff mbox series

Rework GCOV_PREFIX_STRIP env variable.

Message ID a05fe5f8-4891-1663-b484-507f7f15e57e@suse.cz
State New
Headers show
Series Rework GCOV_PREFIX_STRIP env variable. | expand

Commit Message

Martin Liška Feb. 4, 2020, 1 p.m. UTC
Hi.

The patch addresses https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93401#c9
where we currently support mechanism for cross compilation:
GCC manual:
10.5 Data File Relocation to Support Cross-Profiling

That's very much the same what Honza needs for Firefox, where profile-gen
run happens in a different location than profile-use run.
However, I see current meaning of GCOV_PREFIX_STRIP a bit difficult
to use.

That's why I suggest to rename it to GCOV_PREFIX_STRIP_COMPONENTS and
use GCOV_PREFIX_STRIP for real strip prefix.

Thoughts?
Martin

gcc/ChangeLog:

2020-02-04  Martin Liska  <mliska@suse.cz>

	PR gcov-profile/93401
	* doc/gcov.texi: Document new behaviour of GCOV_PREFIX_STRIP
	and introduce GCOV_PREFIX_STRIP_COMPONENTS.

libgcc/ChangeLog:

2020-02-04  Martin Liska  <mliska@suse.cz>

	PR gcov-profile/93401
	* libgcov-driver-system.c (allocate_filename_struct):
	Parse also GCOV_PREFIX_STRIP_COMPONENTS.
	(gcov_exit_open_gcda_file): Handle new meaning
	of GCOV_PREFIX_STRIP and GCOV_PREFIX_STRIP_COMPONENTS.
	* libgcov-driver.c (struct gcov_filename): New field.
---
  gcc/doc/gcov.texi              | 17 +++++++++++------
  libgcc/libgcov-driver-system.c |  7 +++++--
  libgcc/libgcov-driver.c        |  1 +
  3 files changed, 17 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi
index 61250c9407e..154c7eb965a 100644
--- a/gcc/doc/gcov.texi
+++ b/gcc/doc/gcov.texi
@@ -951,11 +951,16 @@  in the object file. Prefix can be absolute, or relative.  The
 default is no prefix.
 
 @item
-GCOV_PREFIX_STRIP indicates the how many initial directory names to strip off
-the hardwired absolute paths. Default value is 0.
+GCOV_PREFIX_STRIP_COMPONENTS indicates the how many initial directory names
+to strip off the hardwired absolute paths.  Default value is 0.
 
-@emph{Note:} If GCOV_PREFIX_STRIP is set without GCOV_PREFIX is undefined,
- then a relative path is made out of the hardwired absolute paths.
+@item
+GCOV_PREFIX_STRIP indicates path prefix to strip off
+the hardwired absolute paths.
+
+@emph{Note:} If GCOV_PREFIX_STRIP_COMPONENTS (or GCOV_PREFIX_STRIP)
+is set without GCOV_PREFIX, then a relative path is made
+out of the hardwired absolute paths.
 @end itemize
 
 For example, if the object file @file{/user/build/foo.o} was built with
@@ -963,8 +968,8 @@  For example, if the object file @file{/user/build/foo.o} was built with
 @file{/user/build/foo.gcda} when running on the target system.  This will
 fail if the corresponding directory does not exist and it is unable to create
 it.  This can be overcome by, for example, setting the environment as
-@samp{GCOV_PREFIX=/target/run} and @samp{GCOV_PREFIX_STRIP=1}.  Such a
-setting will name the data file @file{/target/run/build/foo.gcda}.
+@samp{GCOV_PREFIX=/target/run} and @samp{GCOV_PREFIX_STRIP_COMPONENTS=1}.
+Such a setting will name the data file @file{/target/run/build/foo.gcda}.
 
 You must move the data files to the expected directory tree in order to
 use them for profile directed optimizations (@option{-fprofile-use}), or to
diff --git a/libgcc/libgcov-driver-system.c b/libgcc/libgcov-driver-system.c
index 031f057e318..c17ce72b4b6 100644
--- a/libgcc/libgcov-driver-system.c
+++ b/libgcc/libgcov-driver-system.c
@@ -218,7 +218,7 @@  allocate_filename_struct (struct gcov_filename *gf)
 
   {
     /* Check if the level of dirs to strip off specified. */
-    char *tmp = getenv("GCOV_PREFIX_STRIP");
+    char *tmp = getenv ("GCOV_PREFIX_STRIP_COMPONENTS");
     if (tmp)
       {
         strip = atoi (tmp);
@@ -228,6 +228,7 @@  allocate_filename_struct (struct gcov_filename *gf)
       }
   }
   gf->strip = strip;
+  gf->strip_prefix = getenv ("GCOV_PREFIX_STRIP");
 
   /* Get file name relocation prefix.  Non-absolute values are ignored. */
   gcov_prefix = getenv("GCOV_PREFIX");
@@ -239,7 +240,7 @@  allocate_filename_struct (struct gcov_filename *gf)
 
   /* If no prefix was specified and a prefix stip, then we assume
      relative.  */
-  if (!prefix_length && gf->strip)
+  if (!prefix_length && (gf->strip || gf->strip_prefix))
     {
       gcov_prefix = ".";
       prefix_length = 1;
@@ -286,6 +287,8 @@  gcov_exit_open_gcda_file (struct gcov_info *gi_ptr,
             level--;
           }
     }
+  else if (gf->strip_prefix && strstr (fname, gf->strip_prefix) == fname)
+    fname += strlen (gf->strip_prefix);
 
   /* Update complete filename with stripped original. */
   if (gf->prefix)
diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c
index fb320738e1e..15c2009f8fc 100644
--- a/libgcc/libgcov-driver.c
+++ b/libgcc/libgcov-driver.c
@@ -76,6 +76,7 @@  struct gcov_filename
 {
   char *filename;  /* filename buffer */
   int strip; /* leading chars to strip from filename */
+  char *strip_prefix; /* leading path prefix that should be stripped */
   char *prefix; /* prefix string */
 };