aboutsummaryrefslogtreecommitdiff
path: root/libgcc
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2018-06-07 06:21:35 +0200
committerMartin Liska <marxin@gcc.gnu.org>2018-06-07 04:21:35 +0000
commit6c086e8c75deaedb7db807d8008529747b275275 (patch)
treebf1b9fcbe6c7ae18bf10e75a89c7d5437a865a21 /libgcc
parent37777cd0335f3220e4cbe263099af633f1e1c645 (diff)
downloadgcc-6c086e8c75deaedb7db807d8008529747b275275.zip
gcc-6c086e8c75deaedb7db807d8008529747b275275.tar.gz
gcc-6c086e8c75deaedb7db807d8008529747b275275.tar.bz2
Fix libgcov-driver-system bootstrap failure (PR bootstrap/86057).
2018-06-07 Martin Liska <mliska@suse.cz> PR bootstrap/86057 * 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. From-SVN: r261260
Diffstat (limited to 'libgcc')
-rw-r--r--libgcc/ChangeLog17
-rw-r--r--libgcc/libgcov-driver-system.c34
-rw-r--r--libgcc/libgcov-driver.c23
-rw-r--r--libgcc/libgcov-util.c7
4 files changed, 54 insertions, 27 deletions
diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog
index 5389999..1ff66c5 100644
--- a/libgcc/ChangeLog
+++ b/libgcc/ChangeLog
@@ -1,3 +1,20 @@
+2018-06-07 Martin Liska <mliska@suse.cz>
+
+ PR bootstrap/86057
+ * 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.
+
2018-06-05 Martin Liska <mliska@suse.cz>
PR gcov-profile/47618
diff --git a/libgcc/libgcov-driver-system.c b/libgcc/libgcov-driver-system.c
index 7f3de63..8c1fef0 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 922d9dd..7ae33b8 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 1d26176..37dd186 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;