public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* g++ with -fprofile-dir flag has a bug (backslash instead of forward-slash issue)
@ 2020-04-12  7:27 John Selbie
  2020-04-12  9:55 ` JonY
  0 siblings, 1 reply; 6+ messages in thread
From: John Selbie @ 2020-04-12  7:27 UTC (permalink / raw)
  To: cygwin

TLDR: With gcc/g++ 9.2.0 and 9.30 on Cygwin, when you use
-fprofile-generate and -fprofile-dir together, the target path for the
.gcda file is corrupted with a backslash instead of having a forward slash
used.

Here's a sample run where profile guided optimization is getting enabled
for a simple little C++ program:

    jselbie@IRONMAIDEN ~/bench
    $ g++ bench.cpp -o bench -fprofile-generate
-fprofile-dir=/home/jselbie/bench/profile -O3

    jselbie@IRONMAIDEN ~/bench
    $ ./bench.exe

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

That "profiling...Skip" line is an error indicating that the profiling
library can't save the gcda file. If you look closely,there's backslash
between the encoded path and the filename (bench.gcda).

Doing a strings search on the binary reveals the same thing:

    jselbie@IRONMAIDEN ~/bench
    $ strings bench.exe | grep jselbie
    /home/jselbie/bench/profile/#home#jselbie#bench\bench.gcda

If I switch back to Linux and do the same steps, it not only works, but you
can see there is no backslash embedded into the binary either

    jselbie@IRONMAIDEN:~/bench$ g++ bench.cpp -o bench -fprofile-generate
-fprofile-dir=/home/jselbie/bench/profile -O3

    jselbie@IRONMAIDEN:~/bench$ ./bench

    jselbie@IRONMAIDEN:~/bench$ ls profile/
    bench.gcda

    jselbie@IRONMAIDEN:~/bench$ strings bench | grep jselbie
    /home/jselbie/bench/profile/bench.gcda


The workaround is to just skip the -fprofile-dir flag altogether.

Seems like there is a bug in Cygwin's build of gcc/g++ that puts the wrong
path separator into the executable

Can this be fixed?  Or a place where I can file a bug?

jrs

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

* Re: g++ with -fprofile-dir flag has a bug (backslash instead of forward-slash issue)
  2020-04-12  7:27 g++ with -fprofile-dir flag has a bug (backslash instead of forward-slash issue) John Selbie
@ 2020-04-12  9:55 ` JonY
  2020-04-12 10:59   ` John Selbie
  0 siblings, 1 reply; 6+ messages in thread
From: JonY @ 2020-04-12  9:55 UTC (permalink / raw)
  To: cygwin


[-- Attachment #1.1: Type: text/plain, Size: 1987 bytes --]

On 4/12/20 7:27 AM, John Selbie via Cygwin wrote:
> TLDR: With gcc/g++ 9.2.0 and 9.30 on Cygwin, when you use
> -fprofile-generate and -fprofile-dir together, the target path for the
> .gcda file is corrupted with a backslash instead of having a forward slash
> used.
> 
> Here's a sample run where profile guided optimization is getting enabled
> for a simple little C++ program:
> 
>     jselbie@IRONMAIDEN ~/bench
>     $ g++ bench.cpp -o bench -fprofile-generate
> -fprofile-dir=/home/jselbie/bench/profile -O3
> 
>     jselbie@IRONMAIDEN ~/bench
>     $ ./bench.exe
> 
> profiling:/home/jselbie/bench/profile/#home#jselbie#bench\bench.gcda:Skip
> 
> That "profiling...Skip" line is an error indicating that the profiling
> library can't save the gcda file. If you look closely,there's backslash
> between the encoded path and the filename (bench.gcda).
> 
> Doing a strings search on the binary reveals the same thing:
> 
>     jselbie@IRONMAIDEN ~/bench
>     $ strings bench.exe | grep jselbie
>     /home/jselbie/bench/profile/#home#jselbie#bench\bench.gcda
> 
> If I switch back to Linux and do the same steps, it not only works, but you
> can see there is no backslash embedded into the binary either
> 
>     jselbie@IRONMAIDEN:~/bench$ g++ bench.cpp -o bench -fprofile-generate
> -fprofile-dir=/home/jselbie/bench/profile -O3
> 
>     jselbie@IRONMAIDEN:~/bench$ ./bench
> 
>     jselbie@IRONMAIDEN:~/bench$ ls profile/
>     bench.gcda
> 
>     jselbie@IRONMAIDEN:~/bench$ strings bench | grep jselbie
>     /home/jselbie/bench/profile/bench.gcda
> 
> 
> The workaround is to just skip the -fprofile-dir flag altogether.
> 
> Seems like there is a bug in Cygwin's build of gcc/g++ that puts the wrong
> path separator into the executable
> 
> Can this be fixed?  Or a place where I can file a bug?
> 

Try filing the issue on https://gcc.gnu.org/bugzilla/, include a minimal
test case that shows the problem, thanks.



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: g++ with -fprofile-dir flag has a bug (backslash instead of forward-slash issue)
  2020-04-12  9:55 ` JonY
