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

Will Wilson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 4 06:01:54 PDT 2018


lantictac created this revision.
lantictac added reviewers: zturner, ruiu.
lantictac added a project: lld.
Herald added a subscriber: MaskRay.

Linker command-line arguments containing spaces were being stored without quoting the arguments. This resulted in ambiguous argument strings and prevented reliable parsing. MSVC simply wraps arguments containing spaces in quotes, so we do the same.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D46427

Files:
  COFF/PDB.cpp
  test/COFF/pdb-linker-module.test


Index: test/COFF/pdb-linker-module.test
===================================================================
--- test/COFF/pdb-linker-module.test
+++ test/COFF/pdb-linker-module.test
@@ -1,4 +1,4 @@
-RUN: lld-link /debug /pdb:%t.pdb /nodefaultlib /entry:main %S/Inputs/pdb-diff.obj
+RUN: lld-link /debug /pdb:%t.pdb /nodefaultlib /entry:main /manifestuac:"level='asInvoker' uiAccess='false'" %S/Inputs/pdb-diff.obj
 RUN: llvm-pdbutil dump -modules %t.pdb | FileCheck --check-prefix=MODS %s
 RUN: llvm-pdbutil dump -symbols %t.pdb | FileCheck --check-prefix=SYMS %s
 
@@ -21,4 +21,4 @@
 SYMS-NEXT: - pdb
 SYMS-NEXT: - {{.*}}pdb-linker-module{{.*}}pdb
 SYMS-NEXT: - cmd
-SYMS-NEXT: - /debug /pdb:{{.*}}pdb-linker-module{{.*}}pdb /nodefaultlib /entry:main {{.*}}pdb-diff.obj
+SYMS-NEXT: - /debug /pdb:{{.*}}pdb-linker-module{{.*}}pdb /nodefaultlib /entry:main "/manifestuac:level='asInvoker' uiAccess='false'" {{.*}}pdb-diff.obj
Index: COFF/PDB.cpp
===================================================================
--- COFF/PDB.cpp
+++ COFF/PDB.cpp
@@ -1064,7 +1064,21 @@
   CS.setLanguage(SourceLanguage::Link);
 
   ArrayRef<StringRef> Args = makeArrayRef(Config->Argv).drop_front();
-  std::string ArgStr = llvm::join(Args, " ");
+
+  // MSVC surrounds arguments containing spaces with quotes, so we do the same.
+  SmallString<256> ArgStr;
+  for (StringRef Arg : Args) {
+    if (!ArgStr.empty())
+      ArgStr.push_back(' ');
+
+    bool HasWS = Arg.find(' ') != StringRef::npos;
+    if (HasWS)
+      ArgStr.push_back('"');
+    ArgStr.append(Arg);
+    if (HasWS)
+      ArgStr.push_back('"');
+  }
+
   EBS.Fields.push_back("cwd");
   SmallString<64> cwd;
   sys::fs::current_path(cwd);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46427.145081.patch
Type: text/x-patch
Size: 1695 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180504/ef565e5d/attachment.bin>


More information about the llvm-commits mailing list