diff --git a/llvm/tools/dsymutil/dsymutil.cpp b/llvm/tools/dsymutil/dsymutil.cpp index 87369f2bc3cf..d9760b5c2ab8 100644 --- a/llvm/tools/dsymutil/dsymutil.cpp +++ b/llvm/tools/dsymutil/dsymutil.cpp @@ -436,6 +436,11 @@ getOutputFileName(StringRef InputFile, const DsymutilOptions &Options) { (Options.LinkOpts.Update || !Options.SymbolMap.empty())) return OutputLocation(std::string(InputFile)); + // When dumping the debug map, just return an empty output location. This + // allows us to compute the output location once. + if (Options.DumpDebugMap) + return OutputLocation(""); + // If a flat dSYM has been requested, things are pretty simple. if (Options.Flat) { if (Options.OutputFile.empty()) { @@ -580,6 +585,15 @@ int main(int argc, char **argv) { // Shared a single binary holder for all the link steps. BinaryHolder BinHolder(Options.LinkOpts.VFS); + // Compute the output location and update the resource directory. + Expected OutputLocationOrErr = + getOutputFileName(InputFile, Options); + if (!OutputLocationOrErr) { + WithColor::error() << toString(OutputLocationOrErr.takeError()); + return 1; + } + Options.LinkOpts.ResourceDir = OutputLocationOrErr->getResourceDir(); + // Statistics only require different architectures to be processed // sequentially, the link itself can still happen in parallel. Change the // thread pool strategy here instead of modifying LinkOpts.Threads. @@ -621,14 +635,6 @@ int main(int argc, char **argv) { // types don't work with std::bind in the ThreadPool implementation. std::shared_ptr OS; - Expected OutputLocationOrErr = - getOutputFileName(InputFile, Options); - if (!OutputLocationOrErr) { - WithColor::error() << toString(OutputLocationOrErr.takeError()); - return 1; - } - Options.LinkOpts.ResourceDir = OutputLocationOrErr->getResourceDir(); - std::string OutputFile = OutputLocationOrErr->DWARFFile; if (NeedsTempFiles) { TempFiles.emplace_back(Map->getTriple().getArchName().str()); @@ -678,12 +684,6 @@ int main(int argc, char **argv) { return 1; if (NeedsTempFiles) { - Expected OutputLocationOrErr = - getOutputFileName(InputFile, Options); - if (!OutputLocationOrErr) { - WithColor::error() << toString(OutputLocationOrErr.takeError()); - return 1; - } if (!MachOUtils::generateUniversalBinary(TempFiles, OutputLocationOrErr->DWARFFile, Options.LinkOpts, SDKPath))