[llvm-branch-commits] [lld] a0994cb - lld-link: Let LLD_REPRODUCE control /reproduce:, like in ld.lld

Nico Weber via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Nov 27 10:39:23 PST 2020


Author: Nico Weber
Date: 2020-11-27T13:33:55-05:00
New Revision: a0994cbe2799bf4ec5bc6d72b4fb1e0fe638972f

URL: https://github.com/llvm/llvm-project/commit/a0994cbe2799bf4ec5bc6d72b4fb1e0fe638972f
DIFF: https://github.com/llvm/llvm-project/commit/a0994cbe2799bf4ec5bc6d72b4fb1e0fe638972f.diff

LOG: lld-link: Let LLD_REPRODUCE control /reproduce:, like in ld.lld

Also sync help texts for the option between elf and coff ports.

Decisions:
- Do this even if /lldignoreenv is passed. /reproduce: does not affect
  the main output, and this makes the env var more convenient to use.
  (On the other hand, it's now possible to set this env var and forget
  about it, and all future builds in the same shell will be much slower.
  That's true for ld.lld, but posix shells have an easy way to set an
  env var for a single command; in cmd.exe this is not possible without
  contortions. Then again, lld-link runs in posix shells too.)

Original patch rebased across D68378 and D68381.

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

Added: 
    

Modified: 
    lld/COFF/Driver.cpp
    lld/COFF/Options.td
    lld/ELF/Options.td
    lld/test/COFF/linkrepro.test

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index d52abd100375..35b253ded3ec 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1188,6 +1188,11 @@ Optional<std::string> getReproduceFile(const opt::InputArgList &args) {
     return std::string(path);
   }
 
+  // This is intentionally not guarded by OPT_lldignoreenv since writing
+  // a repro tar file doesn't affect the main output.
+  if (auto *path = getenv("LLD_REPRODUCE"))
+    return std::string(path);
+
   return None;
 }
 

diff  --git a/lld/COFF/Options.td b/lld/COFF/Options.td
index a694c671f9cd..2b8e65587ad7 100644
--- a/lld/COFF/Options.td
+++ b/lld/COFF/Options.td
@@ -58,8 +58,9 @@ def implib  : P<"implib", "Import library name">;
 def lib : F<"lib">,
     HelpText<"Act like lib.exe; must be first argument if present">;
 def libpath : P<"libpath", "Additional library search path">;
-def linkrepro : P<"linkrepro",
-    "Dump linker invocation and input files for debugging">;
+def linkrepro : Joined<["/", "-", "/?", "-?"], "linkrepro:">,
+    MetaVarName<"directory">,
+    HelpText<"Write repro.tar containing inputs and command to reproduce link">;
 def lldignoreenv : F<"lldignoreenv">,
     HelpText<"Ignore environment variables like %LIB%">;
 def lldltocache : P<"lldltocache",
@@ -135,8 +136,9 @@ def noentry : F<"noentry">,
 def profile : F<"profile">;
 def repro : F<"Brepro">,
     HelpText<"Use a hash of the executable as the PE header timestamp">;
-def reproduce : P<"reproduce",
-    "Dump linker invocation and input files for debugging">;
+def reproduce : Joined<["/", "-", "/?", "-?"], "reproduce:">,
+    MetaVarName<"filename">,
+    HelpText<"Write tar file containing inputs and command to reproduce link">;
 def swaprun : P<"swaprun",
   "Comma-separated list of 'cd' or 'net'">;
 def swaprun_cd : F<"swaprun:cd">, Alias<swaprun>, AliasArgs<["cd"]>,
@@ -200,7 +202,7 @@ def help_q : Flag<["/??", "-??", "/?", "-?"], "">, Alias<help>;
 defm auto_import : B_priv<"auto-import">;
 defm runtime_pseudo_reloc : B_priv<"runtime-pseudo-reloc">;
 def end_lib : F<"end-lib">,
