[lld] r348001 - [PDB] Quote linker arguments containing spaces (mimic MSVC)
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 30 08:36:40 PST 2018
Author: aganea
Date: Fri Nov 30 08:36:40 2018
New Revision: 348001
URL: http://llvm.org/viewvc/llvm-project?rev=348001&view=rev
Log:
[PDB] Quote linker arguments containing spaces (mimic MSVC)
Initial patch by Will Wilson (@lantictac)
Differential Revision: https://reviews.llvm.org/D55074
Modified:
lld/trunk/COFF/PDB.cpp
lld/trunk/test/COFF/pdb-linker-module.test
Modified: lld/trunk/COFF/PDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.cpp?rev=348001&r1=348000&r2=348001&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.cpp (original)
+++ lld/trunk/COFF/PDB.cpp Fri Nov 30 08:36:40 2018
@@ -1454,6 +1454,32 @@ static codeview::CPUType toCodeViewMachi
}
}
+// 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 @@ static void addCommonLinkerModuleSymbols
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())
Modified: lld/trunk/test/COFF/pdb-linker-module.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb-linker-module.test?rev=348001&r1=348000&r2=348001&view=diff
==============================================================================
--- lld/trunk/test/COFF/pdb-linker-module.test (original)
+++ lld/trunk/test/COFF/pdb-linker-module.test Fri Nov 30 08:36:40 2018
@@ -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: - {{.*}}lld-link
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
More information about the llvm-commits
mailing list