This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libgcov-driver-system bootstrap failure


On 06/06/2018 02:28 AM, David Edelsohn wrote:
> Martin,
> 
> With your recent patch, I receive the following failure building
> libgcov-driver-system.c
> 
> In file included from
> /nasfarm/edelsohn/src/src/gcc/../libgcc/libgcov-driver.c:322:0:
> /nasfarm/edelsohn/src/src/gcc/../libgcc/libgcov-driver-system.c: In
> function 'char* replace_filename_variables(char*)':
> /nasfarm/edelsohn/src/src/gcc/../libgcc/libgcov-driver-system.c:193:61:
> error: 'mempcpy' was not declared in this scope
>     buffer_ptr = (char *)mempcpy (buffer_ptr, filename, start);
> 
> mempcpy is a GLIBC extension and not defined in POSIX.  There is no
> libiberty implementation.  Please avoid use of GLIBC-specific
> functions.
> 
> Thanks, David
> 

Hi David.

Sorry for the breakage. I'm sending patch where I replace mempcpy with memcpy.
Apart from that I realized that we need to allocate memory for each individual gf->filename
in gcov_exit_open_gcda_file. That's due to fact that expansion of ENV variables can extend
maximum expected length of a filename. Thus max_length is not now needed.

Patch can survives gcov.exp test-suite and I verified that valgrind is happy for various
-fprofile-generate values with expansion variables provided.

Martin
>From e3675ab3eebe27b4112c9fd3a2b4bb28a6ce60fd Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Wed, 6 Jun 2018 10:44:47 +0200
Subject: [PATCH] Fix libgcov-driver-system bootstrap failure.

libgcc/ChangeLog:

2018-06-06  Martin Liska  <mliska@suse.cz>

	* libgcov-driver-system.c (replace_filename_variables): Use
        memcpy instead of mempcpy.
	(allocate_filename_struct): Do not allocate filename, allocate
        prefix and set it.
	(gcov_exit_open_gcda_file): Allocate memory for gf->filename
        here and properly copy content into it.
	* libgcov-driver.c (struct gcov_filename): Remove max_length
        field, change prefix from size_t into char *.
	(compute_summary): Do not calculate longest filename.
	(gcov_do_dump): Release memory of gf.filename after each file.
	* libgcov-util.c (compute_summary): Use new signature of
        compute_summary.
	(calculate_overlap): Likewise.
---
 libgcc/libgcov-driver-system.c | 34 +++++++++++++++++++++++++---------
 libgcc/libgcov-driver.c        | 23 +++++++++--------------
 libgcc/libgcov-util.c          |  7 +++----
 3 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/libgcc/libgcov-driver-system.c b/libgcc/libgcov-driver-system.c
index 7f3de631701..8c1fef00456 100644
--- a/libgcc/libgcov-driver-system.c
+++ b/libgcc/libgcov-driver-system.c
@@ -190,9 +190,12 @@ replace_filename_variables (char *filename)
 
 	  char *buffer = (char *)xmalloc (start + end + repl_length + 1);
 	  char *buffer_ptr = buffer;
-	  buffer_ptr = (char *)mempcpy (buffer_ptr, filename, start);
-	  buffer_ptr = (char *)mempcpy (buffer_ptr, replacement, repl_length);
-	  buffer_ptr = (char *)mempcpy (buffer_ptr, p, end);
+	  buffer_ptr = (char *)memcpy (buffer_ptr, filename, start);
+	  buffer_ptr += start;
+	  buffer_ptr = (char *)memcpy (buffer_ptr, replacement, repl_length);
+	  buffer_ptr += repl_length;
+	  buffer_ptr = (char *)memcpy (buffer_ptr, p, end);
+	  buffer_ptr += end;
 	  *buffer_ptr = '\0';
 
 	  free (filename);
@@ -210,6 +213,7 @@ allocate_filename_struct (struct gcov_filename *gf)
   const char *gcov_prefix;
   size_t prefix_length;
   int strip = 0;
+  gf->filename = NULL;
 
   {
     /* Check if the level of dirs to strip off specified. */
@@ -239,12 +243,16 @@ allocate_filename_struct (struct gcov_filename *gf)
       gcov_prefix = ".";
       prefix_length = 1;
     }
-  gf->prefix = prefix_length;
 
   /* Allocate and initialize the filename scratch space.  */
-  gf->filename = (char *) xmalloc (gf->max_length + prefix_length + 2);
   if (prefix_length)
