Skip to content

Commit 0d53ac8

Browse files
committed
Add /reproduce option to lld/COFF
This patch adds /reproduce:<path> option to lld/COFF. This is an lld-specific option, so we can name it freely. I chose /reproduce over other names (e.g. /lldlinkrepro) for consistency with other lld ports. Differential Revision: https://reviews.llvm.org/D68381 llvm-svn: 373704
1 parent 6785824 commit 0d53ac8

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

lld/COFF/Driver.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ static std::string createResponseFile(const opt::InputArgList &args,
603603
for (auto *arg : args) {
604604
switch (arg->getOption().getID()) {
605605
case OPT_linkrepro:
606+
case OPT_reproduce:
606607
case OPT_INPUT:
607608
case OPT_defaultlib:
608609
case OPT_libpath:
@@ -1071,6 +1072,26 @@ void LinkerDriver::maybeExportMinGWSymbols(const opt::InputArgList &args) {
10711072
});
10721073
}
10731074

1075+
// lld has a feature to create a tar file containing all input files as well as
1076+
// all command line options, so that other people can run lld again with exactly
1077+
// the same inputs. This feature is accessible via /linkrepro and /reproduce.
1078+
//
1079+
// /linkrepro and /reproduce are very similar, but /linkrepro takes a directory
1080+
// name while /reproduce takes a full path. We have /linkrepro for compatibility
1081+
// with Microsoft link.exe.
1082+
Optional<std::string> getReproduceFile(const opt::InputArgList &args) {
1083+
if (auto *arg = args.getLastArg(OPT_reproduce))
1084+
return std::string(arg->getValue());
1085+
1086+
if (auto *arg = args.getLastArg(OPT_linkrepro)) {
1087+
SmallString<64> path = StringRef(arg->getValue());
1088+
sys::path::append(path, "repro.tar");
1089+
return path.str().str();
1090+
}
1091+
1092+
return None;
1093+
}
1094+
10741095
void LinkerDriver::link(ArrayRef<const char *> argsArr) {
10751096
// Needed for LTO.
10761097
InitializeAllTargetInfos();
@@ -1133,17 +1154,15 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
11331154
// options are handled.
11341155
config->mingw = args.hasArg(OPT_lldmingw);
11351156

1136-
if (auto *arg = args.getLastArg(OPT_linkrepro)) {
1137-
SmallString<64> path = StringRef(arg->getValue());
1138-
sys::path::append(path, "repro.tar");
1139-
1157+
// Handle /linkrepro and /reproduce.
1158+
if (Optional<std::string> path = getReproduceFile(args)) {
11401159
Expected<std::unique_ptr<TarWriter>> errOrWriter =
1141-
TarWriter::create(path, "repro");
1160+
TarWriter::create(*path, sys::path::stem(*path));
11421161

11431162
if (errOrWriter) {
11441163
tar = std::move(*errOrWriter);
11451164
} else {
1146-
error("/linkrepro: failed to open " + path + ": " +
1165+
error("/linkrepro: failed to open " + *path + ": " +
11471166
toString(errOrWriter.takeError()));
11481167
}
11491168
}

lld/COFF/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ def noentry : F<"noentry">,
112112
def profile : F<"profile">;
113113
def repro : F<"Brepro">,
114114
HelpText<"Use a hash of the executable as the PE header timestamp">;
115+
def reproduce : P<"reproduce",
116+
"Dump linker invocation and input files for debugging">;
115117
def swaprun : P<"swaprun",
116118
"Comma-separated list of 'cd' or 'net'">;
117119
def swaprun_cd : F<"swaprun:cd">, Alias<swaprun>, AliasArgs<["cd"]>,

lld/test/COFF/linkrepro.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
# RUN: diff %p/Inputs/std32.lib repro/%:p/Inputs/std32.lib
1313
# RUN: FileCheck %s --check-prefix=RSP < repro/response.txt
1414

15+
# RUN: cd %t.dir/build1
16+
# RUN: lld-link %t.obj %p/Inputs/std32.lib /subsystem:console \
17+
# RUN: /entry:main@0 /reproduce:repro2.tar /out:%t.exe
18+
# RUN: tar xf repro2.tar
19+
# RUN: diff %t.obj repro2/%:t.obj
20+
# RUN: diff %p/Inputs/std32.lib repro2/%:p/Inputs/std32.lib
21+
# RUN: FileCheck %s --check-prefix=RSP < repro2/response.txt
22+
1523
# RUN: cd %t.dir/build2
1624
# RUN: lld-link %t.obj /libpath:%p/Inputs /defaultlib:std32 /subsystem:console \
1725
# RUN: /entry:main@0 /linkrepro:. /out:%t.exe

0 commit comments

Comments
 (0)