#2142 Possible bug with character escaping in MSYS- and MSYS2-make

MSYS2
unread
nobody
Bug
none
Unknown
False
2013-12-27
2013-11-29
Lars Kanis
No

The following simple Makefile:

all:
   echo a\=b "c"
   echo a\=b c

should give the following output when started with make:

echo a\=b "c"
a=b c
echo a\=b c
a=b c

but on MSYS and MSYS2 it gives:

echo a\=b "c"
a=b c
echo a\=b c
a\=b c

make passes an additional "\" as arg to the started program (not only to echo). The "\=" sequence in the last line should get un-escaped to a literal "=", but this is curiously only done when some argument is passed to the command using double quotation marks.

If the echo commands above is typed directly in the msys(2)-bash, then the "\=" sequence is correctly interpreted as a "=". But not within a Makefile.

The issue does not occur in Cygwin and not on Linux.

Test system was Windows-7 with MSYS binaries supplied here: http://downloads.sourceforge.net/mingw/
- msysCORE-1.0.17-1-msys-1.0.17-bin.tar.lzma
- make-3.81-3-msys-1.0.13-bin.tar.lzma
- bash-3.1.17-4-msys-1.0.16-bin.tar.lzma

The issue is equally present in the following MSYS2 version: http://sourceforge.net/projects/msys2/files/Alpha-versions/64-bit/x64-msys2-20131022.tar.xz with the following program versions:

$ uname -a
MSYS_NT-6.1 C1255vm 2.0.0(0.270/5/3) 2013-10-18 22:41 x86_64 Msys
$ make -v
GNU Make 4.0.90
Built for x86_64-pc-msys
$ sh --version
GNU bash, version 4.2.45(2)-release (x86_64-pc-msys)

Discussion

  • George Koehler
    George Koehler
    2013-12-02

    I reproduced your bug with
    msysCORE-1.0.18-1-msys-1.0.18-bin.tar.lzma

    I extended Makefile to say

    all:
        echo a\=b "c"
        echo a\=b c
        echo a\=b c;
        echo a\=b c </dev/null
        echo a\=b 'c'
    

    The output, with MSYS on Windows, was

    echo a\=b "c"
    a=b c
    echo a\=b c
    a\=b c
    echo a\=b c;
    a=b c
    echo a\=b c </dev/null
    a=b c
    echo a\=b 'c'
    a\=b c
    

    So ; and < act like " and suppress the bug, but ' does not. The weird thing is that the last line handles ' correctly but \ wrongly.

    I cannot reproduce the bug in sh.exe itself. If I run tail +2 Makefile | sh, then I get a=b c five times, which is correct.

    I suspect that make.exe does something weird when passing commands to sh.exe. To investigate this, I would need to install MSYS developer tools and hack make.

     
  • Eric Lofstad
    Eric Lofstad
    2013-12-27

    I found a similar problem when make uses construct like
    @echo 'ac_maketemp="$(MAKE)"'
    make --debug=j shows
    CreateProcess(C:\msys64\bin\echo.exe,echo ac_maketemp=\"C:/mingw/bin/make\",...)
    result:
    ac_maketemp=\C:/mingw/bin/make"

    for a test, I used cmd.exe to run echo.exe
    c:\msys64\bin>echo.exe a=\"b\"
    result:
    a=\b"

    $ uname -a
    MSYS_NT-6.1 MININT-QNIFAAO 2.0.0(0.271/5/3) 2013-12-07 11:21 x86_64 Msys