]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
driver: Escape special characters in '-fdeps-{file,target}' [PR120974]
authorNathaniel Shead <nathanieloshead@gmail.com>
Sun, 22 Feb 2026 02:09:00 +0000 (13:09 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Sun, 22 Feb 2026 15:25:08 +0000 (02:25 +1100)
The driver uses the 'join' function to calculate the default output for
the -fdeps-file and -fdeps-target parameters from the parameter given to
-o (or the basename of the input file).  But if the path given to -o has
any whitespace in it this causes cc1plus to see arguments like

  "-o some file.o" "-fdeps-file=some" "file.ddi"

which breaks.  Fixed by adjusting the 'join' function to escape any
special characters in the result.

PR c++/120974

gcc/ChangeLog:

* gcc.cc (join_spec_func): Escape special characters.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/gcc.cc

index 065f69c9d8beabbd9c28a96d5dcec025c6b86ffe..f3e0004cdb8b4575ae4b0f0843ee287ba3bceaf9 100644 (file)
@@ -11230,7 +11230,8 @@ find_fortran_preinclude_file (int argc, const char **argv)
   return result;
 }
 
-/* The function takes any number of arguments and joins them together.
+/* The function takes any number of arguments and joins them together,
+   escaping any special characters.
 
    This seems to be necessary to build "-fjoined=foo.b" from "-fseparate foo.a"
    with a %{fseparate*:-fjoined=%.b$*} rule without adding undesired spaces:
@@ -11243,12 +11244,15 @@ find_fortran_preinclude_file (int argc, const char **argv)
 static const char *
 join_spec_func (int argc, const char **argv)
 {
-  if (argc == 1)
-    return argv[0];
-  for (int i = 0; i < argc; ++i)
-    obstack_grow (&obstack, argv[i], strlen (argv[i]));
-  obstack_1grow (&obstack, '\0');
-  return XOBFINISH (&obstack, const char *);
+  const char *result = argv[0];
+  if (argc != 1)
+    {
+      for (int i = 0; i < argc; ++i)
+       obstack_grow (&obstack, argv[i], strlen (argv[i]));
+      obstack_1grow (&obstack, '\0');
+      result = XOBFINISH (&obstack, const char *);
+    }
+  return quote_spec (xstrdup (result));
 }
 
 /* If any character in ORIG fits QUOTE_P (_, P), reallocate the string