@ 2020-04-12 10:59   ` John Selbie
  2020-04-12 11:24     ` JonY
  0 siblings, 1 reply; 6+ messages in thread
From: John Selbie @ 2020-04-12 10:59 UTC (permalink / raw)
  To: cygwin

Sure, but this bug is unique to cygwin.  Why would that be there bug?


On Sun, Apr 12, 2020 at 2:57 AM JonY via Cygwin <cygwin@cygwin.com> wrote:

> On 4/12/20 7:27 AM, John Selbie via Cygwin wrote:
> > TLDR: With gcc/g++ 9.2.0 and 9.30 on Cygwin, when you use
> > -fprofile-generate and -fprofile-dir together, the target path for the
> > .gcda file is corrupted with a backslash instead of having a forward
> slash
> > used.
> >
> > Here's a sample run where profile guided optimization is getting enabled
> > for a simple little C++ program:
> >
> >     jselbie@IRONMAIDEN ~/bench
> >     $ g++ bench.cpp -o bench -fprofile-generate
> > -fprofile-dir=/home/jselbie/bench/profile -O3
> >
> >     jselbie@IRONMAIDEN ~/bench
> >     $ ./bench.exe
> >
> > profiling:/home/jselbie/bench/profile/#home#jselbie#bench\bench.gcda:Skip
> >
> > That "profiling...Skip" line is an error indicating that the profiling
> > library can't save the gcda file. If you look closely,there's backslash
> > between the encoded path and the filename (bench.gcda).
> >
> > Doing a strings search on the binary reveals the same thing:
> >
> >     jselbie@IRONMAIDEN ~/bench
> >     $ strings bench.exe | grep jselbie
> >     /home/jselbie/bench/profile/#home#jselbie#bench\bench.gcda
> >
> > If I switch back to Linux and do the same steps, it not only works, but
> you
> > can see there is no backslash embedded into the binary either
> >
> >     jselbie@IRONMAIDEN:~/bench$ g++ bench.cpp -o bench
> -fprofile-generate
> > -fprofile-dir=/home/jselbie/bench/profile -O3
> >
> >     jselbie@IRONMAIDEN:~/bench$ ./bench
> >
> >     jselbie@IRONMAIDEN:~/bench$ ls profile/
> >     bench.gcda
> >
> >     jselbie@IRONMAIDEN:~/bench$ strings bench | grep jselbie
> >     /home/jselbie/bench/profile/bench.gcda
> >
> >
> > The workaround is to just skip the -fprofile-dir flag altogether.
> >
> > Seems like there is a bug in Cygwin's build of gcc/g++ that puts the
> wrong
> > path separator into the executable
> >
> > Can this be fixed?  Or a place where I can file a bug?
> >
>
> Try filing the issue on https://gcc.gnu.org/bugzilla/, include a minimal
> test case that shows the problem, thanks.
>
>
> --
> Problem reports:      https://cygwin.com/problems.html
> FAQ:                  https://cygwin.com/faq/
> Documentation:        https://cygwin.com/docs.html
> Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
>

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

