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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |10walls at gmail dot com

--- Comment #4 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to John Selbie from comment #3)
> 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.

All right, so it's normal Unix file system. Can you please show me output
of the 'pwd' command?

> 
> 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:

But I bet they don't use them as directory separator character. And that's what
we want for concatenation of -profile-dir and an object name.

> 
> @@ -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

It goes through:

libgcc/libgcov-driver-system.c:
create_file_directory:

static int
create_file_directory (char *filename)
{
#if !defined(TARGET_POSIX_IO) && !defined(_WIN32)
  (void) filename;
  return -1;
#else
  char *s;

  s = filename;

  if (HAS_DRIVE_SPEC(s))
    s += 2;
  if (IS_DIR_SEPARATOR(*s))
    ++s;
  for (; *s != '\0'; s++)
    if (IS_DIR_SEPARATOR(*s))
      {
        char sep = *s;
        *s  = '\0';
...

so again, it uses IS_DIR_SEPARATOR which is:

#if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined
(__CYGWIN__)
...
#  define HAS_DRIVE_SPEC(f) HAS_DOS_DRIVE_SPEC (f)
#  define IS_DIR_SEPARATOR(c) IS_DOS_DIR_SEPARATOR (c)
#  define IS_ABSOLUTE_PATH(f) IS_DOS_ABSOLUTE_PATH (f)

That's why you can't only replace strings in the instrumented binary.

You can test the following patch:

diff --git a/include/filenames.h b/include/filenames.h
index 1ed441221ac..773ba4865b3 100644
--- a/include/filenames.h
+++ b/include/filenames.h
@@ -32,7 +32,7 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA.
 extern "C" {
 #endif

-#if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined
(__CYGWIN__)
+#if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__)
 #  ifndef HAVE_DOS_BASED_FILE_SYSTEM
 #    define HAVE_DOS_BASED_FILE_SYSTEM 1
 #  endif

I'm adding Cygwin port maintainer, he can help us with the path separators.

> 
> 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.

Reply via email to