Skip to content

Commit 4ec7ec4

Browse files
committed
[NFC][lld][ELF] Allow customized reproduce path
Use std::optional<std::string> as return type of getReproduceOption instead of const char *. This is same as getReproduceFile in COFF which allows user to modify reproduce tar name.
1 parent a90d653 commit 4ec7ec4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lld/ELF/Driver.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,14 @@ static void checkOptions(Ctx &ctx) {
482482
ErrAlways(ctx) << "-z force-ibt may not be used with -z retpolineplt";
483483
}
484484

485-
static const char *getReproduceOption(opt::InputArgList &args) {
485+
static std::optional<std::string> getReproduceOption(opt::InputArgList &args) {
486486
if (auto *arg = args.getLastArg(OPT_reproduce))
487487
return arg->getValue();
488-
return getenv("LLD_REPRODUCE");
488+
489+
if (const char *env = getenv("LLD_REPRODUCE"))
490+
return env;
491+
492+
return std::nullopt;
489493
}
490494

491495
static bool hasZOption(opt::InputArgList &args, StringRef key) {
@@ -681,11 +685,11 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
681685
if (args.hasArg(OPT_v) || args.hasArg(OPT_version))
682686
Msg(ctx) << getLLDVersion() << " (compatible with GNU linkers)";
683687

684-
if (const char *path = getReproduceOption(args)) {
688+
if (std::optional<std::string> path = getReproduceOption(args)) {
685689
// Note that --reproduce is a debug option so you can ignore it
686690
// if you are trying to understand the whole picture of the code.
687691
Expected<std::unique_ptr<TarWriter>> errOrWriter =
688-
TarWriter::create(path, path::stem(path));
692+
TarWriter::create(*path, path::stem(*path));
689693
if (errOrWriter) {
690694
ctx.tar = std::move(*errOrWriter);
691695
ctx.tar->append("response.txt", createResponseFile(args));

0 commit comments

Comments
 (0)