diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -1188,6 +1188,11 @@ 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 --- a/lld/COFF/Options.td +++ b/lld/COFF/Options.td @@ -58,8 +58,9 @@ 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 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, AliasArgs<["cd"]>, @@ -200,7 +202,7 @@ 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 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 --- a/lld/ELF/Options.td +++ b/lld/ELF/Options.td @@ -340,7 +340,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 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 --- 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@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:. /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@0 /linkrepro:. /out:%t.exe # RUN: tar xf repro.tar