https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65820
Bug ID: 65820 Summary: escape backslashes in .d file Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: paul_robinson at playstation dot sony.com gcc should escape backslashes when writing a .d file, because that's what GNU make expects. (Yes, I know special characters in filenames are a bad idea...) There are various scenarios, this one seems to be the easiest to demonstrate. $ gcc --version gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ make --version GNU Make 3.81 Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This program built for x86_64-pc-linux-gnu $ cat quote.c #include "a\\b.h" $ # BTW that's two backslashes, not one escaped backslash; C11 6.4.7. $ touch a\\\\b.h $ gcc -c -MMD quote.c $ # But the .d file just copies the string literally. $ cat quote.d quote.o: quote.c a\\b.h $ rm a\\\\b.h $ # Make properly doesn't find the nonexistent file.... $ make -f quote.d quote.o make: *** No rule to make target `a\\b.h', needed by `quote.o'. Stop. $ # Accidentally create the wrong number of backslashes... $ touch a\\b.h $ # ...make will interpret a\\b.h as a\b.h, even though gcc doesn't. $ make -f quote.d quote.o cc -c -o quote.o quote.c quote.c:1:18: fatal error: a\\b.h: No such file or directory #include "a\\b.h" ^ compilation terminated. make: *** [quote.o] Error 1 $ If I modify the .d file to escape backslashes, it works properly. $ cat quote.d quote.o: quote.c a\\\\b.h $ touch a\\\\b.h $ ls a\\b.h quote.c quote.d $ make -f quote.d quote.o cc -c -o quote.o quote.c $