diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index 1223f1800500..bba29250a3ca 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -95,7 +95,7 @@ struct Configuration { llvm::StringRef Sysroot; llvm::StringRef ThinLTOCacheDir; llvm::StringRef ThinLTOIndexOnlyObjectsFile; - llvm::StringRef ThinLTOPrefixReplace; + std::pair ThinLTOPrefixReplace; std::string Rpath; std::vector VersionDefinitions; std::vector AuxiliaryList; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index f9fa1e1d6650..9621b2410689 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -802,8 +802,9 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) { Config->ThinLTOIndexOnly = true; Config->ThinLTOIndexOnlyObjectsFile = S.substr(19); } else if (S.startswith("thinlto-prefix-replace=")) { - Config->ThinLTOPrefixReplace = S.substr(23); - if (!Config->ThinLTOPrefixReplace.contains(';')) + std::tie(Config->ThinLTOPrefixReplace.first, + Config->ThinLTOPrefixReplace.second) = S.substr(23).split(';'); + if (Config->ThinLTOPrefixReplace.second.empty()) error("thinlto-prefix-replace expects 'old;new' format"); } else if (!S.startswith("/") && !S.startswith("-fresolution=") && !S.startswith("-pass-through=") && !S.startswith("thinlto")) { diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp index c9e6448d231b..6befa257be8b 100644 --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -155,13 +155,10 @@ void BitcodeCompiler::init() { Backend = lto::createInProcessThinBackend(Config->ThinLTOJobs); if (Config->ThinLTOIndexOnly) { - std::string OldPrefix; - std::string NewPrefix; - std::tie(OldPrefix, NewPrefix) = Config->ThinLTOPrefixReplace.split(';'); - IndexFile = openFile(Config->ThinLTOIndexOnlyObjectsFile); - Backend = lto::createWriteIndexesThinBackend(OldPrefix, NewPrefix, true, - IndexFile.get(), nullptr); + Backend = lto::createWriteIndexesThinBackend( + Config->ThinLTOPrefixReplace.first, Config->ThinLTOPrefixReplace.second, + true, IndexFile.get(), nullptr); } Conf.SampleProfile = Config->LTOSampleProfile; @@ -193,13 +190,11 @@ static void undefine(Symbol *S) { void BitcodeCompiler::add(BitcodeFile &F) { lto::InputFile &Obj = *F.Obj; - std::string OldPrefix, NewPrefix; - std::tie(OldPrefix, NewPrefix) = Config->ThinLTOPrefixReplace.split(';'); - // Create the empty files which, if indexed, will be overwritten later. if (Config->ThinLTOIndexOnly) - writeEmptyDistributedBuildOutputs(Obj.getName(), OldPrefix, NewPrefix, - false); + writeEmptyDistributedBuildOutputs( + Obj.getName(), Config->ThinLTOPrefixReplace.first, + Config->ThinLTOPrefixReplace.second, false); unsigned SymNum = 0; std::vector Syms = F.getSymbols(); @@ -313,9 +308,8 @@ std::vector BitcodeCompiler::compile() { // For lazy object files not added to link, adds empty index files void BitcodeCompiler::addLazyObjFile(LazyObjFile *File) { - StringRef Identifier = File->getBuffer().getBufferIdentifier(); - std::string OldPrefix, NewPrefix; - std::tie(OldPrefix, NewPrefix) = Config->ThinLTOPrefixReplace.split(';'); - writeEmptyDistributedBuildOutputs(Identifier, OldPrefix, NewPrefix, - /* SkipModule */ true); + writeEmptyDistributedBuildOutputs(File->getBuffer().getBufferIdentifier(), + Config->ThinLTOPrefixReplace.first, + Config->ThinLTOPrefixReplace.second, + /*SkipModule=*/true); }