command line limit in mingw-make

Joe Burmeister <[email protected]> Fri, 25 May 2012 14:19:59 +0100
Newsgroups gmane.comp.gnu.make.windows
Message-ID <[email protected]>
Hi,

I'm building QT5 with MinGW and I've hit the Windows command line limit.

To start off I think I should say I'm don't think changing the build 
system to require the handing around of less flags is the best option. 
The command line limit can be 64k not 8k if things are done in the right 
way.
Yes a @file option file could be used, but that would be hard to do with 
the qmake files so it's only done for MinGW and I'm trying to avoid 
touching other platforms. The QT guys I've spoke to don't think changing 
qmake to do this automatically for MinGW is the right solution. MinGW 
could just be like the other platforms up to 64k characters.

The first time I hit it was with windres.exe.

windres.exe calls gcc with _popen. Normally all is well, but not in this 
case.
POSIX popen is specified to call the shell of the platform.

The shell of the Windows (NT) platform is cmd.exe, which will return 
"command line is too long" if given more then 8k characters.

I solved this with a custom implementation of popen using CreateProcess 
with it's limit of 64k characters.

Next time I hit it was an odd one that took me a while to find. The 
8192nd character of the argument characters was being deleted when g++ 
was being called by mingw-make.
That character was the D part of the a command line define. So 
"-Dsomething" became "-something" and g++ was erroring out about an 
invalid option.

The call to g++ was from a temporary batch file that mingw-make had made.
So I made a custom mingw-make that padded around the 8192nd character, 
and things built.

But this made me uncomfortable. Everything said the limit should be 8191 
characters. So I dug deeper. There is no limit. You can keep adding 
characters until when you call the app it doesn't run, causing the error 
"The system cannot execute the specified program". For console apps that 
was 32733 arg characters, for gui apps it's 32757, which makes sense as 
they are different sub-systems in Windows. Every 8k boundary a character 
was dropped.

So I don't think padding is the right solution because you don't know 
what memory you are overflowing into.

I think better is to change mingw-make so that it doesn't create a 
temporary batch file but uses CreateProcess to get access to the 64k 
limit. If it's longer, error out.

I'm not written this patch yet because I figured I should talk with you 
guys first.

Even if you disagree with me about the solution or that there needs to 
be a solution, I don't think anyone would argue that spitting out what 
should be illegal batch files is the right thing.

What are people thoughts?
Other than, "what happens if you write the right bytes after the crash 
character limit" and "cmd.exe should error before then".



Thanks for any feedback,


Joe