[PATCH] D59530: [LLD][COFF] Fix /linkrepro with options that take a filename or path

Alexandre Ganea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 18 19:13:27 PDT 2019


aganea created this revision.
aganea added reviewers: zturner, mstorsjo, ruiu, rnk.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Some options like `/pdb:` or `/out:` or `/implib:` take a filename or path on the right side. When using partial or full paths with these options, previously this resulted in the paths not being translated relative-to-root by `/linkrepro`:

  $ lld-link /pdb:"F:\some\path\mypdb.pdb" /out:"relative\..\..\real\output\file.exe" /implib:a.lib ... /linkrepro:.

The generated response file might have now non-existent paths on the reproducer's machine:

  /pdb:"F:\some\path\mypdb.pdb"
  /out:"relative\..\..\real\output\file.exe"
  /out:a.lib
  ...

With this patch, the response is fully reproducible/usable as expected:

  /pdb:F/some/path/mypdb.pdb
  /out:F/real/output/file.exe
  /implib:F/other/path/a.lib
  ...


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D59530

Files:
  COFF/Driver.cpp
  Common/Reproduce.cpp
  include/lld/Common/Reproduce.h
  test/COFF/linkrepro-pdb.test


Index: test/COFF/linkrepro-pdb.test
===================================================================
--- test/COFF/linkrepro-pdb.test
+++ test/COFF/linkrepro-pdb.test
@@ -7,3 +7,16 @@
 RUN: lld-link a.obj b.obj -entry:main -debug -out:t.exe -pdb:t.pdb -nodefaultlib -linkrepro:.
 RUN: tar xOf repro.tar repro/%:t/ts.pdb > repro-ts.pdb
 RUN: diff ts.pdb repro-ts.pdb
+
+RUN: tar xf repro.tar
+RUN: cat repro/response.txt | FileCheck -check-prefix=PDB %s
+
+PDB: {{.*}}/linkrepro-pdb.test.tmp/t.exe
+PDB-NEXT: {{.*}}/linkrepro-pdb.test.tmp/t.pdb
+
+RUN: yaml2obj < %p/Inputs/export.yaml > %t1.obj
+RUN: lld-link /out:%t1.dll /dll %t1.obj /implib:t1.lib /export:exportfn1 /export:exportfn2 /linkrepro:.
+RUN: tar xf repro.tar
+RUN: cat repro/response.txt | FileCheck -check-prefix=IMP %s
+
+IMP: {{.*}}/linkrepro-pdb.test.tmp/t1.lib
Index: include/lld/Common/Reproduce.h
===================================================================
--- include/lld/Common/Reproduce.h
+++ include/lld/Common/Reproduce.h
@@ -29,6 +29,7 @@
 
 // Returns the string form of the given argument.
 std::string toString(const llvm::opt::Arg &Arg);
+std::string toString(const llvm::opt::Arg &Arg, bool ValueIsPath);
 }
 
 #endif
Index: Common/Reproduce.cpp
===================================================================
--- Common/Reproduce.cpp
+++ Common/Reproduce.cpp
@@ -49,10 +49,17 @@
 }
 
 std::string lld::toString(const opt::Arg &Arg) {
+  return toString(Arg, false);
+}
+
+std::string lld::toString(const opt::Arg &Arg, bool ValueIsPath) {
   std::string K = Arg.getSpelling();
   if (Arg.getNumValues() == 0)
     return K;
-  std::string V = quote(Arg.getValue());
+  std::string V = Arg.getValue();
+  if (ValueIsPath)
+    V = relativeToRoot(V);
+  V = quote(V);
   if (Arg.getOption().getRenderStyle() == opt::Option::RenderJoinedStyle)
     return K + V;
   return K + " " + V;
Index: COFF/Driver.cpp
===================================================================
--- COFF/Driver.cpp
+++ COFF/Driver.cpp
@@ -523,6 +523,7 @@
   raw_svector_ostream OS(Data);
 
   for (auto *Arg : Args) {
+    bool ValueAsPath = false;
     switch (Arg->getOption().getID()) {
     case OPT_linkrepro:
     case OPT_INPUT:
@@ -535,8 +536,13 @@
     case OPT_manifestinput:
     case OPT_manifestuac:
       break;
+    case OPT_implib:
+    case OPT_pdb:
+    case OPT_out:
+      ValueAsPath = true;
+      LLVM_FALLTHROUGH;
     default:
-      OS << toString(*Arg) << "\n";
+      OS << toString(*Arg, ValueAsPath) << "\n";
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59530.191232.patch
Type: text/x-patch
Size: 2531 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190319/07b9ede6/attachment.bin>


More information about the llvm-commits mailing list