Andrew Burgess <[email protected]> writes:

Ping!


The more I think about this, the more I wonder if upstream gcc should be
reverting the change I made.  This has changed behaviour that has been
in place for years (decades?) and broken compatibility with clang.  But
I really feel like input from wiser gcc minds would be great.

Thanks,
Andrew




> It was brought to my attention that a change I made to libiberty/argv.c
> has had an impact on how GCC 16 parses response files.  This change was
> made in commit:
>
>   commit a87954610f5e48a89b63a3194df9f5087bdc2f77
>   Date:   Wed Dec 6 16:45:31 2023 +0000
>
>     libiberty/buildargv: POSIX behaviour for backslash handling
>
> This change has caused problems for the meson build tool, but has been
> worked around in a change which can be seen here:
>
>   https://github.com/mesonbuild/meson/pull/16276
>
> What has changed in this: before commit a87954610f5e48a8 response files
> were parsed using gcc's bespoke argument splitting/parsing rules.  After
> a87954610f5e48a8 the splitting/parsing follows standard POSIX shell
> rules.
>
> My motivation for making this change was to improve GDB's argument
> splitting/parsing, as (currently) GDB shares this code with gcc.
>
> It is worth noting that on Linux, Clang followed (at least as far as my
> experimentation can tell) the old GCC rules, so by making this change,
> not only has GCC changed from 15 -> 16, but GCC has also changed from
> Clang -> GCC.
>
> What should be done about this?
>
> When I was notified about this (off list) w.r.t. the Meson bug, the
> request I got was "Please document this in the GCC 16 porting guide".
> At the end of this email you'll find a patch, which is a collaboration
> between my and an LLM, that tries to document this change.  The patch is
> for the GCC website docs, and applies to the porting to GCC 16 page.
>
> But I'm not entirely sure that documenting this is the right solution.
> Given this is potentially a significant change, and was not made with a
> full understanding of the impact it was going to have, maybe this is
> something that we should be reverting?  If we now understand that this
> code needs to have non-POSIX shell behaviour, then GDB should maybe just
> fork this function and do its own thing, then GCC can go back to its old
> way of doing things and GDB can do its thing separately.
>
> I'm obviously happy to help however I can to fix this (if it needs
> fixing), but I'm not entirely sure what the correct next step is here,
> so I'm looking for guidance.
>
> Thanks,
> Andrew
>
> ---
>
> commit 48e2bb49cf053c7b57e2fe2e4874f6eabb10c0f8
> Author: Andrew Burgess <[email protected]>
> Date:   Fri Oct 30 16:16:01 2026 +0000
>
>     gcc-16: document new response-file quoting rules
>     
>     Document that the quoting rules used to split the contents of @file
>     response files into individual arguments now follow the POSIX shell:
>     backslashes are literal inside single quotes, inside double quotes
>     they only escape $, backtick, double quote, backslash, and newline,
>     and backslash-newline outside single quotes acts as a line
>     continuation.  Previously a backslash always escaped the following
>     character, even inside quotes.
>     
>     Explain the consequences for generators of response files: quoting
>     alone does not make backslashes literal under either the old or the
>     new rules, and the way to write a literal backslash inside single
>     quotes differs between GCC 15 and GCC 16.  GCC uses the same rules on
>     all operating systems, while Clang continues to use the previous
>     interpretation on non-Windows systems and MSVC-style rules on
>     Windows, so response files containing backslashes may now be
>     interpreted differently by GCC and Clang.  For response files that
>     must be interpreted the same way by multiple compilers or compiler
>     versions, recommend escaping each special character with a backslash
>     outside quotes, with newlines placed inside single quotes since
>     backslash-newline is now a line continuation.
>
> diff --git a/htdocs/gcc-16/porting_to.html b/htdocs/gcc-16/porting_to.html
> index 251000ec5..d8bffd0b5 100644
> --- a/htdocs/gcc-16/porting_to.html
> +++ b/htdocs/gcc-16/porting_to.html
> @@ -219,6 +219,70 @@ The solution is to use (e.g.) 
> <code>std::allocator_traits&lt;A&gt;::destroy</cod
>  in place of <code>A::destroy</code>.
>  </p>
>  
> +<h2 id="rspfiles">Response files</h2>
> +
> +<p>
> +When a command line would otherwise be too long, tools often pass
> +arguments to GCC in a <em>response file</em>, given on the command line
> +as <code>@<var>file</var></code>.  In GCC&nbsp;16, the quoting rules
> +used to split the contents of such a file into individual arguments
> +now follow the POSIX shell
> +(<a 
> href="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html";>Shell
> +Command Language, chapter 2</a>).
> +</p>
> +
> +<p>
> +Up to and including GCC&nbsp;15, a backslash was always treated as an
> +escape character: it was removed from the argument and caused the
> +following character to be taken literally, even inside quotes.  In
> +GCC&nbsp;16, the following rules apply instead:
> +</p>
> +
> +<ul>
> +  <li>Inside single quotes (<code>'&hellip;'</code>), backslashes are
> +      now literal characters and no longer escape the following
> +      character.</li>
> +  <li>Inside double quotes (<code>"&hellip;"</code>), a backslash only
> +      escapes the characters <code>$</code>, <code>`</code>,
> +      <code>"</code>, <code>\</code>, and newline; before any other
> +      character the backslash is kept literally.</li>
> +  <li>Outside single quotes, a backslash followed by a newline is now
> +      a line continuation: both characters are removed, joining the
> +      two lines into a single argument.</li>
> +</ul>
> +
> +<p>
> +For example, the response-file line <code>'\a'</code> used to produce
> +the argument <code>a</code>, but now produces <code>\a</code>; the
> +line <code>"\a"</code> likewise changed from producing <code>a</code>
> +to producing <code>\a</code>, while <code>"\$"</code> still
> +produces <code>$</code>.
> +</p>
> +
> +<p>
> +Note that quoting alone does not make backslashes literal: backslashes
> +are processed inside quotes under both the old and the new rules, and
> +the way to write a literal backslash inside single quotes differs
> +between GCC&nbsp;15 and GCC&nbsp;16.  (GCC uses the same response-file
> +rules on all operating systems.)  Also note that on non-Windows
> +systems Clang continues to use the previous interpretation of
> +backslashes in response files, so a response file containing
> +backslashes may now be interpreted differently by GCC and Clang;
> +on Windows, Clang follows MSVC-style rules instead.
> +</p>
> +
> +<p>
> +If you generate response files and need them to be interpreted the
> +same way by multiple compilers or compiler versions, escape each
> +special character with a backslash instead of relying on quoting:
> +outside quotes, a backslash always escapes the following character,
> +under both the old and the new rules.  The exception is newline,
> +which cannot be escaped this way in GCC&nbsp;16, because
> +backslash-newline is a line continuation; a newline must instead be
> +placed inside single quotes, where it is literal under both the old
> +and the new rules.
> +</p>
> +
>  <h2 id="os">Operating Systems</h2>
>  
>  <h3 id="solaris">Solaris</h3>

Reply via email to