diff --git a/lld/ELF/AArch64ErrataFix.cpp b/lld/ELF/AArch64ErrataFix.cpp index df4d1aea63f1..038d4e08985d 100644 --- a/lld/ELF/AArch64ErrataFix.cpp +++ b/lld/ELF/AArch64ErrataFix.cpp @@ -398,9 +398,9 @@ Patch843419Section::Patch843419Section(Ctx &ctx, InputSection *p, uint64_t off) patchee(p), patcheeOffset(off) { this->parent = p->getParent(); patchSym = addSyntheticLocal( - ctx, saver().save("__CortexA53843419_" + utohexstr(getLDSTAddr())), + ctx, saver(ctx).save("__CortexA53843419_" + utohexstr(getLDSTAddr())), STT_FUNC, 0, getSize(), *this); - addSyntheticLocal(ctx, saver().save("$x"), STT_NOTYPE, 0, 0, *this); + addSyntheticLocal(ctx, saver(ctx).save("$x"), STT_NOTYPE, 0, 0, *this); } uint64_t Patch843419Section::getLDSTAddr() const { diff --git a/lld/ELF/ARMErrataFix.cpp b/lld/ELF/ARMErrataFix.cpp index 7984e84c88a6..15bfbaa6d64a 100644 --- a/lld/ELF/ARMErrataFix.cpp +++ b/lld/ELF/ARMErrataFix.cpp @@ -141,9 +141,9 @@ Patch657417Section::Patch657417Section(Ctx &ctx, InputSection *p, uint64_t off, patchee(p), patcheeOffset(off), instr(instr), isARM(isARM) { parent = p->getParent(); patchSym = addSyntheticLocal( - ctx, saver().save("__CortexA8657417_" + utohexstr(getBranchAddr())), + ctx, saver(ctx).save("__CortexA8657417_" + utohexstr(getBranchAddr())), STT_FUNC, isARM ? 0 : 1, getSize(), *this); - addSyntheticLocal(ctx, saver().save(isARM ? "$a" : "$t"), STT_NOTYPE, 0, 0, + addSyntheticLocal(ctx, saver(ctx).save(isARM ? "$a" : "$t"), STT_NOTYPE, 0, 0, *this); } diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp index 7e3e6ee88aae..850b7980c85c 100644 --- a/lld/ELF/Arch/LoongArch.cpp +++ b/lld/ELF/Arch/LoongArch.cpp @@ -851,7 +851,7 @@ void LoongArch::finalizeRelax(int passes) const { MutableArrayRef rels = sec->relocs(); ArrayRef old = sec->content(); size_t newSize = old.size() - aux.relocDeltas[rels.size() - 1]; - uint8_t *p = context().bAlloc.Allocate(newSize); + uint8_t *p = bAlloc(ctx).Allocate(newSize); uint64_t offset = 0; int64_t delta = 0; sec->content_ = p; diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp index e3333c66777c..4152b403ecfc 100644 --- a/lld/ELF/Arch/RISCV.cpp +++ b/lld/ELF/Arch/RISCV.cpp @@ -947,7 +947,7 @@ void RISCV::finalizeRelax(int passes) const { ArrayRef old = sec->content(); size_t newSize = old.size() - aux.relocDeltas[rels.size() - 1]; size_t writesIdx = 0; - uint8_t *p = context().bAlloc.Allocate(newSize); + uint8_t *p = bAlloc(ctx).Allocate(newSize); uint64_t offset = 0; int64_t delta = 0; sec->content_ = p; @@ -1257,7 +1257,7 @@ mergeAttributesSection(Ctx &ctx, if (hasArch && xlen != 0) { if (auto result = RISCVISAInfo::createFromExtMap(xlen, exts)) { merged.strAttr.try_emplace(RISCVAttrs::ARCH, - saver().save((*result)->toString())); + saver(ctx).save((*result)->toString())); } else { Err(ctx) << result.takeError(); } diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index d07670b76b60..c847a32bb5f1 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -9,6 +9,7 @@ #ifndef LLD_ELF_CONFIG_H #define LLD_ELF_CONFIG_H +#include "lld/Common/CommonLinkerContext.h" #include "lld/Common/ErrorHandler.h" #include "llvm/ADT/CachedHashString.h" #include "llvm/ADT/DenseSet.h" @@ -546,6 +547,7 @@ struct Ctx { LinkerScript *script; std::unique_ptr target; + CommonLinkerContext *commonCtx; ErrorHandler *errHandler; // These variables are initialized by Writer and should not be used before @@ -673,6 +675,14 @@ static inline ArrayRef namedVersionDefs(Ctx &ctx) { return llvm::ArrayRef(ctx.arg.versionDefinitions).slice(2); } +inline llvm::BumpPtrAllocator &bAlloc(Ctx &ctx) { + return ctx.commonCtx->bAlloc; +} +inline llvm::StringSaver &saver(Ctx &ctx) { return ctx.commonCtx->saver; } +inline llvm::UniqueStringSaver &uniqueSaver(Ctx &ctx) { + return ctx.commonCtx->uniqueSaver; +} + struct ELFSyncStream : SyncStream { Ctx &ctx; ELFSyncStream(Ctx &ctx, DiagLevel level) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 81126a91024d..8f23514bcdcd 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -109,6 +109,7 @@ void Ctx::reset() { script = nullptr; target.reset(); + commonCtx = nullptr; errHandler = nullptr; bufferStart = nullptr; @@ -179,6 +180,7 @@ bool link(ArrayRef args, llvm::raw_ostream &stdoutOS, Ctx &ctx = elf::ctx; LinkerScript script(ctx); ctx.script = &script; + ctx.commonCtx = context; ctx.errHandler = &context->e; ctx.symAux.emplace_back(); ctx.symtab = std::make_unique(ctx); @@ -386,7 +388,7 @@ void LinkerDriver::addFile(StringRef path, bool withLOption) { // Add a given library by searching it from input search paths. void LinkerDriver::addLibrary(StringRef name) { if (std::optional path = searchLibrary(ctx, name)) - addFile(saver().save(*path), /*withLOption=*/true); + addFile(saver(ctx).save(*path), /*withLOption=*/true); else ctx.errHandler->error("unable to find library -l" + name, ErrorTag::LibNotFound, {name}); @@ -1675,7 +1677,8 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) { // Parse LTO options. if (auto *arg = args.getLastArg(OPT_plugin_opt_mcpu_eq)) - parseClangOption(ctx, saver().save("-mcpu=" + StringRef(arg->getValue())), + parseClangOption(ctx, + saver(ctx).save("-mcpu=" + StringRef(arg->getValue())), arg->getSpelling()); for (opt::Arg *arg : args.filtered(OPT_plugin_opt_eq_minus)) @@ -2622,7 +2625,7 @@ static std::vector addWrappedSymbols(Ctx &ctx, opt::InputArgList &args) { std::vector v; DenseSet seen; - + auto &ss = saver(ctx); for (auto *arg : args.filtered(OPT_wrap)) { StringRef name = arg->getValue(); if (!seen.insert(name).second) @@ -2632,12 +2635,12 @@ static std::vector addWrappedSymbols(Ctx &ctx, if (!sym) continue; - Symbol *wrap = ctx.symtab->addUnusedUndefined( - saver().save("__wrap_" + name), sym->binding); + Symbol *wrap = + ctx.symtab->addUnusedUndefined(ss.save("__wrap_" + name), sym->binding); // If __real_ is referenced, pull in the symbol if it is lazy. Do this after // processing __wrap_ as that may have referenced __real_. - StringRef realName = saver().save("__real_" + name); + StringRef realName = saver(ctx).save("__real_" + name); if (Symbol *real = ctx.symtab->find(realName)) { ctx.symtab->addUnusedUndefined(name, sym->binding); // Update sym's binding, which will replace real's later in diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp index 6e58545da895..2ea5210997d0 100644 --- a/lld/ELF/DriverUtils.cpp +++ b/lld/ELF/DriverUtils.cpp @@ -94,7 +94,7 @@ static void concatLTOPluginOptions(SmallVectorImpl &args) { for (size_t i = 0, e = args.size(); i != e; ++i) { StringRef s = args[i]; if ((s == "-plugin-opt" || s == "--plugin-opt") && i + 1 != e) { - v.push_back(saver().save(s + "=" + args[i + 1]).data()); + v.push_back(saver(ctx).save(s + "=" + args[i + 1]).data()); ++i; } else { v.push_back(args[i]); @@ -117,7 +117,7 @@ opt::InputArgList ELFOptTable::parse(Ctx &ctx, ArrayRef argv) { // Expand response files (arguments in the form of @) // and then parse the argument again. - cl::ExpandResponseFiles(saver(), getQuotingStyle(ctx, args), vec); + cl::ExpandResponseFiles(saver(ctx), getQuotingStyle(ctx, args), vec); concatLTOPluginOptions(vec); args = this->ParseArgs(vec, missingIndex, missingCount); diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 9fa4f35275b3..fb19fce257a1 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -222,7 +222,7 @@ std::optional elf::readFile(Ctx &ctx, StringRef path) { // The --chroot option changes our virtual root directory. // This is useful when you are dealing with files created by --reproduce. if (!ctx.arg.chroot.empty() && path.starts_with("/")) - path = saver().save(ctx.arg.chroot + path); + path = saver(ctx).save(ctx.arg.chroot + path); bool remapped = false; auto it = ctx.arg.remapInputs.find(path); @@ -427,9 +427,9 @@ static void addDependentLibrary(Ctx &ctx, StringRef specifier, if (!ctx.arg.dependentLibraries) return; if (std::optional s = searchLibraryBaseName(ctx, specifier)) - ctx.driver.addFile(saver().save(*s), /*withLOption=*/true); + ctx.driver.addFile(saver(ctx).save(*s), /*withLOption=*/true); else if (std::optional s = findFromSearchPaths(ctx, specifier)) - ctx.driver.addFile(saver().save(*s), /*withLOption=*/true); + ctx.driver.addFile(saver(ctx).save(*s), /*withLOption=*/true); else if (fs::exists(specifier)) ctx.driver.addFile(specifier, /*withLOption=*/false); else @@ -1515,6 +1515,7 @@ template void SharedFile::parse() { } // DSOs are uniquified not by filename but by soname. + StringSaver &ss = saver(ctx); DenseMap::iterator it; bool wasInserted; std::tie(it, wasInserted) = @@ -1581,8 +1582,7 @@ template void SharedFile::parse() { } StringRef verName = stringTable.data() + verneeds[idx]; versionedNameBuffer.clear(); - name = saver().save( - (name + "@" + verName).toStringRef(versionedNameBuffer)); + name = ss.save((name + "@" + verName).toStringRef(versionedNameBuffer)); } Symbol *s = ctx.symtab->addSymbol( Undefined{this, name, sym.getBinding(), sym.st_other, sym.getType()}); @@ -1627,7 +1627,7 @@ template void SharedFile::parse() { versionedNameBuffer.clear(); name = (name + "@" + verName).toStringRef(versionedNameBuffer); auto *s = ctx.symtab->addSymbol( - SharedSymbol{*this, saver().save(name), sym.getBinding(), sym.st_other, + SharedSymbol{*this, ss.save(name), sym.getBinding(), sym.st_other, sym.getType(), sym.st_value, sym.st_size, alignment}); s->dsoDefined = true; if (s->file == this) @@ -1723,10 +1723,11 @@ BitcodeFile::BitcodeFile(Ctx &ctx, MemoryBufferRef mb, StringRef archiveName, // into consideration at LTO time (which very likely causes undefined // symbols later in the link stage). So we append file offset to make // filename unique. + StringSaver &ss = saver(ctx); StringRef name = archiveName.empty() - ? saver().save(path) - : saver().save(archiveName + "(" + path::filename(path) + - " at " + utostr(offsetInArchive) + ")"); + ? ss.save(path) + : ss.save(archiveName + "(" + path::filename(path) + + " at " + utostr(offsetInArchive) + ")"); MemoryBufferRef mbref(mb.getBuffer(), name); obj = CHECK2(lto::InputFile::create(mbref), this); @@ -1763,7 +1764,7 @@ static void createBitcodeSymbol(Ctx &ctx, Symbol *&sym, // Update objSym.Name to reference (via StringRef) the string saver's copy; // this way LTO can reference the same string saver's copy rather than // keeping copies of its own. - objSym.Name = uniqueSaver().save(objSym.getName()); + objSym.Name = uniqueSaver(ctx).save(objSym.getName()); sym = ctx.symtab->insert(objSym.getName()); } @@ -1816,13 +1817,14 @@ void BitcodeFile::parse() { void BitcodeFile::parseLazy() { numSymbols = obj->symbols().size(); symbols = std::make_unique(numSymbols); + auto &ss = uniqueSaver(ctx); for (auto [i, irSym] : llvm::enumerate(obj->symbols())) { // Symbols can be duplicated in bitcode files because of '#include' and // linkonce_odr. Use uniqueSaver to save symbol names for de-duplication. // Update objSym.Name to reference (via StringRef) the string saver's copy; // this way LTO can reference the same string saver's copy rather than // keeping copies of its own. - irSym.Name = uniqueSaver().save(irSym.getName()); + irSym.Name = ss.save(irSym.getName()); if (!irSym.isUndefined()) { auto *sym = ctx.symtab->insert(irSym.getName()); sym->resolve(ctx, LazySymbol{*this}); @@ -1859,16 +1861,15 @@ void BinaryFile::parse() { if (!isAlnum(c)) c = '_'; - llvm::StringSaver &saver = lld::saver(); - + llvm::StringSaver &ss = saver(ctx); ctx.symtab->addAndCheckDuplicate( - ctx, Defined{ctx, this, saver.save(s + "_start"), STB_GLOBAL, STV_DEFAULT, + ctx, Defined{ctx, this, ss.save(s + "_start"), STB_GLOBAL, STV_DEFAULT, STT_OBJECT, 0, 0, section}); ctx.symtab->addAndCheckDuplicate( - ctx, Defined{ctx, this, saver.save(s + "_end"), STB_GLOBAL, STV_DEFAULT, + ctx, Defined{ctx, this, ss.save(s + "_end"), STB_GLOBAL, STV_DEFAULT, STT_OBJECT, data.size(), 0, section}); ctx.symtab->addAndCheckDuplicate( - ctx, Defined{ctx, this, saver.save(s + "_size"), STB_GLOBAL, STV_DEFAULT, + ctx, Defined{ctx, this, ss.save(s + "_size"), STB_GLOBAL, STV_DEFAULT, STT_OBJECT, data.size(), 0, nullptr}); } diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 9ae70e1385db..736acef778ff 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -130,7 +130,7 @@ void InputSectionBase::decompress() const { { static std::mutex mu; std::lock_guard lock(mu); - uncompressedBuf = bAlloc().Allocate(size); + uncompressedBuf = bAlloc(ctx).Allocate(size); } invokeELFT(decompressAux, ctx, *this, uncompressedBuf, size); diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp index e9363a163207..dc327ce7f781 100644 --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -396,8 +396,8 @@ std::vector BitcodeCompiler::compile() { StringRef ltoObjName; if (bitcodeFilePath == "ld-temp.o") { ltoObjName = - saver().save(Twine(ctx.arg.outputFile) + ".lto" + - (i == 0 ? Twine("") : Twine('.') + Twine(i)) + ext); + saver(ctx).save(Twine(ctx.arg.outputFile) + ".lto" + + (i == 0 ? Twine("") : Twine('.') + Twine(i)) + ext); } else { StringRef directory = sys::path::parent_path(bitcodeFilePath); // For an archive member, which has an identifier like "d/a.a(coll.o at @@ -411,7 +411,7 @@ std::vector BitcodeCompiler::compile() { sys::path::append(path, directory, outputFileBaseName + ".lto." + baseName + ext); sys::path::remove_dots(path, true); - ltoObjName = saver().save(path.str()); + ltoObjName = saver(ctx).save(path.str()); } if (savePrelink || ctx.arg.ltoEmitAsm) saveBuffer(buf[i].second, ltoObjName); diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index ca4877b25a1f..0298294e6155 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -59,11 +59,12 @@ StringRef LinkerScript::getOutputSectionName(const InputSectionBase *s) const { assert(ctx.arg.relocatable && (rel->flags & SHF_LINK_ORDER)); return s->name; } + StringSaver &ss = saver(ctx); if (s->type == SHT_CREL) - return saver().save(".crel" + out->name); + return ss.save(".crel" + out->name); if (s->type == SHT_RELA) - return saver().save(".rela" + out->name); - return saver().save(".rel" + out->name); + return ss.save(".rela" + out->name); + return ss.save(".rel" + out->name); } } diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index ab61b8be0ad6..066c52540123 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -301,8 +301,8 @@ template void MarkLive::run() { // As a workaround for glibc libc.a before 2.34 // (https://sourceware.org/PR27492), retain __libc_atexit and similar // sections regardless of zStartStopGC. - cNamedSections[saver().save("__start_" + sec->name)].push_back(sec); - cNamedSections[saver().save("__stop_" + sec->name)].push_back(sec); + cNamedSections[saver(ctx).save("__start_" + sec->name)].push_back(sec); + cNamedSections[saver(ctx).save("__stop_" + sec->name)].push_back(sec); } } diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 8ab0fd1ebd6f..0e301a4921fe 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -118,9 +118,9 @@ void OutputSection::commitSection(InputSection *isec) { type = SHT_CREL; if (type == SHT_REL) { if (name.consume_front(".rel")) - name = saver().save(".crel" + name); + name = saver(ctx).save(".crel" + name); } else if (name.consume_front(".rela")) { - name = saver().save(".crel" + name); + name = saver(ctx).save(".crel" + name); } } else { if (typeIsSet || !canMergeToProgbits(ctx, type) || diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp index aa89d8c22cf2..f7e3a5e418d5 100644 --- a/lld/ELF/ScriptParser.cpp +++ b/lld/ELF/ScriptParser.cpp @@ -317,7 +317,7 @@ void ScriptParser::addFile(StringRef s) { SmallString<128> pathData; StringRef path = (ctx.arg.sysroot + s).toStringRef(pathData); if (sys::fs::exists(path)) - ctx.driver.addFile(saver().save(path), /*withLOption=*/false); + ctx.driver.addFile(saver(ctx).save(path), /*withLOption=*/false); else setError("cannot find " + s + " inside " + ctx.arg.sysroot); return; @@ -331,7 +331,7 @@ void ScriptParser::addFile(StringRef s) { if (ctx.arg.sysroot.empty()) ctx.driver.addFile(s.substr(1), /*withLOption=*/false); else - ctx.driver.addFile(saver().save(ctx.arg.sysroot + "/" + s.substr(1)), + ctx.driver.addFile(saver(ctx).save(ctx.arg.sysroot + "/" + s.substr(1)), /*withLOption=*/false); } else if (s.starts_with("-l")) { // Case 3: search in the list of library paths. @@ -354,7 +354,7 @@ void ScriptParser::addFile(StringRef s) { } else { // Finally, search in the list of library paths. if (std::optional path = findFromSearchPaths(ctx, s)) - ctx.driver.addFile(saver().save(*path), /*withLOption=*/true); + ctx.driver.addFile(saver(ctx).save(*path), /*withLOption=*/true); else setError("unable to find " + s); } diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 1af7200beb4b..814835449fdf 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -77,7 +77,7 @@ static ArrayRef getVersion() { // This is only for testing. StringRef s = getenv("LLD_VERSION"); if (s.empty()) - s = saver().save(Twine("Linker: ") + getLLDVersion()); + s = saver(ctx).save(Twine("Linker: ") + getLLDVersion()); // +1 to include the terminating '\0'. return {(const uint8_t *)s.data(), s.size() + 1}; @@ -269,7 +269,7 @@ MipsReginfoSection::create(Ctx &ctx) { InputSection *elf::createInterpSection(Ctx &ctx) { // StringSaver guarantees that the returned string ends with '\0'. - StringRef s = saver().save(ctx.arg.dynamicLinker); + StringRef s = saver(ctx).save(ctx.arg.dynamicLinker); ArrayRef contents = {(const uint8_t *)s.data(), s.size() + 1}; return make(ctx.internalFile, SHF_ALLOC, SHT_PROGBITS, 1, diff --git a/lld/ELF/Thunks.cpp b/lld/ELF/Thunks.cpp index e4c78cb3b402..7c5bd0556bc7 100644 --- a/lld/ELF/Thunks.cpp +++ b/lld/ELF/Thunks.cpp @@ -599,7 +599,7 @@ void AArch64ABSLongThunk::writeLong(uint8_t *buf) { } void AArch64ABSLongThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__AArch64AbsLongThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__AArch64AbsLongThunk_" + destination.getName()), STT_FUNC, 0, isec); addSymbol("$x", STT_NOTYPE, 0, isec); if (!getMayUseShortThunk()) @@ -631,13 +631,13 @@ void AArch64ADRPThunk::writeLong(uint8_t *buf) { } void AArch64ADRPThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__AArch64ADRPThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__AArch64ADRPThunk_" + destination.getName()), STT_FUNC, 0, isec); addSymbol("$x", STT_NOTYPE, 0, isec); } void AArch64BTILandingPadThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__AArch64BTIThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__AArch64BTIThunk_" + destination.getName()), STT_FUNC, 0, isec); addSymbol("$x", STT_NOTYPE, 0, isec); } @@ -776,7 +776,7 @@ void ARMV7ABSLongThunk::writeLong(uint8_t *buf) { } void ARMV7ABSLongThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__ARMv7ABSLongThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__ARMv7ABSLongThunk_" + destination.getName()), STT_FUNC, 0, isec); addSymbol("$a", STT_NOTYPE, 0, isec); } @@ -793,7 +793,7 @@ void ThumbV7ABSLongThunk::writeLong(uint8_t *buf) { } void ThumbV7ABSLongThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__Thumbv7ABSLongThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__Thumbv7ABSLongThunk_" + destination.getName()), STT_FUNC, 1, isec); addSymbol("$t", STT_NOTYPE, 0, isec); } @@ -813,7 +813,7 @@ void ARMV7PILongThunk::writeLong(uint8_t *buf) { } void ARMV7PILongThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__ARMV7PILongThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__ARMV7PILongThunk_" + destination.getName()), STT_FUNC, 0, isec); addSymbol("$a", STT_NOTYPE, 0, isec); } @@ -833,7 +833,7 @@ void ThumbV7PILongThunk::writeLong(uint8_t *buf) { } void ThumbV7PILongThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__ThumbV7PILongThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__ThumbV7PILongThunk_" + destination.getName()), STT_FUNC, 1, isec); addSymbol("$t", STT_NOTYPE, 0, isec); } @@ -853,7 +853,7 @@ void ThumbV6MABSLongThunk::writeLong(uint8_t *buf) { } void ThumbV6MABSLongThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__Thumbv6MABSLongThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__Thumbv6MABSLongThunk_" + destination.getName()), STT_FUNC, 1, isec); addSymbol("$t", STT_NOTYPE, 0, isec); if (!getMayUseShortThunk()) @@ -884,8 +884,9 @@ void ThumbV6MABSXOLongThunk::writeLong(uint8_t *buf) { } void ThumbV6MABSXOLongThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__Thumbv6MABSXOLongThunk_" + destination.getName()), - STT_FUNC, 1, isec); + addSymbol( + saver(ctx).save("__Thumbv6MABSXOLongThunk_" + destination.getName()), + STT_FUNC, 1, isec); addSymbol("$t", STT_NOTYPE, 0, isec); } @@ -909,7 +910,7 @@ void ThumbV6MPILongThunk::writeLong(uint8_t *buf) { } void ThumbV6MPILongThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__Thumbv6MPILongThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__Thumbv6MPILongThunk_" + destination.getName()), STT_FUNC, 1, isec); addSymbol("$t", STT_NOTYPE, 0, isec); if (!getMayUseShortThunk()) @@ -924,7 +925,7 @@ void ARMV5LongLdrPcThunk::writeLong(uint8_t *buf) { } void ARMV5LongLdrPcThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__ARMv5LongLdrPcThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__ARMv5LongLdrPcThunk_" + destination.getName()), STT_FUNC, 0, isec); addSymbol("$a", STT_NOTYPE, 0, isec); if (!getMayUseShortThunk()) @@ -940,7 +941,7 @@ void ARMV4ABSLongBXThunk::writeLong(uint8_t *buf) { } void ARMV4ABSLongBXThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__ARMv4ABSLongBXThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__ARMv4ABSLongBXThunk_" + destination.getName()), STT_FUNC, 0, isec); addSymbol("$a", STT_NOTYPE, 0, isec); if (!getMayUseShortThunk()) @@ -958,7 +959,7 @@ void ThumbV4ABSLongBXThunk::writeLong(uint8_t *buf) { } void ThumbV4ABSLongBXThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__Thumbv4ABSLongBXThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__Thumbv4ABSLongBXThunk_" + destination.getName()), STT_FUNC, 1, isec); addSymbol("$t", STT_NOTYPE, 0, isec); addSymbol("$a", STT_NOTYPE, 4, isec); @@ -978,7 +979,7 @@ void ThumbV4ABSLongThunk::writeLong(uint8_t *buf) { } void ThumbV4ABSLongThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__Thumbv4ABSLongThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__Thumbv4ABSLongThunk_" + destination.getName()), STT_FUNC, 1, isec); addSymbol("$t", STT_NOTYPE, 0, isec); addSymbol("$a", STT_NOTYPE, 4, isec); @@ -997,7 +998,7 @@ void ARMV4PILongBXThunk::writeLong(uint8_t *buf) { } void ARMV4PILongBXThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__ARMv4PILongBXThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__ARMv4PILongBXThunk_" + destination.getName()), STT_FUNC, 0, isec); addSymbol("$a", STT_NOTYPE, 0, isec); if (!getMayUseShortThunk()) @@ -1014,7 +1015,7 @@ void ARMV4PILongThunk::writeLong(uint8_t *buf) { } void ARMV4PILongThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__ARMv4PILongThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__ARMv4PILongThunk_" + destination.getName()), STT_FUNC, 0, isec); addSymbol("$a", STT_NOTYPE, 0, isec); if (!getMayUseShortThunk()) @@ -1034,7 +1035,7 @@ void ThumbV4PILongBXThunk::writeLong(uint8_t *buf) { } void ThumbV4PILongBXThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__Thumbv4PILongBXThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__Thumbv4PILongBXThunk_" + destination.getName()), STT_FUNC, 1, isec); addSymbol("$t", STT_NOTYPE, 0, isec); addSymbol("$a", STT_NOTYPE, 4, isec); @@ -1056,7 +1057,7 @@ void ThumbV4PILongThunk::writeLong(uint8_t *buf) { } void ThumbV4PILongThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__Thumbv4PILongThunk_" + destination.getName()), + addSymbol(saver(ctx).save("__Thumbv4PILongThunk_" + destination.getName()), STT_FUNC, 1, isec); addSymbol("$t", STT_NOTYPE, 0, isec); addSymbol("$a", STT_NOTYPE, 4, isec); @@ -1071,7 +1072,7 @@ void AVRThunk::writeTo(uint8_t *buf) { } void AVRThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__AVRThunk_" + destination.getName()), STT_FUNC, 0, + addSymbol(saver(ctx).save("__AVRThunk_" + destination.getName()), STT_FUNC, 0, isec); } @@ -1087,8 +1088,8 @@ void MipsThunk::writeTo(uint8_t *buf) { } void MipsThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__LA25Thunk_" + destination.getName()), STT_FUNC, 0, - isec); + addSymbol(saver(ctx).save("__LA25Thunk_" + destination.getName()), STT_FUNC, + 0, isec); } InputSection *MipsThunk::getTargetInputSection() const { @@ -1111,7 +1112,7 @@ void MicroMipsThunk::writeTo(uint8_t *buf) { void MicroMipsThunk::addSymbols(ThunkSection &isec) { Defined *d = - addSymbol(saver().save("__microLA25Thunk_" + destination.getName()), + addSymbol(saver(ctx).save("__microLA25Thunk_" + destination.getName()), STT_FUNC, 0, isec); d->stOther |= STO_MIPS_MICROMIPS; } @@ -1136,7 +1137,7 @@ void MicroMipsR6Thunk::writeTo(uint8_t *buf) { void MicroMipsR6Thunk::addSymbols(ThunkSection &isec) { Defined *d = - addSymbol(saver().save("__microLA25Thunk_" + destination.getName()), + addSymbol(saver(ctx).save("__microLA25Thunk_" + destination.getName()), STT_FUNC, 0, isec); d->stOther |= STO_MIPS_MICROMIPS; } @@ -1197,7 +1198,7 @@ void PPC32PltCallStub::addSymbols(ThunkSection &isec) { else os << ".plt_pic32."; os << destination.getName(); - addSymbol(saver().save(buf), STT_FUNC, 0, isec); + addSymbol(saver(ctx).save(buf), STT_FUNC, 0, isec); } bool PPC32PltCallStub::isCompatibleWith(const InputSection &isec, @@ -1206,8 +1207,8 @@ bool PPC32PltCallStub::isCompatibleWith(const InputSection &isec, } void PPC32LongThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__LongThunk_" + destination.getName()), STT_FUNC, 0, - isec); + addSymbol(saver(ctx).save("__LongThunk_" + destination.getName()), STT_FUNC, + 0, isec); } void PPC32LongThunk::writeTo(uint8_t *buf) { @@ -1250,7 +1251,7 @@ void PPC64PltCallStub::writeTo(uint8_t *buf) { } void PPC64PltCallStub::addSymbols(ThunkSection &isec) { - Defined *s = addSymbol(saver().save("__plt_" + destination.getName()), + Defined *s = addSymbol(saver(ctx).save("__plt_" + destination.getName()), STT_FUNC, 0, isec); s->setNeedsTocRestore(true); s->file = destination.file; @@ -1294,7 +1295,7 @@ void PPC64R2SaveStub::writeTo(uint8_t *buf) { } void PPC64R2SaveStub::addSymbols(ThunkSection &isec) { - Defined *s = addSymbol(saver().save("__toc_save_" + destination.getName()), + Defined *s = addSymbol(saver(ctx).save("__toc_save_" + destination.getName()), STT_FUNC, 0, isec); s->setNeedsTocRestore(true); } @@ -1338,8 +1339,8 @@ void PPC64R12SetupStub::writeTo(uint8_t *buf) { } void PPC64R12SetupStub::addSymbols(ThunkSection &isec) { - addSymbol(saver().save((gotPlt ? "__plt_pcrel_" : "__gep_setup_") + - destination.getName()), + addSymbol(saver(ctx).save((gotPlt ? "__plt_pcrel_" : "__gep_setup_") + + destination.getName()), STT_FUNC, 0, isec); } @@ -1356,8 +1357,8 @@ void PPC64LongBranchThunk::writeTo(uint8_t *buf) { } void PPC64LongBranchThunk::addSymbols(ThunkSection &isec) { - addSymbol(saver().save("__long_branch_" + destination.getName()), STT_FUNC, 0, - isec); + addSymbol(saver(ctx).save("__long_branch_" + destination.getName()), STT_FUNC, + 0, isec); } bool PPC64LongBranchThunk::isCompatibleWith(const InputSection &isec, diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 2a9d57ec8dee..fc6d88893597 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -2153,11 +2153,11 @@ void Writer::addStartStopSymbols(OutputSection &osec) { StringRef s = osec.name; if (!isValidCIdentifier(s)) return; - Defined *startSym = - addOptionalRegular(ctx, saver().save("__start_" + s), &osec, 0, - ctx.arg.zStartStopVisibility); - Defined *stopSym = addOptionalRegular(ctx, saver().save("__stop_" + s), &osec, - -1, ctx.arg.zStartStopVisibility); + StringSaver &ss = saver(ctx); + Defined *startSym = addOptionalRegular(ctx, ss.save("__start_" + s), &osec, 0, + ctx.arg.zStartStopVisibility); + Defined *stopSym = addOptionalRegular(ctx, ss.save("__stop_" + s), &osec, -1, + ctx.arg.zStartStopVisibility); if (startSym || stopSym) osec.usedInExpression = true; }