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

Alexandre Ganea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 30 08:40:19 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL348001: [PDB] Quote linker arguments containing spaces (mimic MSVC) (authored by aganea, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55074?vs=175947&id=176138#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55074/new/

https://reviews.llvm.org/D55074

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


Index: lld/trunk/test/COFF/pdb-linker-module.test
===================================================================
--- lld/trunk/test/COFF/pdb-linker-module.test
+++ lld/trunk/test/COFF/pdb-linker-module.test
@@ -1,5 +1,5 @@
 RUN: echo "/nodefaultlib" > %t.rsp
-RUN: lld-link /debug /pdb:%t.pdb @%t.rsp /entry:main %S/Inputs/pdb-diff.obj
+RUN: lld-link /debug /pdb:%t.pdb @%t.rsp /entry:"1 "'"'hello'"'" 2" /manifestuac:"level='asInvoker' uiAccess='false'" %S/Inputs/pdb-diff.obj /force
 RUN: llvm-pdbutil dump -modules %t.pdb | FileCheck --check-prefix=MODS %s
 RUN: llvm-pdbutil dump -symbols %t.pdb | FileCheck --check-prefix=SYMS %s
 
@@ -22,4 +22,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:1 ""hello"" 2" "/manifestuac:level='asInvoker' uiAccess='false'" {{.*}}pdb-diff.obj
Index: lld/trunk/COFF/PDB.cpp
===================================================================
--- lld/trunk/COFF/PDB.cpp
+++ lld/trunk/COFF/PDB.cpp
@@ -1454,6 +1454,32 @@
   }
 }
 
+// Mimic MSVC which surrounds arguments containing whitespace with quotes.
+// Double double-quotes are handled, so that the resulting string can be
+// executed again on the cmd-line.
+static std::string quote(ArrayRef<StringRef> Args) {
+  std::string R;
+  R.reserve(256);
+  for (StringRef A : Args) {
+    if (!R.empty())
+      R.push_back(' ');
+    bool HasWS = A.find(' ') != StringRef::npos;
+    bool HasQ = A.find('"') != StringRef::npos;
+    if (HasWS || HasQ)
+      R.push_back('"');
+    if (HasQ) {
+      SmallVector<StringRef, 4> S;
+      A.split(S, '"');
+      R.append(join(S, "\"\""));
+    } else {
+      R.append(A);
+    }
+    if (HasWS || HasQ)
+      R.push_back('"');
+  }
+  return R;
+}
+
 static void addCommonLinkerModuleSymbols(StringRef Path,
                                          pdb::DbiModuleDescriptorBuilder &Mod,
                                          BumpPtrAllocator &Allocator) {
@@ -1489,7 +1515,7 @@
   CS.setLanguage(SourceLanguage::Link);
 
   ArrayRef<StringRef> Args = makeArrayRef(Config->Argv).drop_front();
-  std::string ArgStr = llvm::join(Args, " ");
+  std::string ArgStr = quote(Args);
   EBS.Fields.push_back("cwd");
   SmallString<64> cwd;
   if (Config->PDBSourcePath.empty()) 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55074.176138.patch
Type: text/x-patch
Size: 2448 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181130/0234c1fd/attachment.bin>


More information about the llvm-commits mailing list