[Clang/Support/Windows/Unix] Command lines created by clang may exceed the command...
authorOleg Ranevskyy <oranevskyy@accesssoftek.com>
Tue, 5 Jan 2016 19:56:12 +0000 (19:56 +0000)
committerOleg Ranevskyy <oranevskyy@accesssoftek.com>
Tue, 5 Jan 2016 19:56:12 +0000 (19:56 +0000)
commite597ffa521de978642946160fa5cf05a16d83b7e
treee4f32c436afd802387981783b07498d54863e4ea
parent407f296e22ebcc20c7568f2e66af4eea811b36d5
[Clang/Support/Windows/Unix] Command lines created by clang may exceed the command length limit set by the OS

Summary:
Hi Rafael,

Would you be able to review this patch, please?

(Clang part of the patch is D15832).

When clang runs an external tool, e.g. a linker, it may create a command line that exceeds the length limit.

Clang uses the llvm::sys::argumentsFitWithinSystemLimits function to check if command line length fits the OS

limitation. There are two problems in this function that may cause exceeding of the limit:

1. It ignores the length of the program path in its calculations. On the other hand, clang adds the program

path to the command line when it runs the program.

2. It assumes no space character is inserted after the last argument, which is not true for Windows. The flattenArgs function adds the trailing space for *each* argument. The result of this is that the terminating NULL character is not counted and may be placed beyond the length limit if the command line is exactly 32768 characters long. The WinAPI's CreateProcess does not find the NULL character and fails.

Reviewers: rafael, ygao, probinson

Subscribers: asl, llvm-commits

Differential Revision: http://reviews.llvm.org/D15831

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256866 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Support/Program.h
lib/Support/Unix/Program.inc
lib/Support/Windows/Program.inc