g++ with -fprofile-dir flag has a bug (backslash instead of forward-slash issue)

JonY 10walls@gmail.com
Sun Apr 12 09:55:56 GMT 2020


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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://cygwin.com/pipermail/cygwin/attachments/20200412/29818d4c/attachment.sig>


More information about the Cygwin mailing list