@@ -222,7 +222,7 @@ std::optional<MemoryBufferRef> elf::readFile(Ctx &ctx, StringRef path) {
222222 // The --chroot option changes our virtual root directory.
223223 // This is useful when you are dealing with files created by --reproduce.
224224 if (!ctx.arg .chroot .empty () && path.starts_with (" /" ))
225- path = saver ().save (ctx.arg .chroot + path);
225+ path = saver (ctx ).save (ctx.arg .chroot + path);
226226
227227 bool remapped = false ;
228228 auto it = ctx.arg .remapInputs .find (path);
@@ -427,9 +427,9 @@ static void addDependentLibrary(Ctx &ctx, StringRef specifier,
427427 if (!ctx.arg .dependentLibraries )
428428 return ;
429429 if (std::optional<std::string> s = searchLibraryBaseName (ctx, specifier))
430- ctx.driver .addFile (saver ().save (*s), /* withLOption=*/ true );
430+ ctx.driver .addFile (saver (ctx ).save (*s), /* withLOption=*/ true );
431431 else if (std::optional<std::string> s = findFromSearchPaths (ctx, specifier))
432- ctx.driver .addFile (saver ().save (*s), /* withLOption=*/ true );
432+ ctx.driver .addFile (saver (ctx ).save (*s), /* withLOption=*/ true );
433433 else if (fs::exists (specifier))
434434 ctx.driver .addFile (specifier, /* withLOption=*/ false );
435435 else
@@ -1515,6 +1515,7 @@ template <class ELFT> void SharedFile::parse() {
15151515 }
15161516
15171517 // DSOs are uniquified not by filename but by soname.
1518+ StringSaver &ss = saver (ctx);
15181519 DenseMap<CachedHashStringRef, SharedFile *>::iterator it;
15191520 bool wasInserted;
15201521 std::tie (it, wasInserted) =
@@ -1581,8 +1582,7 @@ template <class ELFT> void SharedFile::parse() {
15811582 }
15821583 StringRef verName = stringTable.data () + verneeds[idx];
15831584 versionedNameBuffer.clear ();
1584- name = saver ().save (
1585- (name + " @" + verName).toStringRef (versionedNameBuffer));
1585+ name = ss.save ((name + " @" + verName).toStringRef (versionedNameBuffer));
15861586 }
15871587 Symbol *s = ctx.symtab ->addSymbol (
15881588 Undefined{this , name, sym.getBinding (), sym.st_other , sym.getType ()});
@@ -1627,7 +1627,7 @@ template <class ELFT> void SharedFile::parse() {
16271627 versionedNameBuffer.clear ();
16281628 name = (name + " @" + verName).toStringRef (versionedNameBuffer);
16291629 auto *s = ctx.symtab ->addSymbol (
1630- SharedSymbol{*this , saver () .save (name), sym.getBinding (), sym.st_other ,
1630+ SharedSymbol{*this , ss .save (name), sym.getBinding (), sym.st_other ,
16311631 sym.getType (), sym.st_value , sym.st_size , alignment});
16321632 s->dsoDefined = true ;
16331633 if (s->file == this )
@@ -1723,10 +1723,11 @@ BitcodeFile::BitcodeFile(Ctx &ctx, MemoryBufferRef mb, StringRef archiveName,
17231723 // into consideration at LTO time (which very likely causes undefined
17241724 // symbols later in the link stage). So we append file offset to make
17251725 // filename unique.
1726+ StringSaver &ss = saver (ctx);
17261727 StringRef name = archiveName.empty ()
1727- ? saver () .save (path)
1728- : saver () .save (archiveName + " (" + path::filename (path) +
1729- " at " + utostr (offsetInArchive) + " )" );
1728+ ? ss .save (path)
1729+ : ss .save (archiveName + " (" + path::filename (path) +
1730+ " at " + utostr (offsetInArchive) + " )" );
17301731 MemoryBufferRef mbref (mb.getBuffer (), name);
17311732
17321733 obj = CHECK2 (lto::InputFile::create (mbref), this );
@@ -1763,7 +1764,7 @@ static void createBitcodeSymbol(Ctx &ctx, Symbol *&sym,
17631764 // Update objSym.Name to reference (via StringRef) the string saver's copy;
17641765 // this way LTO can reference the same string saver's copy rather than
17651766 // keeping copies of its own.
1766- objSym.Name = uniqueSaver ().save (objSym.getName ());
1767+ objSym.Name = uniqueSaver (ctx ).save (objSym.getName ());
17671768 sym = ctx.symtab ->insert (objSym.getName ());
17681769 }
17691770
@@ -1816,13 +1817,14 @@ void BitcodeFile::parse() {
18161817void BitcodeFile::parseLazy () {
18171818 numSymbols = obj->symbols ().size ();
18181819 symbols = std::make_unique<Symbol *[]>(numSymbols);
1820+ auto &ss = uniqueSaver (ctx);
18191821 for (auto [i, irSym] : llvm::enumerate (obj->symbols ())) {
18201822 // Symbols can be duplicated in bitcode files because of '#include' and
18211823 // linkonce_odr. Use uniqueSaver to save symbol names for de-duplication.
18221824 // Update objSym.Name to reference (via StringRef) the string saver's copy;
18231825 // this way LTO can reference the same string saver's copy rather than
18241826 // keeping copies of its own.
1825- irSym.Name = uniqueSaver () .save (irSym.getName ());
1827+ irSym.Name = ss .save (irSym.getName ());
18261828 if (!irSym.isUndefined ()) {
18271829 auto *sym = ctx.symtab ->insert (irSym.getName ());
18281830 sym->resolve (ctx, LazySymbol{*this });
@@ -1859,16 +1861,15 @@ void BinaryFile::parse() {
18591861 if (!isAlnum (c))
18601862 c = ' _' ;
18611863
1862- llvm::StringSaver &saver = lld::saver ();
1863-
1864+ llvm::StringSaver &ss = saver (ctx);
18641865 ctx.symtab ->addAndCheckDuplicate (
1865- ctx, Defined{ctx, this , saver .save (s + " _start" ), STB_GLOBAL, STV_DEFAULT,
1866+ ctx, Defined{ctx, this , ss .save (s + " _start" ), STB_GLOBAL, STV_DEFAULT,
18661867 STT_OBJECT, 0 , 0 , section});
18671868 ctx.symtab ->addAndCheckDuplicate (
1868- ctx, Defined{ctx, this , saver .save (s + " _end" ), STB_GLOBAL, STV_DEFAULT,
1869+ ctx, Defined{ctx, this , ss .save (s + " _end" ), STB_GLOBAL, STV_DEFAULT,
18691870 STT_OBJECT, data.size (), 0 , section});
18701871 ctx.symtab ->addAndCheckDuplicate (
1871- ctx, Defined{ctx, this , saver .save (s + " _size" ), STB_GLOBAL, STV_DEFAULT,
1872+ ctx, Defined{ctx, this , ss .save (s + " _size" ), STB_GLOBAL, STV_DEFAULT,
18721873 STT_OBJECT, data.size (), 0 , nullptr });
18731874}
18741875
0 commit comments