Index: lld/COFF/Driver.cpp =================================================================== --- lld/COFF/Driver.cpp +++ lld/COFF/Driver.cpp @@ -1000,6 +1000,16 @@ config->pdbAltPath = buf; } +static const char *getLinkreproOption(opt::InputArgList &args) { + if (auto *arg = args.getLastArg(OPT_linkrepro)) + return arg->getValue(); + + // This is intentionally not guarded by OPT_lldignoreenv since writing + // a repro tar file doesn't affect the main output. + return getenv("LLD_REPRODUCE"); +} + + /// Convert resource files and potentially merge input resource object /// trees into one resource tree. /// Call after ObjFile::Instances is complete. @@ -1133,9 +1143,7 @@ // options are handled. config->mingw = args.hasArg(OPT_lldmingw); - if (auto *arg = args.getLastArg(OPT_linkrepro)) { - const char *path = arg->getValue(); - + if (const char *path = getLinkreproOption(args)) { Expected> errOrWriter = TarWriter::create(path, path::stem(path)); if (errOrWriter) { Index: lld/COFF/Options.td =================================================================== --- lld/COFF/Options.td +++ lld/COFF/Options.td @@ -44,7 +44,7 @@ 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">; + "Write tar file containing inputs and command to reproduce link">; def lldignoreenv : F<"lldignoreenv">, HelpText<"Ignore environment variables like %LIB%">; def lldltocache : P<"lldltocache", @@ -171,7 +171,7 @@ // LLD extensions 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", @@ -187,7 +187,7 @@ 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">; Index: lld/ELF/Options.td =================================================================== --- lld/ELF/Options.td +++ lld/ELF/Options.td @@ -309,7 +309,9 @@ 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 rpath: Eq<"rpath", "Add a DT_RUNPATH to the output">; Index: lld/test/COFF/linkrepro.test =================================================================== --- lld/test/COFF/linkrepro.test +++ 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 > %t.obj # RUN: cd %t.dir/build1 @@ -13,6 +13,14 @@ # RUN: FileCheck %s --check-prefix=RSP < repro/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@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@0 /linkrepro:repro.tar /out:%t.exe # RUN: tar xf repro.tar @@ -20,7 +28,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@0 /linkrepro:repro.tar /out:%t.exe # RUN: tar xf repro.tar