diff options
author | Oleg Ranevskyy <oranevskyy@accesssoftek.com> | 2016-01-05 19:56:12 +0000 |
---|---|---|
committer | Oleg Ranevskyy <oranevskyy@accesssoftek.com> | 2016-01-05 19:56:12 +0000 |
commit | 2e83790c37bd53c89389b59bc51bfcf7c33b688f (patch) | |
tree | afd9ca63c2f1a052f871b8b59ea244620073df08 /llvm/lib/Support/Unix/Program.inc | |
parent | cd5163720f105a5a372257c8ad543c2737e9531c (diff) | |
download | bcm5719-llvm-2e83790c37bd53c89389b59bc51bfcf7c33b688f.tar.gz bcm5719-llvm-2e83790c37bd53c89389b59bc51bfcf7c33b688f.zip |
[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
llvm-svn: 256866
Diffstat (limited to 'llvm/lib/Support/Unix/Program.inc')
-rw-r--r-- | llvm/lib/Support/Unix/Program.inc | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc index a8d1fe3c07d..7d3537e2072 100644 --- a/llvm/lib/Support/Unix/Program.inc +++ b/llvm/lib/Support/Unix/Program.inc @@ -446,7 +446,7 @@ llvm::sys::writeFileWithEncoding(StringRef FileName, StringRef Contents, return EC; } -bool llvm::sys::argumentsFitWithinSystemLimits(ArrayRef<const char*> Args) { +bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program, ArrayRef<const char*> Args) { static long ArgMax = sysconf(_SC_ARG_MAX); // System says no practical limit. @@ -456,7 +456,7 @@ bool llvm::sys::argumentsFitWithinSystemLimits(ArrayRef<const char*> Args) { // Conservatively account for space required by environment variables. long HalfArgMax = ArgMax / 2; - size_t ArgLength = 0; + size_t ArgLength = Program.size() + 1; for (ArrayRef<const char*>::iterator I = Args.begin(), E = Args.end(); I != E; ++I) { ArgLength += strlen(*I) + 1; |