public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "marxin at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug gcov-profile/94570] -fprofile-dir is broken on Cygwin
Date: Wed, 15 Apr 2020 07:47:30 +0000	[thread overview]
Message-ID: <bug-94570-4-cj1lS1QbCC@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94570-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94570

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to John Selbie from comment #0)
> The following bug is unique to gcc and g++ running on Cygwin.  I can repro
> this on both gcc 9.2 and 9.3.
> 
> Using almost any source file, execute the following to start the first phase
> of a profile guided optimization on Cygwin with a target directory to store
> .gcda files:
> 
> $ g++ anyprogram.cpp -o anyprogram -fprofile-generate
> -fprofile-dir=profiledata
> 
> Then run the compiled code to start the program:
> 
> $ ./anyprogram.exe
> 
> After the program completes, the following output is revealed to show that
> the coverage code couldn't save the gcda file:
> 
> profiling:profiledata/#home#jselbie\anyprogram.gcda:Skip
> 
> The .gcda file is not crated.

Thank you for the report and the analysis.
I see, we mix '/' and *separator (in this case '\'). So a possible fix could
be:

diff --git a/gcc/coverage.c b/gcc/coverage.c
index 30ae84df90f..aa1d1b0d120 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -1199,6 +1199,13 @@ coverage_obj_finish (vec<constructor_elt, va_gc> *ctor)
 void
 coverage_init (const char *filename)
 {
+#if HAVE_DOS_BASED_FILE_SYSTEM
+  const char *dir_separator = "\\";
+#else
+  const char *dir_separator = "/";
+#endif
+
+
   int len = strlen (filename);
   int prefix_len = 0;

@@ -1215,12 +1222,7 @@ coverage_init (const char *filename)
         of filename in order to prevent file path clashing.  */
       if (profile_data_prefix)
        {
-#if HAVE_DOS_BASED_FILE_SYSTEM
-         const char *separator = "\\";
-#else
-         const char *separator = "/";
-#endif
-         filename = concat (getpwd (), separator, filename, NULL);
+         filename = concat (getpwd (), dir_separator, filename, NULL);
          filename = mangle_path (filename);
          len = strlen (filename);
        }
@@ -1238,7 +1240,7 @@ coverage_init (const char *filename)
   if (profile_data_prefix)
     {
       memcpy (da_file_name, profile_data_prefix, prefix_len);
-      da_file_name[prefix_len++] = '/';
+      da_file_name[prefix_len++] = *dir_separator;
     }
   memcpy (da_file_name + prefix_len, filename, len);
   strcpy (da_file_name + prefix_len + len, GCOV_DATA_SUFFIX);

> 
> You can even see the mangled string it in the resulting binary:
> 
> $ strings anyprogram.exe | grep jselbie
> profiledata/#home#jselbie\anyprogram.gcda
> 
> 
> I see two possible issues that's causing this.
> 
> First, the anyprogram.gcda string is getting appended with a back slash
> instead of a forward slash
> 
> A quick cursory glace of GCC sources would suggest the issue is in
> \gcc\coverage.c. Looking at the code for coverage_init inside
> gcc/converage.c reveals the following:
> 
>           if (profile_data_prefix)
>         {
> #if HAVE_DOS_BASED_FILE_SYSTEM
>      const char *separator = "\\";
>     #else
>      const char *separator = "/";
>     #endif
>      filename = concat (getpwd (), separator, filename, NULL);
>      filename = mangle_path (filename);
>      len = strlen (filename);
>     }
> 
> 
> Another cursory search of gcc sources suggest HAVE_DOS_BASED_FILE_SYSTEM is
> defined by this preprocessor stuff:
> 
> #if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined
> (__CYGWIN__)
> #  ifndef HAVE_DOS_BASED_FILE_SYSTEM
> #    define HAVE_DOS_BASED_FILE_SYSTEM 1
> #  endif
> 
> Because HAVE_DOS_BASED_FILE_SYSTEM is getting defined for Cygwin, then
> coverage_init is going to use a backslash separator as well. Whether CYGWIN
> should be considered a DOS based file system or a special exception needs to
> be made in coverage_init, well, I'm not sure.

I guess we should use backslashes, or?

> 
> The second issue is with the way the path gets mangled with # chars.  That's
> not consistent with the Linux build (at least with g++ 7.5 that I have
> going).

Yes, that's expected and it's the answer for PR85759.

> 
> 
> The workaround for now is to skip using the -fprofile-dir flag and allow
> default save behavior for the gcda flag.

  parent reply	other threads:[~2020-04-15  7:47 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-12 21:02 [Bug gcov-profile/94570] New: " john at selbie dot com
2020-04-14  6:22 ` [Bug gcov-profile/94570] " marxin at gcc dot gnu.org
2020-04-15  7:47 ` marxin at gcc dot gnu.org [this message]
2020-04-15  8:32 ` john at selbie dot com
2020-04-15  8:55 ` marxin at gcc dot gnu.org
2020-04-15  9:07 ` john at selbie dot com
2020-04-15 10:40 ` marxin at gcc dot gnu.org
2020-04-15 12:24 ` 10walls at gmail dot com
2020-04-15 12:27 ` 10walls at gmail dot com
2020-04-15 12:46 ` 10walls at gmail dot com
2020-04-15 16:11 ` 10walls at gmail dot com
2020-04-16  7:57 ` marxin at gcc dot gnu.org
2020-04-17  7:23 ` cvs-commit at gcc dot gnu.org
2020-04-17  7:26 ` marxin at gcc dot gnu.org
2020-04-20  9:27 ` cvs-commit at gcc dot gnu.org
2020-04-20  9:28 ` marxin at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-94570-4-cj1lS1QbCC@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).