public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] gcov: add new option (--hash-names) (PR gcov-profile/36412).
@ 2016-08-09 14:32 Martin Liška
  2016-08-15 10:47 ` Nathan Sidwell
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Liška @ 2016-08-09 14:32 UTC (permalink / raw)
  To: GCC Patches; +Cc: Nathan Sidwell, Jan Hubicka, peter.klotz99

[-- Attachment #1: Type: text/plain, Size: 284 bytes --]

Hello.

Following enhancement for gcov solves issues when we cannot create a file due to a filesystem
path length limit. Selected approach utilizes existing md5sum functions.

Patch survives make check -k RUNTESTFLAGS="gcov.exp" on x86_64-linux-gnu.

Ready for trunk?
Thanks,
Martin


[-- Attachment #2: 0001-gcov-add-new-option-hash-names-PR-gcov-profile-36412.patch --]
[-- Type: text/x-patch, Size: 5295 bytes --]

From 42393a73c0433d7de28dc560f47ff61e615718bf Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 9 Aug 2016 16:27:10 +0200
Subject: [PATCH] gcov: add new option (--hash-names) (PR gcov-profile/36412).

gcc/ChangeLog:

2016-08-09  Martin Liska  <mliska@suse.cz>

	PR gcov-profile/36412
	* doc/gcov.texi: Document --hash-names (-e).
	* gcov.c (print_usage): Add the option.
	(process_args): Process the option.
	(md5sum_to_hex): New function.
	(make_gcov_file_name): Do the md5sum and append it to a
	filename.
---
 gcc/doc/gcov.texi |  6 ++++++
 gcc/gcov.c        | 47 +++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi
index 89d8049..78c0c75 100644
--- a/gcc/doc/gcov.texi
+++ b/gcc/doc/gcov.texi
@@ -123,6 +123,7 @@ gcov [@option{-v}|@option{--version}] [@option{-h}|@option{--help}]
      [@option{-b}|@option{--branch-probabilities}]
      [@option{-c}|@option{--branch-counts}]
      [@option{-d}|@option{--display-progress}]
+     [@option{-e}|@option{--hash-names}]
      [@option{-f}|@option{--function-summaries}]
      [@option{-i}|@option{--intermediate-format}]
      [@option{-l}|@option{--long-file-names}]
@@ -171,6 +172,11 @@ be shown, unless the @option{-u} option is given.
 Write branch frequencies as the number of branches taken, rather than
 the percentage of branches taken.
 
+@item -e
+@itemx --hash-names
+For situations when a long name can potentially hit filesystem path limit,
+let's calculate md5sum of the patch and create file x.gcov##md5sum.gcov.
+
 @item -n
 @itemx --no-output
 Do not create the @command{gcov} output file.
diff --git a/gcc/gcov.c b/gcc/gcov.c
index f05ef7c..97739b7 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -43,6 +43,7 @@ along with Gcov; see the file COPYING3.  If not see
 
 #include <vector>
 #include <algorithm>
+#include "md5.h"
 
 using namespace std;
 
@@ -359,6 +360,11 @@ static int flag_demangled_names = 0;
 
 static int flag_long_names = 0;
 
+/* For situations when a long name can potentially hit filesystem path limit,
+   let's calculate md5sum of the patch and create file x.gcov##md5sum.gcov.  */
+
+static int flag_hash_names = 0;
+
 /* Output count information for every basic block, not merely those
    that contain line number information.  */
 
@@ -655,6 +661,8 @@ print_usage (int error_p)
   fnotice (file, "  -c, --branch-counts             Output counts of branches taken\n\
                                     rather than percentages\n");
   fnotice (file, "  -d, --display-progress          Display progress information\n");
+  fnotice (file, "  -e, --hash-names                Use hash of file path in "
+	   "file names\n");
   fnotice (file, "  -f, --function-summaries        Output summaries for each function\n");
   fnotice (file, "  -i, --intermediate-format       Output .gcov file in intermediate text format\n");
   fnotice (file, "  -l, --long-file-names           Use long output file names for included\n\
@@ -694,6 +702,7 @@ static const struct option options[] =
   { "all-blocks",           no_argument,       NULL, 'a' },
   { "branch-probabilities", no_argument,       NULL, 'b' },
   { "branch-counts",        no_argument,       NULL, 'c' },
+  { "long-file-names",      no_argument,       NULL, 'e' },
   { "intermediate-format",  no_argument,       NULL, 'i' },
   { "no-output",            no_argument,       NULL, 'n' },
   { "long-file-names",      no_argument,       NULL, 'l' },
@@ -716,8 +725,8 @@ process_args (int argc, char **argv)
 {
   int opt;
 
-  while ((opt = getopt_long (argc, argv, "abcdfhilmno:s:pruv", options, NULL)) !=
-         -1)
+  const char *opts = "abcdefhilmno:s:pruv";
+  while ((opt = getopt_long (argc, argv, opts, options, NULL)) != -1)
     {
       switch (opt)
 	{
@@ -730,6 +739,9 @@ process_args (int argc, char **argv)
 	case 'c':
 	  flag_counts = 1;
 	  break;
+	case 'e':
+	  flag_hash_names = 1;
+	  break;
 	case 'f':
 	  flag_function_summary = 1;
 	  break;
@@ -2147,6 +2159,15 @@ canonicalize_name (const char *name)
   return result;
 }
 
+/* Print hex representation of 16 bytes from SUM and write it to BUFFER.  */
+
+static void
+md5sum_to_hex (const char *sum, char *buffer)
+{
+  for (unsigned i = 0; i < 16; i++)
+    sprintf (buffer + (2 * i), "%02x", sum[i]);
+}
+
 /* Generate an output file name. INPUT_NAME is the canonicalized main
    input file and SRC_NAME is the canonicalized file name.
    LONG_OUTPUT_NAMES and PRESERVE_PATHS affect name generation.  With
@@ -2184,6 +2205,28 @@ make_gcov_file_name (const char *input_name, const char *src_name)
   ptr = mangle_name (src_name, ptr);
   strcpy (ptr, ".gcov");
 
+  if (flag_hash_names)
+    {
+      md5_ctx ctx;
+      char md5sum[16];
+      char md5sum_hex[33];
+
+      md5_init_ctx (&ctx);
+      md5_process_bytes (result, strlen (result), &ctx);
+      md5_finish_ctx (&ctx, md5sum);
+      md5sum_to_hex (md5sum, md5sum_hex);
+      free (result);
+
+      result = XNEWVEC (char, strlen (src_name) + 50);
+      ptr = result;
+      ptr = mangle_name (src_name, ptr);
+      ptr[0] = ptr[1] = '#';
+      ptr += 2;
+      memcpy (ptr, md5sum_hex, 32);
+      ptr += 32;
+      strcpy (ptr, ".gcov");
+    }
+
   return result;
 }
 
-- 
2.9.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gcov: add new option (--hash-names) (PR gcov-profile/36412).
  2016-08-09 14:32 [PATCH] gcov: add new option (--hash-names) (PR gcov-profile/36412) Martin Liška
@ 2016-08-15 10:47 ` Nathan Sidwell
  2016-08-15 11:43   ` Martin Liška
  0 siblings, 1 reply; 9+ messages in thread
From: Nathan Sidwell @ 2016-08-15 10:47 UTC (permalink / raw)
  To: Martin Liška, GCC Patches; +Cc: Jan Hubicka, peter.klotz99

On 08/09/16 10:32, Martin Liška wrote:
> Hello.
>
> Following enhancement for gcov solves issues when we cannot create a file due to a filesystem
> path length limit. Selected approach utilizes existing md5sum functions.
>
> Patch survives make check -k RUNTESTFLAGS="gcov.exp" on x86_64-linux-gnu.
>
> Ready for trunk?
> Thanks,
> Martin
>

+     [@option{-e}|@option{--hash-names}]
'--hash-filenames' would be better.  Let's not confuse the user with thinking 
may be  the function names are hashed. (or perhaps '--hash-paths'?  The world's 
a little unclear on whether 'filename->last bit of file path, or the whole thing')


+/* For situations when a long name can potentially hit filesystem path limit,
+   let's calculate md5sum of the patch and create file x.gcov##md5sum.gcov.  */
+
+static int flag_hash_names = 0;
+
s/patch/path.
Which  bit of 'x.gcov##md5sum.gcov' is the hash?  is it 'x' or sommethihg else? 
Perhaps this more detailed comment should be near where the filename is 
generated.  And this flag just labelled as someting like 'hash long pathnames'

+  fnotice (file, "  -e, --hash-names                Use hash of file path in "
.. and ..
+  { "long-file-names",      no_argument,       NULL, 'e' },

don't seem to match?  Why 'e'?

nathan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gcov: add new option (--hash-names) (PR gcov-profile/36412).
  2016-08-15 10:47 ` Nathan Sidwell
