[Bug gcov-profile/94570] -fprofile-dir is broken on Cygwin

john at selbie dot com gcc-bugzilla@gcc.gnu.org
Wed Apr 15 08:32:15 GMT 2020


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

--- Comment #3 from John Selbie <john at selbie dot com> ---
I am not sure I agree.  But I do defer to your expertise.

The problem is that Cygwin is not really a DOS_BASED_FILE_SYSTEM.  It's
emulating Unix - including using forward-slashes everywhere.  So I don't know
why it's trying to embed backslashes in the code.

Wouldn't the fix be this:

@@ -1215,7 +1215,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
+#if HAVE_DOS_BASED_FILE_SYSTEM && !CYGWIN
          const char *separator = "\\";
 #else
          const char *separator = "/";


There's so reason to use backslashes at all, even for native Win32. Windows and
DOS can't handle forward slashes at the command line, but absolutely can handle
paths with forward slashes in code.  So an even simpler fix:

@@ -1215,12 +1215,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 (), "/", filename, NULL);
          filename = mangle_path (filename);
          len = strlen (filename);
        }


But even then I'm skeptical. I had "hacked the binary" with a hex editor to
change the backslash to a forward slash.  Same error, even though the modified
path appears on the screen:

   profiling:profile/#home#jselbie#bench/anyprogram.gcda:Skip

I even hacked it the other way to use forward slashes more consistently.  Same
thing:

    profiling:profile\#home#jselbie#bench\anyprogram.gcda:Skip

So while I think forward-slash consistency is a key.  It's not the only bug
preventing the -fprofile-dir flag to work.


More information about the Gcc-bugs mailing list