-    memcpy (gf->filename, gcov_prefix, prefix_length);
+    {
+      gf->prefix = (char *) xmalloc (prefix_length + 1);
+      char *p = (char *) memcpy (gf->prefix, gcov_prefix, prefix_length);
+      *(p + prefix_length) = '\0';
+    }
+  else
+    gf->prefix = NULL;
 }
 
 /* Open a gcda file specified by GI_FILENAME.
@@ -255,7 +263,7 @@ gcov_exit_open_gcda_file (struct gcov_info *gi_ptr,
 			  struct gcov_filename *gf)
 {
   const char *fname = gi_ptr->filename;
-  char *dst = gf->filename + gf->prefix;
+  int append_slash = 0;
 
   fname = gi_ptr->filename;
 
@@ -288,9 +296,17 @@ gcov_exit_open_gcda_file (struct gcov_info *gi_ptr,
 	fname += 2;
 
       if (!IS_DIR_SEPARATOR (*fname))
-	*dst++ = '/';
+	append_slash = 1;
     }
-  strcpy (dst, fname);
+
+  size_t prefix_length = gf->prefix ? strlen (gf->prefix) : 0;
+  gf->filename = (char *) xmalloc (prefix_length + strlen (fname) + 2);
+  *gf->filename = '\0';
+  if (prefix_length)
+    strcat (gf->filename, gf->prefix);
+  if (append_slash)
+    *gf->filename++ = '/';
+  strcat (gf->filename, fname);
 
   gf->filename = replace_filename_variables (gf->filename);
 
diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c
index 922d9dde833..7ae33b8d417 100644
--- a/libgcc/libgcov-driver.c
+++ b/libgcc/libgcov-driver.c
@@ -72,9 +72,8 @@ struct gcov_summary_buffer
 struct gcov_filename
 {
   char *filename;  /* filename buffer */
-  size_t max_length;  /* maximum filename length */
   int strip; /* leading chars to strip from filename */
-  size_t prefix; /* chars to prepend to filename */
+  char *prefix; /* prefix string */
 };
 
 static struct gcov_fn_buffer *
@@ -259,15 +258,13 @@ static struct gcov_fn_buffer *fn_buffer;
 static struct gcov_summary_buffer *sum_buffer;
 
 /* This function computes the program level summary and the histo-gram.
-   It computes and returns CRC32 and stored summary in THIS_PRG.
-   Also determines the longest filename length of the info files.  */
+   It computes and returns CRC32 and stored summary in THIS_PRG.  */
 
 #if !IN_GCOV_TOOL
 static
 #endif
 gcov_unsigned_t
-compute_summary (struct gcov_info *list, struct gcov_summary *this_prg,
-		 size_t *max_length)
+compute_summary (struct gcov_info *list, struct gcov_summary *this_prg)
 {
   struct gcov_info *gi_ptr;
   const struct gcov_fn_info *gfi_ptr;
@@ -278,13 +275,8 @@ compute_summary (struct gcov_info *list, struct gcov_summary *this_prg,
 
   /* Find the totals for this execution.  */
   memset (this_prg, 0, sizeof (*this_prg));
-  *max_length = 0;
   for (gi_ptr = list; gi_ptr; gi_ptr = gi_ptr->next)
     {
-      size_t len = strlen (gi_ptr->filename);
-      if (len > *max_length)
-	*max_length = len;
-      
       crc32 = crc32_unsigned (crc32, gi_ptr->stamp);
       crc32 = crc32_unsigned (crc32, gi_ptr->n_functions);
 
@@ -799,7 +791,7 @@ gcov_do_dump (struct gcov_info *list, int run_counted)
   struct gcov_summary all_prg;
   struct gcov_summary this_prg;
 
-  crc32 = compute_summary (list, &this_prg, &gf.max_length);
+  crc32 = compute_summary (list, &this_prg);
 
   allocate_filename_struct (&gf);
 #if !GCOV_LOCKED
@@ -808,9 +800,12 @@ gcov_do_dump (struct gcov_info *list, int run_counted)
 
   /* Now merge each file.  */
   for (gi_ptr = list; gi_ptr; gi_ptr = gi_ptr->next)
-    dump_one_gcov (gi_ptr, &gf, run_counted, crc32, &all_prg, &this_prg);
+    {
+      dump_one_gcov (gi_ptr, &gf, run_counted, crc32, &all_prg, &this_prg);
+      free (gf.filename);
+    }
 
-  free (gf.filename);
+  free (gf.prefix);
 }
 
 #if IN_GCOV_TOOL
diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c
index 1d26176940b..37dd186beaa 100644
--- a/libgcc/libgcov-util.c
+++ b/libgcc/libgcov-util.c
@@ -1202,7 +1202,7 @@ matched_gcov_info (const struct gcov_info *info1, const struct gcov_info *info2)
 
 /* Defined in libgcov-driver.c.  */
 extern gcov_unsigned_t compute_summary (struct gcov_info *,
-                 struct gcov_summary *, size_t *);
+					struct gcov_summary *);
 
 /* Compute the overlap score of two profiles with the head of GCOV_LIST1 and
    GCOV_LIST1. Return a number ranging from [0.0, 1.0], with 0.0 meaning no
@@ -1215,15 +1215,14 @@ calculate_overlap (struct gcov_info *gcov_list1,
   struct gcov_summary this_prg;
   unsigned list1_cnt = 0, list2_cnt= 0, all_cnt;
   unsigned int i, j;
-  size_t max_length;
   const struct gcov_info *gi_ptr;
   struct overlap_t *all_infos;
 
-  compute_summary (gcov_list1, &this_prg, &max_length);
+  compute_summary (gcov_list1, &this_prg);
   overlap_sum_1 = (double) (this_prg.sum_all);
   p1_sum_all = this_prg.sum_all;
   p1_run_max = this_prg.run_max;
-  compute_summary (gcov_list2, &this_prg, &max_length);
+  compute_summary (gcov_list2, &this_prg);
   overlap_sum_2 = (double) (this_prg.sum_all);
   p2_sum_all = this_prg.sum_all;
   p2_run_max = this_prg.run_max;
-- 
2.17.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]