[PATCH] D51941: [Support] Avoid calling CommandLineToArgvW from shell32.dll

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 11 10:38:23 PDT 2018


rnk created this revision.
rnk added a reviewer: zturner.
Herald added a subscriber: hiraditya.

Shell32.dll depends on gdi32.dll and user32.dll, which are mostly DLLs
for Windows GUI functionality. LLVM's utilities don't typically need GUI
functionality, and loading these DLLs seems to be slowing down startup.
Also, we already have an implementation of Windows command line
tokenization in cl::TokenizeWindowsCommandLine, so we can just use it.

The goal is to get the original argv in UTF-8, so that it can pass
through most LLVM string APIs. A Windows process starts life with a
UTF-16 string for its command line, and it can be retreived with
GetCommandLineW from kernel32.dll.

Previously, we would:

1. Get the wide command line
2. Call CommandLineToArgvW to handle quoting rules and separate it into arguments.
3. For each wide argument, expand wildcards (* and ?) using FindFirstFileW.
4. Convert each argument to UTF-8

Now we:

1. Get the wide command line, convert the whole thing to UTF-8
2. Tokenize the UTF-8 command line with cl::TokenizeWindowsCommandLine
3. For each argument, expand wildcards if present
  - This requires converting back to UTF-16 to call FindFirstFileW
  - Results of FindFirstFileW must be converted back to UTF-8


https://reviews.llvm.org/D51941

Files:
  llvm/lib/Support/Windows/Process.inc

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51941.164927.patch
Type: text/x-patch
Size: 5371 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180911/4814c8b7/attachment.bin>


More information about the llvm-commits mailing list