This is an archive of the discontinued LLVM Phabricator instance.

[Clang/Support/Windows/Unix] Command lines created by clang may exceed the command length limit set by the OS
ClosedPublic

Authored by iid_iunknown on Dec 30 2015, 2:14 PM.

Details

Summary

LLVM part of the patch is D15831.

When clang runs an external tool such as 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.

  1. 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.

Diff Detail

Repository
rL LLVM

Event Timeline

iid_iunknown retitled this revision from to [Clang/Support/Windows/Unix] Command lines created by clang may exceed the command length limit set by the OS.
iid_iunknown updated this object.
iid_iunknown added a reviewer: rafael.
iid_iunknown set the repository for this revision to rL LLVM.
iid_iunknown added subscribers: llvm-commits, asl.
asl added a comment.Jan 4 2016, 9:59 AM

LGTM as soon as LLVM change would be accepted.

asl accepted this revision.Jan 5 2016, 11:38 AM
asl added a reviewer: asl.
This revision is now accepted and ready to land.Jan 5 2016, 11:38 AM
iid_iunknown closed this revision.Jan 5 2016, 11:58 AM