[ELF] Change some DenseMap<StringRef, *> to DenseMap<CachedHashStringRef, *>. NFC

This commit is contained in:
Fangrui Song 2022-01-16 21:19:01 -08:00
parent e205445434
commit 769057a5d0
5 changed files with 18 additions and 14 deletions

View File

@ -1460,9 +1460,10 @@ template <class ELFT> void SharedFile::parse() {
}
// DSOs are uniquified not by filename but by soname.
DenseMap<StringRef, SharedFile *>::iterator it;
DenseMap<CachedHashStringRef, SharedFile *>::iterator it;
bool wasInserted;
std::tie(it, wasInserted) = symtab->soNames.try_emplace(soName, this);
std::tie(it, wasInserted) =
symtab->soNames.try_emplace(CachedHashStringRef(soName), this);
// If a DSO appears more than once on the command line with and without
// --as-needed, --no-as-needed takes precedence over --as-needed because a

View File

@ -135,7 +135,7 @@ uint64_t ExprValue::getSectionOffset() const {
OutputSection *LinkerScript::createOutputSection(StringRef name,
StringRef location) {
OutputSection *&secRef = nameToOutputSection[name];
OutputSection *&secRef = nameToOutputSection[CachedHashStringRef(name)];
OutputSection *sec;
if (secRef && secRef->location.empty()) {
// There was a forward reference.
@ -150,7 +150,7 @@ OutputSection *LinkerScript::createOutputSection(StringRef name,
}
OutputSection *LinkerScript::getOrCreateOutputSection(StringRef name) {
OutputSection *&cmdRef = nameToOutputSection[name];
OutputSection *&cmdRef = nameToOutputSection[CachedHashStringRef(name)];
if (!cmdRef)
cmdRef = make<OutputSection>(name, SHT_PROGBITS, 0);
return cmdRef;
@ -645,14 +645,16 @@ void LinkerScript::processSectionCommands() {
// Process OVERWRITE_SECTIONS first so that it can overwrite the main script
// or orphans.
DenseMap<StringRef, OutputSection *> map;
DenseMap<CachedHashStringRef, OutputSection *> map;
size_t i = 0;
for (OutputSection *osec : overwriteSections)
if (process(osec) && !map.try_emplace(osec->name, osec).second)
if (process(osec) &&
!map.try_emplace(CachedHashStringRef(osec->name), osec).second)
warn("OVERWRITE_SECTIONS specifies duplicate " + osec->name);
for (SectionCommand *&base : sectionCommands)
if (auto *osec = dyn_cast<OutputSection>(base)) {
if (OutputSection *overwrite = map.lookup(osec->name)) {
if (OutputSection *overwrite =
map.lookup(CachedHashStringRef(osec->name))) {
log(overwrite->location + " overwrites " + osec->name);
overwrite->sectionIndex = i++;
base = overwrite;

View File

@ -271,7 +271,8 @@ class LinkerScript final {
uint64_t tbssAddr = 0;
};
llvm::DenseMap<StringRef, OutputSection *> nameToOutputSection;
llvm::DenseMap<llvm::CachedHashStringRef, OutputSection *>
nameToOutputSection;
void addSymbol(SymbolAssignment *cmd);
void assignSymbol(SymbolAssignment *cmd, bool inSec);

View File

@ -48,7 +48,7 @@ public:
void handleDynamicList();
// Set of .so files to not link the same shared object file more than once.
llvm::DenseMap<StringRef, SharedFile *> soNames;
llvm::DenseMap<llvm::CachedHashStringRef, SharedFile *> soNames;
// Comdat groups define "link once" sections. If two comdat groups have the
// same name, only one of them is linked, and the other is ignored. This map

View File

@ -1264,14 +1264,14 @@ static DenseMap<const InputSectionBase *, int> buildSectionOrder() {
// Build a map from symbols to their priorities. Symbols that didn't
// appear in the symbol ordering file have the lowest priority 0.
// All explicitly mentioned symbols have negative (higher) priorities.
DenseMap<StringRef, SymbolOrderEntry> symbolOrder;
DenseMap<CachedHashStringRef, SymbolOrderEntry> symbolOrder;
int priority = -config->symbolOrderingFile.size();
for (StringRef s : config->symbolOrderingFile)
symbolOrder.insert({s, {priority++, false}});
symbolOrder.insert({CachedHashStringRef(s), {priority++, false}});
// Build a map from sections to their priorities.
auto addSym = [&](Symbol &sym) {
auto it = symbolOrder.find(sym.getName());
auto it = symbolOrder.find(CachedHashStringRef(sym.getName()));
if (it == symbolOrder.end())
return;
SymbolOrderEntry &ent = it->second;
@ -1299,7 +1299,7 @@ static DenseMap<const InputSectionBase *, int> buildSectionOrder() {
if (config->warnSymbolOrdering)
for (auto orderEntry : symbolOrder)
if (!orderEntry.second.present)
warn("symbol ordering file: no such symbol: " + orderEntry.first);
warn("symbol ordering file: no such symbol: " + orderEntry.first.val());
return sectionOrder;
}
@ -1947,7 +1947,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
for (SharedFile *file : sharedFiles) {
bool allNeededIsKnown =
llvm::all_of(file->dtNeeded, [&](StringRef needed) {
return symtab->soNames.count(needed);
return symtab->soNames.count(CachedHashStringRef(needed));
});
if (!allNeededIsKnown)
continue;