From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0D62A385F011; Wed, 15 Apr 2020 08:55:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0D62A385F011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1586940915; bh=H7d9vAyMpOePBP/TN18mflwXtocYygt0EgTwaWkauP8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rUmqMwkIGzd4MaA5DKCpaNIqdtnZwDyYNwOyhW1U2si3lGbdYHKJKp6wDdJt8q1Ax Srw0zBjg86hpdCnEkYkoo5+HCDKR38dye3KeCmMfaorWOSmmvG0SHYXLRXKV7xxa3q UA1rrkkErfvQaG+n1hLyvIreQ1CcoBrCOmsfRPag= From: "marxin at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug gcov-profile/94570] -fprofile-dir is broken on Cygwin Date: Wed, 15 Apr 2020 08:55:14 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: gcov-profile X-Bugzilla-Version: 9.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: marxin at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: marxin at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Apr 2020 08:55:15 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94570 Martin Li=C5=A1ka changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |10walls at gmail dot com --- Comment #4 from Martin Li=C5=A1ka --- (In reply to John Selbie from comment #3) > I am not sure I agree. But I do defer to your expertise. >=20 > 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? >=20 > Wouldn't the fix be this: >=20 > @@ -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 =3D "\\"; > #else > const char *separator =3D "/"; >=20 >=20 > There's so reason to use backslashes at all, even for native Win32. Windo= ws > 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. >=20 > @@ -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 =3D "\\"; > -#else > - const char *separator =3D "/"; > -#endif > - filename =3D concat (getpwd (), separator, filename, NULL); > + filename =3D concat (getpwd (), "/", filename, NULL); > filename =3D mangle_path (filename); > len =3D strlen (filename); > } >=20 >=20 > 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: >=20 > 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 =3D filename; if (HAS_DRIVE_SPEC(s)) s +=3D 2; if (IS_DIR_SEPARATOR(*s)) ++s; for (; *s !=3D '\0'; s++) if (IS_DIR_SEPARATOR(*s)) { char sep =3D *s; *s =3D '\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, Bosto= n, 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. >=20 > I even hacked it the other way to use forward slashes more consistently.= =20 > Same thing: >=20 > profiling:profile\#home#jselbie#bench\anyprogram.gcda:Skip >=20 > So while I think forward-slash consistency is a key. It's not the only b= ug > preventing the -fprofile-dir flag to work.=