-  HelpText<"Ends group of objects treated as if they were in a library">;
+  HelpText<"End group of objects treated as if they were in a library">;
 def exclude_all_symbols : F<"exclude-all-symbols">;
 def export_all_symbols : F<"export-all-symbols">;
 defm demangle : B<"demangle",
@@ -218,7 +220,7 @@ def pdb_source_path : P<"pdbsourcepath",
 def rsp_quoting : Joined<["--"], "rsp-quoting=">,
   HelpText<"Quoting style for response files, 'windows' (default) or 'posix'">;
 def start_lib : F<"start-lib">,
-  HelpText<"Starts group of objects treated as if they were in a library">;
+  HelpText<"Start group of objects treated as if they were in a library">;
 def thinlto_emit_imports_files :
     F<"thinlto-emit-imports-files">,
     HelpText<"Emit .imports files with -thinlto-index-only">;

diff  --git a/lld/ELF/Options.td b/lld/ELF/Options.td
index db1c5d969842..f81f13d4d445 100644
--- a/lld/ELF/Options.td
+++ b/lld/ELF/Options.td
@@ -340,7 +340,9 @@ def push_state: F<"push-state">,
 def print_map: F<"print-map">,
   HelpText<"Print a link map to the standard output">;
 
-defm reproduce: Eq<"reproduce", "Write a tar file containing input files and command line options to reproduce link">;
+defm reproduce:
+  Eq<"reproduce",
+     "Write tar file containing inputs and command to reproduce link">;
 
 defm rosegment: BB<"rosegment",
   "Put read-only non-executable sections in their own segment (default)",

diff  --git a/lld/test/COFF/linkrepro.test b/lld/test/COFF/linkrepro.test
index 9a1db6e26369..29208fd6652a 100644
--- a/lld/test/COFF/linkrepro.test
+++ b/lld/test/COFF/linkrepro.test
@@ -1,7 +1,7 @@
 # REQUIRES: x86, shell
 
 # RUN: rm -rf %t.dir
-# RUN: mkdir -p %t.dir/build1 %t.dir/build2 %t.dir/build3
+# RUN: mkdir -p %t.dir/build1 %t.dir/build2 %t.dir/build3 %t.dir/build4
 # RUN: yaml2obj %p/Inputs/hello32.yaml -o %t.obj
 
 # RUN: cd %t.dir/build1
@@ -21,6 +21,14 @@
 # RUN: FileCheck %s --check-prefix=RSP < repro2/response.txt
 
 # RUN: cd %t.dir/build2
+# RUN: env LLD_REPRODUCE=repro.tar lld-link %t.obj %p/Inputs/std32.lib \
+# RUN:    /subsystem:console /entry:main at 0 /out:%t.exe
+# RUN: tar xf repro.tar
+# RUN: 
diff  %t.obj repro/%:t.obj
+# RUN: 
diff  %p/Inputs/std32.lib repro/%:p/Inputs/std32.lib
+# RUN: FileCheck %s --check-prefix=RSP < repro/response.txt
+
+# RUN: cd %t.dir/build3
 # RUN: lld-link %t.obj /libpath:%p/Inputs /defaultlib:std32 /subsystem:console \
 # RUN:   /entry:main at 0 /linkrepro:. /out:%t.exe
 # RUN: tar xf repro.tar
@@ -28,7 +36,7 @@
 # RUN: 
diff  %p/Inputs/std32.lib repro/%:p/Inputs/std32.lib
 # RUN: FileCheck %s --check-prefix=RSP < repro/response.txt
 
-# RUN: cd %t.dir/build3
+# RUN: cd %t.dir/build4
 # RUN: env LIB=%p/Inputs lld-link %t.obj /defaultlib:std32 /subsystem:console \
 # RUN:   /entry:main at 0 /linkrepro:. /out:%t.exe
 # RUN: tar xf repro.tar


        


More information about the llvm-branch-commits mailing list