bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug binutils/27594] build processes broken by changed space handling


From: martin at martin dot st
Subject: [Bug binutils/27594] build processes broken by changed space handling
Date: Thu, 29 Apr 2021 11:59:45 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=27594

Martin Storsjö <martin at martin dot st> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |martin at martin dot st

--- Comment #2 from Martin Storsjö <martin at martin dot st> ---
+1, there's predecent that windres takes this parameter as a
supposedly-pre-quoted/escaped string that is passed as-is to popen().

The same also goes for other preprocessor arguments, like -D and
--preprocessor-arg - they are passed almost (will elaborate below) as-is on to
popen(). This means that any caller that wants to pass e.g. a define for a
quoted string needs to escape quotes doubly - see e.g.
https://git.savannah.gnu.org/gitweb/?p=libiconv.git;a=blob;f=windows/windres-options;h=779fddec305d1e78f1e5c3123683b3c380e4a82e;hb=4b1a76b8e7f718fb23eb1a48cd1be208cfff6c2a
for an example of projects in the wild, doing extra escaping when passing
defines to windres.

A minimal example of that double quoting:
$ cat test1.rc
STRINGTABLE {
  1 STRING1
}
$ x86_64-w64-mingw32-windres -DSTRING1=\"foo\" test1.rc
x86_64-w64-mingw32-windres: test1.rc:2: syntax error
$ x86_64-w64-mingw32-windres -DSTRING1=\\\"foo\\\" test1.rc
[..snip..]
STRINGTABLE MOVEABLE PURE DISCARDABLE
BEGIN
  1, "foo"
END


Windres does try to escape one kind of char in the provided argument strings;
it tries to escape spaces with a backslash. Unfortunately, as the shells
(invoked by popen) differ between unix and windows (one can't backslash escape
spaces in windows command lines, the argument has to be quoted), this only
actually works when run on unix:

$ x86_64-w64-mingw32-windres "-DSTRING1=\\\"foo bar\\\"" test1.rc
[..snip..]
STRINGTABLE MOVEABLE PURE DISCARDABLE
BEGIN
  1, "foo bar"
END

If you try to run the same on windows (built as mingw executables), it fails:

$ windres test1.rc "-DSTRING1=\\\"foo bar\\\""
gcc: error: bar": Invalid argument
C:\msys64\mingw64\bin\windres.exe: preprocessing failed.


Furthermore, other things that differ between how shells interpret things in
popen():

)$ x86_64-w64-mingw32-windres -DSTRING1=\\\"foo\\\\\\\\bar\\\" test1.rc -v
Using `x86_64-w64-mingw32-gcc -E -xc -DRC_INVOKED -DSTRING1=\"foo\\\\bar\"
test1.rc'
Using popen to read preprocessor output
[..snip..]
STRINGTABLE MOVEABLE PURE DISCARDABLE
BEGIN 
  1, "foo\\bar"
END

But on windows:

$ windres test1.rc -DSTRING1=\\\"foo\\\\\\\\bar\\\" -v
[..snip..]
STRINGTABLE MOVEABLE PURE DISCARDABLE
BEGIN
  1, "foo\\\\bar"
END
Using `C:\msys64\mingw64\bin\gcc -E -xc -DRC_INVOKED -DSTRING1=\"foo\\\\bar\"
test1.rc'


The last few are hypothetical. However the habit of double-escaping quotes for
such strings exists in the wild, and should be documented as such. The fact
that it differs between platforms exactly how one should do the double escaping
is problematic too, when it comes to more complicated strings.

(I recently implemented llvm-windres, and went to some lengths to mimic the GNU
windres behaviour of these options, to make it work as a drop-in replacement
for how existing projects in the wild call windres.)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]