Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c5ffe7

Browse files
authored
[lld][ELF/MachO] Use .contains rather than .count for set membership. NFC (#177404)
This matches the usage in the other linker backends. See #176610, #177067
1 parent c31e506 commit 4c5ffe7

12 files changed

Lines changed: 29 additions & 28 deletions

File tree

lld/ELF/Arch/ARM.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ template <class ELFT> void ObjFile<ELFT>::importCmseSymbols() {
12291229
continue;
12301230
}
12311231

1232-
if (ctx.symtab->cmseImportLib.count(sym->getName())) {
1232+
if (ctx.symtab->cmseImportLib.contains(sym->getName())) {
12331233
Err(ctx) << "CMSE symbol '" << sym->getName()
12341234
<< "' is multiply defined in import library '" << this << "'";
12351235
continue;
@@ -1343,7 +1343,7 @@ ArmCmseSGSection::ArmCmseSGSection(Ctx &ctx)
13431343
addSGVeneer(cast<Defined>(entryFunc.acleSeSym),
13441344
cast<Defined>(entryFunc.sym));
13451345
for (auto &[_, sym] : ctx.symtab->cmseImportLib) {
1346-
if (!ctx.symtab->inCMSEOutImpLib.count(sym->getName()))
1346+
if (!ctx.symtab->inCMSEOutImpLib.contains(sym->getName()))
13471347
Warn(ctx)
13481348
<< "entry function '" << sym->getName()
13491349
<< "' from CMSE import library is not present in secure application";
@@ -1352,7 +1352,7 @@ ArmCmseSGSection::ArmCmseSGSection(Ctx &ctx)
13521352
if (!ctx.symtab->cmseImportLib.empty() && ctx.arg.cmseOutputLib.empty()) {
13531353
for (auto &[_, entryFunc] : ctx.symtab->cmseSymMap) {
13541354
Symbol *sym = entryFunc.sym;
1355-
if (!ctx.symtab->inCMSEOutImpLib.count(sym->getName()))
1355+
if (!ctx.symtab->inCMSEOutImpLib.contains(sym->getName()))
13561356
Warn(ctx) << "new entry function '" << sym->getName()
13571357
<< "' introduced but no output import library specified";
13581358
}
@@ -1361,7 +1361,7 @@ ArmCmseSGSection::ArmCmseSGSection(Ctx &ctx)
13611361

13621362
void ArmCmseSGSection::addSGVeneer(Symbol *acleSeSym, Symbol *sym) {
13631363
entries.emplace_back(acleSeSym, sym);
1364-
if (ctx.symtab->cmseImportLib.count(sym->getName()))
1364+
if (ctx.symtab->cmseImportLib.contains(sym->getName()))
13651365
ctx.symtab->inCMSEOutImpLib[sym->getName()] = true;
13661366
// Symbol addresses different, nothing to do.
13671367
if (acleSeSym->file != sym->file ||

lld/ELF/Arch/PPC64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,7 @@ void PPC64::relocateAlloc(InputSection &sec, uint8_t *buf) const {
17191719
// entry, there may be R_PPC64_TOC16_HA not paired with
17201720
// R_PPC64_TOC16_LO_DS. Don't relax. This loses some relaxation
17211721
// opportunities but is safe.
1722-
if (ctx.ppc64noTocRelax.count({rel.sym, rel.addend}) ||
1722+
if (ctx.ppc64noTocRelax.contains({rel.sym, rel.addend}) ||
17231723
!tryRelaxPPC64TocIndirection(ctx, rel, loc))
17241724
relocate(loc, rel, val);
17251725
break;

lld/ELF/Driver.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ static void ltoValidateAllVtablesHaveTypeInfos(Ctx &ctx,
11551155

11561156
SmallSetVector<StringRef, 0> vtableSymbolsWithNoRTTI;
11571157
for (StringRef s : vtableSymbols)
1158-
if (!typeInfoSymbols.count(s))
1158+
if (!typeInfoSymbols.contains(s))
11591159
vtableSymbolsWithNoRTTI.insert(s);
11601160

11611161
// Remove known safe symbols.
@@ -2315,11 +2315,11 @@ static DenseSet<StringRef> getExcludeLibs(opt::InputArgList &args) {
23152315
// This is not a popular option, but some programs such as bionic libc use it.
23162316
static void excludeLibs(Ctx &ctx, opt::InputArgList &args) {
23172317
DenseSet<StringRef> libs = getExcludeLibs(args);
2318-
bool all = libs.count("ALL");
2318+
bool all = libs.contains("ALL");
23192319

23202320
auto visit = [&](InputFile *file) {
23212321
if (file->archiveName.empty() ||
2322-
!(all || libs.count(path::filename(file->archiveName))))
2322+
!(all || libs.contains(path::filename(file->archiveName))))
23232323
return;
23242324
ArrayRef<Symbol *> symbols = file->getSymbols();
23252325
if (isa<ELFFileBase>(file))
@@ -2687,7 +2687,7 @@ static void markBuffersAsDontNeed(Ctx &ctx, bool skipLinkedOutput) {
26872687
for (BitcodeFile *file : ctx.lazyBitcodeFiles)
26882688
bufs.insert(file->mb.getBufferStart());
26892689
for (MemoryBuffer &mb : llvm::make_pointee_range(ctx.memoryBuffers))
2690-
if (bufs.count(mb.getBufferStart()))
2690+
if (bufs.contains(mb.getBufferStart()))
26912691
mb.dontNeedIfMmap();
26922692
}
26932693

lld/ELF/LTO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ void BitcodeCompiler::add(BitcodeFile &f) {
258258
r.VisibleToRegularObj = ctx.arg.relocatable || sym->isUsedInRegularObj ||
259259
sym->referencedAfterWrap ||
260260
(r.Prevailing && sym->isExported) ||
261-
usedStartStop.count(objSym.getSectionName());
261+
usedStartStop.contains(objSym.getSectionName());
262262
// Identify symbols exported dynamically, and that therefore could be
263263
// referenced by a shared library not visible to the linker.
264264
r.ExportDynamic = sym->computeBinding(ctx) != STB_LOCAL &&

lld/ELF/LinkerScript.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,8 @@ void LinkerScript::diagnoseMissingSGSectionAddress() const {
10931093
return;
10941094

10951095
OutputSection *sec = findByName(sectionCommands, ".gnu.sgstubs");
1096-
if (sec && !sec->addrExpr && !ctx.arg.sectionStartMap.count(".gnu.sgstubs"))
1096+
if (sec && !sec->addrExpr &&
1097+
!ctx.arg.sectionStartMap.contains(".gnu.sgstubs"))
10971098
ErrAlways(ctx) << "no address assigned to the veneers output section "
10981099
<< sec->name;
10991100
}
@@ -1904,5 +1905,5 @@ bool LinkerScript::shouldAddProvideSym(StringRef symName) {
19041905
unusedProvideSyms.insert(sym);
19051906
return false;
19061907
}
1907-
return !unusedProvideSyms.count(sym);
1908+
return !unusedProvideSyms.contains(sym);
19081909
}

lld/ELF/ScriptParser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,9 @@ void ScriptParser::readRegionAlias() {
541541
StringRef name = readName();
542542
expect(")");
543543

544-
if (ctx.script->memoryRegions.count(alias))
544+
if (ctx.script->memoryRegions.contains(alias))
545545
setError("redefinition of memory region '" + alias + "'");
546-
if (!ctx.script->memoryRegions.count(name))
546+
if (!ctx.script->memoryRegions.contains(name))
547547
setError("memory region '" + name + "' is not defined");
548548
ctx.script->memoryRegions.insert({alias, ctx.script->memoryRegions[name]});
549549
}
@@ -1590,7 +1590,7 @@ Expr ScriptParser::readPrimary() {
15901590
}
15911591
if (tok == "LENGTH") {
15921592
StringRef name = readParenName();
1593-
if (ctx.script->memoryRegions.count(name) == 0) {
1593+
if (!ctx.script->memoryRegions.contains(name)) {
15941594
setError("memory region not defined: " + name);
15951595
return [] { return 0; };
15961596
}
@@ -1626,7 +1626,7 @@ Expr ScriptParser::readPrimary() {
16261626
}
16271627
if (tok == "ORIGIN") {
16281628
StringRef name = readParenName();
1629-
if (ctx.script->memoryRegions.count(name) == 0) {
1629+
if (!ctx.script->memoryRegions.contains(name)) {
16301630
setError("memory region not defined: " + name);
16311631
return [] { return 0; };
16321632
}

lld/ELF/SyntheticSections.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ void MipsGotSection::build() {
943943
// using 32-bit value at the end of 16-bit entries.
944944
for (FileGot &got : gots) {
945945
got.relocs.remove_if([&](const std::pair<Symbol *, size_t> &p) {
946-
return got.global.count(p.first);
946+
return got.global.contains(p.first);
947947
});
948948
set_union(got.local16, got.local32);
949949
got.local32.clear();
@@ -1005,7 +1005,7 @@ void MipsGotSection::build() {
10051005
// by subtracting "global" entries in the primary GOT.
10061006
primGot = &gots.front();
10071007
primGot->relocs.remove_if([&](const std::pair<Symbol *, size_t> &p) {
1008-
return primGot->global.count(p.first);
1008+
return primGot->global.contains(p.first);
10091009
});
10101010

10111011
// Calculate indexes for each GOT entry.

lld/ELF/Writer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ removeEmptyPTLoad(Ctx &ctx, SmallVector<std::unique_ptr<PhdrEntry>, 0> &phdrs) {
117117
for (auto it2 = it; it2 != phdrs.end(); ++it2)
118118
removed.insert(it2->get());
119119
for (OutputSection *sec : ctx.outputSections)
120-
if (removed.count(sec->ptLoad))
120+
if (removed.contains(sec->ptLoad))
121121
sec->ptLoad = nullptr;
122122
phdrs.erase(it, phdrs.end());
123123
}
@@ -682,7 +682,7 @@ unsigned elf::getSectionRank(Ctx &ctx, OutputSection &osec) {
682682

683683
// We want to put section specified by -T option first, so we
684684
// can start assigning VA starting from them later.
685-
if (ctx.arg.sectionStartMap.count(osec.name))
685+
if (ctx.arg.sectionStartMap.contains(osec.name))
686686
return rank;
687687
rank |= RF_NOT_ADDR_SET;
688688

@@ -1799,10 +1799,10 @@ static void removeUnusedSyntheticSections(Ctx &ctx) {
17991799
for (SectionCommand *cmd : osec->commands)
18001800
if (auto *isd = dyn_cast<InputSectionDescription>(cmd))
18011801
llvm::erase_if(isd->sections, [&](InputSection *isec) {
1802-
return unused.count(isec);
1802+
return unused.contains(isec);
18031803
});
18041804
llvm::erase_if(ctx.script->orphanSections, [&](const InputSectionBase *sec) {
1805-
return unused.count(sec);
1805+
return unused.contains(sec);
18061806
});
18071807
}
18081808

@@ -1943,7 +1943,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
19431943
for (SharedFile *file : ctx.sharedFiles) {
19441944
bool allNeededIsKnown =
19451945
llvm::all_of(file->dtNeeded, [&](StringRef needed) {
1946-
return ctx.symtab->soNames.count(CachedHashStringRef(needed));
1946+
return ctx.symtab->soNames.contains(CachedHashStringRef(needed));
19471947
});
19481948
if (!allNeededIsKnown)
19491949
continue;

lld/MachO/InputFiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ void ObjFile::registerEhFrames(Section &ehFrameSection) {
14511451
continue;
14521452
}
14531453

1454-
assert(cieMap.count(cieIsec));
1454+
assert(cieMap.contains(cieIsec));
14551455
const CIE &cie = cieMap[cieIsec];
14561456
// Offset of the function address within the EH frame.
14571457
const size_t funcAddrOff = dataOff;

lld/MachO/ObjC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ void ObjcCategoryChecker::parseCategory(const ConcatInputSection *catIsec) {
264264

265265
auto *classSym = cast<Symbol *>(classReloc->referent);
266266
if (auto *d = dyn_cast<Defined>(classSym))
267-
if (!classMap.count(d))
267+
if (!classMap.contains(d))
268268
parseClass(d);
269269

270270
if (const auto *r = catIsec->getRelocAt(catLayout.classMethodsOffset)) {
@@ -1179,7 +1179,7 @@ void ObjcCategoryMerger::collectAndValidateCategoriesData() {
11791179
assert(categorySym &&
11801180
"Failed to get a valid category at __objc_catlit offset");
11811181

1182-
if (nlCategories.count(categorySym))
1182+
if (nlCategories.contains(categorySym))
11831183
continue;
11841184

11851185
auto *catBodyIsec = dyn_cast<ConcatInputSection>(categorySym->isec());

0 commit comments

Comments
 (0)