[lld] r337628 - [PDB] Write the command line after response file expansion

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 20 15:34:20 PDT 2018


Author: rnk
Date: Fri Jul 20 15:34:20 2018
New Revision: 337628

URL: http://llvm.org/viewvc/llvm-project?rev=337628&view=rev
Log:
[PDB] Write the command line after response file expansion

Summary: Fixes PR38085

Reviewers: ruiu, zturner

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D49566

Modified:
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/DriverUtils.cpp
    lld/trunk/test/COFF/pdb-linker-module.test

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=337628&r1=337627&r2=337628&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Fri Jul 20 15:34:20 2018
@@ -64,7 +64,6 @@ bool link(ArrayRef<const char *> Args, b
       " (use /errorlimit:0 to see all errors)";
   errorHandler().ExitEarly = CanExitEarly;
   Config = make<Configuration>();
-  Config->Argv = {Args.begin(), Args.end()};
 
   Symtab = make<SymbolTable>();
 
@@ -875,7 +874,7 @@ void LinkerDriver::link(ArrayRef<const c
 
   // Parse command line options.
   ArgParser Parser;
-  opt::InputArgList Args = Parser.parseLINK(ArgsArr.slice(1));
+  opt::InputArgList Args = Parser.parseLINK(ArgsArr);
 
   // Parse and evaluate -mllvm options.
   std::vector<const char *> V;

Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=337628&r1=337627&r2=337628&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Fri Jul 20 15:34:20 2018
@@ -791,26 +791,31 @@ opt::InputArgList ArgParser::parse(Array
   // Make InputArgList from string vectors.
   unsigned MissingIndex;
   unsigned MissingCount;
-  SmallVector<const char *, 256> Vec(Argv.data(), Argv.data() + Argv.size());
 
   // We need to get the quoting style for response files before parsing all
   // options so we parse here before and ignore all the options but
   // --rsp-quoting.
-  opt::InputArgList Args = Table.ParseArgs(Vec, MissingIndex, MissingCount);
+  opt::InputArgList Args = Table.ParseArgs(Argv, MissingIndex, MissingCount);
 
   // Expand response files (arguments in the form of @<filename>)
   // and then parse the argument again.
-  cl::ExpandResponseFiles(Saver, getQuotingStyle(Args), Vec);
-  Args = Table.ParseArgs(Vec, MissingIndex, MissingCount);
+  SmallVector<const char *, 256> ExpandedArgv(Argv.data(), Argv.data() + Argv.size());
+  cl::ExpandResponseFiles(Saver, getQuotingStyle(Args), ExpandedArgv);
+  Args = Table.ParseArgs(makeArrayRef(ExpandedArgv).drop_front(), MissingIndex,
+                         MissingCount);
 
   // Print the real command line if response files are expanded.
-  if (Args.hasArg(OPT_verbose) && Argv.size() != Vec.size()) {
+  if (Args.hasArg(OPT_verbose) && Argv.size() != ExpandedArgv.size()) {
     std::string Msg = "Command line:";
-    for (const char *S : Vec)
+    for (const char *S : ExpandedArgv)
       Msg += " " + std::string(S);
     message(Msg);
   }
 
+  // Save the command line after response file expansion so we can write it to
+  // the PDB if necessary.
+  Config->Argv = {ExpandedArgv.begin(), ExpandedArgv.end()};
+
   // Handle /WX early since it converts missing argument warnings to errors.
   errorHandler().FatalWarnings = Args.hasFlag(OPT_WX, OPT_WX_no, false);
 
@@ -862,11 +867,11 @@ opt::InputArgList ArgParser::parseLINK(s
   // Concatenate LINK env and command line arguments, and then parse them.
   if (Optional<std::string> S = Process::GetEnv("LINK")) {
     std::vector<const char *> V = tokenize(*S);
-    Argv.insert(Argv.begin(), V.begin(), V.end());
+    Argv.insert(std::next(Argv.begin()), V.begin(), V.end());
   }
   if (Optional<std::string> S = Process::GetEnv("_LINK_")) {
     std::vector<const char *> V = tokenize(*S);
-    Argv.insert(Argv.begin(), V.begin(), V.end());
+    Argv.insert(std::next(Argv.begin()), V.begin(), V.end());
   }
   return parse(Argv);
 }

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=337628&r1=337627&r2=337628&view=diff
==============================================================================
--- lld/trunk/test/COFF/pdb-linker-module.test (original)
+++ lld/trunk/test/COFF/pdb-linker-module.test Fri Jul 20 15:34:20 2018
@@ -1,4 +1,5 @@
-RUN: lld-link /debug /pdb:%t.pdb /nodefaultlib /entry:main %S/Inputs/pdb-diff.obj
+RUN: echo "/nodefaultlib" > %t.rsp
+RUN: lld-link /debug /pdb:%t.pdb @%t.rsp /entry:main %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
 




More information about the llvm-commits mailing list