@ 2016-08-15 11:43   ` Martin Liška
  2016-08-15 12:18     ` Nathan Sidwell
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Liška @ 2016-08-15 11:43 UTC (permalink / raw)
  To: Nathan Sidwell, GCC Patches; +Cc: Jan Hubicka, peter.klotz99

[-- Attachment #1: Type: text/plain, Size: 1509 bytes --]

On 08/15/2016 12:47 PM, Nathan Sidwell wrote:
> On 08/09/16 10:32, Martin Liška wrote:
>> Hello.
>>
>> Following enhancement for gcov solves issues when we cannot create a file due to a filesystem
>> path length limit. Selected approach utilizes existing md5sum functions.
>>
>> Patch survives make check -k RUNTESTFLAGS="gcov.exp" on x86_64-linux-gnu.
>>
>> Ready for trunk?
>> Thanks,
>> Martin
>>
> 
> +     [@option{-e}|@option{--hash-names}]
> '--hash-filenames' would be better.  Let's not confuse the user with thinking may be  the function names are hashed. (or perhaps '--hash-paths'?  The world's a little unclear on whether 'filename->last bit of file path, or the whole thing')
> 
> 
> +/* For situations when a long name can potentially hit filesystem path limit,
> +   let's calculate md5sum of the patch and create file x.gcov##md5sum.gcov.  */
> +
> +static int flag_hash_names = 0;
> +
> s/patch/path.
> Which  bit of 'x.gcov##md5sum.gcov' is the hash?  is it 'x' or sommethihg else? Perhaps this more detailed comment should be near where the filename is generated.  And this flag just labelled as someting like 'hash long pathnames'
> 
> +  fnotice (file, "  -e, --hash-names                Use hash of file path in "
> .. and ..
> +  { "long-file-names",      no_argument,       NULL, 'e' },

Hi Nathan.

All nits are applied in the second version of patch.

> 
> don't seem to match?  Why 'e'?

I've renamed it to -x, well, a lot of letters are already occupied.

Martin

> 
> nathan


[-- Attachment #2: 0001-gcov-add-new-option-hash-filenames-PR-gcov-profile-3-v2.patch --]
[-- Type: text/x-patch, Size: 4995 bytes --]

From b923bc8d838cf1de01a97db8f5ea5c78519a782b Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 9 Aug 2016 16:27:10 +0200
Subject: [PATCH] gcov: add new option (--hash-filenames) (PR
 gcov-profile/36412).

gcc/ChangeLog:

2016-08-09  Martin Liska  <mliska@suse.cz>

	PR gcov-profile/36412
	* doc/gcov.texi: Document --hash-filenames(-x).
	* gcov.c (print_usage): Add the option.
	(process_args): Process the option.
	(md5sum_to_hex): New function.
	(make_gcov_file_name): Do the md5sum and append it to a
	filename.
---
 gcc/doc/gcov.texi |  7 +++++++
 gcc/gcov.c        | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi
index df58df8..1737416 100644
--- a/gcc/doc/gcov.texi
+++ b/gcc/doc/gcov.texi
@@ -133,6 +133,7 @@ gcov [@option{-v}|@option{--version}] [@option{-h}|@option{--help}]
      [@option{-r}|@option{--relative-only}]
      [@option{-s}|@option{--source-prefix} @var{directory}]
      [@option{-u}|@option{--unconditional-branches}]
+     [@option{-x}|@option{--hash-filenames}]
      @var{files}
 @c man end
 @c man begin SEEALSO
@@ -278,6 +279,12 @@ branch:28,nottaken
 Display demangled function names in output. The default is to show
 mangled function names.
 
+@item -x
+@itemx --hash-filenames
+For situations when a long name can potentially hit filesystem path limit,
+let's calculate md5sum of the path and create file
+@file{source_file.c##<md5sum>.gcov}.
+
 @end table
 
 @command{gcov} should be run with the current directory the same as that
diff --git a/gcc/gcov.c b/gcc/gcov.c
index 30fc167..614f371 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -43,6 +43,7 @@ along with Gcov; see the file COPYING3.  If not see
 
 #include <vector>
 #include <algorithm>
+#include "md5.h"
 
 using namespace std;
 
@@ -359,6 +360,11 @@ static int flag_demangled_names = 0;
 
 static int flag_long_names = 0;
 
+/* For situations when a long name can potentially hit filesystem path limit,
+   let's calculate md5sum of the path and append it to a file name.  */
+
+static int flag_hash_filenames = 0;
+
 /* Output count information for every basic block, not merely those
    that contain line number information.  */
 
@@ -667,6 +673,7 @@ print_usage (int error_p)
   fnotice (file, "  -s, --source-prefix DIR         Source prefix to elide\n");
   fnotice (file, "  -u, --unconditional-branches    Show unconditional branch counts too\n");
   fnotice (file, "  -v, --version                   Print version number, then exit\n");
+  fnotice (file, "  -x, --hash-filenames            Hash long pathnames\n");
   fnotice (file, "\nFor bug reporting instructions, please see:\n%s.\n",
 	   bug_report_url);
   exit (status);
@@ -706,6 +713,7 @@ static const struct option options[] =
   { "source-prefix",        required_argument, NULL, 's' },
   { "unconditional-branches", no_argument,     NULL, 'u' },
   { "display-progress",     no_argument,       NULL, 'd' },
+  { "hash-filenames",	    no_argument,       NULL, 'x' },
   { 0, 0, 0, 0 }
 };
 
@@ -716,8 +724,8 @@ process_args (int argc, char **argv)
 {
   int opt;
 
-  while ((opt = getopt_long (argc, argv, "abcdfhilmno:s:pruv", options, NULL)) !=
-         -1)
+  const char *opts = "abcdfhilmno:s:pruvx";
+  while ((opt = getopt_long (argc, argv, opts, options, NULL)) != -1)
     {
       switch (opt)
 	{
@@ -770,6 +778,9 @@ process_args (int argc, char **argv)
           break;
 	case 'v':
 	  print_version ();
+	case 'x':
+	  flag_hash_filenames = 1;
+	  break;
 	  /* print_version will exit.  */
 	default:
 	  print_usage (true);
@@ -2147,6 +2158,15 @@ canonicalize_name (const char *name)
   return result;
 }
 
+/* Print hex representation of 16 bytes from SUM and write it to BUFFER.  */
+
+static void
+md5sum_to_hex (const char *sum, char *buffer)
+{
+  for (unsigned i = 0; i < 16; i++)
+    sprintf (buffer + (2 * i), "%02x", sum[i]);
+}
+
 /* Generate an output file name. INPUT_NAME is the canonicalized main
    input file and SRC_NAME is the canonicalized file name.
    LONG_OUTPUT_NAMES and PRESERVE_PATHS affect name generation.  With
@@ -2184,6 +2204,30 @@ make_gcov_file_name (const char *input_name, const char *src_name)
   ptr = mangle_name (src_name, ptr);
   strcpy (ptr, ".gcov");
 
+  /* With -x flag, file names will be in format:
+     source_file.c##<md5sum>.gcov.  */
+  if (flag_hash_filenames)
+    {
+      md5_ctx ctx;
+      char md5sum[16];
+      char md5sum_hex[33];
+
+      md5_init_ctx (&ctx);
+      md5_process_bytes (result, strlen (result), &ctx);
+      md5_finish_ctx (&ctx, md5sum);
+      md5sum_to_hex (md5sum, md5sum_hex);
+      free (result);
+
+      result = XNEWVEC (char, strlen (src_name) + 50);
+      ptr = result;
+      ptr = mangle_name (src_name, ptr);
+      ptr[0] = ptr[1] = '#';
+      ptr += 2;
+      memcpy (ptr, md5sum_hex, 32);
+      ptr += 32;
+      strcpy (ptr, ".gcov");
+    }
+
   return result;
 }
 
-- 
2.9.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gcov: add new option (--hash-names) (PR gcov-profile/36412).
  2016-08-15 11:43   ` Martin Liška
@ 2016-08-15 12:18     ` Nathan Sidwell
  2016-08-16 12:41       ` Martin Liška
  0 siblings, 1 reply; 9+ messages in thread
From: Nathan Sidwell @ 2016-08-15 12:18 UTC (permalink / raw)
  To: Martin Liška, GCC Patches; +Cc: Jan Hubicka, peter.klotz99

On 08/15/16 07:43, Martin Liška wrote:

> All nits are applied in the second version of patch.
>
>>
>> don't seem to match?  Why 'e'?
>
> I've renamed it to -x, well, a lot of letters are already occupied.

I guess 'x' may be better.  If there is no good choice, do we really need a 
short name? (There didn't seem to be a good letter available.  I'm ambivalent so 
will leave it to you.)

gcc/doc/gcov.texi
+For situations when a long name can potentially hit filesystem path limit,
+let's calculate md5sum of the path and create file

Sorry I missed this first time round.  The language is straight from the comment 
you added, so not really suitable for user documentation.  Add a bit of 
backstory.  How about:

  "By default, gcov uses the full pathname of the source files to to create an 
output filename.  This can lead to long filenames that can overflow filesystem 
limits.  This option creates names of the form 
@file{@var{source-file}##@var{md5}.gcov}, where the @var{source-file} component 
is the final filename part and the @var{md5} component is calculated from the 
full mangled name that would have been used otherwise."

+  const char *opts = "abcdfhilmno:s:pruvx";
Could you fix the alphabetization while you're there? (s:pr)

+  /* With -x flag, file names will be in format:
+     source_file.c##<md5sum>.gcov.  */

comment shouldn't really mention the option name.  Use some indirection to avoid 
another place that could get inconsistent :)

/* When hashing filenames, we shorten them by only using the filename
    component and appending a hash of the full (mangled) pathname.  */

nathan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gcov: add new option (--hash-names) (PR gcov-profile/36412).
  2016-08-15 12:18     ` Nathan Sidwell
@ 2016-08-16 12:41       ` Martin Liška
  2016-08-16 13:29         ` Nathan Sidwell
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Liška @ 2016-08-16 12:41 UTC (permalink / raw)
  To: Nathan Sidwell, GCC Patches; +Cc: Jan Hubicka, peter.klotz99

[-- Attachment #1: Type: text/plain, Size: 1834 bytes --]

On 08/15/2016 02:18 PM, Nathan Sidwell wrote:
> On 08/15/16 07:43, Martin Liška wrote:
> 
>> All nits are applied in the second version of patch.
>>
>>>
>>> don't seem to match?  Why 'e'?
>>
>> I've renamed it to -x, well, a lot of letters are already occupied.
> 
> I guess 'x' may be better.  If there is no good choice, do we really need a short name? (There didn't seem to be a good letter available.  I'm ambivalent so will leave it to you.)
> 
> gcc/doc/gcov.texi
> +For situations when a long name can potentially hit filesystem path limit,
> +let's calculate md5sum of the path and create file
> 
> Sorry I missed this first time round.  The language is straight from the comment you added, so not really suitable for user documentation.  Add a bit of backstory.  How about:
> 
>  "By default, gcov uses the full pathname of the source files to to create an output filename.  This can lead to long filenames that can overflow filesystem limits.  This option creates names of the form @file{@var{source-file}##@var{md5}.gcov}, where the @var{source-file} component is the final filename part and the @var{md5} component is calculated from the full mangled name that would have been used otherwise."
> 
> +  const char *opts = "abcdfhilmno:s:pruvx";
> Could you fix the alphabetization while you're there? (s:pr)
> 
> +  /* With -x flag, file names will be in format:
> +     source_file.c##<md5sum>.gcov.  */
> 
> comment shouldn't really mention the option name.  Use some indirection to avoid another place that could get inconsistent :)
> 
> /* When hashing filenames, we shorten them by only using the filename
>    component and appending a hash of the full (mangled) pathname.  */
> 
> nathan

Thank you for the improvement, all suggested changes are part of new version
of the patch.

Ready for trunk?
Thanks,
Martin

[-- Attachment #2: 0001-gcov-add-new-option-hash-filenames-PR-gcov-profile-3-v3.patch --]
[-- Type: text/x-patch, Size: 5340 bytes --]

From 5ea3c46b9c638a17fd56aa7536c2715cf0b97b4e Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 9 Aug 2016 16:27:10 +0200
Subject: [PATCH] gcov: add new option (--hash-filenames) (PR
 gcov-profile/36412).

gcc/ChangeLog:

2016-08-09  Martin Liska  <mliska@suse.cz>

	PR gcov-profile/36412
	* doc/gcov.texi: Document --hash-filenames(-x).
	* gcov.c (print_usage): Add the option.
	(process_args): Process the option, sort options alphabetically.
	(md5sum_to_hex): New function.
	(make_gcov_file_name): Do the md5sum and append it to a
	filename.
---
 gcc/doc/gcov.texi | 11 +++++++++++
 gcc/gcov.c        | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi
index df58df8..a0a7af7 100644
--- a/gcc/doc/gcov.texi
+++ b/gcc/doc/gcov.texi
@@ -133,6 +133,7 @@ gcov [@option{-v}|@option{--version}] [@option{-h}|@option{--help}]
      [@option{-r}|@option{--relative-only}]
      [@option{-s}|@option{--source-prefix} @var{directory}]
      [@option{-u}|@option{--unconditional-branches}]
+     [@option{-x}|@option{--hash-filenames}]
      @var{files}
 @c man end
 @c man begin SEEALSO
@@ -278,6 +279,16 @@ branch:28,nottaken
 Display demangled function names in output. The default is to show
 mangled function names.
 
+@item -x
+@itemx --hash-filenames
+By default, gcov uses the full pathname of the source files to to create
+an output filename.  This can lead to long filenames that can overflow
+filesystem limits.  This option creates names of the form
+@file{@var{source-file}##@var{md5}.gcov},
+where the @var{source-file} component is the final filename part and
+the @var{md5} component is calculated from the full mangled name that
+would have been used otherwise.
+
 @end table
 
 @command{gcov} should be run with the current directory the same as that
diff --git a/gcc/gcov.c b/gcc/gcov.c
index 30fc167..da0bc97 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -43,6 +43,7 @@ along with Gcov; see the file COPYING3.  If not see
 
 #include <vector>
 #include <algorithm>
+#include "md5.h"
 
 using namespace std;
 
@@ -359,6 +360,11 @@ static int flag_demangled_names = 0;
 
 static int flag_long_names = 0;
 
+/* For situations when a long name can potentially hit filesystem path limit,
+   let's calculate md5sum of the path and append it to a file name.  */
+
+static int flag_hash_filenames = 0;
+
 /* Output count information for every basic block, not merely those
    that contain line number information.  */
 
@@ -667,6 +673,7 @@ print_usage (int error_p)
   fnotice (file, "  -s, --source-prefix DIR         Source prefix to elide\n");
   fnotice (file, "  -u, --unconditional-branches    Show unconditional branch counts too\n");
   fnotice (file, "  -v, --version                   Print version number, then exit\n");
+  fnotice (file, "  -x, --hash-filenames            Hash long pathnames\n");
   fnotice (file, "\nFor bug reporting instructions, please see:\n%s.\n",
 	   bug_report_url);
   exit (status);
@@ -706,6 +713,7 @@ static const struct option options[] =
   { "source-prefix",        required_argument, NULL, 's' },
   { "unconditional-branches", no_argument,     NULL, 'u' },
   { "display-progress",     no_argument,       NULL, 'd' },
+  { "hash-filenames",	    no_argument,       NULL, 'x' },
   { 0, 0, 0, 0 }
 };
 
@@ -716,8 +724,8 @@ process_args (int argc, char **argv)
 {
   int opt;
 
-  while ((opt = getopt_long (argc, argv, "abcdfhilmno:s:pruv", options, NULL)) !=
-         -1)
+  const char *opts = "abcdfhilmno:prs:uvx";
+  while ((opt = getopt_long (argc, argv, opts, options, NULL)) != -1)
     {
       switch (opt)
 	{
@@ -770,6 +778,9 @@ process_args (int argc, char **argv)
           break;
 	case 'v':
 	  print_version ();
+	case 'x':
+	  flag_hash_filenames = 1;
+	  break;
 	  /* print_version will exit.  */
 	default:
 	  print_usage (true);
@@ -2147,6 +2158,15 @@ canonicalize_name (const char *name)
   return result;
 }
 
+/* Print hex representation of 16 bytes from SUM and write it to BUFFER.  */
+
+static void
+md5sum_to_hex (const char *sum, char *buffer)
+{
+  for (unsigned i = 0; i < 16; i++)
+    sprintf (buffer + (2 * i), "%02x", sum[i]);
+}
+
 /* Generate an output file name. INPUT_NAME is the canonicalized main
    input file and SRC_NAME is the canonicalized file name.
    LONG_OUTPUT_NAMES and PRESERVE_PATHS affect name generation.  With
@@ -2184,6 +2204,30 @@ make_gcov_file_name (const char *input_name, const char *src_name)
   ptr = mangle_name (src_name, ptr);
   strcpy (ptr, ".gcov");
 
+  /* When hashing filenames, we shorten them by only using the filename
+     component and appending a hash of the full (mangled) pathname.  */
+  if (flag_hash_filenames)
+    {
+      md5_ctx ctx;
+      char md5sum[16];
+      char md5sum_hex[33];
+
+      md5_init_ctx (&ctx);
+      md5_process_bytes (result, strlen (result), &ctx);
+      md5_finish_ctx (&ctx, md5sum);
+      md5sum_to_hex (md5sum, md5sum_hex);
+      free (result);
+
+      result = XNEWVEC (char, strlen (src_name) + 50);
+      ptr = result;
+      ptr = mangle_name (src_name, ptr);
+      ptr[0] = ptr[1] = '#';
+      ptr += 2;
+      memcpy (ptr, md5sum_hex, 32);
+      ptr += 32;
+      strcpy (ptr, ".gcov");
+    }
+
   return result;
 }
 
-- 
2.9.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gcov: add new option (--hash-names) (PR gcov-profile/36412).
  2016-08-16 12:41       ` Martin Liška
@ 2016-08-16 13:29         ` Nathan Sidwell
  2016-08-16 14:18           ` Martin Liška
  0 siblings, 1 reply; 9+ messages in thread
From: Nathan Sidwell @ 2016-08-16 13:29 UTC (permalink / raw)
  To: Martin Liška, GCC Patches; +Cc: Jan Hubicka, peter.klotz99

On 08/16/16 08:41, Martin Liška wrote:

> Thank you for the improvement, all suggested changes are part of new version
> of the patch.
>
> Ready for trunk?

ok, thanks

nathan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gcov: add new option (--hash-names) (PR gcov-profile/36412).
  2016-08-16 13:29         ` Nathan Sidwell
@ 2016-08-16 14:18           ` Martin Liška
  2016-08-16 14:58             ` Nathan Sidwell
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Liška @ 2016-08-16 14:18 UTC (permalink / raw)
  To: Nathan Sidwell, GCC Patches; +Cc: Jan Hubicka, peter.klotz99

On 08/16/2016 03:28 PM, Nathan Sidwell wrote:
> On 08/16/16 08:41, Martin Liška wrote:
> 
>> Thank you for the improvement, all suggested changes are part of new version
>> of the patch.
>>
>> Ready for trunk?
> 
> ok, thanks
> 
> nathan
> 

Installed as r239503.
Well, the creator of the PR reported that he's been using GCC 6.x,
may I install the same patch to gcc-6 branch?

Martin

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gcov: add new option (--hash-names) (PR gcov-profile/36412).
  2016-08-16 14:18           ` Martin Liška
@ 2016-08-16 14:58             ` Nathan Sidwell
  2016-08-16 15:01               ` Martin Liška
  0 siblings, 1 reply; 9+ messages in thread
From: Nathan Sidwell @ 2016-08-16 14:58 UTC (permalink / raw)
  To: Martin Liška, GCC Patches; +Cc: Jan Hubicka, peter.klotz99

On 08/16/16 10:18, Martin Liška wrote:
> On 08/16/2016 03:28 PM, Nathan Sidwell wrote:
>> On 08/16/16 08:41, Martin Liška wrote:

>
> Installed as r239503.
> Well, the creator of the PR reported that he's been using GCC 6.x,
> may I install the same patch to gcc-6 branch?

I see the 6 branch is now frozen, except for blocking regressions & docs.

nathan



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gcov: add new option (--hash-names) (PR gcov-profile/36412).
  2016-08-16 14:58             ` Nathan Sidwell
@ 2016-08-16 15:01               ` Martin Liška
  0 siblings, 0 replies; 9+ messages in thread
From: Martin Liška @ 2016-08-16 15:01 UTC (permalink / raw)
  To: Nathan Sidwell, GCC Patches; +Cc: Jan Hubicka, peter.klotz99

On 08/16/2016 04:58 PM, Nathan Sidwell wrote:
> I see the 6 branch is now frozen, except for blocking regressions & docs.
> 
> nathan

Sure, I'm planning to commit after 6.2 will be released, thus the patch can
land 6.3?

Martin

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-08-16 15:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-09 14:32 [PATCH] gcov: add new option (--hash-names) (PR gcov-profile/36412) Martin Liška
2016-08-15 10:47 ` Nathan Sidwell
2016-08-15 11:43   ` Martin Liška
2016-08-15 12:18     ` Nathan Sidwell
2016-08-16 12:41       ` Martin Liška
2016-08-16 13:29         ` Nathan Sidwell
2016-08-16 14:18           ` Martin Liška
2016-08-16 14:58             ` Nathan Sidwell
2016-08-16 15:01               ` Martin Liška

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).