[PATCH] D46427: [PDB] Quote linker arguments containing spaces (mimic MSVC)

Adrian McCarthy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 7 15:54:33 PDT 2018


amccarth added inline comments.


================
Comment at: COFF/PDB.cpp:1075-1076
+    bool HasWS = Arg.find(' ') != StringRef::npos;
+    if (HasWS)
+      ArgStr.push_back('"');
+    ArgStr.append(Arg);
----------------
lantictac wrote:
> zturner wrote:
> > In addition to what rui suggested, can you only do this if the string is not already quoted?  Furthermore, you may need to escape embedded quotes (is that something we need to worry about?)
> The arguments always appear to have all double-quotes removed. This applies for both the MS linker and lld-link (by the time this code sees the arguments anyhow).
> 
> I've also tried escaping embedded double-quotes but they seem to be eaten by the argument parser and never appear in the tokenized args. Not to mention that there's really no place embedded quotes could be in any valid linker command-line (to the best of my knowledge).
> 
> So I can't see either case being worth worrying about.
Since quotation marks are not valid in file names, I believe lantictac is correct that this is not worth worrying about escaping quotation marks within an argument (for linker commands).

The rules for escaping quotation marks and backslashes in the Windows command line are arcane.  Worse, they differ slightly depending on whether the program relies on the CRT to parse the command into a main-style argument vector of whether it calls CommandLineToArgvW to parse it explicitly.

This Raymond Chen post touches on the some of the complexity, but the juiciest bits are in the comments:  
https://blogs.msdn.microsoft.com/oldnewthing/20100917-00/?p=12833



https://reviews.llvm.org/D46427





More information about the llvm-commits mailing list