Skip to content

Commit 2991a4e

Browse files
committed
[ELF] Replace functions bAlloc/saver/uniqueSaver with member access
1 parent 8f238f6 commit 2991a4e

18 files changed

+69
-78
lines changed

lld/ELF/AArch64ErrataFix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ Patch843419Section::Patch843419Section(Ctx &ctx, InputSection *p, uint64_t off)
398398
patchee(p), patcheeOffset(off) {
399399
this->parent = p->getParent();
400400
patchSym = addSyntheticLocal(
401-
ctx, saver(ctx).save("__CortexA53843419_" + utohexstr(getLDSTAddr())),
401+
ctx, ctx.saver.save("__CortexA53843419_" + utohexstr(getLDSTAddr())),
402402
STT_FUNC, 0, getSize(), *this);
403-
addSyntheticLocal(ctx, saver(ctx).save("$x"), STT_NOTYPE, 0, 0, *this);
403+
addSyntheticLocal(ctx, ctx.saver.save("$x"), STT_NOTYPE, 0, 0, *this);
404404
}
405405

406406
uint64_t Patch843419Section::getLDSTAddr() const {

lld/ELF/ARMErrataFix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ Patch657417Section::Patch657417Section(Ctx &ctx, InputSection *p, uint64_t off,
141141
patchee(p), patcheeOffset(off), instr(instr), isARM(isARM) {
142142
parent = p->getParent();
143143
patchSym = addSyntheticLocal(
144-
ctx, saver(ctx).save("__CortexA8657417_" + utohexstr(getBranchAddr())),
144+
ctx, ctx.saver.save("__CortexA8657417_" + utohexstr(getBranchAddr())),
145145
STT_FUNC, isARM ? 0 : 1, getSize(), *this);
146-
addSyntheticLocal(ctx, saver(ctx).save(isARM ? "$a" : "$t"), STT_NOTYPE, 0, 0,
146+
addSyntheticLocal(ctx, ctx.saver.save(isARM ? "$a" : "$t"), STT_NOTYPE, 0, 0,
147147
*this);
148148
}
149149

lld/ELF/Arch/LoongArch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ void LoongArch::finalizeRelax(int passes) const {
851851
MutableArrayRef<Relocation> rels = sec->relocs();
852852
ArrayRef<uint8_t> old = sec->content();
853853
size_t newSize = old.size() - aux.relocDeltas[rels.size() - 1];
854-
uint8_t *p = bAlloc(ctx).Allocate<uint8_t>(newSize);
854+
uint8_t *p = ctx.bAlloc.Allocate<uint8_t>(newSize);
855855
uint64_t offset = 0;
856856
int64_t delta = 0;
857857
sec->content_ = p;

lld/ELF/Arch/PPC64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static void writeSequence(Ctx &ctx, const char *prefix, int from,
271271
char name[16];
272272
int first;
273273
const size_t size = 32 - from + tail.size();
274-
MutableArrayRef<uint32_t> buf(bAlloc(ctx).Allocate<uint32_t>(size), size);
274+
MutableArrayRef<uint32_t> buf(ctx.bAlloc.Allocate<uint32_t>(size), size);
275275
uint32_t *ptr = buf.data();
276276
for (int r = from; r < 32; ++r) {
277277
format("%s%d", prefix, r).snprint(name, sizeof(name));

lld/ELF/Arch/RISCV.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ void RISCV::finalizeRelax(int passes) const {
947947
ArrayRef<uint8_t> old = sec->content();
948948
size_t newSize = old.size() - aux.relocDeltas[rels.size() - 1];
949949
size_t writesIdx = 0;
950-
uint8_t *p = bAlloc(ctx).Allocate<uint8_t>(newSize);
950+
uint8_t *p = ctx.bAlloc.Allocate<uint8_t>(newSize);
951951
uint64_t offset = 0;
952952
int64_t delta = 0;
953953
sec->content_ = p;
@@ -1257,7 +1257,7 @@ mergeAttributesSection(Ctx &ctx,
12571257
if (hasArch && xlen != 0) {
12581258
if (auto result = RISCVISAInfo::createFromExtMap(xlen, exts)) {
12591259
merged.strAttr.try_emplace(RISCVAttrs::ARCH,
1260-
saver(ctx).save((*result)->toString()));
1260+
ctx.saver.save((*result)->toString()));
12611261
} else {
12621262
Err(ctx) << result.takeError();
12631263
}

lld/ELF/Config.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,6 @@ static inline ArrayRef<VersionDefinition> namedVersionDefs(Ctx &ctx) {
686686
return llvm::ArrayRef(ctx.arg.versionDefinitions).slice(2);
687687
}
688688

689-
inline llvm::BumpPtrAllocator &bAlloc(Ctx &ctx) { return ctx.bAlloc; }
690-
inline llvm::StringSaver &saver(Ctx &ctx) { return ctx.saver; }
691-
inline llvm::UniqueStringSaver &uniqueSaver(Ctx &ctx) {
692-
return ctx.uniqueSaver;
693-
}
694-
695689
struct ELFSyncStream : SyncStream {
696690
Ctx &ctx;
697691
ELFSyncStream(Ctx &ctx, DiagLevel level)

lld/ELF/Driver.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ void LinkerDriver::addFile(StringRef path, bool withLOption) {
330330
// Add a given library by searching it from input search paths.
331331
void LinkerDriver::addLibrary(StringRef name) {
332332
if (std::optional<std::string> path = searchLibrary(ctx, name))
333-
addFile(saver(ctx).save(*path), /*withLOption=*/true);
333+
addFile(ctx.saver.save(*path), /*withLOption=*/true);
334334
else
335335
ctx.e.error("unable to find library -l" + name, ErrorTag::LibNotFound,
336336
{name});
@@ -1619,8 +1619,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
16191619

16201620
// Parse LTO options.
16211621
if (auto *arg = args.getLastArg(OPT_plugin_opt_mcpu_eq))
1622-
parseClangOption(ctx,
1623-
saver(ctx).save("-mcpu=" + StringRef(arg->getValue())),
1622+
parseClangOption(ctx, ctx.saver.save("-mcpu=" + StringRef(arg->getValue())),
16241623
arg->getSpelling());
16251624

16261625
for (opt::Arg *arg : args.filtered(OPT_plugin_opt_eq_minus))
@@ -2567,7 +2566,7 @@ static std::vector<WrappedSymbol> addWrappedSymbols(Ctx &ctx,
25672566
opt::InputArgList &args) {
25682567
std::vector<WrappedSymbol> v;
25692568
DenseSet<StringRef> seen;
2570-
auto &ss = saver(ctx);
2569+
auto &ss = ctx.saver;
25712570
for (auto *arg : args.filtered(OPT_wrap)) {
25722571
StringRef name = arg->getValue();
25732572
if (!seen.insert(name).second)
@@ -2582,7 +2581,7 @@ static std::vector<WrappedSymbol> addWrappedSymbols(Ctx &ctx,
25822581

25832582
// If __real_ is referenced, pull in the symbol if it is lazy. Do this after
25842583
// processing __wrap_ as that may have referenced __real_.
2585-
StringRef realName = saver(ctx).save("__real_" + name);
2584+
StringRef realName = ctx.saver.save("__real_" + name);
25862585
if (Symbol *real = ctx.symtab->find(realName)) {
25872586
ctx.symtab->addUnusedUndefined(name, sym->binding);
25882587
// Update sym's binding, which will replace real's later in

lld/ELF/DriverUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void concatLTOPluginOptions(Ctx &ctx,
9595
for (size_t i = 0, e = args.size(); i != e; ++i) {
9696
StringRef s = args[i];
9797
if ((s == "-plugin-opt" || s == "--plugin-opt") && i + 1 != e) {
98-
v.push_back(saver(ctx).save(s + "=" + args[i + 1]).data());
98+
v.push_back(ctx.saver.save(s + "=" + args[i + 1]).data());
9999
++i;
100100
} else {
101101
v.push_back(args[i]);
@@ -118,7 +118,7 @@ opt::InputArgList ELFOptTable::parse(Ctx &ctx, ArrayRef<const char *> argv) {
118118

119119
// Expand response files (arguments in the form of @<filename>)
120120
// and then parse the argument again.
121-
cl::ExpandResponseFiles(saver(ctx), getQuotingStyle(ctx, args), vec);
121+
cl::ExpandResponseFiles(ctx.saver, getQuotingStyle(ctx, args), vec);
122122
concatLTOPluginOptions(ctx, vec);
123123
args = this->ParseArgs(vec, missingIndex, missingCount);
124124

lld/ELF/InputFiles.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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(ctx).save(ctx.arg.chroot + path);
225+
path = ctx.saver.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(ctx).save(*s), /*withLOption=*/true);
430+
ctx.driver.addFile(ctx.saver.save(*s), /*withLOption=*/true);
431431
else if (std::optional<std::string> s = findFromSearchPaths(ctx, specifier))
432-
ctx.driver.addFile(saver(ctx).save(*s), /*withLOption=*/true);
432+
ctx.driver.addFile(ctx.saver.save(*s), /*withLOption=*/true);
433433
else if (fs::exists(specifier))
434434
ctx.driver.addFile(specifier, /*withLOption=*/false);
435435
else
@@ -1512,7 +1512,7 @@ template <class ELFT> void SharedFile::parse() {
15121512
}
15131513

15141514
// DSOs are uniquified not by filename but by soname.
1515-
StringSaver &ss = saver(ctx);
1515+
StringSaver &ss = ctx.saver;
15161516
DenseMap<CachedHashStringRef, SharedFile *>::iterator it;
15171517
bool wasInserted;
15181518
std::tie(it, wasInserted) =
@@ -1720,7 +1720,7 @@ BitcodeFile::BitcodeFile(Ctx &ctx, MemoryBufferRef mb, StringRef archiveName,
17201720
// into consideration at LTO time (which very likely causes undefined
17211721
// symbols later in the link stage). So we append file offset to make
17221722
// filename unique.
1723-
StringSaver &ss = saver(ctx);
1723+
StringSaver &ss = ctx.saver;
17241724
StringRef name = archiveName.empty()
17251725
? ss.save(path)
17261726
: ss.save(archiveName + "(" + path::filename(path) +
@@ -1761,7 +1761,7 @@ static void createBitcodeSymbol(Ctx &ctx, Symbol *&sym,
17611761
// Update objSym.Name to reference (via StringRef) the string saver's copy;
17621762
// this way LTO can reference the same string saver's copy rather than
17631763
// keeping copies of its own.
1764-
objSym.Name = uniqueSaver(ctx).save(objSym.getName());
1764+
objSym.Name = ctx.uniqueSaver.save(objSym.getName());
17651765
sym = ctx.symtab->insert(objSym.getName());
17661766
}
17671767

@@ -1814,14 +1814,13 @@ void BitcodeFile::parse() {
18141814
void BitcodeFile::parseLazy() {
18151815
numSymbols = obj->symbols().size();
18161816
symbols = std::make_unique<Symbol *[]>(numSymbols);
1817-
auto &ss = uniqueSaver(ctx);
18181817
for (auto [i, irSym] : llvm::enumerate(obj->symbols())) {
18191818
// Symbols can be duplicated in bitcode files because of '#include' and
18201819
// linkonce_odr. Use uniqueSaver to save symbol names for de-duplication.
18211820
// Update objSym.Name to reference (via StringRef) the string saver's copy;
18221821
// this way LTO can reference the same string saver's copy rather than
18231822
// keeping copies of its own.
1824-
irSym.Name = ss.save(irSym.getName());
1823+
irSym.Name = ctx.uniqueSaver.save(irSym.getName());
18251824
if (!irSym.isUndefined()) {
18261825
auto *sym = ctx.symtab->insert(irSym.getName());
18271826
sym->resolve(ctx, LazySymbol{*this});
@@ -1858,7 +1857,7 @@ void BinaryFile::parse() {
18581857
if (!isAlnum(c))
18591858
c = '_';
18601859

1861-
llvm::StringSaver &ss = saver(ctx);
1860+
llvm::StringSaver &ss = ctx.saver;
18621861
ctx.symtab->addAndCheckDuplicate(
18631862
ctx, Defined{ctx, this, ss.save(s + "_start"), STB_GLOBAL, STV_DEFAULT,
18641863
STT_OBJECT, 0, 0, section});

lld/ELF/InputSection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void InputSectionBase::decompress() const {
130130
{
131131
static std::mutex mu;
132132
std::lock_guard<std::mutex> lock(mu);
133-
uncompressedBuf = bAlloc(ctx).Allocate<uint8_t>(size);
133+
uncompressedBuf = ctx.bAlloc.Allocate<uint8_t>(size);
134134
}
135135

136136
invokeELFT(decompressAux, ctx, *this, uncompressedBuf, size);

lld/ELF/LTO.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ std::vector<InputFile *> BitcodeCompiler::compile() {
397397
StringRef ltoObjName;
398398
if (bitcodeFilePath == "ld-temp.o") {
399399
ltoObjName =
400-
saver(ctx).save(Twine(ctx.arg.outputFile) + ".lto" +
401-
(i == 0 ? Twine("") : Twine('.') + Twine(i)) + ext);
400+
ctx.saver.save(Twine(ctx.arg.outputFile) + ".lto" +
401+
(i == 0 ? Twine("") : Twine('.') + Twine(i)) + ext);
402402
} else {
403403
StringRef directory = sys::path::parent_path(bitcodeFilePath);
404404
// For an archive member, which has an identifier like "d/a.a(coll.o at
@@ -412,7 +412,7 @@ std::vector<InputFile *> BitcodeCompiler::compile() {
412412
sys::path::append(path, directory,
413413
outputFileBaseName + ".lto." + baseName + ext);
414414
sys::path::remove_dots(path, true);
415-
ltoObjName = saver(ctx).save(path.str());
415+
ltoObjName = ctx.saver.save(path.str());
416416
}
417417
if (savePrelink || ctx.arg.ltoEmitAsm)
418418
saveBuffer(buf[i].second, ltoObjName);

lld/ELF/LinkerScript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ StringRef LinkerScript::getOutputSectionName(const InputSectionBase *s) const {
5959
assert(ctx.arg.relocatable && (rel->flags & SHF_LINK_ORDER));
6060
return s->name;
6161
}
62-
StringSaver &ss = saver(ctx);
62+
StringSaver &ss = ctx.saver;
6363
if (s->type == SHT_CREL)
6464
return ss.save(".crel" + out->name);
6565
if (s->type == SHT_RELA)

lld/ELF/MarkLive.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ template <class ELFT> void MarkLive<ELFT>::run() {
301301
// As a workaround for glibc libc.a before 2.34
302302
// (https://sourceware.org/PR27492), retain __libc_atexit and similar
303303
// sections regardless of zStartStopGC.
304-
cNamedSections[saver(ctx).save("__start_" + sec->name)].push_back(sec);
305-
cNamedSections[saver(ctx).save("__stop_" + sec->name)].push_back(sec);
304+
cNamedSections[ctx.saver.save("__start_" + sec->name)].push_back(sec);
305+
cNamedSections[ctx.saver.save("__stop_" + sec->name)].push_back(sec);
306306
}
307307
}
308308

lld/ELF/OutputSections.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ void OutputSection::commitSection(InputSection *isec) {
118118
type = SHT_CREL;
119119
if (type == SHT_REL) {
120120
if (name.consume_front(".rel"))
121-
name = saver(ctx).save(".crel" + name);
121+
name = ctx.saver.save(".crel" + name);
122122
} else if (name.consume_front(".rela")) {
123-
name = saver(ctx).save(".crel" + name);
123+
name = ctx.saver.save(".crel" + name);
124124
}
125125
} else {
126126
if (typeIsSet || !canMergeToProgbits(ctx, type) ||

lld/ELF/ScriptParser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ void ScriptParser::addFile(StringRef s) {
317317
SmallString<128> pathData;
318318
StringRef path = (ctx.arg.sysroot + s).toStringRef(pathData);
319319
if (sys::fs::exists(path))
320-
ctx.driver.addFile(saver(ctx).save(path), /*withLOption=*/false);
320+
ctx.driver.addFile(ctx.saver.save(path), /*withLOption=*/false);
321321
else
322322
setError("cannot find " + s + " inside " + ctx.arg.sysroot);
323323
return;
@@ -331,7 +331,7 @@ void ScriptParser::addFile(StringRef s) {
331331
if (ctx.arg.sysroot.empty())
332332
ctx.driver.addFile(s.substr(1), /*withLOption=*/false);
333333
else
334-
ctx.driver.addFile(saver(ctx).save(ctx.arg.sysroot + "/" + s.substr(1)),
334+
ctx.driver.addFile(ctx.saver.save(ctx.arg.sysroot + "/" + s.substr(1)),
335335
/*withLOption=*/false);
336336
} else if (s.starts_with("-l")) {
337337
// Case 3: search in the list of library paths.
@@ -354,7 +354,7 @@ void ScriptParser::addFile(StringRef s) {
354354
} else {
355355
// Finally, search in the list of library paths.
356356
if (std::optional<std::string> path = findFromSearchPaths(ctx, s))
357-
ctx.driver.addFile(saver(ctx).save(*path), /*withLOption=*/true);
357+
ctx.driver.addFile(ctx.saver.save(*path), /*withLOption=*/true);
358358
else
359359
setError("unable to find " + s);
360360
}

lld/ELF/SyntheticSections.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static ArrayRef<uint8_t> getVersion(Ctx &ctx) {
7777
// This is only for testing.
7878
StringRef s = getenv("LLD_VERSION");
7979
if (s.empty())
80-
s = saver(ctx).save(Twine("Linker: ") + getLLDVersion());
80+
s = ctx.saver.save(Twine("Linker: ") + getLLDVersion());
8181

8282
// +1 to include the terminating '\0'.
8383
return {(const uint8_t *)s.data(), s.size() + 1};
@@ -270,7 +270,7 @@ MipsReginfoSection<ELFT>::create(Ctx &ctx) {
270270

271271
InputSection *elf::createInterpSection(Ctx &ctx) {
272272
// StringSaver guarantees that the returned string ends with '\0'.
273-
StringRef s = saver(ctx).save(ctx.arg.dynamicLinker);
273+
StringRef s = ctx.saver.save(ctx.arg.dynamicLinker);
274274
ArrayRef<uint8_t> contents = {(const uint8_t *)s.data(), s.size() + 1};
275275

276276
return make<InputSection>(ctx.internalFile, SHF_ALLOC, SHT_PROGBITS, 1,

0 commit comments

Comments
 (0)