[PATCH] D15831: [Clang/Support/Windows/Unix] Command lines created by clang may exceed the command length limit set by the OS
Oleg Ranevskyy via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 5 10:47:06 PST 2016
iid_iunknown updated this revision to Diff 44026.
iid_iunknown added a comment.
Obtaining of the program path length changed according to the Paul's remark.
Repository:
rL LLVM
http://reviews.llvm.org/D15831
Files:
include/llvm/Support/Program.h
lib/Support/Unix/Program.inc
lib/Support/Windows/Program.inc
Index: lib/Support/Windows/Program.inc
===================================================================
--- lib/Support/Windows/Program.inc
+++ lib/Support/Windows/Program.inc
@@ -535,14 +535,15 @@
return EC;
}
-bool llvm::sys::argumentsFitWithinSystemLimits(ArrayRef<const char*> Args) {
+bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program, ArrayRef<const char*> Args) {
// The documented max length of the command line passed to CreateProcess.
static const size_t MaxCommandStringLength = 32768;
- size_t ArgLength = 0;
+ // Account for the trailing space for the program path and the
+ // trailing NULL of the last argument.
+ size_t ArgLength = ArgLenWithQuotes(Program.str().c_str()) + 2;
for (ArrayRef<const char*>::iterator I = Args.begin(), E = Args.end();
I != E; ++I) {
- // Account for the trailing space for every arg but the last one and the
- // trailing NULL of the last argument.
+ // Account for the trailing space for every arg
ArgLength += ArgLenWithQuotes(*I) + 1;
if (ArgLength > MaxCommandStringLength) {
return false;
Index: lib/Support/Unix/Program.inc
===================================================================
--- lib/Support/Unix/Program.inc
+++ lib/Support/Unix/Program.inc
@@ -446,7 +446,7 @@
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 @@
// 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;
Index: include/llvm/Support/Program.h
===================================================================
--- include/llvm/Support/Program.h
+++ include/llvm/Support/Program.h
@@ -130,7 +130,7 @@
/// Return true if the given arguments fit within system-specific
/// argument length limits.
- bool argumentsFitWithinSystemLimits(ArrayRef<const char*> Args);
+ bool commandLineFitsWithinSystemLimits(StringRef Program, ArrayRef<const char*> Args);
/// File encoding options when writing contents that a non-UTF8 tool will
/// read (on Windows systems). For UNIX, we always use UTF-8.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15831.44026.patch
Type: text/x-patch
Size: 2557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160105/6bb951eb/attachment.bin>
More information about the llvm-commits
mailing list