@@ -603,6 +603,7 @@ static std::string createResponseFile(const opt::InputArgList &args,
603
603
for (auto *arg : args) {
604
604
switch (arg->getOption ().getID ()) {
605
605
case OPT_linkrepro:
606
+ case OPT_reproduce:
606
607
case OPT_INPUT:
607
608
case OPT_defaultlib:
608
609
case OPT_libpath:
@@ -1071,6 +1072,26 @@ void LinkerDriver::maybeExportMinGWSymbols(const opt::InputArgList &args) {
1071
1072
});
1072
1073
}
1073
1074
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
+
1074
1095
void LinkerDriver::link (ArrayRef<const char *> argsArr) {
1075
1096
// Needed for LTO.
1076
1097
InitializeAllTargetInfos ();
@@ -1133,17 +1154,15 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
1133
1154
// options are handled.
1134
1155
config->mingw = args.hasArg (OPT_lldmingw);
1135
1156
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)) {
1140
1159
Expected<std::unique_ptr<TarWriter>> errOrWriter =
1141
- TarWriter::create (path, " repro " );
1160
+ TarWriter::create (* path, sys::path::stem (*path) );
1142
1161
1143
1162
if (errOrWriter) {
1144
1163
tar = std::move (*errOrWriter);
1145
1164
} else {
1146
- error (" /linkrepro: failed to open " + path + " : " +
1165
+ error (" /linkrepro: failed to open " + * path + " : " +
1147
1166
toString (errOrWriter.takeError ()));
1148
1167
}
1149
1168
}
0 commit comments