* Re: g++ with -fprofile-dir flag has a bug (backslash instead of forward-slash issue)
  2020-04-12 10:59   ` John Selbie
@ 2020-04-12 11:24     ` JonY
  2020-04-12 11:39       ` John Selbie
  0 siblings, 1 reply; 6+ messages in thread
From: JonY @ 2020-04-12 11:24 UTC (permalink / raw)
  To: cygwin


[-- Attachment #1.1: Type: text/plain, Size: 191 bytes --]

On 4/12/20 10:59 AM, John Selbie via Cygwin wrote:
> Sure, but this bug is unique to cygwin.  Why would that be there bug?
> 

Because Cygwin does not modify gcc to use Windows paths.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: g++ with -fprofile-dir flag has a bug (backslash instead of forward-slash issue)
  2020-04-12 11:24     ` JonY
@ 2020-04-12 11:39       ` John Selbie
  2020-04-12 12:56         ` JonY
  0 siblings, 1 reply; 6+ messages in thread
From: John Selbie @ 2020-04-12 11:39 UTC (permalink / raw)
  To: JonY; +Cc: cygwin

I would file a bug, but that link you provided takes me to a sign-up page
that says, "Account creation restricted.  Please contact ... response
within 24 hours..."

A quick cursory glace of GCC sources would suggest the issue is in
\gcc\coverage.c. This is a snippit of a function that builds the mangled
path for the .gcda file.

          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);
    }

I'm not an expert on building gcc.  I just suspect that somewhere in the
build chain  HAVE_DOS_BASED_FILE_SYSTEM is getting defined for or by cygwin.

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

Still a gcc bug?  I'm guessing so.




On Sun, Apr 12, 2020 at 4:26 AM JonY via Cygwin <cygwin@cygwin.com> wrote:

> On 4/12/20 10:59 AM, John Selbie via Cygwin wrote:
> > Sure, but this bug is unique to cygwin.  Why would that be there bug?
> >
>
> Because Cygwin does not modify gcc to use Windows paths.
>
> --
> Problem reports:      https://cygwin.com/problems.html
> FAQ:                  https://cygwin.com/faq/
> Documentation:        https://cygwin.com/docs.html
> Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
>

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

* Re: g++ with -fprofile-dir flag has a bug (backslash instead of forward-slash issue)
  2020-04-12 11:39       ` John Selbie
@ 2020-04-12 12:56         ` JonY
  0 siblings, 0 replies; 6+ messages in thread
From: JonY @ 2020-04-12 12:56 UTC (permalink / raw)
  To: cygwin


[-- Attachment #1.1: Type: text/plain, Size: 1289 bytes --]

On 4/12/20 11:39 AM, John Selbie wrote:
> I would file a bug, but that link you provided takes me to a sign-up page
> that says, "Account creation restricted.  Please contact ... response
> within 24 hours..."
> 
> A quick cursory glace of GCC sources would suggest the issue is in
> \gcc\coverage.c. This is a snippit of a function that builds the mangled
> path for the .gcda file.
> 
>           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);
>     }
> 
> I'm not an expert on building gcc.  I just suspect that somewhere in the
> build chain  HAVE_DOS_BASED_FILE_SYSTEM is getting defined for or by cygwin.
> 
> 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
> 
> Still a gcc bug?  I'm guessing so.
> 

The file is in gcc, so yes.



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2020-04-12 12:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-12  7:27 g++ with -fprofile-dir flag has a bug (backslash instead of forward-slash issue) John Selbie
2020-04-12  9:55 ` JonY
2020-04-12 10:59   ` John Selbie
2020-04-12 11:24     ` JonY
2020-04-12 11:39       ` John Selbie
2020-04-12 12:56         ` JonY

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